How to connect rpi 4 to blynk dashboard, blynk app still offline

Can someone help i am using rpi4 as a microcontroller, the dht22 sends a temperature and humidity other sensor data to the rpi4b but it does not connect to blynk cloud I already check the auth token and v0 and v1 digital pins in the web dashboard and it alligned with my code 0,1 am I missing something? The app is offline but it reads.

Our project is A-IoT greenhouse monitoring and controlling system using raspi 4 and blynk as application.

This is the code I use

import board
import blynklib
import time

BLYNK_AUTH = 'remove for this post'  # Replace with your actual Blynk Auth Token
blynk = blynklib.Blynk(BLYNK_AUTH)

# Attempt to connect to Blynk server
def connect_to_blynk():
    global blynk
    try:
        blynk.connect()
    except Exception as e:
        print(f"Error connecting to Blynk server: {e}")
        time.sleep(5)  # Wait for 5 seconds before retrying
        connect_to_blynk()

dht_device = adafruit_dht.DHT22(board.D5)  # DHT22 connected to GPIO5

def read_sensor_data():
    try:
        # Read temperature and humidity
        temperature = dht_device.temperature
        humidity = dht_device.humidity
        if humidity is not None and temperature is not None:
            print(f'Temp={temperature:0.1f}*C  Humidity={humidity:0.1f}%')
            try:
                blynk.virtual_write(0, temperature)
                blynk.virtual_write(1, humidity)
            except AttributeError:
                print("Lost connection to Blynk server. Reconnecting...")
                connect_to_blynk()
            except Exception as e:
                print(f"Failed to write to Blynk: {e}")
        else:
            print('Failed to get reading from the sensor')
    except RuntimeError as error:
        print(error.args[0])

# Ensure initial connection to Blynk
connect_to_blynk()

while True:
    read_sensor_data()
    if blynk.connected():
        blynk.run()
    else:
        connect_to_blynk()
    time.sleep(10)  # Delay between readings```

@babibabw Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

1 Like

What version of the Blynk Python library are you using? (What version number does it show in the Blynk splash screen of the serial monitor?

Pete.

Blynk for python v0.2.6

That’s why it’s not working. You need to be using library version 1.0.0 from here…

It’s not a bundled release, so you’ll need to manually copy the files.
You’ll also need to take a look at the examples, as the syntax has changed.

Pete.