Reputation: 1
I've successfully sent value of float number=5 from my esp32 to IBM Watson IoT platform and it got captured or received in the board which I created by selecting number in the board but when I'm sending a string or text value instead of number then it was not able to capture so now im confused because while creating the board I've set to text value for capturing or receiving string/text. Here is the code snippet that I used to send my number value but when I change to string value it does not work so any suggestion:
float number=5; String text="hello";
String payload = "{\"d\":{\"Name\":\"" DEVICE_ID "\"";
payload += ",\"text\":";
payload += text;
payload += "}}";
Upvotes: 0
Views: 80
Reputation: 36
I'd think you should enclose your string literal in double-quotes too, here the JSON will be malformed as it will end up as:
{"d":{"Name":"DEVICE_ID","text":hello}}
So the hello
text is an invalid JSON token. Should be written as:
String payload = "{\"d\":{\"Name\":\"" DEVICE_ID "\"";
payload += ",\"text\":\"";
payload += text;
payload += "\"}}";
Upvotes: 0