please format code with </> button * homework policy * asking questions
I wish to set PC to communicate with my microcontroller over serial port.
The data format i use JSON.
The microcontroller to PC is working well but i can not send from the PC to the controller.
write function has no support for JSON object data type.
I assume write function supports text. JSON is almost always transferred as text. JSON-objects are constructs of programming languages to help handling of JSON. Anyway payLoad.tostring() will give you your JSON-object as a string
One other thing i notice:
anytime I am packing of JSON object inside the function call to SerialPortWrite.
I get null pointer to the json object instance.
Now to solve it my own way.
I use String to manually pack the JSON struct and then forward it to the serial write.
Something like:
String payload ="{";
payload +=“key:”;
payload +=str(value);
payload +="}";
write(payload);
This truly is crook way but since the data size is small from the PC to my microcontroller. I dont mine.
I still open to learn should someone know better way to handle that.
Something is did not mention before.
A call to Serialport is handle by thread, something like thread (“SerialPortWrite”)
Anytime i need to send data to microcontroller will create the
thread(“SerialPortWrite”);
could this be the reason?