Power factor on Emoncms from emonPi

The problem, which you’ve identified, is the information is available but it is not sent to emonCMS.

The solution is a little complicated:

  1. You must download from GitHub and edit the sketch that runs on the Atmega328P inside your emonPi to send those values.
  2. You must compile the sketch on the emonPi (or transfer the compiled sketch onto the emonPi) and load it into the Atmega328P.
  3. You must edit emonHub to accept the new values and send them to emonCMS.

1). The source file is here: GitHub - openenergymonitor/emonpi: Raspberry Pi Based Energy Monitor. Hardware, Firmware & related software for the PI.
You need to edit src.ino to add the things you want to send. Around line 133, you must name the new variables and add them to the data structure. You can choose your own names, I’ve added my suggestion in bold. You do not need both powerFactor and apparentPower, because powerFactor = realPower / apparentPower.

typedef struct { int power1;
int apparentPower1;
int powerFactor1;
int power2;
int apparentPower2;
int powerFactor2;
int power1_plus_2; int Vrms; int temp[MaxOnewire]; unsigned long pulseCount; } PayloadTX; // create JeeLabs RF packet structure - a neat way of packaging data for RF comms PayloadTX emonPi;

Next, you must assign the calculated values to those names. At around line 280, immediately after the line
ct1.calcVI(no_of_half_wavelengths,timeout);
you must add:
emonPi.apparentPower1=ct1.apparentPower; emonPi.powerFactor1=ct1.powerFactor*100;

And similarly for input no 2 (ct2), a little lower down the sketch.

2). Using the Arduino IDE, compile the sketch, you’ll need to check the Arduino documentation for your operating system to find out where it puts the compiled (.hex) file.
You load the compiled .hex file using the instruction here: EmonPi - OpenEnergyMonitor Wiki

3). Finally, you need to change emonhub.conf to make it accept the changes. When you have done that, the emonPi will again be recognised (it will disappear if you try it after you make the change above). Look at the comment at the top of the sketch. This gives the emohub.conf setup for the emonPi (Node 5) before you changed it. The four lines, names = …, datacodes = …, scales = … and units = … tell emonHub what is coming. You must add the new variables names etc (I have made them bold) in the correct places (there is a 1:1 relationship along the 4 lines):

[[5]]
    nodename = emonPi
    firmware = emonPi_RFM69CW_RF12Demo_DiscreteSampling.ino
    hardware = emonpi
    [[[rx]]]
       names = power1,apparentPower1,powerFactor1,
         power2,apparentPower2,powerFactor2, power1_plus_power2,Vrms, T1,T2,T3,T4,T5,T6,pulseCount
       datacodes = h, h, h, h, h, h, h, h, h, h, h, h, h, h, L
       scales = 1, 1, 0.01, 1, 1, 0.01, 1,0.01,0.1,0.1,0.1,0.1,0.1,0.1,1
       units = W,VA,n, W,VA,n, W,V,C,C,C,C,C,C,p

We need a scale of 0.01 for power factor because we multiplied by 100 to send the value as an integer, here we convert it back to a decimal.
Make those changes in your emonhub.conf file.

I have not had time to test this, but it should be correct (someone who knows more will no doubt correct me if it is not).

2 Likes