I have an arduino node in my garage that I had been using with HomeGenie. It parsed the simple JSON string in C# no problems. I haven’t had much time to get it working with SmartThings yet but I keep having trouble parsing the JSON. I validated the JSON string with a couple online utilities.
The DTH is getting the JSON string into the msg.body but not parsing it automatically into msg.json so I tried to add JSON.parse… //msg.body={“door1”:“0”}
var j = JSON.parse(msg.body);
log.debug “j.door1 ${j.door1}”
This keeps giving NULL pointer. Does the arduino server have to report “Content-Type: application/json”?
If I try this it fails…
var j = JSON.parse("{“door1”:“0”}");
log.debug "j.door1 ${j.door1}"
until I escape the JSON required quotation marks, then fails for NULL again.
Any ideas? Pointers to ST documentation for JSON parsing? Thanks in advance!
I believe that the message returned from your device needs to have a Content-Type: application/json header in order for it to be parsed automatically into msg.json (I assume you use def msg = parseLanMessage(message) in the beginning of your parse(String message) method?
{"door1":"1"} doesn’t match Content-Length: 122 header (it should be Content-Length: 13 instead). Are you sure you are sending the correct Content-Length from your Arduino sketch?
Sorry… I trimmed some extra data out of the JSON string to keep it simpler in the forum here. I think the ESP8266 library is adding that, I just send with…
I pasted the JSON from browser into a validator a few weeks ago since my device is behind firewall. I think I am having problems before the parse now; debug at the top of it doesn’t print. I need to figure out the flow through these. Also I try adding a device from IDE and it is accepted. On my phone app, I add the device but it is failing now, nothing shows in the “Garage” room… just “Error loading things”. This was working before and I was able to add tiles for the various sensors I plan to have working.
Does the device have to be added into phone app to work from IDE debugger? The device type is compiling ok and I add the device in IDE. So after I publish, and select location home, it shows in the list of devices to test with. it all seems same as a couple weeks ago when I did see the JSON string in log (I just could get it to parse). Now it seems to be failing before that.
How are you communicating with the device? You mentioned that it is behind the firewall, but ALL smartApps execute in the SmartThings cloud. My guess is you are trying to call an local endpoint and its not resolving giving you the null.
Looks like I am using hub action, I started with the ESP8266 Contact Sensor code. I am reverting back to it again to see where I went astray because I was getting data from my device at one point. Probably won’t have time to work on it again until after the weekend. Thank you all again!