Count time that feed is above

I want to calculate the amount of time that a certain feed (power1) is above a certain level (100 watts). Does anyone know how to achieve this? I thought it could be accomplished by creating an "input on-time" variable, but that does not allow me to specify a treshold...

Robert Wall's picture

Re: Count time that feed is above

Do the logic in the sensor node or the base node, and send it as a separate quantity?

fversteegen's picture

Re: Count time that feed is above

Thanks Robert, but how? I already figured I need to do the logic there, but would I need to do something like this:

(Power1 - 100) -> ontime

Sorry for being a Emoncms newbie...

Robert Wall's picture

Re: Count time that feed is above

First, you need to add a variable to the data structure:

typedef struct { int power1, power2, power3, Vrms; } PayloadTX;         // neat way of packaging data for RF comms
PayloadTX emontx;

becomes (note the comma):

typedef struct { int power1, power2, power3, Vrms, power1On; } PayloadTX;         // neat way of packaging data....
PayloadTX emontx;

Then somewhere in loop(  ) after you know the value of power1, which is the middle line here:

  ct1.calcVI(20,2000);                                                  // Calculate all. No.of crossings, time-out
  emontx.power1 = ct1.realPower;
  Serial.print(emontx.power1);

but before the values are sent out by radio - send_rf_data(); - you add the logic:

 if (emontx.power1 > 100)
    emontx.power1On = 1;
else
    emontx.power1On = 0;

or if you want to be really economical with the typing:

emontx.power1On = (emontx.power1 > 100) ? 1 : 0;

Both versions are equivalent, and set power1On to 1 or zero depending on the value of power1 being greater than 100 or not.

Your base should handle the change automatically, but if you have an emonGLCD you might need to modify the struct in that sketch (but if you don't want to display the state, do nothing more with it there).

Then of course in emoncms, a new Input should pop up and you can apply the input on-time to it.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.