ESPEasy and EMONTX - it seems to work!

After discovering that a lot of my packets were getting lost on my 433MHz RFM69 Network due to radio congestion I’ve just switched over to an independently powered ESP8266 module running ESPEasy build 120 to send the radio packets.
I realise that there already is an OEM project to do this with alternative firmware, but it doesn’t allow any of the ESP’s GPIO Ports to be used for additional things such as controlling relays via Openhab.
For anyone interested in following in my footsteps, all that is needed to get this to work is for both the ESP Serial Port and the Arduino Serial speed to be changed to 57600 in both ESPEasy and in the EMONTX Sketch. The Sketch also needs the following small modification in the debug section, after if (debug==1) { to send the MQTT packets

On my system In place of the existing debug output I have:

  Serial.print("Publish emon/esp1/p1 ");Serial.println(emontx.power1);
  Serial.print("Publish emon/esp1/p2 ");Serial.println(emontx.power2);
  Serial.print("Publish emon/esp1/p3 ");Serial.println(emontx.power3);
  Serial.print("Publish emon/esp1/p4 ");Serial.println(emontx.power4);
  Serial.print("Publish emon/esp1/v ");Serial.println(emontx.Vrms);

where the topic being published to is emon/esp1. It also seems to want at least one

 Serial.println(" ");

sent afterwards to work reliably

Doing this on the standard sketch leaves the RFM still working, which I’ll disable now I know everything is working correctly. It’s been working for 12 hours now which isn’t long, however I have 2 other ESP’s running ESPEasy used elsewhere which seem reliable enough.

2 Likes

For more info on ESPEasy, see:

www.esp8266.nu/index.php/ESPEasy

1 Like

Hi Kevin,
I also have a network with ESP8266 modules running espeasy and emonesp firmware and I am interested to check your modification in the Emontx sketch because the Espeasy project looks more advanced. Do you have any idea that the I2c sensors connected to GPIO pins 4 and 5 in the ESP8266 will send data in the same time with
Emontx connected on Rx,Tx pins ?
Thank you

I can’t see any reason why not - the ESP firmware has no modifications other than turning off serial logging by setting the serial port log level to 0 in the advanced tab of the web interface. I2C uses different pins to the serial port which the EMONTX is connected to.
I don’t have any I2C devices so can’t say for definite

Hi Kevin,
I did all the modifications in emontx sketch you suggested it, but I got an error when I try to verify it. Can you please post your complete modified sketch which is working?
Thank you

I’ve attached the sketch to this post. A few things to be aware of

  1. the calibration values WILL be incorrect for your location - I have changed all my Burden Resistors and calibrated my AC Voltage so these will need changing to reflect your location - I am in New Zealand which has 230V / 50Hz power
  2. the pulse output is disabled as I don’t use it
  3. some of the RF parts have been removed when they were obvious, some may remain
  4. some of the USA parts have been disabled in the interest of saving memory
  5. At some stage I will likely either move to a continuous sampling sketch or modify the official EMONTX ESP sketch when everything becomes stable and I recalibrate everything
    EMONTX_V2.1_Downstairs_ESP_Added_Beta4.ino (19.1 KB)

Hi Kevin,
I loaded your sketch in one arduino pro mini 3v3 for testing purpose and I connected it with an esp8266 module running espeasy build 120. Also I enabled analog input readings from Esp8266 module. I’ve got the inputs p1,p2,p3,p4, v and analog in Emoncms from my emonpi but only the analog input is updating every 10s the others from arduino only if I reset it. I am not a programmer, but I think that with small modifications ( like adding a watchdog reset) the sketch will work properly.
Well done!

Interesting that it doesn’t give continuous readings - I’ve got the same sketch working right now on 2 x EMONTX V3.4’s and its updating every 5 seconds, and has done for many days on end, in fact since moving to the ESP I haven’t needed to reset them once. On one system I have the ESP output PWM at the same time to drive a dimmer, again without needing additional watchdogs. Is your system EMONTX’s and a Raspberry Pi or something else?
I wonder if you have different library versions on your system that causes the Arduino to stop updating, or maybe a power supply rail that dips? My ESP Modules have their own power supply, and as of yesterday one is powered from its EMONTX’s USB input after I removed the jumper and recalibrated the AC voltage.

Hi Kevin,
I don’t have Emontx board.
I have a Raspberry Pi loaded with the last EmonSD image.
I wanted more precision in measurements and I used Arduino Due/GLCD and build a board with current and voltage measurement input circuits.
I am planning to install a new measurement point in garage where I have installed PV inverter and battery storage so I have to use an ESP07 with an external antenna and to connect to it an arduino promini and several other I2C sensors like INA219 for DC battery current and voltage measurement and a light intensity measurement sensor BH1750. I already have installed another ESP07 ( running espeasy) which is controlling two relays for connecting and disconnecting the inverter and the charger from grid and receiving data from an BME280 sensor for measurement of air pressure, temperature and humidity.
I modified the sketch EmonESP example for the EmonTx v3 to publish every 10 seconds data to the mqtt topic and the inputs are updating now in EmonCMS but i have another problem. The first 4 inputs are working properly but if I add another will not be shown correctly in EmonCMS. What is strange is that it will be overlapped to the analog input which I added to be posted to the same or even another mqtt topic, for example Emon/ESP2. Every 10 seconds will alternate as the fifth input the E4 energy measurement output from arduino with the analog measurement from ESP.
The other measurements except the first 4 posted from arduino will not be displayed. Do you have any idea from where is coming this limitation, from ESP, from mqtt broker or from emoncms, or maybe from nodered .
Thanks for your support.

Hi Stefan,
that sounds like a very interesting project, I use 2 EMONTX’s, one to monitor my solar which I have split into 4 with one CT around each leg so I can compare each string of Micro Inverters against the others to see if all is as it should be. I then use Openhab to sequence my power diversion between Spa and Hot Water.
My first suggestion for you is to connect the Arduino Output to a PC serial port using the programmer, then use a simple terminal program (I use termite) to see what is being output by the Arduino.
I had 2 problems along the way,
the first was using 115200 as a serial port speed which led to corruption as the number of channels increased so I dropped it down to 57600, maybe you could try slower and then work up?
the other problem was I needed to add a space and carriage return to the serial port which I did in lines 343 and 347. I think line 347 may be the one that helped which reads

Serial.println(" ");

from memory ESPEasy needs an extra carriage return before the next string, and termite displays exactly what its receiving. Any change in format will cause the data to not arrive. You need to see exactly

Publish mytopic value

The spaces are important as is a carriage return after each line. I also use MQTT.fx to monitor the MQTT Traffic, although its difficult to find a downloadable version of this that works. I use version 1.1.0

Hopefully this helps!

Hi Kevin,
I succeeded to get 8 inputs + esp ADC input in Emoncms by inserting a delay of 500ms between the first 4 published values and the next 4. Also I added a row with
Serial.println() before the first publish topic value because first topic was not sent always correctly by esp module. The part with debug section modification it is not needed for the sketch “EmonESP example for the EmonTx v3” to work properly.
Best regards

Well done, if it works out the same as mine it is a very reliable upgrade from the RFM69 Module. Mine has been up for 8 days now since I last played with it and it also operates my light dimmer in its spare time.

Hi Kevin,
one more question please. Do you have any idea why the emontx sketches are using 4 separate emonlib instances to calculate the 4 active powers. It is annoying to see in the display 4 active powers updating one by one from 2 to 2 seconds, in total 8 seconds for a complete reading. To built a fast automation and regulation with a balance a powers all powers should be readed in the same time so emonlib also should be modified and I think is not a big deal to do this…
best regards

It is all down to the sampling rate available from the standard Arduino library functions. The “CM” library, which addresses this issue, is a work in progress.

1 Like

Thanks for answer Robert. We have to wait for this library.

Anyone could help me by adding pin reading in emonesp sketch? I would like to have my wemos d1 mini read from pins rather then serial uart because the d1 shields and other sensors i have dont use tx and rx.
This would open many doors to emonesp as a control unit (dht or relay).
Any help?

Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling Serial.swap() after Serial.begin. Calling swap again maps UART0 back to GPIO1 and GPIO3.
I hope it helps

Thank you for the info. I read something about this but i can’t understand how it could help.
Can you explain me the difference between using serial and pins?
How do you connect a dht or ds18b20 to the nodemcu to make it read data in emonesp?these sensors have an output that goes to one pin and not serial uart…this is the missing link i need to achieve. Surely someone can tweak the code to have pins reading included.

ESPEasy running on an ESP module can read a DS18B20 module directly connected to it OR one connected to an EMONTX connected to it via serial. The sketch posted above works the second way. Elsewhere i use WemosD1 mini without EMONTX to read 3 DS18B20 modules, and control relays.
Read the thread above, I’m in New Zealand and its quicker to read than wait for a reply with our GMT+12 timezone

Wonderful help!