I have a raspi running Blynk-Library-Python to monitor my solar panels. I want to be able to write the solar wattage value to a ESP8266 that controls a device which I want to run only when the panels are generating above a certain level. I see many good examples for setting up the bridge code for Arduino, but none for python library. appreciate any help on proper syntax for python
"""
Downloads, docs, tutorials: http://www.blynk.cc
"""
import BlynkLib
import time
import smbus
import time
import struct
bus = smbus.SMBus(1)
address = 0x03
solar_data = [0.0,0.0,0.0,0.0]
BLYNK_AUTH = 'xxxxxxx'
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
# Register virtual pin handler
@blynk.VIRTUAL_READ(2)
def v2_read_handler():
global solar_data
valid = True
while valid:
try:
data = bus.read_i2c_block_data(address, 0);
valid = False
except:
print "Error getting data\n"
for i in range(0, 4):
bytes = data[4*i:4*i+4]
# Python 2 struct.unpack takes the data to be unpacked
# in string format, so the bytes need to be joined
solar_data[i] = struct.unpack('f', "".join(map(chr, bytes)))[0]
# This widget will show solar data..
blynk.virtual_write(2, solar_data[3])
# blynk.virtual_write(3, solar_data[0])
@blynk.VIRTUAL_READ(3)
def v3_read_handler():
global solar_data
blynk.virtual_write(3, solar_data[0])
# Start Blynk (this call should never return)
blynk.run()