Update to continuous monitoring, random "-4" power readings?

Hi,

I updated my emonpi to continuous monitoring today, making the required changes to the emonhub config and blowing the firmware.

All seems to be OK until I look in the emonhub log, for example:

2024-06-06 12:38:22,912 DEBUG RFM2Pi 63 NEW FRAME : OK 5 62 0 0 0 222 1 0 0 222 1 55 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 65 0 0 0 0 0 0 0 (-0)
2024-06-06 12:38:22,916 DEBUG RFM2Pi 63 Timestamp : 1717673902.911705
2024-06-06 12:38:22,917 DEBUG RFM2Pi 63 From Node : 5
2024-06-06 12:38:22,918 DEBUG RFM2Pi 63 Values : [62, 478, 0, 478, 0.55, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0.0]

Then, ten seconds later I see:

2024-06-06 12:38:32,776 DEBUG RFM2Pi 64 NEW FRAME : OK 5 63 0 0 0 252 255 0 0 252 255 56 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 65 0 0 0 0 0 0 0 (-0)
2024-06-06 12:38:32,781 DEBUG RFM2Pi 64 Timestamp : 1717673912.776247
2024-06-06 12:38:32,782 DEBUG RFM2Pi 64 From Node : 5
2024-06-06 12:38:32,782 DEBUG RFM2Pi 64 Values : [63, -4, 0, -4, 0.56, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0.0]

As you can see, I and getting a ā€˜-4ā€™ reading.

After this message, all continues as normal until I see another ā€˜-4ā€™ reading.

Could anyone give me some tips please?

Welcome, Jason, to the OEM forum.

Whatā€™s happened to your voltage - why only 0.55 ā€“ 0.56 V? Have you forgotten your a.c. adapter, or has it got unplugged or failed?

Hi Robert,

Itā€™s odd isnā€™t it?

My setup is simple enough an emonpi which had the RF board on it. It has been working for a god few years. The pi is powered from an adapter; no adapter, no comms!

Perhaps I should open it up and check that the board looks OK?

I didnā€™t mean the 5 V d.c. power supply, Iā€™m interested in the a.c. adapter from which it gets a sample of the a.c. mains in order to measure it and compute the real (or active) power. It plugs into the socket labelled ā€œ9V AC SAMPLEā€. You should be seeing a value of about 240 V for the 5th value, not 0.56 V.

My suspicion is thereā€™s not quite enough voltage there when it reads 0.55 V to trigger the voltage detector, so it guesses apparent power based on an assumed 240 V; but when it sees 0.56 V, it reverts to doing as it should and calculates real power, but with a weird phase shift hence the negative value.

Hence my suggestion that your a.c. adapter isnā€™t giving out the correct 12 V or so (even though it says 9 V on the label).

Ah yes, I had forgotten about the capability to use a PSU to provide a sense value for the a.c. supply voltage.

The thing is, I donā€™t have that PSU. Perhaps this means that we have a problem with ripple?
But, Iā€™m not sure - Iā€™m looking at EmonLibCM_interrupt where the acPresent flag is set.

I see that there looks to be problematic code in that ISR - the calculation seems to be as follows (omitting all code that does not access acSense) ā€¦

  static unsigned int acSense = 0;
  .
  .
  .
      acSense -= acSense >> 2;
      acSense += sampleV_minusDC > 0 ? sampleV_minusDC : -sampleV_minusDC;
      acPresent = acSense > acDetectedThreshold;

This is odd - acSense does not seem to be read anywhere before the calculation is made?
Doesā€™t this make the value of acPresent random ?

The full snip of code is belowā€¦

  static unsigned int acSense = 0;
  
#ifdef SAMPPIN
    digitalWrite(SAMPPIN,HIGH);
#endif
  
  rawSample = ADC;
  next = sample_index + 2;
  if (next>no_of_channels)                 // no_of_channels = count of Current channels in use. Voltage channel (0) is always read, so total is no_of_channels + 1
      next -= no_of_channels+1;
  
  ADMUX = ADCRef + ADC_Sequence[next];     // set up the next-but-one conversion
#ifdef SAMPPIN
    digitalWrite(SAMPPIN,LOW);
#endif
  // Count ADC samples for timing when voltage is unavailable
  missing_VoltageSamples++;

  
  if (sample_index==0)                                               // ADC_Sample 0 is always the voltage channel.
  {
#ifdef SAMPPIN
    digitalWrite(SAMPPIN,HIGH);
#endif
      // Removing the d.c. offset - new method:
      // Rather than use a filter, which takes time to settle and will always contain a residual ripple, and which can lock
      // up under start-up conditions, it is possible to remove the effect of the offset at the final stage of measurement.
      // First take off the theoretical (constant) offset to reduce the size of the numbers (as Robin's original method).
      // Then accumulate the sum of the resulting values so as to be able at the end of the measurement period to 
      // recalculate the true rms based on the rms with the offset and the average remaining offset. The remaining offset 
      // should be only a few counts.
      //
      lastSampleV_minusDC = sampleV_minusDC;                         // required for phaseCal algorithm
      sampleV_minusDC = rawSample - (ADC_Counts >> 1);               // remove nominal offset (a small offset will remain)
      // Detect the ac input voltage. This is a 'rough&ready" rectifier/filter. It only needs to be good enough to detect
      //  sufficient voltage to provide assurance that the crossing detector will function properly
      acSense -= acSense >> 2;
      acSense += sampleV_minusDC > 0 ? sampleV_minusDC : -sampleV_minusDC;
      acPresent = acSense > acDetectedThreshold;

I donā€™t understand your thinking.

      // Detect the ac input voltage. This is a 'rough&ready" rectifier/filter. It only needs to be good enough to detect
      //  sufficient voltage to provide assurance that the crossing detector will function properly

What you have in the lines following that explanation is a variable that gets the peak value and then decays with each sample set. Itā€™s not expected nor intended to do anything other than what it says. Bear in mind too that without the mains voltage reference, all you are able to measure is current, it wonā€™t and canā€™t give you an accurate value of the quantity you pay for, which is energy, the time integral of real (active) power, because you canā€™t calculate power without knowing the instantaneous relationship between current and voltage.

If you donā€™t intend to use the voltage, then your easiest change is in line 215 - just raise the threshold, say:
unsigned int acDetectedThreshold = ADC_Counts >> 3;
which if itā€™s triggering on pickup spikes with an rms value of 0.56 V, should raise that to over 2 V, yet low enough to still work with an a.c. adapter.

If this is indeed the problem, youā€™re only the second person to report it, the emonPiCM has been available for nearly 3 years, and emonLibCM has been used in the emonTx V3 (with effectively the same hardware) for over 5 years, so itā€™s not exactly a common problem.

Itā€™s not really a PSU, just a ā€œwall wart.ā€
(just in case you or - other users - were thinking that itā€™s an actual power supply)

Well, itā€™s a transformer isnā€™t it? A kind of power supply ā€¦

But itā€™s not supplying any significant power, all the power comes from the 5 V d.c. psu.

Sorry Robert, I had missed the ā€˜staticā€™ storage classifier - I was rushing out when I send the last post.

Iā€™m fully aware of how to calculate power in systems - in my case, Iā€™m more interested in the pattern of current draw rather than any absolute accuracy though - this allows me to spot what is happening in our home.

Perhaps to actually solve the problem I had though, it might be better to ensure that only sensible values are returned from the library? Returning a negative value, for example, is clearly not a good idea. Alternatively, a configuration flag would allow for the problem to be obviated once and for all? Iā€™ll ponder and send you a pull request when I get to it.

When Iā€™m back from holidays in a couple of weeks, Iā€™ll pop the scope on to see what is happening on the ADC input - it could be that I am suffering from some unexpected noise.

Meanwhile Iā€™ll make the change you suggest to see if that resolves my short-term problem.

Iā€™ll update when I know a bit more - but many thanks for now.

Yes, itā€™s used to sense voltage here, but the device is a PSU ā€¦ thatā€™s what the data sheet says!

Really? What if you have PV and want to know how much electricity youā€™re exporting?

Iā€™ve done/repeated some tests:
unsigned int acDetectedThreshold = ADC_Counts >> 5; show AC detected around 9.6 V
ADC_Counts >> 4 moves it to around 19 V,
ADC_Counts >> 3 moves it to around 39 V.

With the a.c. adapter unplugged, it reads between 0.06 and 0.12 V.

All this was done with an emonTx V3.4 out of its case. I donā€™t think I can justify changing emonLibCM on the evidence so far, especially as no more emonTxā€™s or emonPis will be sold with software that uses emonLibCM.

Ah yes, as my main use for the past number of years has been measuring usage rather than managing feed in, I had missed that point.

Perhaps emonhub should so something about that ā€¦ it can understand the context and can be easily configured.

Iā€™m going to look a little deeper - what is interesting is that the power value being returned is plausible yet with an obviously incorrect VRMS.

The ā€˜-4ā€™ is also consistent - also odd.

Iā€™ll take a look over the next few days.

icon_question icon_question

It would make sense for emonhub to discard data that is invalid in the context of a feed.

A simple flag or feed type that indicated that a feed was import only, export only or both would make sense wouldnā€™t it?

Otherwise, how is junk data spotted and discarded?

BTW, I donā€™t think It is appropriate for the firmware to understand the context of a feed - although it might discard data that is clearly junk.

You can already discard ā€œjunkā€ input data before adding it to a feed, why duplicate that capability in emonHub?

For example, hereā€™s input processing I use to set any values from my Solar of ā€œless than 5ā€ to zero before logging them to the feed. Any value greater than 5W is logged as normal.

My solar inverter shows a few W of power generation during the night that I wanted to filter out.

1 Like

If that relates to Github, donā€™t bother, I donā€™t use it so Iā€™ll never see it. The procedure is to post in the support topic related to the post from where you download emonLibCM (thereā€™s a link on that page) for consistency, but Iā€™ll probably see it anywhere else on this forum.