Try this code when you finally get your Mesh Argon working with a few Xenons. Just change the number for each Mesh Device. I use 1 for the Argon and comment out the particle.publish line for the Xenons.
IMPORTANT: This code has been updated to make the Particle Featherwing Plug and Play
Also now includes an Antenna for both the Xenon and the Argon
See High School Robotics Course using the Particle.io Mesh Devices Blog for distance testing.
// next 2 lines are for plug and play particle featherwing
SYSTEM_THREAD(ENABLED);
STARTUP(System.enableFeature(FEATURE_ETHERNET_DETECTION));
/////////////////////////// important globals here ///////////////////////////////
int myCode = 3; // different number for each device
bool myXenonAntennaAttached = false;
bool myArgonBothAntennaAttached = false;
bool myPublishToConsole = false; // set true for Argon or debugging
/////////////////////////////// end globals ////////////////////////////
void setup() {
pinMode(D7, OUTPUT);
Mesh.subscribe("mySendToAll", myHandler);
if (myXenonAntennaAttached){
#if (PLATFORM_ID == PLATFORM_XENON)
digitalWrite(ANTSW1, 0);
digitalWrite(ANTSW2, 1);
#endif
}
if (myArgonBothAntennaAttached){
#if (PLATFORM_ID == PLATFORM_ARGON)
digitalWrite(ANTSW1, 1);
digitalWrite(ANTSW2, 0);
#endif
}
}
void loop() {
Mesh.publish("mySendToAll", String(myCode));
for (int myLoop = 0; myLoop < myCode; myLoop++){
digitalWrite(D7, HIGH);
delay(200); // very quick flash
digitalWrite(D7, LOW);
delay(200);
}
delay(30000); // mesh publish every 30 seconds
}
// Event listener for "mySendToAll" event from Xenons
void myHandler(const char *event, const char *data) {
String parse = data; //Cast char*data to String class
int myNumber = parse.toInt();
if (myPublishToConsole){ // mainly for Argon gateway unless debugging
Particle.publish("Talked to device number:", parse);
}
for (int myLoop = 0; myLoop < myNumber; myLoop++){
digitalWrite(D7, HIGH);
delay(200); // very quick flash
digitalWrite(D7, LOW);
delay(200);
}
}
The code is kind of fun. Remember to flash the Xenons before you flash the Argon and pull the Argons plug and replug it in before testing everything. I flash the xenons when only one is connected to the Argon.
Also be aware that the gold star determines which Xenon gets flashed, not sure how many times I have messed that up and flashed the wrong code to the wrong Xenon.
If you uncommented the particle.publish for the Argon you can use the console to monitor the connections. You can uncomment the Particle.publish for each Xenon but that is a lot of traffic.
What does it do:
It is a 30 second cycle.When the Argon flashes once, all the other devices flash once. The first Xenon flashes twice all the other Xenons flash twice. If they overlap, then reset one Xenon until they have a space between flashes. When you walk away with Xenon #2 it will always flash twice, but it should also flash once for the Argon and 3 or 4 times for the other Xenons.
Note: Disconnect the Argon and the local mesh still works. Very Cool. Reset a Xenon and it reconnects without the Argon. Pull the plug on a xenon and everything dies, can’t reset to the other Xenons. Re plug in the Argon and everything is fine again.
My blog is at High School Robotics Course using the Particle.io Mesh Devices Blog
I am still waiting for the ability to connect multiple Argons to a mesh.
Note: Working with a mesh is a bit more complex than using a single Photon. With the mesh you need to make sure the correct device gets the correct code. For the Mesh Hello World program you must make sure the devices have a different myCode number so that when they flash the D7 LED your know which device is talking.
Do not set the antenna true unless you have an antenna attached.
Example of a Xenon with an antenna attached
Example of an Argon with both antenna attached and console data published.
An Argon with both antennas and a Xenon with a mesh antenna. I got this result 230 m. May have done better if the buildings weren’t near
And after losing connection they returned but reconnected at 120 m