Hello everyone!
Need help with connecting Pico W to Blynk with WiFi. Raspberry Pico W is a new platform for modelling, and i don`t find docs for blink connecting.
I use these example https://github.com/blynkkk/lib-python/blob/master/examples/raspberry/01_weather_station_pi3b.py
Sensor BME280 is working but Pico W don`t connecting to Blynk
I use blynklib ver.0.2.6
Maybe you will find an error in my code
from machine import Pin, I2C
import time
import bme280
import blynklib
import network
ssid = '****'
password = '******'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
# Wait for connect or fail
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
print('connected')
status = wlan.ifconfig()
print( 'ip = ' + status[0] )
BLYNK_AUTH='token'
blynk = blynklib.Blynk(BLYNK_AUTH)
T_VPIN = 1
P_VPIN = 2
H_VPIN = 3
@blynk.handle_event('read V{}'.format(T_VPIN))
def read_handler(vpin):
i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
bme = bme280.BME280(i2c=i2c)
temperature = bme.values[0]
pressure = bme.values[1]
humidity = bme.values[2]
blynk.virtual_write(T_VPIN, temperature)
blynk.virtual_write(P_VPIN, pressure)
blynk.virtual_write(H_VPIN, humidity)
while True:
blynk.run()
Are you using Blynk IoT, or Blynk Legacy?
What does your serial monitor show?
Pete.
1 Like
Blynk IoT
I am using Thonny IDE and in shell shows only successful connection to wifi
``
connected
ip = 192.168.1.6
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ for Python v0.2.6
``
John93
November 2, 2022, 7:08am
4
kozaklevko:
Blynk IoT
In this case you should update the library to the latest version (1.0.0)
Blynk library for Python. Works with Python 2, Python 3, MicroPython. - GitHub - vshymanskyy/blynk-library-python: Blynk library for Python. Works with Python 2, Python 3, MicroPython.
You can use this command
pip install blynk-library-python
To install the library, but for some reason it doesn’t pull the latest version of the library, so after installing the library, you have to download the files and move them to the library directory manually.
1 Like
Yes, thats it! Thank you.
My final working sketch
from machine import Pin, I2C
import time
import bme280
import BlynkLib
import network
ssid = '****' # wifi
password = '****' #password
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
# Wait for connect or fail
max_wait = 10
while max_wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
max_wait -= 1
print('waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
print('connected')
status = wlan.ifconfig()
print( 'ip = ' + status[0] )
BLYNK_AUTH='******'
blynk = BlynkLib.Blynk(BLYNK_AUTH)
T_VPIN = 1 #Virtual Pin 1, Gauge temperature
P_VPIN = 2 #Virtual Pin 2, Gauge pressure
H_VPIN = 3 #Virtual Pin 3, Gauge humidity
i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
bme = bme280.BME280(i2c=i2c) #BME280 object created
while True:
temperature = bme.values[0] #reading the value of temperature
pressure = bme.values[1]
humidity = bme.values[2]
blynk.virtual_write(T_VPIN, float(temperature[:len(temperature)-1])) #writing to blynk virtual value
blynk.virtual_write(P_VPIN, float(pressure[:len(pressure)-3]))
blynk.virtual_write(H_VPIN, float(humidity[:len(humidity)-1]))
while True:
blynk.run()