BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Python Virtual_write problem on Raspberry pi 3

Hi, I am doing my uni project by using raspberry Pi 3 and python with blynk app. Currently, I got a problem with using python to send data to blynk app. I’m using dht22 sensor as a test to see the result on the app, but it does not appear any data, the temperature is V3 and humidity is V4 virtual pin. I tried to use virtual_write to debug, add a button to V1 or V0, when it is on, the data would be sent to the app, and this works My code is on the below

import BlynkLib
import Adafruit_DHT
import RPi.GPIO as GPIO
import time,os


# Initialize Blynk
BLYNK_AUTH = 'f894xx9b95x64xx39531xx75xx05xxe5'

blynk = BlynkLib.Blynk(BLYNK_AUTH)

##Initialize GPIO setup
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
FAN_PIN = 26. ##GPIO 26 as relay test
GPIO.setup(FAN_PIN, GPIO.OUT)
GPIO.output(FAN_PIN, GPIO.HIGH)

humidity,temperature = Adafruit_DHT.read_retry(22, 4)
# Register Virtual Pins
#@blynk.VIRTUAL_WRITE(0)
#def v0_write_handler(value):
#    if value == '1':
#        blynk.virtual_write(3,'{0:0.1f}'.format(tem))

# this WRITE debug works but use Virtual read then virtual write does not work

@blynk.VIRTUAL_READ(3)
def v3_read_handler():
    blynk.virtual_write(3,'{0:0.1f}'.format(tem))


@blynk.VIRTUAL_READ(4)
def v4_read_handler():
    blynk.virtual_write(4,'{0:0.1f}'.format(hum))

# Start Blynk (this call should never return)
blynk.run()


 

maybe this post could help you