I need to get device name, but Particle.publish(“spark/device/name”) don’t work.
on the other hand Particle.publish(“spark/device/ip”) worked.
Please help!
int DEBUG = 1;
char deviceName[64];
void handler(const char *topic, const char *data) {
Serial.printlnf("%s: %s", topic, data);
if (strstr(topic, "spark/device/name"))
{
strcpy(deviceName, data);
Serial.printlnf("deviceName = %s", deviceName);
Serial.printlnf("data = %s", data);
}
if (strstr(topic, "spark/device/ip"))
{
Serial.printlnf("data = %s", data);
}
}
void setup() {
if (DEBUG) {
Serial.begin(115200);
}
for(int i=0;i<5;i++) {
Serial.println("waiting... " + String(5 - i));
delay(1000);
}
Particle.subscribe("spark/", handler);
Particle.publish("spark/device/ip");
Particle.publish("spark/device/name");
}