I am observing strange behavior of the virtual pin read event handler in python. Here is the case:
HW is Raspberry pi. In the app:
One “Numeric Input” widget on virtual pin 10 (get volume to be pumped)
One “Value display” widget on VP11 (display how long will take the pumping)
One “Button” widget on VP12 to trigger the pump
One “Value display” widget to show,when pump has been turned on, how much time is left before it is turned off.
The code here below works fine for pump1.
The second part of the code is the exact same code with pump2 on VP14-17 but for some reasons, the value display widgets are not updated (the events are not handled).
Any idea ?
Thanks
#------------------------------------------- P U M P 1 -----------
PUMP1_duration = 0
NOW_PUMPING1 = False
PUMP1_off = time.time()
# register handler for virtual pin V10 write event (get volume to be pumped)
@blynk.handle_event('write V10')
def write_virtual_pin_handler(pin, value):
global PUMP1_duration
PUMP1_duration = float(value[0])/flowRatePump1
# register handler for virtual pin V11 reading (display duration of pumping)
@blynk.handle_event('read V11')
def read_virtual_pin_handler(pin):
global PUMP1_duration
blynk.virtual_write(pin, PUMP1_duration)
# register handler for virtual pin V12 write event (push button to trigger the pump)
@blynk.handle_event('write V12')
def write_virtual_pin_handler(pin, value):
global PUMP1_duration
global PUMP1_off
global NOW_PUMPING1
NOW_PUMPING1 = True
PUMP1_off = time.time()+PUMP1_duration
pin0.value = True
# register handler for virtual pin V13 reading (time left fefore switchng off pump1)
@blynk.handle_event('read V13')
def read_virtual_pin_handler(pin):
global PUMP1_off
global NOW_PUMPING1
timeLeft = max(0,int(PUMP1_off - time.time()))
blynk.virtual_write(pin,timeLeft)
if timeLeft == 0 and NOW_PUMPING1:
NOW_PUMPING1 = False
pin0.value =False
#------------------------------------- P U M P 2 ------------------------------------
PUMP2_duration = 0
NOW_PUMPING2 = False
PUMP2_off = time.time()
# register handler for virtual pin V14 write event (get volume to be pumped)
@blynk.handle_event('write V14')
def write_virtual_pin_handler(pin, value):
global PUMP2_duration
PUMP2_duration = float(value[0])/flowRatePump2
# register handler for virtual pin V15 reading (display duration of pumping)
@blynk.handle_event('read V15')
def read_virtual_pin_handler(pin):
global PUMP2_duration
blynk.virtual_write(pin, PUMP2_duration)
# register handler for virtual pin V16 write event (push button to trigger pump2)
@blynk.handle_event('write V16')
def write_virtual_pin_handler(pin, value):
global PUMP2_duration
global PUMP2_off
global NOW_PUMPING2
NOW_PUMPING2 = True
PUMP2_off = time.time()+PUMP2_duration
pin1.value = True
# register handler for virtual pin V17 reading (time left fefore switchng off pump2)
@blynk.handle_event('read V17')
def read_virtual_pin_handler(pin):
global PUMP2_off
global NOW_PUMPING2
timeLeft = max(0,int(PUMP2_off - time.time()))
blynk.virtual_write(pin,timeLeft)
if timeLeft == 0 and NOW_PUMPING2:
NOW_PUMPING2 = False
pin1.value = 0