diff --git a/pico-w/.gitignore b/pico-w/.gitignore new file mode 100644 index 0000000..2f379ae --- /dev/null +++ b/pico-w/.gitignore @@ -0,0 +1,3 @@ +.env +env.json +config.py \ No newline at end of file diff --git a/pico-w/.picowgo b/pico-w/.picowgo new file mode 100644 index 0000000..3de3977 --- /dev/null +++ b/pico-w/.picowgo @@ -0,0 +1,3 @@ +{ + "info": "This file is just used to identify a project folder." +} \ No newline at end of file diff --git a/pico-w/.vscode/Pico-W-Stub b/pico-w/.vscode/Pico-W-Stub new file mode 120000 index 0000000..f410427 --- /dev/null +++ b/pico-w/.vscode/Pico-W-Stub @@ -0,0 +1 @@ +/home/eliasrenman/.config/Code/User/Pico-W-Stub \ No newline at end of file diff --git a/pico-w/.vscode/extensions.json b/pico-w/.vscode/extensions.json new file mode 100644 index 0000000..2d69e4c --- /dev/null +++ b/pico-w/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "ms-python.python", + "visualstudioexptteam.vscodeintellicode", + "ms-python.vscode-pylance" + ] +} \ No newline at end of file diff --git a/pico-w/.vscode/settings.json b/pico-w/.vscode/settings.json new file mode 100644 index 0000000..9671941 --- /dev/null +++ b/pico-w/.vscode/settings.json @@ -0,0 +1,16 @@ +{ + "python.linting.enabled": true, + "python.languageServer": "Pylance", + "python.analysis.typeCheckingMode": "basic", + "picowgo.syncFolder": "", + "python.analysis.typeshedPaths": [ + ".vscode/Pico-W-Stub" + ], + "python.analysis.extraPaths": [ + ".vscode/Pico-W-Stub/stubs" + ], + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + }, + "python.formatting.provider": "none" +} \ No newline at end of file diff --git a/pico-w/boot.py b/pico-w/boot.py new file mode 100644 index 0000000..2732d2a --- /dev/null +++ b/pico-w/boot.py @@ -0,0 +1,4 @@ +from wireless import enableWireless + + +enableWireless() diff --git a/pico-w/config.py.example b/pico-w/config.py.example new file mode 100644 index 0000000..4394a39 --- /dev/null +++ b/pico-w/config.py.example @@ -0,0 +1,2 @@ +ssid = "ssid" +password = "password" diff --git a/pico-w/wireless.py b/pico-w/wireless.py new file mode 100644 index 0000000..65aaa47 --- /dev/null +++ b/pico-w/wireless.py @@ -0,0 +1,40 @@ +import time +import network +from machine import Pin +from config import ssid, password + + +def enableWireless(): + + led = Pin("LED", Pin.OUT) + led.value(1) # LED On + led.value(0) # LED Off + + 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: + s = 3 + while s > 0: + s -= 1 + led.value(1) + time.sleep(0.5) + led.value(0) + time.sleep(0.5) + + # print('connected') + status = wlan.ifconfig() + print('Connected to ' + ssid + '. ' + 'Device IP: ' + status[0])