Help parsing a string to grab a value?
-
Is anyone able to help me parse a string using arduino code that is getting returned by a IP based temperature sensor?
I have a URL that I can call and this is what is returned...
{"temp":19.3,"id":"373650"}
I need to just grab the 19.3 so I can store it.....
I appreciate I may not be asking in the best forum based on this not being specifically related to MySensors but any help would be appreciated.....
-
This may help you in the correct direction
It is a LUA script that I run in Domoticz.
commandArray = {} cmd = otherdevices_svalues["!!nodename!!"] local watt, energy, a, b print(cmd) _,_,watt, energy, a, b = string.find(cmd, "(.+):(.+):(.+):(.+)") print(watt) print(energy) print(a) print(b) return commandArray
-
@TommySharp you can use a json library. Example: https://github.com/bblanchon/ArduinoJson
StaticJsonBuffer<200> jsonBuffer; JsonObject& root = jsonBuffer.parseObject(thetextfromurl); float temp = root["temp"];
-
Thanks for your help guys! I got it resolved....