I’m trying to send temperature from a DS18S20 sensor information to EMONCMS using a PHP script. The response is always the following json:
{“success”:false,“message”:“Username or password empty”}
EMONCMS version is: low-write 9.7.5 | 2016.10.14
I’ve tried the following URLs with curl (where $EmonCMSApiKey is my read/write API key):
$url = 'http://localhost/emoncms/input/post.json?node=19&csv=20875&apikey=' . $EmonCMSApiKey . '';
$url = 'http://localhost/emoncms/input/post.json?apikey=' . $EmonCMSApiKey . '&node=19&csv=20875';
$url = 'http://localhost/emoncms/input/post.json?node=19&json={20875}&apikey=' . $EmonCMSApiKey . '';
$url = 'http://localhost/emoncms/input/post.json?apikey=' . $EmonCMSApiKey . '&node=19&json={20875}';
$url = 'http://localhost/emoncms/input/post.json?node=19&json={"1":20875}&apikey=' . $EmonCMSApiKey . '';
$url = 'http://localhost/emoncms/input/post.json?apikey=' . $EmonCMSApiKey . '&node=19&json={"1":20875}';
When I use the URLs in a Firefox Browser from a different PC (replacing ‘localhost’ with the local IP) and while logged into the web interface, the data is logged correctly. Then again, those URLs work without the ApiKey when logged into the browser. It seems that it is only from the RaspberryPi itself that the URL does not work
I also tried adding the ApiKey to the POST data and the header with the same results:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $EmonCMSApiKey));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('apiKey' => $EmonCMSApiKey));
As another test, I tried using wget in bash, but also the same results.
Any ideas why I can’t post to localhost?
thanks!