Hey everyone. Recently I have been experimenting with the Python Blynk Library on a raspberry pi. I have successfully setup the library and have gotten the library mostly working. I am able to get data from a gps, button, display a value at the start of the program and send notifications. One thing I am struggling on is writing to a Labeled Value Display whenever I have data that needs to be updated. For example, when I first run my code, I set the display to “nothing”. I want to update the value display with coordinates from the gps whenever I receive those coordinates. I tried calling
blynk.virtual_write(10, 'new string')
but the display never seems to update. I have tried it a couple others ways as well, using a global variable and setting the display to update with the global variable every second, but nothing seems to work. Is this possible or am I just oblivious to an obvious solution? Any help is appreciated. Thank you! I will attach my code below for help.
import BlynkLib
import time
import gpiozero as gpio
ledP = gpio.LED(20)
BLYNK_AUTH = '' #PROJECT
BLYNK_AUTH_APP = '' #APP
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
lat = None
lon = None
steps = 0
Value_display = "Nothing"
@blynk.VIRTUAL_READ(10)
def v10_read_handler():
global Value_display
blynk.virtual_write(10, Value_display)
@blynk.VIRTUAL_WRITE(11)
def my_write_handler(value):
global lat,lon,steps, Value_display
if steps == 0:
lat = value
steps = steps + 1
elif steps == 1:
lon = value
steps = steps + 1
elif steps == 2:
steps = steps + 1
elif steps == 3:
steps = 0
latlon = (lat, lon)
print(latlon)
elif steps == 4:
steps = 0
latlon = (lat, lon)
print(latlon)
Value_display = 'String 2'
blynk.sync_all()
v10_read_handler()
@blynk.VIRTUAL_WRITE(20)
def my_write_handlers(value):
print('Current button value: {}'.format(value))
print(value)
if value == "1":
ledP.on()
#blynk.notify('You pressed the button and I know it')
else:
ledP.off()
@blynk.VIRTUAL_READ(21)
def v21_read_handler():
# Display a Gauge
import random
rannum = random.randint(1,20)*5
print(rannum)
blynk.virtual_write(21, rannum)
blynk.run()
Github link for easy downloading of code : Github