Requesting Photon Device Name

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]“
”‘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
      ApplicationWatchdog wd(150000, System.reset); // 2.5 minutes to system reset if no data is received

      void setup()
       Particle.subscribe("spark/device/name", handler);

       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

Sorry I meant to say …

I was thinking of adding a “delay(10000);” just after the “Particle.connect();” in the void loop.

Since you are running SYSTEM_THREAD(ENABLED) your Particle.publish() may happen before you got a connection.
If you add a waitUntil(Particle.connected) or any other delay/repeat logic to make sure you only publish when you got an active connection your problem should go away.

Also calling Particle.connect() over and over again while !Particle.connected() is bad style.

BTW, is this indentation by accident or by design without structure?
Indentation should make reading code easier - the above doesn’t.

1 Like

Are you stating that when the command “Particle.connect();” is executed. the firmware does not stop and wait for a connect?

If so I see your point.


Yes, that’s what I’m saying. At least this is what was definetly true for 0.6.2 and before. But I know that this has been argued about and with 0.7.0-rc.X this had been changed.
No idea if 0.6.3 already had got this change inside too.
Nevertheless guarding against this is good practice anyway.

Thank You

I will adjust my code

Thanks again