I need to know the Photon Particle Device Name.
I have read the following posts that are similar to mine …
"‘device/name’ and ‘device/random’ and ‘device/ip’ does not work on Photon [Solved]“
and
”‘device/name’ and ‘device/random’ and ‘device/ip’ does not work on Photon [Solved]"
They describe a bug in earlier firmware which I assume has been fixed.
I am running firmware 6.3
The below code works MOST of the time (at least 99%). But when it does not, I get nothing, or garbled data in String “Data”.
I am assuming this is because the request is made before the Photon is either connected to the cloud and/or the data has not been received fully yet.
The request is made in “void setup”. But I feel from other posts above, I need to wait for the cloud to respond.
I was thinking of adding a “delay(10000);” just after the “Particle.publish(“spark/device/name”);” in the void setup.
But what would happened if the cloud responded before the 10 seconds was up?
Would it be Q waiting for a handshake of my Photon or lost?
I do use a Timer so that is why the Particle.publish(“spark/device/name”);" is in the “void setup” so not to effect the timer.
String Data;
int PV = 9; // Product Version
PRODUCT_ID(6375);
PRODUCT_VERSION(PV);
SYSTEM_THREAD(ENABLED)
ApplicationWatchdog wd(150000, System.reset); // 2.5 minutes to system reset if no data is received
void setup()
{
...
Particle.subscribe("spark/device/name", handler);
Particle.publish("spark/device/name");
}
void handler(const char *topic, const char *data) { // get the Device Name of the Photon
Data = String(data);
char name[24];
strcpy(name, data);
EEPROM.put(24, name);
}
void loop()
{
if (! listeningMode) {
if (! Particle.connected()) {
digitalWrite(led_pin, HIGH); // Turn off Booster Fan
Particle.connect(); }
...
}
// display instructions on how to connect the Photon
} // end of void loop