consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(logFormatter) _log.addHandler(consoleHandler) _log.setLevel(parser.get('logging', 'logLevel', fallback=logging.CRITICAL)) _log.critical("critical") _log.error("error") _log.warning("warning") _log.info("info") _log.debug("debug") _log.info("/home/pi/droneponics/config/configAir/" + drone.gethostname() + ".ini") # Initialize Blynk _log.debug("Creating blynk object for BLYNK_AUTH " + parser.get('blynk', 'BLYNK_AUTH')) blynk = blynklib.Blynk(parser.get('blynk', 'BLYNK_AUTH')) timer = blynktimer.Timer() _log.debug("Created blynk object and timer for BLYNK_AUTH " + parser.get('blynk', 'BLYNK_AUTH')) #except: # _log.critical("Failed to create object for the blynk") # _log.critical("Set log level to CRITICAL to auto reboot") # if (parser.get('logging', 'logLevel', fallback=logging.DEBUG) =="CRITICAL"): # os.system('sh /home/pi/updateDroneponics.sh') # os.system('sudo reboot') try: tslI2C = busio.I2C(board.SCL, board.SDA) if not 0x29 in tslI2C.scan(): tslI2C = busio.I2C(board.D1, board.D0) if not 0x29 in tslI2C.scan():
# Setup the LED LED = 'USR3' GPIO.setup(LED, GPIO.OUT) GPIO.output(LED, 1) # Setup the button button = 'P9_11' GPIO.setup(button, GPIO.IN) # print("button: " + str(GPIO.input(button))) # Get the autherization code (See setup.sh) BLYNK_AUTH = os.getenv('BLYNK_AUTH') # Initialize Blynk blynk = blynklib.Blynk(BLYNK_AUTH) # Register Virtual Pins # The V* says to response to all virtual pins @blynk.handle_event('write V0') def my_write_handler(pin, value): print('Current V{} value: {}'.format(pin, value)) GPIO.output(LED, int(value[0])) # This calback is called everytime the button changes # channel is the name of the pin that changed def pushed(channel): # Read the current value of the input state = GPIO.input(channel)
consoleHandler = logging.StreamHandler() consoleHandler.setFormatter(logFormatter) _log.addHandler(consoleHandler) _log.setLevel(parser.get('logging', 'logLevel', fallback=logging.DEBUG)) _log.critical("critical") _log.error("error") _log.warning("warning") _log.info("info") _log.debug("debug") _log.info("/home/pi/droneponics/config/configMonitor/" + drone.gethostname() + ".ini") # Initialize Blynk blynk = blynklib.Blynk(parser.get('droneMonitor', 'BLYNK_AUTH')) timer = blynktimer.Timer() blynk.run() #blynk.virtual_write(98, "clr") blynk.set_property(systemLED, 'color', drone.colours['ONLINE']) _log.info("Blynk created") sensors = [] sensors = drone.buildSensors(sensors, _log) _log.info("All Monitor Sensors created") # Initialize the sensor. # try: # for sensor in sensors: # sensor.sensor = AtlasI2C(sensor.sensorId) # blynk.set_property(sensor.displayPin, 'color', colours['ONLINE'])
from threading import Thread import blynklib blynk = blynklib.Blynk("IwQyTY8WqD0SkkLROJM9mHomLPOrzRrj") measuring = False @blynk.handle_event("write v1") def change_state(pin, value): print(pin, value) global measuring measuring = value[0] == '1' def measure(): while True: if measuring: ''' measure pulse rate here ''' print("measuring") Thread(target=measure).start() while True: blynk.run()
#!/usr/bin/env python3 import blynklib from display_mod import * import random ORDER = neopixel.GRBW num_pix = 17 crickit.init_neopixel(num_pix, bpp=4, pixel_order=ORDER) np = crickit.neopixel BLYNK_AUTH = 'API_KEY_HERE' blynk = blynklib.Blynk(BLYNK_AUTH, server='SERVER_ADDR_HERE', port=8080) @blynk.handle_event('write V0') def animate_pix1(pin, value): if int(value[0]) == 1: fill_strip(np, num_pix, AQUA) sleep(0.1) if int(value[0]) == 0: fill_strip(np, num_pix, BLACK) sleep(0.1) @blynk.handle_event('write V1') def animate_pix2(pin, value): if int(value[0]) == 1: randomFlashes(np, 4) sleep(0.1)
def bl(self): blynk = blynklib.Blynk('1234', log=print) yield blynk