output json

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
novembre62
Normal user
Posts: 30
Joined: 10 May 2019, 15:39
Location: italy

output json

#1 Post by novembre62 » 20 Apr 2021, 15:56

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

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: output json

#2 Post by Ath » 20 Apr 2021, 16:03

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.
/Ton (PayPal.me)

novembre62
Normal user
Posts: 30
Joined: 10 May 2019, 15:39
Location: italy

Re: output json

#3 Post by novembre62 » 20 Apr 2021, 16:11

thank you very much

... can I post the scripts here?

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: output json

#4 Post by Ath » 20 Apr 2021, 16:24

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)
/Ton (PayPal.me)

novembre62
Normal user
Posts: 30
Joined: 10 May 2019, 15:39
Location: italy

Re: output json

#5 Post by novembre62 » 07 Jul 2021, 09:56

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

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: output json

#6 Post by TD-er » 07 Jul 2021, 10:03

Do you happen to have the JSON output of the old build?

novembre62
Normal user
Posts: 30
Joined: 10 May 2019, 15:39
Location: italy

Re: output json

#7 Post by novembre62 » 07 Jul 2021, 12:09

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]

novembre62
Normal user
Posts: 30
Joined: 10 May 2019, 15:39
Location: italy

Re: output json

#8 Post by novembre62 » 08 Jul 2021, 15:18

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]

User avatar
Ath
Normal user
Posts: 3416
Joined: 10 Jun 2018, 12:06
Location: NL

Re: output json

#9 Post by Ath » 08 Jul 2021, 16:02

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.
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests