I created a new main.py that just uses just the flowmeter.py and uasyncio
full code is at https://github.com/thetreerat/WaterPump
=== main irc code ===
flowCount = 0
"""Add on to Counter """
flowCount += 1
print("""callback count: %s""" % (flowCount))
#register callback for flowmeter
=== end ====
=== Monitor flow coro ===
async def monitorFlowMeter(self):
"""coroutine for monitoring flow"""
print("""MonitroFlowMeter count: %s""" % (flowCount))
=== end ===
I get a this when I reboot the controller. I tried it with my image with frozen bitcode last pull micropython 3 days ago, 1.8.7 seems to not work with the current uasyncio, and esp8266-20170428-v1.8.7-673-g49de9b6.bin
==== error on 1.8.7-673 ====
Traceback (most recent call last):
File "main.py", line 29, in <module>
File "/flash/lib/uasyncio/core.py", line 129, in run_forever
File "/flash/lib/uasyncio/core.py", line 87, in run_forever
File "WaterPumps/flowMeters.py", line 75, in monitorFlowMeter
NameError: name 'flowCount' is not defined
==== end error =====
I know it something I am missing or don't understand.
per your comment on irq and application design.
Flow sensor is just a hall affect sensor, so I think that it needs to be a irq callback that just increases the count on every hit.
I am assuming that way I do not loose pluses.
if in the process of setting the var, if I have the monitor coroutine reset 0 when it reads, a interrupt comes in but that would be only one pulse that gets lost, and not cause errors(right?). This would cause the flow rate to be off (low).
would it be better to let counter just grow, and keep track of last read and current read in monitor. This way the coroutines only read the var. I was worried that this would cause the program to crash when the var gets to big, or dose micropython handle the var when it grows too big.
The thought I had last night was that I could build a driver board that would do the counting, caluating the flow rate and conncect this to the board with ic2 but I have to do lots of research and might be over kill for just running to pumps for home.
sorry for the long reply.
thanks for any help