Help decoding JSON data from socket.http.request - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Help decoding JSON data from socket.http.request (/showthread.php?tid=1075) |
Help decoding JSON data from socket.http.request - mooselight - 01.11.2017 Dear All, I'm trying to retrieve consumption info from an "Ecocompteur" box from Legrand with the following code, but it does not work as expected. The returned Content-Type is "text/plain" while it should be "application/json", so the json.decode function does not work. Is there another way to retrieve data values from the returned "json" data ? Thanks in advance Code: Accessing "http://192.168.1.xx/inst.json" give this data in return : Code: require 'ltn12' Here is the log output : Code: Ecocompteur 01.11.2017 20:33:54 RE: Help decoding JSON data from socket.http.request - Erwin van der Zwart - 01.11.2017 Hi, Try this: Code: if type(response_body) == 'table' then Erwin RE: Help decoding JSON data from socket.http.request - admin - 02.11.2017 Try running this then post both log entries. What it looks like is that the response is incorrect. JSON functions expect valid input which does not have "Content-Type" set anywhere so it's not the problem. Code: require('json') RE: Help decoding JSON data from socket.http.request - mooselight - 02.11.2017 (02.11.2017, 06:55)admin Wrote: Try running this then post both log entries. What it looks like is that the response is incorrect. JSON functions expect valid input which does not have "Content-Type" set anywhere so it's not the problem. Here is the log entries I got : Code: Ecocompteur 02.11.2017 07:58:47 (I PM you more info) Thx (01.11.2017, 21:50)Erwin van der Zwart Wrote: Hi, Thx Erwin, but it does not work. Here is the log entry : Ecocompteur 02.11.2017 08:33:27 * nil RE: Help decoding JSON data from socket.http.request - admin - 02.11.2017 Strange, I've tested it with your access details and it works correctly. Which firmware version are you running? RE: Help decoding JSON data from socket.http.request - admin - 02.11.2017 Can you also try running request like this? Code: sock = require('socket').tcp() RE: Help decoding JSON data from socket.http.request - mooselight - 02.11.2017 (02.11.2017, 07:44)admin Wrote: Strange, I've tested it with your access details and it works correctly. Which firmware version are you running? 1Version 2: 20170620 It should be the last I think ? I'll try again .. (02.11.2017, 07:48)admin Wrote: Can you also try running request like this? Thanks, it works perfectly ! |