That is what I have done. Not going full tilt but seems to work OK.
2020-06-30 10:43:08,444 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 94
2020-06-30 10:43:09,446 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 95
2020-06-30 10:43:10,020 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 96
2020-06-30 10:43:10,070 DEBUG pulse2 75 NEW FRAME :
2020-06-30 10:43:10,074 DEBUG pulse2 75 Timestamp : 1593510190.0
2020-06-30 10:43:10,077 DEBUG pulse2 75 From Node : 3
2020-06-30 10:43:10,081 DEBUG pulse2 75 Values : [96]
2020-06-30 10:43:10,084 DEBUG pulse2 75 Sent to channel(start)' : ToEmonCMS
2020-06-30 10:43:10,087 DEBUG pulse2 75 Sent to channel(end)' : ToEmonCMS
2020-06-30 10:43:10,277 DEBUG MQTT Publishing: emon/3/Pulse 96
2020-06-30 10:43:10,336 DEBUG MQTT3 Publishing: emon/3/Pulse 96
2020-06-30 10:43:10,340 DEBUG MQTT2 Publishing: emon/3/Pulse 96
2020-06-30 10:43:10,577 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 97
2020-06-30 10:43:11,131 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 98
2020-06-30 10:43:11,689 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 99
2020-06-30 10:43:12,017 DEBUG pulse2 76 NEW FRAME :
2020-06-30 10:43:12,020 DEBUG pulse2 76 Timestamp : 1593510192.0
2020-06-30 10:43:12,023 DEBUG pulse2 76 From Node : 3
2020-06-30 10:43:12,026 DEBUG pulse2 76 Values : [99]
2020-06-30 10:43:12,029 DEBUG pulse2 76 Sent to channel(start)' : ToEmonCMS
2020-06-30 10:43:12,033 DEBUG pulse2 76 Sent to channel(end)' : ToEmonCMS
2020-06-30 10:43:12,118 DEBUG MQTT Publishing: emon/3/Pulse 99
2020-06-30 10:43:12,191 DEBUG MQTT3 Publishing: emon/3/Pulse 99
2020-06-30 10:43:12,194 DEBUG MQTT2 Publishing: emon/3/Pulse 99
2020-06-30 10:43:12,247 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 100
2020-06-30 10:43:12,801 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 101
2020-06-30 10:43:13,359 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 102
2020-06-30 10:43:13,917 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 103
2020-06-30 10:43:14,056 DEBUG pulse2 77 NEW FRAME :
2020-06-30 10:43:14,069 DEBUG pulse2 77 Timestamp : 1593510194.0
2020-06-30 10:43:14,081 DEBUG pulse2 77 From Node : 3
2020-06-30 10:43:14,085 DEBUG pulse2 77 Values : [103]
2020-06-30 10:43:14,107 DEBUG pulse2 77 Sent to channel(start)' : ToEmonCMS
2020-06-30 10:43:14,111 DEBUG pulse2 77 Sent to channel(end)' : ToEmonCMS
2020-06-30 10:43:14,228 DEBUG MQTT3 Publishing: emon/3/Pulse 103
2020-06-30 10:43:14,232 DEBUG MQTT2 Publishing: emon/3/Pulse 103
2020-06-30 10:43:14,258 DEBUG MQTT Publishing: emon/3/Pulse 103
2020-06-30 10:43:14,471 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 104
2020-06-30 10:43:15,031 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 105
2020-06-30 10:43:15,589 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 106
2020-06-30 10:43:16,045 DEBUG pulse2 78 NEW FRAME :
2020-06-30 10:43:16,048 DEBUG pulse2 78 Timestamp : 1593510196.0
2020-06-30 10:43:16,052 DEBUG pulse2 78 From Node : 3
2020-06-30 10:43:16,057 DEBUG pulse2 78 Values : [106]
2020-06-30 10:43:16,062 DEBUG pulse2 78 Sent to channel(start)' : ToEmonCMS
2020-06-30 10:43:16,067 DEBUG pulse2 78 Sent to channel(end)' : ToEmonCMS
2020-06-30 10:43:16,148 DEBUG Dummy-5 pulse2 : Pulse Channel 15 pulse: 107
2020-06-30 10:43:16,165 DEBUG MQTT2 Publishing: emon/3/Pulse 106
2020-06-30 10:43:16,170 DEBUG MQTT3 Publishing: emon/3/Pulse 106
2020-06-30 10:43:16,185 DEBUG MQTT Publishing: emon/3/Pulse 106
In the init, define the start point
self.last_time = time.time()
In the read check for when last called - fixed time of 2 seconds.
if not self.pulse_received:
return False
elif self.last_time + 2 > time.time():
return False
self.pulse_received = False
self.last_time += 2
Yes, I know it needs tidying up.
There is also a race condition between setting the flag to false and reading the number of pulses. I think at worst, the ‘read’ would return the same pulse number twice.
Instead of setting a received flag would it be better to keep a ‘last count’ and compare the new count against the last count?
There is also the point that the accumulator does not need to be a dict. We started off with reading several pins in the one interfacer but decided to move to multiple interfacers one for each pin if required.