Page 1 of 1
Re: Decode JSON
Posted: Saturday 19 September 2015 7:29
by Egregius
Can you use PHP? Then it would be easy
Code: Select all
<?php
$data=json_decode(file_get_contents('http://ip:port/json.htm?type=devices&rid=10'),true);
$co2 = filter_var($data['result']['0']['Data'], FILTER_SANITIZE_NUMBER_INT);
echo $co2;
$co2 contains only the numbers, so would echo 693

Re: Decode JSON
Posted: Saturday 19 September 2015 10:55
by simonrg
- Send the request (openurl?) ? - use the Lua socket library
- parse the json reply in LUA ? - use the Lua json library
- Get only the data part (693) ? - select from the table created when the json is decoded
If you have a look at the code for the smappee Lua script then you will see an example of how to do this -
http://www.domoticz.com/wiki/Smappee
Re: Decode JSON
Posted: Saturday 19 September 2015 14:19
by simonrg
Lisa wrote:
Since Domoticz is running on windows, linux examples won't help me. 'use the Lua socket library' this isn't helpfull (besides the fact that the socket library isn't implemented in Domoticz)...
To jumpstart the Lua coding part, i'm in need of coding examples so that i can copy-paste the examples pieces i need. An API can be interpreted many ways, the examples create a shortcut to use the API...
I'm not an experienced LUA developer, nor do i wish to become one. The only reason i'm doing this, is to create a work-around for a bug in Domoticz...
Sorry to give you misleading advice, it would be helpful if you added a description of what you are running in your signature, then people wouldn't give you duff advice.
Any Lua library is available in Domoticz, if the platform on which you are running it has it implemented, so Windows or Linux are often both possible, I think the socket library is available for Windows, I don't think the SSL library is though.
But if you don't want to hack enough Lua to get this to work, then you could always execute a Curl / jq commands once again the Wiki has a number of examples of the use of Curl and jq from Lua.
If you are only doing this to get around a bug in Domoticz, then it would seem more effective to explain the bug clearly enough so the developer's can more easily fix the Domoticz code.
Re: Decode JSON
Posted: Saturday 15 October 2016 22:48
by hannibal2206
Do you have a pointer where to find the solution ?
Re: RE: Re: Decode JSON
Posted: Saturday 15 October 2016 23:34
by tequila
hannibal2206 wrote:Do you have a pointer where to find the solution ?
have a look at this:
https://www.domoticz.com/wiki/Battery_level_check
it's a good example of how to read a value using jquery, including how to get jquery itself.
Re: Decode JSON
Posted: Sunday 16 October 2016 19:12
by hannibal2206
jquery ? sorry, did not find that there
Re: RE: Re: Decode JSON
Posted: Wednesday 19 October 2016 6:29
by tequila
hannibal2206 wrote:jquery ? sorry, did not find that there
right at the top of the page is a description how to install jq. below is a nice script reading values using jq.