I’m trying to use the BlynkLib for python (Running on a Raspberry pi 3) to read in data from multiple files and display it in a superchart on my smart phone. I’ve been confused by a lot of the documentation so far, as it’s unclear to me how to send the actual data using “blynk.run()”. Here is the code I’ve developed so far:
import datetime
import time
import BlynkLib
BLYNK_AUTH = "xxxxx"
# Initalize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
#Read data from pH, Temp, Air Temp, and Humd files
pHDatafile = "/home/pi/Logs/LastpH.csv"
TempDatafile = "/home/pi/Logs/LastWaterTemp.csv"
AirTempDatafile = "/home/pi/Logs/LastAirTempHum.csv"
#Define function to write to each virtual pin
def pHBlynker(pHdata):
blynk.virtual_write(2, pHdata)
print(pHdata)
def TempBlynker(Tempdata):
blynk.virtual_write(3, Tempdata)
print(Tempdata)
def AirTempBlynker(AirTempdata):
blynk.virtual_write(4, AirTempdata)
print(AirTempdata)
def RHBlynker(RHdata):
blynk.virtual_write(5, RHdata)
print(RHdata)
while True:
blynk.run()
#Read in most recent pH data point
pHFile = open(pHDatafile, 'r')
pHData = pHFile.readline()
pHData = float(pHData)
pHFile.close()
#Read in most recent barrel temp data point
TempFile = open(TempDatafile, 'r')
TempData = TempFile.readline()
TempData = float(TempData)
TempFile.close()
#Read in most recent data point
AirFile = open(AirTempDatafile, 'r')
data = AirFile.readline()
spliter = data.split(',')
AirTemp = float(spliter[0])
RH = float(spliter[1])
AirFile.close()
pHBlynker(pHData)
TempBlynker(TempData)
AirTempBlynker(AirTemp)
RHBlynker(RH)
time.sleep(60)
Within the while loop, I’d like to read in each of these files, and push the data to my Blynk chart, but it looks like this code only sends the data once, and after running for a short amount of time returns a connection error