No Input in Emoncms

Hi

i have a Raspberry B+ with 5 sensors 18B20.

The sensors are working, but Emoncms input is not working. "No input created"

I use the following script with my API Key(Read/Write), and changed also the sensor id.

Please give me a tip, thank you in advance

 

<?php
//================ Config ===========================
//Replace your DS18B20 serial here!
$SENSORID = "28-000005c68110";
 
//Set the emoncms API Key, the Hostname or IP and the  internal Sensor ID (Numeric only)
$EmonCMSApiKey = "d5fc60b7e270c380ef0a2b418f632a84";
$EmonCMSHost = "localhost";<a href="http://cdn.raspberry.tips/2014/12/temperatur.php_.txt">temperatur.php</a>
$ecmsSENSORID = "1";
//==================================================
 
//BuildSensor Path
$SensorPath = '/sys/bus/w1/devices/'. $SENSORID .'/w1_slave';
 
// Open resource file for thermometer
$thermometer = fopen($SensorPath, "r");
 
// Get the contents of the resource
$thermometerReadings = fread($thermometer, filesize($SensorPath));
// Close resource file for thermometer
fclose($thermometer);
// We're only interested in the 2nd line, and the value after the t= on the 2nd line
preg_match("/t=(.+)/", preg_split("/\n/", $thermometerReadings)[1], $matches);
$temperature = $matches[1];
 
//Write to emoncms - Example http://192.168.178.24/emoncms/input/post.json?node=1&csv=100,200,300
// You may want to add other parsed values
$url = 'http://' . $EmonCMSHost . '/emoncms/api/post.json?node=' . $ecmsSENSORID . '&csv=' . $temperature .'&apikey=' . $EmonCMSApiKey  . '';
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);
?>

 

 

Robert Wall's picture

Re: No Input in Emoncms

Is "localhost" being resolved, or should you have the dotted IP address assigned by your router there?

And what is the second statement on this line?
$EmonCMSHost = "localhost";<a href="http://cdn.raspberry.tips/2014/12/temperatur.php_.txt">temperatur.php</a>

tomrossi's picture

Re: No Input in Emoncms

Localhost is working

I deleted the second statement out of the script

Reboot Raspi

No success.

Any further tip

Robert Wall's picture

Re: No Input in Emoncms

As I understand it, emonCMS ought to accept ".../emoncms/api/post.json?node=..." but the preferred syntax is as you quote it in the comment (using "input/post"). My PHP's a bit rusty, have you checked that the assembled $url is correct?

What is your set-up? Is this PHP running on the RPi - the same one that has emonCMS running on it?

tomrossi's picture

Re: No Input in Emoncms

Hi

yep it is a Raspberry B+

PHP and emonCMS is running on it

I followed this description

http://raspberry.tips/raspberrypi-tutorials/visualisierung-von-temperatu...

My php is stored in /home/pi and is started with a cronjob

 

Robert Wall's picture

Re: No Input in Emoncms

I'll need to hand over to a RPi expert.

pb66's picture

Re: No Input in Emoncms

Although not an expert I have a couple of suggestions you could try.

Firstly what is the result of manually entering a url string via a browser in the intended format? if not on the same machine use the numeric dotted IP address in place of "localhost", In fact I would recommend using the IP address either way until you know it works. we know using "localhost" can be quirky so it hampers troubleshooting when you are less than sure of the expected result.

Something like this (replace bold as required)

http://IP.OF.PI.HOST/emoncms/api/post.json?node=1&csv=20&apikey=abc123

​or in the other format as Robert suggests

http://IP.OF.PI.HOST/emoncms/input/post.json?node=1&csv=20&apikey=abc123

The guide you followed although only a couple of months old uses the debian packaged emoncms which although it should work as far as I know, is not guaranteed as it is no longer maintained. (this is why some users refer to the missing "cog" symbol that bug still exists in the deb even though it was fixed many months ago). But for now we will assume the deb version is ok.

It was also pre-Pi 2 B and the config.txt needs editing to include the line

dtoverlay=w1-gpio,gpiopin=4

at the end and reboot. Pin 4 being the "usual" w1 pin on the Pi. (If you intend to use the RFM2Pi module you should use another pin)

My php isn't good enough to comment on the script but if you can confirm the server side of things by manually typing out the url and can confirm the w1 interface is working by using

ls /sys/bus/w1/devices

If these parts work ok we can then look closer at the script if needed.

Paul

tomrossi's picture

Re: No Input in Emoncms

Changed localhost to my IP address

Tried to fill the url with the creds i have (used csv=100, i don't know if ok)

in both url's the webpage shows me

OK

as text

The hardware should be ok, the sensors changes the value i hold them in my hand

Script problem?

pb66's picture

Re: No Input in Emoncms

So it looks like the server and emoncms is working when the correct url is used. So we can assume it's not getting the (correct) url. 

The hardware should be ok, the sensors changes the value i hold them in my hand
Script problem?

Quite possibly but when you say the value of the sensors changes when you hold them, how are you determining that? If you get the value using

cat /sys/bus/w1/devices/SENSOR_ID/w1_slave

then yes that confirms hardware is available to the script. 

Is the php script running? Try commenting out the url created by the script and add one of the 2 you have tried and tested above don't use variables just hardcoded to test cron is triggering the script and the script can send ok.

Having now looked a little closer at the script it appears to only be geared up for a single sensor so for now just focus on one sensor as you will need to

A) edit the script to poll each of the 5 sensors and then construct a url string containing all 5 values 

B) edit the script to poll each of the 5 sensors and send a url string for each using a different node id

C) duplicate the script and cron entry for each of the 5 sensors, each with it's own node id etc

Obviously A) is the preferred method but C) is probably the easiest way to get you going if you were stuck.

Paul

 

tomrossi's picture

Re: No Input in Emoncms

Paul,

the crontab seems not to run the script.

Terminl: sudo nano /etc/crontab

added:

*/5 * * * * root /home/pi/temperatur.php

Crontab should be ok, i assume

If i open a second browser window with the hardcoded url and click on refresh the input of the other browser is filled

Yep, i prefer to have the A methode, but this is for later

pb66's picture

Re: No Input in Emoncms

To edit the crontab use

crontab -e

" */5 * * * * root /home/pi/temperatur.php" should be

*/5 * * * * sudo php /home/pi/temperatur.php

This will run the script using php, with root user permissions

Paul 

tomrossi's picture

Re: No Input in Emoncms

Its not working, url hardcoded or not.

How can i check if the cronjob is running?

If i run sudo php /home/pi/temperatur.php in the terminal system tells me

Could not open input file: /home/pi/temperatur.php

 

pb66's picture

Re: No Input in Emoncms

and what is returned if you run

ls -la /home/pi/temperatur.php

I assume you are user "pi" and the file exists so it is probably a permission issue perhaps. But "sudo php ..." should of overcome that. Is there a typo in the filename or location?

sudo php /path/to/file.php

should definitely work from the command line,

Once it works from the command line we can recheck cron as maybe the script should be run without sudo from roots crontab eg

sudo crontab -e

 and instead use the line 

*/5 * * * * php /home/pi/temperatur.php

if cron still doesn't work after getting it to work from " sudo php ..."

 

tomrossi's picture

Re: No Input in Emoncms

It seems that it don't like to see .php

temperatur without .php works

pi@raspberrypi ~ $ sudo ls -la /home/pi/temperatur
-rwxrwxr-x 1 pi pi 1528 Apr  1 15:43 /home/pi/temperatur
pi@raspberrypi ~ $ sudo ls -la /home/pi/temperatur.php
ls: cannot access /home/pi/temperatur.php: No such file or directory
pi@raspberrypi ~ $ sudo php /home/pi/temperatur
PHP Parse error:  syntax error, unexpected '$SensorPath' (T_VARIABLE) in /home/pi/temperatur on line 14
 
Now we have an error
pb66's picture

Re: No Input in Emoncms

mv /home/pi/temperatur /home/pi/temperatur.php

Will resolve the naming issue,

line 14 in the script in your OP is blank, so which line is now 14? 

    $SensorPath = '/sys/bus/w1/devices/'. $SENSORID .'/w1_slave';
 or 
    $thermometer = fopen($SensorPath, "r");

 

tomrossi's picture

Re: No Input in Emoncms

This on

$SensorPath = '/sys/bus/w1/devices/' . $SENSORID . '/w1_slave';

tomrossi's picture

Re: No Input in Emoncms

If i try

/sys/bus/w1/devices/28-0114652d46ff/w1_slave in th efile browser, it says it not vailid

I think it is because the w1_slave is a text document

Can this be?

I have to leave no, i will have a look later in the evening

Many thx in advance

pb66's picture

Re: No Input in Emoncms

Did you get any response earlier using

cat /sys/bus/w1/devices/SENSOR_ID/w1_slave

replacing SENSOR_ID with the ID of your chosen sensor? Is this "ID" also correctly typed in the the script?

tomrossi's picture

Re: No Input in Emoncms

Hi

this works

pi@raspberrypi ~ $ cat /sys/bus/w1/devices/28-0114652d46ff/w1_slave 
40 01 55 00 7f ff 0c 10 81 : crc=81 YES
40 01 55 00 7f ff 0c 10 81 t=20000

Replace of the $SENSORID with the sensor ID is not working

pi@raspberrypi ~ $ sudo php /home/pi/temperatur.php
PHP Parse error:  syntax error, unexpected '$SensorPath' (T_VARIABLE) in /home/pi/temperatur.php on line 14
pi@raspberrypi ~ $ 

 

 

pb66's picture

Re: No Input in Emoncms

That confirms the 1-wire bus is ok and the script isn't doing it's bit, which is where I stop being of any use I'm afraid, as I'm not fluent enough in php to be useful.

You could try "hardcoding" the sensor id into line 14 to see if it's the use of a variable causing the issue or the variable itself.

Paul

tomrossi's picture

Re: No Input in Emoncms

I recreated the script, edit it once more and now it is working

Strange

I will try to go now for concept A mentioned earlier in the post.

Cross the fingers

 

Many thx to you Paul, create support!!

pb66's picture

Re: No Input in Emoncms

No problem, 

I can't give you any pointers for making the php multi sensor but I have just hashed a python script together from a couple of examples I found on-line, I'm not able to test so can't guarantee it would work 1st go but it may help you adapt the php script or if you want to try it, rename it temperture.py, put it in /home/pi and in crontab use

python /home/pi/temperature.py

in place of php /home/pi/temperatur.php

When I get a chance I will try and complete the script so it works with emonHub rather than emonCMS directly.

Paul

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.