The following test code is used to turn on/off several widget leds.
The code connects to blynk-clouds (have not tried a local server yet) and works fine for a while till it crushes with a Broken Pipe error 32. To recover automatically from it (since I cannot find the reason of the crush), I’m using the sync_all() function but, I get a warning shown below. How are the v pins registered in Python?
TIA
#!/usr/bin/env python
#import libraries
import BlynkLib
import sys
from gpio import ledsOn #from gpio.py script
BLYNK_AUTH = '****'
#widgets virtual leds
wleds = [11,12,13,14,15,16]
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
#get leds status to turn leds ON/OFF on app
def widgetsleds():
ledslist = []
for i in range(6): #total 6 contacts
ledslist.insert(i,ledsOn(i)) #get swicth status
if ledslist[i] == 1:
blynk.virtual_write(wleds[i], 0)
else:
blynk.virtual_write(wleds[i], 255)
ledslist.clear()
def blynk_connected():
print("Updating all values from the server...")
blynk.sync_all()
def blynk_loop():
# Start Blynk (this call should never return)
blynk.run()
#activate timers must be multiple of 50ms
blynk.set_user_task(widgetsleds(), 1000)
if __name__ == "__main__":
while True:
try:
blynk_loop()
except BrokenPipeError as e:
print('Socket error {}'.format(e))
blynk.on_connect(blynk_connected)
except IOError as e:
if e.Errno == Errno.EPIPE:
print('EPIPE error {}'.format(e))
blynk.on_connect(blynk_connected)
else:
print("Unexpected error:", sys.exc_info()[0])
raise
I believe this means you have a widget set to V20 in your project that has no registered (matching) code in your script. Normally it would not do anything until used in the App, or called by a sync command, and then you get the error.
Well it was an answer from me as I have seen that error many times until I realised the issue and removed the rogue widget I was unaware that I wasn’t using. BTW, it will do the same thing if presented with an API call for same missing vPin, so no widget required for that.