Page 1 of 1

output json

Posted: 20 Apr 2021, 15:56
by novembre62
Hello,
i have a basic sonoff with
ESPEasy_v2.0.0-dev11
with Pulse Counter and DS18b20 devices
that I use to monitor water consumption and outside temperature

its json output is

Code: Select all

{"System":{
"Build": 20000,
"Unit": 1,
"Uptime": 4534,
"Free RAM": 22008
},
"Sensors":[
{
"TaskName": Count",
"Count": 0.00,
"Total": 1918.00,
"Time": 1903.00
},
{
"TaskName": "outside temperature",
"Temperature": 17.87
}
]}
now i have updated the sonoff to have more functions with
ESP_Easy_mega_20210223

its json output is now

Code: Select all

........
......
........
"Sensors": [
{
"TaskValues": [
{"ValueNumber": 1,
"Name": "temperature",
"NrDecimals": 2,
"Value": 0.00
}],
"DataAcquisition": [
{"Controller": 1,
"IDX": 0,
"Enabled": "false"
},
{"Controller": 2,
"IDX": 0,
"Enabled": "false"
},
{"Controller": 3,
"IDX": 0,
"Enabled": "false"
}],
"TaskInterval": 60,
"Type": "Environment - DS18b20",
"TaskName": "outside temperature",
"TaskDeviceNumber": 4,
"TaskEnabled": "false",
"TaskNumber": 1
},
{
"TaskValues": [
{"ValueNumber": 1,
"Name": "Count",
"NrDecimals": 2,
"Value": 0.00
},
{"ValueNumber": 2,
"Name": "Total",
"NrDecimals": 2,
"Value": 0.00
},
{"ValueNumber": 3,
"Name": "Time",
"NrDecimals": 2,
"Value": 0.00
}],
unfortunately my scripts are written to read ESPEasy_v2.0.0-dev11 json output and i don't know how to adapt them to the new json output

..you can get the json output of ESPEasy_v2.0.0-dev11
with ESP_Easy_mega_20210223

thank you

Re: output json

Posted: 20 Apr 2021, 16:03
by Ath
novembre62 wrote: 20 Apr 2021, 15:56 unfortunately my scripts are written to read ESPEasy_v2.0.0-dev11 json output and i don't know how to adapt them to the new json output

..you can get the json output of ESPEasy_v2.0.0-dev11
with ESP_Easy_mega_20210223
There is no way to 'go back' to a previous json layout, you could share the script you use to parse the 'old' output so we can try to help adjusting to the new structure.

Re: output json

Posted: 20 Apr 2021, 16:11
by novembre62
thank you very much

... can I post the scripts here?

Re: output json

Posted: 20 Apr 2021, 16:24
by Ath
novembre62 wrote: 20 Apr 2021, 16:11 ... can I post the scripts here?
Sure, unless you can't (aren't allowed to) share it in the open. Please use a [ code ] tag to make it more readable (use the </> button)

Re: output json

Posted: 07 Jul 2021, 09:56
by novembre62
Hello
this is the script I use to monitor temperature and humidity (I use a raspberry .... see metern.org) with a DHT22 sensor, with the old JSON format

Code: Select all

 
	  } elseif ($argv[1] == 'temp-scant') {
	    $url = 'http://192.168.1.43/json?tasknr=1';
	    $pagina = file_get_contents($url);
            $json_output = json_decode($pagina, true);
	    $outstr = $json_output['Temperature'];
	    $outstr = "11($outstr*°C)";
	    } elseif ($argv[1] == 'umid-scant') {
	    $url = 'http://192.168.1.43/json?tasknr=1';
	    $pagina = file_get_contents($url);
	    $json_output = json_decode($pagina, true);
	    $outstr = $json_output['Humidity'];
	    $outstr = "12($outstr*Â%)";
how can I change it to the new JOSN format

http://192.168.1.43/json?tasknr=1

Code: Select all

{
"TaskValues": [
{"ValueNumber":1,
"Name":"Temperature",
"NrDecimals":2,
"Value":26.50
},
{"ValueNumber":2,
"Name":"Humidity",
"NrDecimals":2,
"Value":56.60
}],
"TTL":5000,
"DataAcquisition": [
{"Controller":1,
"IDX":0,
"Enabled":"false"
},
{"Controller":2,
"IDX":0,
"Enabled":"false"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":5,
"Type":"Environment - DHT11/12/22  SONOFF2301/7021",
"TaskName":"tem",
"TaskDeviceNumber":5,
"TaskEnabled":"true",
"TaskNumber":1
}
thank you

Re: output json

Posted: 07 Jul 2021, 10:03
by TD-er
Do you happen to have the JSON output of the old build?

Re: output json

Posted: 07 Jul 2021, 12:09
by novembre62
this is the old JSON

http://192.168.1.43/json?tasknr=1

Code: Select all

{
"TaskName": "temp",
"Temperature": 31.06,
"TaskName": "umid",
"Humidity": 51.06
}
[code]

Re: output json

Posted: 08 Jul 2021, 15:18
by novembre62
this is the old JSON exact

http://192.168.1.43/json?tasknr=1

Code: Select all

{"System":{
"Name":"ESP_Easy","Unit":0,"Build":20100,"Git Build":"mega-20180220","Local time":"1970-00-00 00:00:00","Uptime":1376,"Free RAM":17024},
"Sensors":[
{
"TaskName":"tem",
"Temperature": 27.70,
"Humidity": 50.70
}
]}
[code]

Re: output json

Posted: 08 Jul 2021, 16:02
by Ath
It looks like the json_decode function that is called in your Raspberry Pi script is expecting "Sensors", and ESPEasy is currently sending "TaskValues" there. Could you check the rest of your script, and change "Sensors" to "TaskValues", to see if that works?

Edit:
Or you could post the entire script.