Emoncms on raspberry, no inputs from esp8266

Blockquote
Is there anything in the log window on the admin page to indicate if there are any errors? If not, in the emoncms folder you will find a file settings.php . Look for the logging option and change it to INFO level.

Hmm, I cannot find the folder emoncms and settings.php, I’m sorry…

It is in the root www folder so /var/www/emoncms or /var/www/html/emoncms/

now the log looks like this:

LAST ENTRIES ON THE LOG FILE

2019-05-06 18:54:41.815|INFO|rememberme_model.php|getCookieValues: not present

2019-05-06 18:54:41.818|INFO|rememberme_model.php|clearCookie

2019-05-06 18:54:41.818|INFO|rememberme_model.php|getCookieValues: not present

2019-05-06 18:54:41.834|INFO|index.php|feed/list

2019-05-06 18:54:42.231|INFO|index.php|feed/list.json

2019-05-06 18:54:42.282|INFO|index.php|schedule/list.json

2019-05-06 18:54:42.293|INFO|index.php|input/list.json

2019-05-06 18:54:42.286|INFO|index.php|process/list.json

2019-05-06 18:54:42.381|INFO|index.php|feed/list.json

2019-05-06 18:54:44.174|INFO|index.php|device/list.json

2019-05-06 18:54:44.180|INFO|rememberme_model.php|login

2019-05-06 18:54:44.181|INFO|rememberme_model.php|getCookieValues: not present

2019-05-06 18:54:44.200|INFO|index.php|input/list.json

2019-05-06 18:54:44.206|INFO|rememberme_model.php|login

2019-05-06 18:54:44.206|INFO|rememberme_model.php|getCookieValues: not present

2019-05-06 18:54:47.226|INFO|index.php|feed/list.json

2019-05-06 18:54:49.184|INFO|index.php|device/list.json

2019-05-06 18:54:49.190|INFO|rememberme_model.php|login

2019-05-06 18:54:49.191|INFO|rememberme_model.php|getCookieValues: not present

2019-05-06 18:54:49.211|INFO|index.php|input/list.json

2019-05-06 18:54:49.217|INFO|rememberme_model.php|login

2019-05-06 18:54:49.218|INFO|rememberme_model.php|getCookieValues: not present

2019-05-06 18:54:50.437|INFO|index.php|admin/view

2019-05-06 18:54:51.787|INFO|index.php|admin/getlog

2019-05-06 18:54:51.787|INFO|index.php|feed/buffersize.json

When your system posts the data, you should see a specific entry relating to your posting of the data and then the processing of it.

If you use

 tail -f /var/log/emoncms.log | grep input

You should be able to see just the entry. If you get that try

tail -f /var/log/emoncms.log to get the whole log.

You can test it by using one of the sample links on the Input API page.

If you do not see anything, then the URL is not formatted correctly. Can you do a print of the actual URL you have generated from your script?

pi@emonpi:~ $ tail -f /var/log/emoncms.log | grep input
2019-05-06 20:24:32.907|INFO|index.php|input/list.json   2019-05-06 
20:24:37.903|INFO|index.php|input/list.json
2019-05-06 20:24:42.907|INFO|index.php|input/list.json

 pi@emonpi:~ $ tail -f /var/log/emoncms.log
 2019-05-06 20:22:42.892|INFO|rememberme_model.php|getCookieValues: not present
2019-05-06 20:22:42.906|INFO|index.php|input/list.json
2019-05-06 20:22:42.913|INFO|rememberme_model.php|login
2019-05-06 20:22:42.913|INFO|rememberme_model.php|getCookieValues: not present
2019-05-06 20:22:47.883|INFO|index.php|device/list.json

And so on…

Can you tell which one relates to the input from your device?

You need to look at the actual URL you generate from your script or else use something like tshark on the Pi to determine what is actually being sent.

Can you post all the code?

[edit] you will need to install tshark (do some Googling) but something like this may help

Ok, I’ll take a look at tspark. Sounds complicated, though…
Thank you for your help !!

Unless you can put a print statement into your code and get the URL it is sending and if there is nothing in the emoncms log, it is the only way of tracing the issue.

You could post all the code and someone may spot the issue. The API with emoncms.org is slightly different IIRC.

Unless you can put a print statement into your code and get the URL it is sending

This is exactly what I mean with complicated… :slight_smile:
I’m a totally newby who just copy code together, which I may can adjust to my needs and that’s it…
I’ll do a research and give it a try, I want to get this going !

1 Like
tshark -Y http.request -T fields -e http.request.full_uri

and resetting the node gives me immediately the following output:

http://172.23.56.146/input/post.json?node=Kitchen&apikey=emonpicmsreadandwriteapikey&json={temperature:22.20,humidity:23.42,pressure:957.39}

The IP differs from my first post, since the node connects to a different router now.
For my humble knowledge it looks all good, but there are still no inputs, yet.
I also put the whole link from above, except the measured values, in the host line of the emoncms setting section,
but again, no success…

1 Like

If you cut and paste that request into a browser bar and enter, what response do you get?

Should it not be

http://172.23.56.146/emoncms/input/post.json?node=Kitchen&apikey=emonpicmsreadandwriteapikey&json={temperature:22.20,humidity:23.42,pressure:957.39}

I get a 404 on my emonSD image if I omit the /emoncms sub-directory.

1 Like

Oh, I missed that, thanks !!
… and cannot try it out before tomorrow, because I forgot the sd card at work…

1 Like

The request from tshark from my last post wasn’t from the node.
I ran it again and from the node comes nothing, but every 5 min an output, that mqtt server got 0 data…

I get a 404 on my emonSD image if I omit the /emoncms sub-directory.

So do I and with /emoncms I also get an error, but didn’t copy it, because this seems to be a dead end for me.
I do not understand what’s going on here and can’t get it to work. I’m not able to expand the code for posting a print line to get the url, too. Maybe I find some ohter code for the nodemcu and emoncms. I just wanted something neat to display temperature and humidity with a little bit of logging and the code that I have was exactly what I wanted, when using it with “emoncms.org” as host for the cms.
But since it is not possible for me to run emoncms locally, I’ll may check for something else.

Thanks all for your help, it was definitely educational
Cheers,
Oli

That becomes a bit of a self-fulfilling prophecy, it will be a dead end if you do not pay attention to the error messages.

If you tell us what the error is we might be able to help.

If it works for emoncms.org, it should also work for local emoncms. Don’t worry too much about getting the nodemcu to print the url right now.

If you are getting an error and unable to post an input via the api in a browser then that needs resolving first.

Once we are able to post via an api, then we can retest the nodemcu. AFAIA all you may need to do is alter the const char* host = "192.168.0.133" to const char* host = "192.168.0.133/emoncms" IF we are able to get the url with /emoncms in it to work, but not without it.

Paul, your’re right!! Yesterday was frustrating and killed my motivation :slight_smile:

Ok, a added /emoncms in the browser:
http://172.23.56.146/emoncms/input/post.json?node=Kitchen&apikey=emonpicmsreadandwriteapikey&json={temperature:22.20,humidity:23.42,pressure:957.39}
gives back in the browser window:
{"success": false, "message": "Format error, json value is not numeric"}

AFAIA all you may need to do is alter the const char* host = "192.168.0.133" to const char* host = "192.168.0.133/emoncms" IF we are able to get the url with /emoncms in it to work, but not without it.

I already tried that before, but got the same results:
no inputs and enter the link from above in the browser gives the same output:

{"success": false, "message": "Format error, json value is not numeric"}

Good to hear the fight isn’t over yet!

So looking at the input api docs

it would seem the format of the url isn’t right, unless you go fulljson and add all the quote marks, you would need to just remove .json from your url eg

http://172.23.56.146/emoncms/input/post?node=Kitchen&apikey=emonpicmsreadandwriteapikey&json={temperature:22.20,humidity:23.42,pressure:957.39}

As I said, this isn’t important until you get it working in a browser, BUT it is good news that it is returning the same error, that potentially indicates that all will be well once you fix the url in the browser and introduce those edits (and the /emoncms) to your firmware.

:+1:
And again, I’ll have to postpone my teaks until tomorrow…
I’ll post back my insights then immediately !

Guys, we’re getting closer:

I’ve added /emoncms in the firmware:
const char* host = "192.168.0.133/emoncms";

and putting this into the browser:
http://172.23.56.146/emoncms/input/post?node=Kitchen&apikey=emonpicmsreadandwriteapikey&json={temperature:22.20,humidity:23.42,pressure:957.39}

which gives me back
ok

AND when I’m checking the inputs in the emoncms menu then there are the 3 inputs with the values from the link above !!

So far so good, but I have still no idea, how to get the whole thing with real values into the cms…
Sorry, but at the moment, I’m more confused than in the beginning…

So it all sounds good and hopefully the final piece is to remove the .json from the nodemcu firmware. Somewhere it will currently have something like /input/post.json? which needs changing to /input/post?, this might be part of a longer string including node= etc, but the change is the smae, whatever is there that includes .json remove the .json and it should work, if your unsure, post the section of code that needs amending or the whole sketch for us to look at.

1 Like

After a reboot I’ll get my 3 inputs, but no values and it’s not updating, the cms shows:
n/a NULL

Here’s the whole code

// Including the Libraries for WiFi Connection, HTTP Send and bme280 Sensor
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// Replace with your network details
const char* ssid = "mySSID";
const char* password = "RouterPasswd";
Adafruit_BME280 bme;

//emoncms settings, change node ID for every node
const char* host = "192.168.0.133/emoncms";
const char* nodeId   = "Kitchen";
const char* privateKey = "readandwriteapikey";
float h = 0;
float t = 0;
float p = 0;
int vcc;
ADC_MODE(ADC_VCC);
char temperatureCString[6];
char humiditiyString[6];
char pressureString[7];
const int httpPort = 80;

//Seconds to deep sleep 300 = 5Min
const int sleepTimeInSec = 300;

//Variables to store values


// ==============================================
// only runs once on boot then go deep sleep again
// ==============================================
void setup() {
  
  // Initializing serial port for debugging purposes
  Serial.begin(115200);
  delay(500);

  //Start sensor orginal bei 0x76
  bme.begin(0x76);

  //Connect WiFi
  //Fix  https://github.com/esp8266/Arduino/issues/2186
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");


  // Sensor readings may also be up to 2 seconds 'old', so we read twice
  h = bme.readHumidity();
  t = bme.readTemperature();
  p = bme.readPressure() / 100.0;
  delay(2500);
  h = bme.readHumidity();
  t = bme.readTemperature();
  p = bme.readPressure() / 100.0;
 
  //vcc = ESP.getVcc();//readvdd33();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from bme280 sensor!");
    return;
  }

  Serial.print("Luftfeuchte: ");
  Serial.print(h);
  Serial.print(" %\t Temperatur: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print("%\t Luftdruck: ");
  Serial.print(p);
  
  //Send data to emoncms
  sendData();

  //go to deep sleep
  ESP.deepSleep(30e6);
}

// ==============================================
// Send Data to emoncms
// ==============================================
void sendData() {

  WiFiClient emonHTTPClient;

  //Connect by http
  const int httpPort = 80;
  if (!emonHTTPClient.connect(host, httpPort)) {
    return;
  }

  //Build the JSON for emoncms to send data
  String json = "{temperature:";
  json += t;
  json += ",humidity:";
  json += h; 
  json += ",pressure:";
  json += p; 
  //json += ",vcc:";
  //json += vcc;
  json += "}";

  //Build emoncms URL for sending data to
  String url = "/input/post?node=";
  url += nodeId;
  url += "&apikey=";
  url += privateKey;
  url += "&json=";
  url += json;

  // Send the HTTP Request to the emoncms server
  emonHTTPClient.print(String("GET ") + url + " HTTP/1.1\r\n" +
                  "Host: " + host + "\r\n" +
                  "Connection: close\r\n\r\n");
  delay(10);

  // Read all the lines of the reply from server and print them to Serial
  while (emonHTTPClient.available()) {
    String line = emonHTTPClient.readStringUntil('\r');
  }

  emonHTTPClient.stop();
}



void loop(void) {
}

Sorry, it’s not formatting correctly… [no worries, I’ve formatted it by adding ``` (3x backticks) on the lines before and after the code - pb66]