Monitoring of underlying Raspi Paramter

I copied and adopted a script found here to work on the emupi and the url is working excellent when copied into the browser.
But the script himself doesnt work (the curl statement is somehow not executing the URL at the commandline).
The script himself works without any error and the url shown also works. But not running localy by php monitor-pi.php
any tips why the curl_exec is not pushing the data into my instance but when i use the url in the browser of my workstation it works ?
is there no browser installed on emonpi or any librarby missing to process this accordingly ?
i have latest image of emonpi.
thnx
Alex

================================== the script

<?php
$nodeid = "emonpi"; // change “0” with the node id that will receive data
$apikey="xxxxx"; // change “XXXXXXXXXXXXXX” with your APIKEY
$target="localhost/emoncms";
$mem = preg_split("#\s+#",shell_exec("free -m | grep Me"));
$GPU_temp=round(shell_exec("cat /sys/class/thermal/thermal_zone0/temp"));
$GPU_temp=round($GPU_temp/1000);
$CPU_temp=shell_exec("/opt/vc/bin/vcgencmd measure_temp | cut -d '=' -f2 | cut -d '.' -f1");
$cmd="top -bn1 | grep 'Cpu(s)' | sed 's/., ([0-9.])% id.*/\1/' | awk '{print 100 - $1}'";
$CPU_usage=round(shell_exec($cmd));
$CPU_usage=0;
$url = "http://".$target."/input/post?node=".$nodeid."&json={mem_used:".$mem[2].",mem_free:".$mem[3].",mem_shared:".$mem[4].",mem_buffers:".$mem[5].",mem_cached:".$mem[6].",GPU_temp:".$GPU_temp.",CPU_temp:".$CPU_temp.",CPU_usage:".$CPU_usage."}&apikey=".$apikey;
echo "url:".$url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($ch);
curl_close ($ch);
?>

I suspect it’s this line -

$target=“localhos/emoncms”;

Assuming you’re running this on your EmonPi and want to send the info to your EmonPi, that line should say “localhost” rather than “localhos”.

No sorry this was just a typo when exchanging my real hostname against localhost in this post.
It doesnt work with “localhost” nor the “real” machine name.
So you can test this on your EMONPI and let me know the result.
when you copy the url (displayed on screen via echo) into a browser and exchange localhost against ip or machinename it works.
so i guess there is something missing in the EMONPI installation which is needed by php “curl” function.

Solved ! there was a blank after the CPU_temp in the jason string and this is only shown when you call it via the webserver and post the url then into the browser :slight_smile:
so i needed to add a trim and then the execution from commandline also works :slight_smile: