mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 11:19:57 +00:00
Added Pico Files
Added the files used on the raspberry pi pico to send and receive data
This commit is contained in:
36
pico_files/connection.py
Normal file
36
pico_files/connection.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import config as c
|
||||
import network
|
||||
from time import sleep
|
||||
|
||||
connection = network.WLAN(network.STA_IF)
|
||||
|
||||
|
||||
def connect():
|
||||
# Check for established connection
|
||||
if connection.isconnected():
|
||||
print("[connection.py]: Already connected")
|
||||
return
|
||||
|
||||
# Enable network interface
|
||||
print("[connection.py]: Enabling network interface")
|
||||
connection.active(True)
|
||||
|
||||
# Connect to configurated SSID
|
||||
print(f"[connection.py]: Connecting to SSID {c.ssid}")
|
||||
connection.connect(c.ssid, c.password)
|
||||
|
||||
retry = 0
|
||||
while not connection.isconnected():
|
||||
if retry == 10:
|
||||
print("Could not establish connection, check your settings")
|
||||
retry = 0
|
||||
retry += 1
|
||||
|
||||
sleep(1)
|
||||
|
||||
# no exit, we have a connection!
|
||||
print("[connection.py]: Connection established")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
connect()
|
||||
Reference in New Issue
Block a user