Sorry, having problems getting this onto the forum - bear with me please, it’s my first post.
Anyway, I have my Blynk app on an Andoid 8 Moto E5 and that seems to be fine. I have 3 buttons and one LED. All are virtual pins.
My code is written in Python and is running on a RPi 3B+.
The buttons operate as virtual writes to the Python code and they switch pins on the RPi and that works great!
My problem is getting the virtual read to work.
I have looked at the sample code in 02_virtual_read.py but I don’t see how to get the function to be called.
By the way, just to complicate matters the virtual pins make calls to MQTT, but that doesn’t appear to be part of my issue.
Here is my code …
import BlynkLib, time
from gpiozero import PWMLED
import paho.mqtt.client as mqtt
red = PWMLED(21) # set up LEDs to pulse using PWM
yellow = PWMLED(20) # for 201 r=3 y=4 g=2
green = PWMLED(16) # for Pi3 r=21 y=20 g=16
BLYNK_AUTH = '61cc1d16f6e0490db628c25423adba54' # Blynk code
blynk = BlynkLib.Blynk(BLYNK_AUTH) #Initialise Blynk
status = 0 # This is for the virtual read for the LED
mqttc.connect("192.168.1.203", 1883,60) #sub Q on 203, port 1883, 60 sec keep alive
@blynk.VIRTUAL_WRITE(1) #Register Virtual Pin
red.value=1 # Switch on LED
print('ON RED'+str(status)) # Print update
mqttc.connect("192.168.1.203", 1883,60) # connect
mqttc.publish("hello/world", "RED on" ,1) # Publish to MQ try QOS 1
mqttc.publish("highmount/heating", "R3on" ,1) # Publish to 199
mqttc.disconnect() # disconnect
mqttc.publish("hello/world", "RED off" ,1)
mqttc.publish("highmount/heating", "R3off" ,1) # Publish to 199
@blynk.VIRTUAL_READ(4) # Now get the app to read this..
blynk.virtual_write(4, status // 1000)
blynk.run() # Start Blynk (this call should never return)
mqttc.loop_forever() # try this to keep it sending messages
So what I am looking for is the syntax to get the VIRTUAL_READ to get read? How do I do that?
I tried adding the “//1000” but I don’t know what that does.
Is there any more detailed documentation beyond the stuff at https://github.com/vshymanskyy/blynk-library-python ?