Implement conecting to network
This commit is contained in:
parent
526e7d6551
commit
4546c6c5d0
1
pico/.gitignore
vendored
1
pico/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
.venv
|
.venv
|
||||||
typings
|
typings
|
||||||
|
src/secret.py
|
2
pico/secret.py.example
Normal file
2
pico/secret.py.example
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
SSID = "AzureDiamondNet"
|
||||||
|
PASSWORD = "hunter_2"
|
@ -1,5 +1,6 @@
|
|||||||
from machine import Pin
|
from machine import Pin
|
||||||
import machine
|
import machine
|
||||||
|
import network
|
||||||
import time
|
import time
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
@ -63,8 +64,34 @@ class UltraSonicSensor:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def ensure_network():
|
||||||
|
from secret import SSID, PASSWORD
|
||||||
|
|
||||||
|
nic = network.WLAN(network.STA_IF)
|
||||||
|
print("[net] setting up WLAN interface...")
|
||||||
|
nic.active(True)
|
||||||
|
print("[net] connecting...")
|
||||||
|
nic.connect(SSID, PASSWORD)
|
||||||
|
|
||||||
|
logged = False
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if nic.status() == network.STAT_GOT_IP:
|
||||||
|
STATUS_LED.status(2)
|
||||||
|
if not logged:
|
||||||
|
logged = True
|
||||||
|
print(f"[net] Got IP: {nic.ifconfig()!r}")
|
||||||
|
rssi = nic.status("rssi") # pyright: ignore[reportAny]
|
||||||
|
print(f"[net] {rssi=}")
|
||||||
|
else:
|
||||||
|
STATUS_LED.status(1)
|
||||||
|
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
async def _main():
|
async def _main():
|
||||||
asyncio.create_task(STATUS_LED.task())
|
asyncio.create_task(STATUS_LED.task())
|
||||||
|
asyncio.create_task(ensure_network())
|
||||||
sensor = UltraSonicSensor(22, 21)
|
sensor = UltraSonicSensor(22, 21)
|
||||||
while True:
|
while True:
|
||||||
d = sensor.query_mm()
|
d = sensor.query_mm()
|
||||||
|
Loading…
Reference in New Issue
Block a user