i got device id for electron and i need to post to http,
i am getting error because device id is String object and i need to post to http as char array
- You can just cast
(const char*)yourString
- or use
yourString.c_str()
- or copy to an
char[]
viayourString.toCharArray()
- or copy to a byte buffer via
yourString.getBytes()
- …
thanks for reply, will try it
i used string.tocharArray() to store in char array but it not prints device id to serial port when called Serial.println()
Can you post your exact code?
char id[12];
void setup()
{
pinMode( D7, OUTPUT);
Particle.publish("App Started");
Serial.begin(9600);
Serial4.begin(9600);// carbon monoxide sensor
Serial.println("Hello World!");
String MyId = System.deviceID();
MyId.toCharArray(id, sizeof(id));
Serial.println(id);
}
got it i need to declare char id[] much bigger to store device id
I just tested your coud (with my alterations) and do see the device ID just fine
char id[25];
void setup()
{
pinMode(D7, OUTPUT);
Particle.publish("App Started");
Serial.begin(9600);
Serial4.begin(9600);// carbon monoxide sensor
System.deviceID().toCharArray(id, sizeof(id));
Serial.println(id);
Serial.println("Hello World!");
}
void loop() {
delay(1000);
Serial.println(id);
digitalWrite(D7, !digitalRead(D7));
}
thanks ScruffR. i am getting device id also posting to http