Configuring EMONPI to collect several electric consumption data


I am a new EMONPI user. My goal is to use several of EMONPIs to collect data describing the electricity consumption in households. The data I want to acquire are : rms Voltage, rms Current, Phase angle, Power factor, Active Power, Reactive power.

Yet, I can’t seem to collect more than power, energy, and rms Voltage, using 1CT and 1AC-AC, through the web app of the EMONPI (EMONCMS).

Can you help? Thank you in advance.

The emonPi comprises two parts, a Raspberry Pi and a cut-down emonTx. The emonTx sends the data it collects to the RPi via a serial link.

The “emon” part runs a sketch that’s very similar to the Discrete Sample sketch for the emonTx, which uses emonLib to make the calculations. EmonLib calculates all the quantities you require except for phase angle and reactive power - but you do get apparent power, and you can derive phase angle from real and apparent power (but you cannot know whether it is leading or lagging).

In order to make these available, you need to download the firmware for the analogue part from emonpi/firmware/src at master · openenergymonitor/emonpi · GitHub, add the variables you need to the declaration of the data structure PayloadTX, then
assign values to the new variables like in line 286.
The names of all the quantities available are:


You must then compile and load the new sketch. Instructions for that are here: EmonPi - OpenEnergyMonitor Wiki

Having done that, you must modify the entry in emonhub.conf to match the data that you are sending in PayloadTX. If you compare the existing PayloadTX and the section to decode it in the existing emonhub.conf, you’ll see what is required.

1 Like

Thank you for your precious response… It took me long to understand your instructions.
Yet, I seem to fail to make things work, I am sure I am doing something wrong.

Here is a list of everything I did, maybe with this you can pinpoint what I am doing wrong:

  1. Config/update/activate SSH EMONPI using ethernet cable
  2. connect to the EMONPI by SSH using MobaXtrem
  3. make changes in the original src inside the firmware folder, following the example EnergyMeter/lcd_serial.ino at master · buchananwp/EnergyMeter · GitHub
  4. compile and upload at the firmware directory (/opt/openenergymonitor/emonpi/firmware/src/) following the instructions in the aformentioned example:
  • sudo pio init
  • sudo pio run #compiles
  • sudo pio run -t upload #uploads
  1. Uploading Arduino Firmware:
  • sudo service emonhub stop
  • avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200 -U flash:w:/opt/openenergymonitor/emonpi/firmware/.pio/build/emonpi/firmware.hex # after changing to directory : /opt/openenergymonitor/emonpi/firmware/.pio/build/emonpi/
  • sudo service emonhub start

I have no idea what that software is or does, you should use the proper OEM software for the emonPi, from here: GitHub - openenergymonitor/emonpi: Raspberry Pi Based Energy Monitor. Hardware, Firmware & related software for the PI.

I don’t support platformio, so I don’t know whether what you have done there is right or wrong, equally I cannot help you if you use somebody else’s software - you need to go there for support.

Did you change emonhub.conf like I told you to:

Actually i did not use any other software than the OEM’s…
To comply with your instructions in your first response, I ve come across that software that has apparently made changes to extract other features as well. Hence, it was very helpful to check their src and lcd_serial files to get a better understanding of how to do your instructions.
Concerning the emonhub.config, I did yes! I added the quantities names, units and all at the end of the other existing quantities… Yet, nothing changed in the EMONCMS inputs…

Would it be possible for you to give me the specific codes to do the compiling,the upload,and the rest? Please bare in mind that this is truely my first time doing this…

What does your src.ino look like?
What does the Node 5 section of your emonhub.conf look like?

I can’t tell you how to use platformio because it destroyed my system on my machine, so it had to go. I only use the proper Arduino IDE. Then I take the emonPi apart and load the ‘emon’ front end directly using the programmer - it’s much easier (for me).

1 Like

Okay you can find attached the src.ino file.
But for a quick peek, here is the two section I edited:


Concerning the emonhub.config, here is the requested Node 5, the sole section I edited:

Great tip for using the programmer directly! (y)
src.ino (18.1 KB)

OK - I see one trap you’ve fallen into. What you’ve done is almost correct, but remember, you declared the new variables as type integer:

int Irms;
int Power_appar;
int Power_factor;

What that means is a current less than 1 A will be rounded down to zero, apparent power will be ok but as power factor can never be greater than 1, that will almost always be zero too. What you need to do is as we do with temperature to retain the decimal part: multiply by (say) 100 before you assign the value to the variable, then multiply by 0.01 in emonHub to restore the value.

Otherwise, what you’ve done looks correct. I have not tried to compile it (and even if I did, my emonPi can’t be taken off the job it’s doing) and I can’t test it.

I should have mentioned that if you take the “emon” board out of your emonPi, you’ll still need the USB power while you are uploading to it. And note which way round the connectors to the LCD go.

If you’re using the Arduino IDE, you need to add this declaration at the top of lcd_serial.ino

static void showString (PGM_P s);

(I don’t know whether platformio needs that or not.)

1 Like

I see I see!
Okay, I have done the changes in the emonhub.config. I just added the declaration on top of the lcd_serial.ino contained in the firmware folder. Now, I only have one question, should I be compiling and uploading the src.ino file into the emon part? (using the arduino IDE under the type of arduino board I ll be getting out)

I am Gratefully Thankful for your precise instructions and constant help!

You need all the other files in the GitHub “firmware.src” as well as the ones you changed, then compile it as Arduino Uno.

If you take the “emon” PCB out and you’re using a programmer, plug it in on the FTDI header and it works exactly as an emonTx or an Arduino would. If you’re uploading with SSH via the Raspberry Pi, you must instead make the .hex file and upload that to your RPi, then use Avrdude to load it into the “emon” Atmel 328P.

As I wrote before, I have no idea how platformio does any of this, so I cannot help you with that.