I want to publish my device macID to webpage using JSON format.But the issue is when I tried to use the function System.deviceID() I got an error saying that
"no match for ‘operator=’ (operand types are ‘ArduinoJson::JsonVariant’ and ‘const String’)"
and my code is as follows:
// This #include statement was automatically added by the Particle IDE.
#include <ArduinoJson.h>
char JSONmessageBuffer[250];
String myID;
DynamicJsonBuffer jsonBuffer(100); //allocates memory on heap
void setup() {
Serial.begin(9600);
}
void loop() {
myID=System.deviceID();
JsonObject& root = jsonBuffer.createObject();
root["macid"] = myID;
root.printTo(JSONmessageBuffer);
Serial.println(JSONmessageBuffer);
delay(1000);
}
Help me how can i solve this.Here the device may change so it has to update its new macID to the webpage
Have you tried to interpret the error message yourself?
If you hit the red SHOW RAW button you will get extra info about the error.
Looking at - and posting - the context of the error message might provide some extra insight.
You have not actually provided the info which line produced that error, but since I doubt it's in direct connection with System.deviceID()
myID=System.deviceID();
I'd assume it's this line
root["macid"] = myID;
And when you say
I wonder why you try assigning the device ID as MAC 
Sir I solved that problem.
Yes I am in a quite dilemma whether both SystemID and MAC ID are same or different.
One of my senior who works on Particle Photon told they both are same.But I was not satisfied by his answer.
Anyhow he told me to publish the device ID so the question was like that.
I apologize for my mistake.
I realized after seeing your reply about my mistake
Thank you for your response Sir.
Nope a MAC is a six byte number that globally identifies the WiFi module in the network and device ID is a proprietory 12 byte number to identify the whole device in the Particle eco system.
And both "numbers" are used for something completely different.
While the MAC is required for the network traffic to find its way to the device the Particle device ID is used to link the device to an account and does not have anything to do with the network traffic as such.
BTW, when you find the solution to a problem it's always appreciated when you also post that solution for others to benefit of your findings.
Update:
Since OP didn't provide the solution, here it is
root["macid"] = (const char*)myID;
// alternative
//root["macid"] = myID.c_str();
This does the trick as it forces the String
object to be converted into a const char*
C-string.
4 Likes
Thank You for your reply Sir,
I have already solved this by myself.But I have learnt a lot from you during my project.Keep helping whenevr I face problem
1 Like