Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Parsing Failed #278

Closed
jaymzx opened this issue Apr 24, 2020 · 9 comments
Closed

JSON Parsing Failed #278

jaymzx opened this issue Apr 24, 2020 · 9 comments

Comments

@jaymzx
Copy link

jaymzx commented Apr 24, 2020

Hi, there! I'm glad I found this project as I'd like to get Alexa to control my Honeywell tower fan via IR. They don't seem to re-use Sony codes like a lot of appliances do, so I need to send the raw command.
I'm attempting to use the URLs generated on the received code screen and they return 'Error! JSON parsing failed'.
Until I get this up and running, I left the password and Amazon user ID fields empty.
Here's an example URL string:
http://192.168.1.50:80/json?plain=[{'data':[1278,438,1252,436,410,1280,1250,442,1276,418,410,1284,408,1284,408,1286,408,1284,1252,440,410,1284,408,8768,1278,436,1254,438,410,1280,1250,440,1252,414,436,1284,408,1286,408,1286,408,1284,1252,440,410,1284,408,8768,1278,438,1252,436,412,1280,1250,440,1252,440,412,1284,408,1286,408,1284,410,1284,1252,442,408,1286,410,8768,1278,406,1284,438,408,1280,1252,440,1252,442,408,1286,408,1284,408,1286,408,1286,1250,442,408,1286,408,8768,1278,436,1254,438,408,1280,1252,440,1250,444,408,1284,408,1284,408,1284,408,1286,1250,444,410,1284,408,8766,1278,438,1252,436,410,1280,1252,440,1252,442,408,1284,408,1284,408,1286,408,1286,1250,442,410,1284,408,8770,1278,438,1252,436,410],'type':'raw','khz':38}]

The serial output looks like this (snipped the header stuff):
New client request: GET /json?plain=[{'data':[1278,438,1252,436,410,1280,1250,442,1276,418,410,1284,408,1284,408,1286,408,1284,1252,440,410,1284,408,8768,1278,436,1254,438,410,1280,1250,440,1252,414,436,1284,408,1286,408,1286,408,1284,1252,440,410,1284,408,8768,1278,438,1252,436,412,1280,1250,440,1252,440,412,1284,408,1286,408,1284,410,1284,1252,442,408,1286,410,8768,1278,406,1284,438,408,1280,1252,440,1252,442,408,1286,408,1284,408,1286,408,1286,1250,442,408,1286,408,8768,1278,436,1254,438,408,1280,1252,440,1250,444,408,1284,408,1284,408,1284,408,1286,1250,444,410,1284,408,8766,1278,438,1252,436,410,1280,1252,440,1252,442,408,1284,408,1284,408,1286,408,1286,1250,442,410,1284,408,8770,1278,438,1252,436,410],'type':'raw','khz':38}] HTTP/1.1
method: GET url: /json search: plain=[{'data':[1278,438,1252,436,410,1280,1250,442,1276,418,410,1284,408,1284,408,1286,408,1284,1252,440,410,1284,408,8768,1278,436,1254,438,410,1280,1250,440,1252,414,436,1284,408,1286,408,1286,408,1284,1252,440,410,1284,408,8768,1278,438,1252,436,412,1280,1250,440,1252,440,412,1284,408,1286,408,1284,410,1284,1252,442,408,1286,410,8768,1278,406,1284,438,408,1280,1252,440,1252,442,408,1286,408,1284,408,1286,408,1286,1250,442,408,1286,408,8768,1278,436,1254,438,408,1280,1252,440,1250,444,408,1284,408,1284,408,1284,408,1286,1250,444,410,1284,408,8766,1278,438,1252,436,410,1280,1252,440,1252,442,408,1284,408,1284,408,1286,408,1286,1250,442,410,1284,408,8770,1278,438,1252,436,410],'type':'raw','khz':38}]
<...>
args: plain=[{'data':[1278,438,1252,436,410,1280,1250,442,1276,418,410,1284,408,1284,408,1286,408,1284,1252,440,410,1284,408,8768,1278,436,1254,438,410,1280,1250,440,1252,414,436,1284,408,1286,408,1286,408,1284,1252,440,410,1284,408,8768,1278,438,1252,436,412,1280,1250,440,1252,440,412,1284,408,1286,408,1284,410,1284,1252,442,408,1286,410,8768,1278,406,1284,438,408,1280,1252,440,1252,442,408,1286,408,1284,408,1286,408,1286,1250,442,408,1286,408,8768,1278,436,1254,438,408,1280,1252,440,1250,444,408,1284,408,1284,408,1284,408,1286,1250,444,410,1284,408,8766,1278,438,1252,436,410,1280,1252,440,1252,442,408,1284,408,1284,408,1286,408,1286,1250,442,410,1284,408,8770,1278,438,1252,436,410],'type':'raw','khz':38}] args count: 1 Request: /json

final list of key/value pairs: key:'plain' value:'[{'data':[1278,438,1252,436,410,1280,1250,442,1276,418,410,1284,408,1284,408,1286,408,1284,1252,440,410,1284,408,8768,1278,436,1254,438,410,1280,1250,440,1252,414,436,1284,408,1286,408,1286,408,1284,1252,440,410,1284,408,8768,1278,438,1252,436,412,1280,1250,440,1252,440,412,1284,408,1286,408,1284,410,1284,1252,442,408,1286,410,8768,1278,406,1284,438,408,1280,1252,440,1252,442,408,1286,408,1284,408,1286,408,1286,1250,442,408,1286,408,8768,1278,436,1254,438,408,1280,1252,440,1250,444,408,1284,408,1284,408,1284,408,1286,1250,444,410,1284,408,8766,1278,438,1252,436,410,1280,1252,440,1252,442,408,1284,408,1284,408,1286,408,1286,1250,442,410,1284,408,8770,1278,438,1252,436,410],'type':'raw','khz':38}]'
Connection received - JSON
JSON parsing failed
Any thoughts? The libraries are up-to-date and they compiled fine with just some nonfatal warnings about deprecated declarations. I'm using the /dev branch as I had the issue on my WEMOS D1 Mini where the web server was freezing after about 5 seconds. I also noticed that Chrome likes to be helpful and encode some of the characters in the URL, where Edge does not. So I've been using Edge to keep things simple.

Thanks for your help.
-James

@mdhiggins
Copy link
Owner

Try removing the single quotes from around the keys (data, type, khz) and see if that helps
I think that was a change enforced by the newer versions of the json library

@jaymzx
Copy link
Author

jaymzx commented Apr 24, 2020

Hey, alright. That got me somewhere.
I was running the string through a json validator and what got it to work was to remove the single quotes on the keys, as you suggested, and placing double quotes around the string after the data key.
e.g.;
http://192.168.1.50/json?plain=[{data:"[1278,438,<...>1252,436,410],type:raw,khz:38"}]

Thanks for the tip!

@jaymzx
Copy link
Author

jaymzx commented Apr 24, 2020

Actually, I spoke too soon. The JSON parsing now works in the UI, however. the LED isn't transmitting. The new serial output shows the transmitting string is null, so it appears to me that the new JSON string is breaking somewhere else:

Connection received - JSON
Blasting off
Blocking incoming IR signals
0:null:0
Transmission complete
Reenabling receiving
Sending home page
Turning off the LED to save power

The LED transmits fine if I use one of the built-in codes, e.g.; msg?code=A90:SONY:12
Would the simplest solution for the time being be to revert to an earlier ArduinoJSON library? If so, which one do you suggest?

@mdhiggins
Copy link
Owner

Remove the double quotes from the array

@jaymzx
Copy link
Author

jaymzx commented Apr 24, 2020

That's the rub - it returns the parsing error without the double quotes around the array (even with no single quotes around the keys, as suggested). I tried replacing the doubles with single quotes as well and while it doesn't return the parsing error, it also returns null.

@mdhiggins
Copy link
Owner

Does it work if you put the individual numbers in quotes?

@jaymzx
Copy link
Author

jaymzx commented Apr 24, 2020

Negative.
This passes as 'successful' in the Web UI, but returns null. Note the double quotes after the data key
192.168.1.50/json?plain=[{data:"['1278','438','1252',<...>'410'],type:raw,khz:38"}]

These fail json validation, as do other various permutations of quotes around the keys and values:
192.168.1.50/json?plain=[{data:"["1278","438","1252",<...>"410"],type:raw,khz:38"}]
192.168.1.50/json?plain=[{data:['1278','438','1252',<...>,'410'],type:raw,khz:38}]
192.168.1.50/json?plain=[{data:'['1278','438','1252',<...>'410'],type:raw,khz:38'}]

It seems that the URL json validation is contingent upon placing the 'data' values in double quotes.

@mdhiggins
Copy link
Owner

Alright I was able to get it to work using this format

http://10.0.1.46:667/json?plain=[{data:[1278,438,1252,436,410,1280,1250,442,1276,418,410,1284,408,1284,408,1286,408,1284,1252,440,410,1284,408,8768,1278,436,1254,438,410,1280,1250,440,1252,414,436,1284,408,1286,408,1286,408,1284,1252,440,410,1284,408,8768,1278,438,1252,436,412,1280,1250,440,1252,440,412,1284,408,1286,408,1284,410,1284,1252,442,408,1286,410,8768,1278,406,1284,438,408,1280,1252,440,1252,442,408,1286,408,1284,408,1286,408,1286,1250,442,408,1286,408,8768,1278,436,1254,438,408,1280,1252,440,1250,444,408,1284,408,1284,408,1284,408,1286,1250,444,410,1284,408,8766,1278,438,1252,436,410,1280,1252,440,1252,442,408,1284,408,1284,408,1286,408,1286,1250,442,410,1284,408,8770,1278,438,1252,436,410],type:'raw',khz:38}]

But the issue is that the JSON parsing error was due to lack of memory. I just pushed an update that expands the allocated memory to accommodate raw commands of this size. I also improved the error logging to include why the json parsing error was flagged since that can be misleading

@jaymzx
Copy link
Author

jaymzx commented Apr 25, 2020

You nailed it. Works like a champ now. Thanks for your help on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants