Télécharger Imprimer la page

Raspberry PICO Mode D'emploi page 96

Publicité

from
secretsmq
import
from
onewire
import
from
ds18x20
import
from
umqtt.simple
from
machine
import
#led declaration
led
= machine.Pin('LED', machine.Pin.OUT)
#sensor DS18b20 on pin 28
ds
= DS18X20(OneWire(machine.Pin(28)))
roms
= ds.scan()
#network declaration
# Set country to avoid possible errors /
https://randomnerdtutorials.com/micropython-mqtt-esp32-esp8266/
rp2.country('CA')
wlan
= network.WLAN(network.STA_IF)
wlan.active(True)
# See the MAC address in the wireless chip OTP
#mac = ubinascii.hexlify(network.WLAN().config('mac'),':').decode()
#print('mac = ' + mac)
# Load login data from different file for safety reasons
#set static IP
# (IP,mask,gateway,dns)
#wlan.ifconfig(('10.11.12.21', '255.255.255.0', '10.11.12.253', '8.8.8.8'))
#connect using ssid
wlan.connect(secrets['ssid'],secrets['pw'])
while not
wlan.isconnected():
machine.idle()
# Wait for connection with 10 second timeout
timeout
=
10
while
timeout
> 0:
if
wlan.status() <
break
timeout
-=
1
print('Waiting for
time.sleep(1)
# Handle connection error
# Error meanings
# 0
Link Down
# 1
Link Join
# 2
Link NoIp
# 3
Link Up
# -1 Link Fail
# -2 Link NoNet
# -3 Link BadAuth
if
wlan.status() != 3:
raise
RuntimeError('Wi-Fi connection
else:
for
i
in
range(wlan.status()):
led.on()
time.sleep(.1)
secrets
OneWire
DS18X20
import
MQTTClient
Pin
# save power while waiting
0
or
wlan.status() >= 3:
connection...')
failed')

Publicité

loading

Ce manuel est également adapté pour:

Pico w