reading sensor drop down

Talks about metering
Post Reply
megamarco83
Posts: 36
Joined: Tue Apr 14, 2015 9:25 am

reading sensor drop down

Post by megamarco83 » Wed Sep 12, 2018 6:10 pm

hi, i'm monitoring two DHT22 connected over two different ESP8266
but i have drop down of value recorded from one device
it's working good
Image
it's not working good
Image

the request is made by reqsdm:
device that works:

Code: Select all

reqsdm espdht22t
reqsdm espdht22u
device that not work:

Code: Select all

reqsdm espdht22t_primo_piano
reqsdm espdht22u_primo_piano

Code: Select all

      } elseif ($argv[1] == 'espdht22t') {
         $outstr =  exec('curl -s http://192.168.0.195/json?tasknr=2 | egrep "Temperature"  | cut -d: -f2 | cut -d, -f1 | tr -d  [:blank:]');
         $outstr = "16($outstr*°C)";
      } elseif ($argv[1] == 'espdht22u') {
         $outstr =  exec('curl -s http://192.168.0.195/json?tasknr=2 | egrep "Humidity"  | cut -d: -f2 | cut -d, -f1 | tr -d  [:blank:]');
         $outstr = "17($outstr*%)";
	  } elseif ($argv[1] == 'espdht22t_primo_piano') {
         $outstr =  exec('curl -s http://192.168.0.198/json?tasknr=3 | egrep "Temperature"  | cut -d: -f2 | cut -d, -f1 | tr -d  [:blank:]');
         $outstr = "18($outstr*°C)";
      } elseif ($argv[1] == 'espdht22u_primo_piano') {
         $outstr =  exec('curl -s http://192.168.0.198/json?tasknr=3 | egrep "Humidity"  | cut -d: -f2 | cut -d, -f1 | tr -d  [:blank:]');
         $outstr = "19($outstr*%)";
why there is so differences on reading?
both has a good singnal

jeanmarc
Posts: 1574
Joined: Thu Aug 29, 2013 7:16 am

Re: reading sensor drop down

Post by jeanmarc » Wed Sep 12, 2018 6:38 pm

Hi,
I guess your curl request output a timeout. You can try this :

Code: Select all

    $url      = 'http://192.168.1.195/json?tasknr=2';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 3000); // error
    $espjson = array();
    if (($espjson = curl_exec($ch)) === false) {
        die(curl_error($ch) . "\n");
    }
    $espjson = json_decode($espjson, true);
    // print_r($espjson); // uncomment to see the output
    $val    = (float) $espjson['Count']; // count ? 
    $outstr = utf8_decode("17($val*%\n");
    echo "$outstr";

megamarco83
Posts: 36
Joined: Tue Apr 14, 2015 9:25 am

Re: reading sensor drop down

Post by megamarco83 » Wed Sep 12, 2018 9:36 pm

Hey jeanmarc you are right...as well :D
i create a php file putting inside your code and saved as json.php
then i lunch the php and this is the result:

Code: Select all

pi@raspberrypi:/var/www/MyScripts $ sudo php json.php
Connection timed out after 3001 milliseconds
how i can solve?
thanks

p.s. anyway the sensor on 192.168.0.195 (that you put in your php test code) is the one that works well (never a drop down) but anyway i receive the error > 3000milliseconds also on that

the 192.168.0.198 sensor is the one that drow down very often

jeanmarc
Posts: 1574
Joined: Thu Aug 29, 2013 7:16 am

Re: reading sensor drop down

Post by jeanmarc » Thu Sep 13, 2018 6:20 am

You can increase the timeout in curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 3000); // it's 3000ms

megamarco83
Posts: 36
Joined: Tue Apr 14, 2015 9:25 am

Re: reading sensor drop down

Post by megamarco83 » Fri Oct 05, 2018 1:29 pm

jeanmarc wrote:
Thu Sep 13, 2018 6:20 am
You can increase the timeout in curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 3000); // it's 3000ms
hi, i succed on that using this:

Code: Select all

} elseif ($argv[1] == 'esp_dht22_temp_primo_piano') {
         $url = 'http://192.168.0.198/json?tasknr=2';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $outstr = $json_output['Temperature'];
         $outstr = "18($outstr*°C)";        
     } elseif ($argv[1] == 'esp_dht22_umid_primo_piano') {
         $url = 'http://192.168.0.198/json?tasknr=2';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $outstr = $json_output['Humidity'];
         $outstr = "19($outstr*%)"; 
now i'm a bit in truble because espeasy new version has changed the json output, old version was:

Code: Select all

pi@raspberrypi:~ $ curl -s http://192.168.0.198/json?tasknr=2
{
"TaskName": "dht22",
"Temperature": 24.10,
"Humidity": 55.30
the new version of json is:

Code: Select all

pi@raspberrypi:~ $ curl -s http://192.168.0.198/json?tasknr=2
{
"TaskValues": [
{"ValueNumber":1,
"Name":"Temperature",
"NrDecimals":2,
"Value":24.10
},
{"ValueNumber":2,
"Name":"Humidity",
"NrDecimals":2,
"Value":55.30
}],
"TTL":60000,
"DataAcquisition": [
{"Controller":1,
"IDX":21,
"Enabled":"true"
},
{"Controller":2,
"IDX":0,
"Enabled":"false"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":60,
"Type":"Environment - DHT11/12/22  SONOFF2301/7021",
"TaskName":"dht22",
"TaskEnabled":"true",
"TaskNumber":2
}
that is more completed but use the same "label" value to store the humidity and temperature values, how i can catch the temp and hum value and put in metern format using json in reqsdm ?
thanks

jeanmarc
Posts: 1574
Joined: Thu Aug 29, 2013 7:16 am

Re: reading sensor drop down

Post by jeanmarc » Fri Oct 05, 2018 2:38 pm

Code: Select all

...
    $val    = $espjson['TaskValues'][1]['Value'];
    $outstr = utf8_decode("Humidity($val*hum)\n");
    echo "$outstr";
...

megamarco83
Posts: 36
Joined: Tue Apr 14, 2015 9:25 am

Re: reading sensor drop down

Post by megamarco83 » Fri Oct 05, 2018 3:07 pm

jeanmarc wrote:
Fri Oct 05, 2018 2:38 pm

Code: Select all

...
    $val    = $espjson['TaskValues'][1]['Value'];
    $outstr = utf8_decode("Humidity($val*hum)\n");
    echo "$outstr";
...
sorry...

my working reqsdm for the old version of json is:

Code: Select all

      } elseif ($argv[1] == 'esp_dht22_temp_primo_piano') {
         $url = 'http://192.168.0.198/json?tasknr=2';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $outstr = $json_output['Temperature'];
         $outstr = "18($outstr*°C)";  		 
	  } elseif ($argv[1] == 'esp_dht22_umid_primo_piano') {
         $url = 'http://192.168.0.198/json?tasknr=2';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $outstr = $json_output['Humidity'];
         $outstr = "19($outstr*%)";  
so if i understand well now i have to:

Code: Select all

} elseif ($argv[1] == 'esp_dht22_temp_primo_piano') {
   $url = 'http://192.168.0.198/json?tasknr=2';
    $pagina = file_get_contents($url);
    $json_output = json_decode($pagina, true);
    $val    = $json_output['TaskValues'][1]['Value'];
    $outstr = utf8_decode("18($val*°C\n");
 } elseif ($argv[1] == 'esp_dht22_umid_primo_piano') {
         $url = 'http://192.168.0.198/json?tasknr=2';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $val    = $json_output['TaskValues'][2]['Value'];
         $outstr = utf8_decode("19($val*%\n"); 
but is not working...
thanks

jeanmarc
Posts: 1574
Joined: Thu Aug 29, 2013 7:16 am

Re: reading sensor drop down

Post by jeanmarc » Fri Oct 05, 2018 3:29 pm

It's not $outstr = utf8_decode("19($val*%\n"); but $outstr = utf8_decode("19($val*%)\n"); :)

megamarco83
Posts: 36
Joined: Tue Apr 14, 2015 9:25 am

Re: reading sensor drop down

Post by megamarco83 » Fri Oct 05, 2018 4:18 pm

jeanmarc wrote:
Fri Oct 05, 2018 3:29 pm
It's not $outstr = utf8_decode("19($val*%\n"); but $outstr = utf8_decode("19($val*%)\n"); :)
thanks!
but should be something else wrong :(

Code: Select all

pi@raspberrypi:/var/www/MyScripts $ curl -s http://192.168.0.151/json?tasknr=7
{
"TaskValues": [
{"ValueNumber":1,
"Name":"Temperature",
"NrDecimals":2,
"Value":24.90
},
{"ValueNumber":2,
"Name":"Humidity",
"NrDecimals":2,
"Value":52.00
}],
"TTL":60000,
"DataAcquisition": [
{"Controller":1,
"IDX":0,
"Enabled":"false"
},
{"Controller":2,
"IDX":0,
"Enabled":"false"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":60,
"Type":"Environment - DHT11/12/22  SONOFF2301/7021",
"TaskName":"dht",
"TaskEnabled":"true",
"TaskNumber":7
}
this is the output of json

now:

Code: Select all

pi@raspberrypi:/var/www/MyScripts $ reqsdm esp_dht22_temp_primo_piano_NEW
18(50*▒C)
pi@raspberrypi:/var/www/MyScripts $ reqsdm esp_dht22_umid_primo_piano_NEW
PHP Notice:  Undefined offset: 2 in /var/www/comapps/reqsdm.php on line 64
19(*%)
pi@raspberrypi:/var/www/MyScripts $
and this is the reqsdm

Code: Select all

      } elseif ($argv[1] == 'esp_dht22_temp_primo_piano_NEW') { //DHT22 su ESP NUOVE versioni espeasy
         $url = 'http://192.168.0.151/json?tasknr=7';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $val    = $json_output['TaskValues'][1]['Value'];
         $outstr = utf8_decode("18($val*°C)\n");
       } elseif ($argv[1] == 'esp_dht22_umid_primo_piano_NEW') {
         $url = 'http://192.168.0.151/json?tasknr=7';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $val    = $json_output['TaskValues'][2]['Value'];
         $outstr = utf8_decode("19($val*%)\n"); 
when i request for the temperature it respond with value of humidity and when i request for humidity it respond with an error
is it better to "navigate" inside json using the "ValueNumber" 1 (temp) or 2(hum) or using "Temperature" and "Humidity" laber? how i have to do it?

and a strange simble before °C (the "°" is not correct exported) ->> 18(50*▒C) maybe is the utf8_decode, is better json_decode?

with the old json structure was all good:

Code: Select all

pi@raspberrypi:/var/www/MyScripts $ reqsdm esp_dht22_temp_primo_piano
18(25.5*°C)pi@raspberrypi:/var/www/MyScripts $ reqsdm esp_dht22_umid_primo_piano
19(50.1*%)pi@raspberrypi:/var/www/MyScripts $
the old reqsdm is:

Code: Select all

      } elseif ($argv[1] == 'esp_dht22_temp_primo_piano') { //DHT22 su ESP vecchie versioni espeasy
         $url = 'http://192.168.0.198/json?tasknr=2';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $outstr = $json_output['Temperature'];
         $outstr = "18($outstr*°C)";  		 
	  } elseif ($argv[1] == 'esp_dht22_umid_primo_piano') {
         $url = 'http://192.168.0.198/json?tasknr=2';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $outstr = $json_output['Humidity'];
         $outstr = "19($outstr*%)"; 

thanks so much again

megamarco83
Posts: 36
Joined: Tue Apr 14, 2015 9:25 am

Re: reading sensor drop down

Post by megamarco83 » Fri Oct 05, 2018 6:06 pm

ok, i succed on that :-)

Code: Select all

      } elseif ($argv[1] == 'esp_dht22_temp_primo_piano_NEW') { //DHT22 su ESP NUOVE versioni espeasy (NON FA BUCHI NELLE LETTURE)
         $url = 'http://192.168.0.198/json?tasknr=2';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $val    = $json_output['TaskValues'][0]['Value'];
         $outstr = ("18($val*°C)\n");
       } elseif ($argv[1] == 'esp_dht22_umid_primo_piano_NEW') {
         $url = 'http://192.168.0.198/json?tasknr=2';
         $pagina = file_get_contents($url);
         $json_output = json_decode($pagina, true);
         $val    = $json_output['TaskValues'][1]['Value'];
         $outstr = ("19($val*%)\n"); 	

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests