reqsdm for ds18b20 sensor

Talks about metering
margan
Posts: 14
Joined: Fri Sep 16, 2016 11:48 am

reqsdm for ds18b20 sensor

Post by margan » Fri Aug 18, 2017 8:16 am

Hi,
on the previous meterN version not had problems to add the boiler °C as a meter. With 0.8.3 can't solve it.

On reqsdm.php in the comapps folder I added this lines (to other meters/indicator):
} elseif ($argv[1] == '°C Boiler') {
$outstr = exec('cat /dev/shm/boiler7.txt | egrep "^7\(" | grep "*°C)"');
} elseif ($argv[1] == '°C Boiler-live') {
$outstr = exec('cat /dev/shm/boiler7.txt | egrep "^7\(" | grep "*°C)"');

I see the boiler7.txt with the boiler temperature but on meterN not and the test comm button fails.

In my hands non so easy these new reqsm commands, sorry! Anyone solved in any way ?

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

Re: reqsdm for ds18b20 sensor

Post by jeanmarc » Fri Aug 18, 2017 8:32 am

Hi,
Try your com app from the command line and see what it returns. (php reqsdm.php)

margan
Posts: 14
Joined: Fri Sep 16, 2016 11:48 am

Re: reqsdm for ds18b20 sensor

Post by margan » Fri Aug 18, 2017 8:45 am

Hi JM, nice to meet you.

pi@raspberrypi:~ $ php reqsdm.php
Could not open input file: reqsdm.php
pi@raspberrypi:~ $

But other meters/indicators work properly on meterN, here are as listed in:
if (!isset($argv[1])) {
die("Abording: no valid argument given.\nUsage: reqsdm (tensione|corrente|cospi|boiler-status|boiler-live|boiler-main|resistenza|°C Boiler|°C Boiler-live|cpu-temp)\n");

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

Re: reqsdm for ds18b20 sensor

Post by jeanmarc » Fri Aug 18, 2017 10:00 am

You have to put the full path :
php /var/www/somewherecomapp/reqsdm.php
or if you created a sym link
php reqsdm

margan
Posts: 14
Joined: Fri Sep 16, 2016 11:48 am

Re: reqsdm for ds18b20 sensor

Post by margan » Fri Aug 18, 2017 11:49 am

pi@raspberrypi:~ $ php /var/www/comapps/reqsdm.php
Abording: no valid argument given.
Usage: reqsdm (tensione|corrente|cospi|boiler-status|boiler-live|boiler-main|resistenza|▒C Boiler|▒C Boiler-live|cpu-temp)
pi@raspberrypi:~ $

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

Re: reqsdm for ds18b20 sensor

Post by jeanmarc » Fri Aug 18, 2017 12:26 pm

php /var/www/comapps/reqsdm.php °C Boiler
I guess it does not like the "°" nor the space argument ..

Change your command $argv[1] == 'CBoiler' and $argv[1] == 'Boiler-live'
Then php /var/www/comapps/reqsdm.php CBoiler

margan
Posts: 14
Joined: Fri Sep 16, 2016 11:48 am

Re: reqsdm for ds18b20 sensor

Post by margan » Fri Aug 18, 2017 12:56 pm

pi@raspberrypi:~ $ php /var/www/comapps/reqsdm.php C_boiler
Usage: reqsdm (tensione|corrente|cospi|boiler-status|boiler-live|boiler-main|resistenza|C_Boiler|C_Boiler-live|cpu-temp)
pi@raspberrypi:~ $ php /var/www/comapps/reqsdm.php C_boiler-live
Usage: reqsdm (tensione|corrente|cospi|boiler-status|boiler-live|boiler-main|resistenza|C_Boiler|C_Boiler-live|cpu-temp)
pi@raspberrypi:~ $

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

Re: reqsdm for ds18b20 sensor

Post by jeanmarc » Fri Aug 18, 2017 1:10 pm

could you past your full script ? :roll:

margan
Posts: 14
Joined: Fri Sep 16, 2016 11:48 am

Re: reqsdm for ds18b20 sensor

Post by margan » Fri Aug 18, 2017 4:24 pm

Code: Select all

#!/usr/bin/php
<?php
// This script will output a meterN compatible format for the main or live command
// You'll need to setup correct permission chmod +x 
// then ln -s /var/www/comapps/reqsdm.php /usr/bin/reqsdm
// Request command with 'reqsdm tensione' or 'reqsdm corrente' or ......

if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
if (!isset($argv[1])) {
	die("Abording: no valid argument given.\nUsage: reqsdm (tensione|corrente|cospi|boiler-status|boiler-live|boiler-main|resistenza|C_Boiler|C_Boiler-live|cpu-temp)\n");
		} elseif ($argv[1] == 'tensione') {
			$outstr =  exec('cat /dev/shm/metern2.txt | egrep "^2_1\(" | grep "*V)"');
		} elseif ($argv[1] == 'corrente') {
			$outstr =  exec('cat /run/shm/metern2.txt | egrep "^2_2\(" | grep "*A)"');
		} elseif ($argv[1] == 'cospi') {
			$outstr =  exec('cat /run/shm/metern2.txt | egrep "^2_4\(" | grep "*F)"');
		} elseif ($argv[1] == 'boiler-status') {
         		$outstr =  exec('echo "pwm_ssr_dimmer("`pgrep -c pwm_ssr_dimmer`"*X)"');
      		} elseif ($argv[1] == 'boiler-live') {
         		$outstr =  exec('cat /dev/shm/boiler6.txt | egrep "^6\(" | grep "*W)"');
      		} elseif ($argv[1] == 'boiler-main') {
         		$outstr =  exec('cat /dev/shm/boiler6.txt | egrep "^6\(" | grep "*Wh)"');
      		} elseif ($argv[1] == 'resistenza') {
         		$outstr =  exec('cat /dev/shm/boiler6.txt | egrep "^6_1\(" | grep "*%)"');
		} elseif ($argv[1] == 'C_Boiler') {
         		$outstr =  exec('cat /dev/shm/boiler7.txt | egrep "^7\(" | grep "*°C)"');
		} elseif ($argv[1] == 'C_Boiler-live') {
         		$outstr =  exec('cat /dev/shm/boiler7.txt | egrep "^7\(" | grep "*°C)"');
		} elseif ($argv[1] == 'cpu-temp') {
			$outstr =  exec('cat /sys/class/thermal/thermal_zone0/temp');
			$outstr = $outstr/1000;
			$outstr = "cpu($outstr*°C)";
		// and so on ....
	} else {
    die("Usage: reqsdm (tensione|corrente|cospi|boiler-status|boiler-live|boiler-main|resistenza|C_Boiler|C_Boiler-live|cpu-temp)\n");
	}
echo "$outstr";
?>
and

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

w1 gpio
w1_therm

 /boot/config.txt

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on
core_freq=250
sdram_freq=400
over_voltage=0

#device tree config
dtoverlay=w1-gpio,gpiopin=4


/usr/local/bin/ds18b20.py

#!/usr/bin/env python
import sys
from w1thermsensor import W1ThermSensor
address = sys.argv[1]
sensor = W1ThermSensor(W1ThermSensor.THERM_SENSOR_DS18B20, address)
temperature_in_celsius = sensor.get_temperature()
print("{0:.2f}".format(temperature_in_celsius))


/usr/local/bin/ds18b20

#!/bin/sh
DATA="$(ds18b20.py $1)"
echo "$2($DATA*C)" > /run/shm/metern$2.txt



/etc/cron.d/ds18b20

#!/bin/bash
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
# Minute Hour Day of Month Month Day of Week User Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
1,6,11,16,21,26,31,36,41,46,51,56 * * * * root /usr/local/bin/ds18b20 0315937deaff 7 > /dev/null 2>&1


etc/rc.local

# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
sudo /usr/local/bin/ds18b20 0315937deaff 7
exit 0
 - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - 

with manual call
pi@raspberrypi:~ $ ds18b20.py 0315937deaff
93.19

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

Re: reqsdm for ds18b20 sensor

Post by jeanmarc » Fri Aug 18, 2017 5:30 pm

Well it does work for me :
[root@i3 comapps]# php atest.php C_Boiler-live
cat: /dev/shm/boiler7.txt: No such file or directory

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests