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

Blynk app gives wrong temperature and humidity reading

hy my this sketch run succesfully on python

import Adafruit_DHT
import BlynkLib
import time
sensor=Adafruit_DHT.DHT11
gpio=17
BLYNK_AUTH=’ c8622877538a49258f2d0202ea136c64’
blynk=BlynkLib.Blynk(BLYNK_AUTH)
humidity,temperature=Adafruit_DHT.read_retry(sensor,gpio)
if humidity is not None and temperature is not None:
print (‘Temp={0:0.1f}*C Humidity={1:0.1f}%’.format(temperature,humidity))
@blynk.VIRTUAL_WRITE(2)
def my_write_handler(value):
print(‘Current V1 value: {}’.format(value))
@blynk.VIRTUAL_READ(2)
def my_read_handler():
blynk.virtual_write(1, time.ticks_ms() // 1000)
blynk.run()
else:
print (‘Failed to get reading.Try again!’)

but my blynk app does not receive any reading

I used this code to read DHT11 and push it to virtual pin 1 and 3 to then graph it in a SuperChart by using 2 data streams.
Maybe this can help.
hook up the DHT to gpio as indicated here

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


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)


BLYNK_AUTH = 'your auth code'
blynk = BlynkLib.Blynk(BLYNK_AUTH)
   
        
def readHandT():
    sensor_type = Adafruit_DHT.DHT11
    sensor_pin = 2
    localtime = time.asctime( time.localtime(time.time()) )
    humidity, temperature = Adafruit_DHT.read_retry(sensor_type, sensor_pin)
    if humidity is not None and temperature is not None:
        print(localtime,' Humidity = {:.2f}%\tTemperature = {:.2f}C'.format(humidity, temperature))
        blynk.virtual_write(1, temperature)
        blynk.virtual_write(3, humidity)
        
    else:
        print("could not get data from DHT")

def wait(wachttijd):  
    print(wachttijd,"sec zzzzzzz")
    i=wachttijd
    while i>0:
        time.sleep(1) 
        i=i-1



try: #probeer de volgende statements tenzij 'except' op deze hoogte
    blynk.run() 
    print("start")
    while 1:
        readHandT()
        wait(2)
               
        
except KeyboardInterrupt: 
    GPIO.cleanup()       

have fun
you can map H and T every 2 seconds. change to wait(60) if you want it every minute.
Still need to find out how to capture the broken pipe error 32 and recover from it, but that’s for later.