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


#1

Issuing the Standard HTTP Command
https://api.particle.io/v1/devices/xxx/WFanData?access_token=xxx
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…
~Steve~


#2

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.


#3

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


#4

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?


#5

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:
http://georgepavlides.info/json-data-on-the-android-mobile-with-app-inventor-2/


#6

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,

https://api.particle.io/v1/devices/xxx/WFanData?format=raw&access_token=xxx


#7

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.


#8

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.


#9

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.


#10

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


#11

Here you go, I removed all my passwords and keys for obvious reasons :slight_smile:
http://steveries.com/temp/Control_Room_No_Keys.aia


#12

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.