HTTP Response suddenly changed on Two Photons but not others [Workarround Working]

Issuing the Standard HTTP Command
I’m suddenly getting Two different responses from my devices.

One unit responds with {“cmd”:“VarReturn”,“name”:“ContRoom”,“error”:null,“result”:“68,67,73,40,74,43,77,45,1”,“coreInfo”:{“last_app”:"",“last_heard”:“2017-03-20T02:56:16.687Z”,“connected”:true,“last_handshake_at”:“2017-03-18T11:45:01.799Z”,“deviceID”:“xxx”,“product_id”:6}}

The Others Respond with:{“cmd”:“VarReturn”,“name”:“WFanData”,“result”:“1,0,0,38,”,“coreInfo”:{“last_app”:"",“last_heard”:“2017-03-20T02:49:47.376Z”,“connected”:true,“last_handshake_at”:“2017-03-19T04:21:40.127Z”,“deviceID”:“xxx”,“product_id”:6}}

The main difference being the “error”:null
I’m parsing the string via char count, so when that changes it breaks my app.
I don’t understand why it suddenly changed on some of my devices but not all?
I’m also wondering if this is why my app will randomly fail to get data when I ask.

Any insight would be great, Thanks in advance…

Not answering the immediate question, but it’s no good to rely on the string position anyway.
You could scan for \"result\":\" or use a JSON lib to parse the whole response.

I haven’t figure out how to do that in MIT App Inventor II so I had to go with the Char count…

Another difference is that “name” is “ContRoom” from the device that also has an error field, whereas the others have “name” as “WFanData”. What is the difference in the code you’re running on that one device vs. the other two?

You could use any of the split blocks to do that.
Or you could use a combination of starts at and segment

And here you can find a rather elaborate JSON decoder :wink:

You can use the .JsonTextDecode block to process the response from Particle, and feed that (as the “pairs” parameter) into the “look up in pairs” block with the key “result” to get just the data.

Alternatively, you can get just the result from Particle directly by adding format=raw to your GET request,


That Raw format was AWESOME…
Still bugs the heck out of me why some have “error null” and others don’t since they all run the same “particle.Variable ()” command.

But that RAW is EXACTLY what I needed.
No need to hunt down my data now, Now I just strip it into an Array from CSV’s
Easy as pie!!! Thanks!!

So I would not call this “Solved” perse’ because we still have no clue why they are behaving the way they are but. The Raw option is a perfect work-around that I think will make my code more robust and reliable!! Many thanks!!

Now my code looks like this.

Yeah, I agree; there’s some inconsistency in the response from Particle’s cloud, that should be fixed.

BTW, you might want to edit your last post to include an image of your MIT App Inventor code that’s much bigger, so anyone interested in that app could learn something from it.

It’s not really that small, the forums made it that small for some reason.
I deleted it and re-added it back and it resized correctly :slight_smile:

Here is a screen shot of my app that pulls data from 3 photons around the house.
And I can send data to them all as well.

1 Like

@funman1, nice! I would love to see the whole Inventor code if possible :wink:

Here you go, I removed all my passwords and keys for obvious reasons :slight_smile:

1 Like

In case anyone is interested in how to extract the data from the complete response to a variable GET, here is one way to do that in MIT App Inventer.

1 Like