I’ve just built a prototype remote temperature sensor using an ESP8266-12E and a DHT11, the goal is eventually to investigate changing our dual zone gas combi boiler heating thermostats to diy smart ones integrating with my emonpi/emoncms and multiple wifi temperature sensors.
I have previously posted data to the emonpi via emonhub using sockets on a raspberry pi, I assume this functionality is possible on the ESP as some of the other openenergymonitor devices are using the ESP, however I haven’t been able to work out how to do it and would greatly appreciate some pointers as to how to get this working.
I’m doing that using Wemos D1 Mini’s, and using a MQTT ESP library to send data back to emoncms.
The pubsubclient library is a popular choice, and has been updated quite a bit in the past few days.
The big problem with this approach is battery usage, as WiFi consumption is heavy, even if you put the ESP into sleep mode between readings. Not a problem though if you’re not using batteries!
Yes, all you need to do is to write the code to do it. It’s pretty easy. If you do it this way you can do it directly rather than going through MQTT. I send 7 temperature readings from DS18B20s through to emoncms on a local Pi using the websockets interface.
You’d have to put the following code snippets into a program but these are the essential bits for sending the package.
Declarations for the server
char* emoncmsserver = “192.168.0.17”; // you need to change this to your pi address
WiFiClient emoncmsClient;
int emoncmssocketPort = 20100;
char nodeid = “11”;
String emoncmspayload;
Publish to emoncms routine
void publishtoemoncms(){
// Publish to emoncms
// first build the payload
emoncmspayload = String(nodeid); // initialise the payload with first node id, payload is space delimited
for (int j = 0; j < numTempSensors; j++) { // then add in the temperature readings from all available sensors
emoncmspayload = emoncmspayload + " " + String(temperatures[j],1);
}
// for the socket version need to add cr newline
emoncmspayload = emoncmspayload + + “\r\n”;
#ifdef DEBUG
Serial.print("Connecting to emoncms on: ");
Serial.println(emoncmsserver); #endif
if (emoncmsClient.connect((char*) emoncmsserver, emoncmssocketPort)) {
// send the payload, nodeid and Temperatures.
emoncmsClient.print (emoncmspayload); #ifdef DEBUG
Serial.print("emoncmsClient connected: publishing data: ");
Serial.println (emoncmspayload); #endif
// close connection to emoncms socket
emoncmsClient.stop();
}
else { #ifdef DEBUG
Serial.println(“emoncms connect failed”); #endif
}
}
Assuming you mean “EmonHubSocketInterfacer”, unfortunately not, unless you make amendments to the emonESP code.
It was agreed some months ago that it would be beneficial for the emonESP code to be updated to permit posting to emonhub via a socketinterfacer but as yet, that has not happened.
If you decide to tackle the task, please keep us up to date with your progress and/or submit a PR to the emonESP repo, as this would be of great use, neither of the current emonESP options (MQTT or HTTP direct to emonCMS) allow posting to multiple emoncms instances simultaneously, not does it provide buffering, error logs or support full SSL on an outgoing emoncms connection.
Thanks all for your help. I was waiting to reply until I had actually got everything up and running, but other things came up and I’m not sure when I’ll get a chance to work on it again!
I tried the socket example by @Bramco but I couldn’t get it to work, however, I have also been fiddling with a recently acquired emonEVSE which required me to talk to it via MQTT (thanks for the pointer @Paul and this seems to be a very straightforward solution and is what I am intending on using for this project, at least for the time being
If you want to use QoS 1 or 2, you could always try this fork of the pubsubclient library.
I have it running in a couple of projects, and it’s very stable, it also includes a number of MQTT classes, making it very configurable.