I need to know the device name of the Photon and display it on a OLED even if it has not connected to the cloud yet. With that being said, I am assuming the Photon has connected at least once prior to get that data. I need to save the Photon’s name in EEPROM so I will have it on powerup / reset. I could not find any documentation on the maximum photon’s name length however, I am starting at address 24 and only looking at 24 bytes of data in the EEPROM. I used the following code to get the Photon’s name in void setup
void setup() {
...
Particle.subscribe("spark/device/name", handler);
Particle.publish("spark/device/name");
}
I created a routine called handler…
void handler(const char *topic, const char *data) { // to get the Hardware name of the Photon
Serial.println("received " + String(topic) + ": " + String(data));
Data = String(data);
Serial.println(Data);
EEPROM.put(24, Data);
}
In a serial terminal window I get the following from line 2 of the handler
“received spark/device/name: ROOM_DISPLAY_6”
Great, this is what I expect.
In a serial terminal window I get the following from line 4 of the handler
“ROOM_DISPLAY_6”
Great, also what I expect.
But after line 5 executes, I get the following from the EEPROM using this code…
for (int i = 24; i < 49; i++) { Serial.print(EEPROM.read(i)); Serial.print(" "); } Serial.println( );
“88 93 0 32 14 0 0 0 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0”
I have read about data stored to EEPROM must be saved as char[ ] but can’t seem to figure out how to convert a “const char *data” to char EEPROMdata[ ].
Any suggestions or links to suggested reading?