Hello,
I can’t find any advice on how to set up emoncms.
I use ESP32 for water meter (one turn = 1 litr) , one turns water meter → ESP will send emoncms pulse “1” → then (pause) send “0” → next turn ESP32 send “1”…and so on. Emoncms record only 0 or 1. I need to add these impulses together one day.
example count pulse: 1+0+1+0+1+0+1+0+1 = 5 pulses
I tried using “Total pulse count to pulse increment” but without result.
Can you help me?
Welcome, @Frantisek to the OEM forum.
How often are pulses generated?
Normally, we count pulses as early as possible, then every 5 or 10 s we send the number of pulses counted to emoncms and use the “accumulate” function. But if you send the number faster than the Feed Interval you choose in emonCMS, pulses will be lost because it accepts only the last number to arrive during that interval.
Alternatively, we accumulate the count of pulses over all time and send this always-increasing number to emonCMS.
If you do as you are doing, you must set the Feed Interval in emonCMS to be at least equal to the rate at which pulses arrive - which might not be practical. Therefore, I recommend you accumulate the pulses in your ESP32 and every 10 or however many seconds you want (ideally a fraction less, say every 9.8 s if your Feed Interval is 10 s), and send that number, so 0 … 1 … 4 … 7 … 10 … 10 … 10 … 11 … 11 … 11 … (meaning a little water was used for the first 3 intervals, then none, a little, and finally none again).
When turn water meter ESP32 immediately send pulse “1”.
-I will try send impulses every 60second.
-I will try accumulate pulse and send increased summary pulse.
You can look at one of our sketches for the emonTx to see how we count pulses.
- We set the input pin to generate an interrupt.
- When a pulse is received the Interrupt Service Routine adds to the count of pulses.
- When it is time to send the data to emonCMS - every 9.8 s, the main program adds
From the emonPi sketch, setup:
attachInterrupt(emonPi_int1, onPulse, FALLING); // Attach pulse counting interrupt on RJ45 (Dig 3 / INT 1)
emonPi.pulseCount = 0; // Reset Pulse Count
The Interrupt Service Routine:
void onPulse()
{
if ( (millis() - pulsetime) > min_pulsewidth) {
pulseCount++; //calculate wh elapsed from time between pulses
}
pulsetime=millis();
}
And in the main program:
if (pulseCount) // if the ISR has counted some pulses, update the total count
{
cli(); // Disable interrupt just in case pulse comes in while we are updating the count
emonPi.pulseCount += pulseCount;
pulseCount = 0;
sei(); // Re-enable interrupts
}
It is emonPi.pulseCount
, the always-increasing pulse count, that is sent to emonCMS.every 9.8 s.