Added Pico W lab code
This commit is contained in:
parent
4dbe7119d2
commit
a23bf2ca82
29 changed files with 974 additions and 7 deletions
13
picow-lab-code/Lab09Code/blink.py
Normal file
13
picow-lab-code/Lab09Code/blink.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
import time
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
LED_PIN = digitalio.DigitalInOut(board.LED)
|
||||
LED_PIN.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
while True:
|
||||
print("Loop")
|
||||
LED_PIN.value = True
|
||||
time.sleep(1)
|
||||
LED_PIN.value = False
|
||||
time.sleep(1)
|
4
picow-lab-code/Lab09Code/secrets.py
Normal file
4
picow-lab-code/Lab09Code/secrets.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
secrets = {
|
||||
'ssid': 'cset@stcc',
|
||||
'password': 'c1s2e3t4',
|
||||
}
|
12
picow-lab-code/Lab09Code/settings.toml
Normal file
12
picow-lab-code/Lab09Code/settings.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Comments are supported
|
||||
# CSET SSID and pass
|
||||
|
||||
LOCATION="STCC"
|
||||
|
||||
CIRCUITPY_WIFI_SSID="cset@stcc"
|
||||
CIRCUITPY_WIFI_PASSWORD="c1s2e3t4"
|
||||
|
||||
CIRCUITPY_WEB_API_PORT=80
|
||||
CIRCUITPY_WEB_API_PASSWORD="passw0rd"
|
||||
test_variable="this is a test"
|
||||
thumbs_up="\U0001f44d"
|
12
picow-lab-code/Lab09Code/test-settings.py
Normal file
12
picow-lab-code/Lab09Code/test-settings.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
import os
|
||||
|
||||
print("Location:",os.getenv("LOCATION"),"\n")
|
||||
|
||||
print(os.getenv("CIRCUITPY_WIFI_SSID"))
|
||||
print(os.getenv("CIRCUITPY_WIFI_PASSWORD"))
|
||||
|
||||
print(os.getenv("CIRCUITPY_WEB_API_PORT"))
|
||||
print(os.getenv("CIRCUITPY_WEB_API_PASSWORD"))
|
||||
|
||||
print(os.getenv("test_variable"))
|
||||
print(os.getenv("thumbs_up"))
|
8
picow-lab-code/Lab09Code/test_secrets.py
Normal file
8
picow-lab-code/Lab09Code/test_secrets.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from secrets import secrets
|
||||
|
||||
# Load login data from different file for safety reasons
|
||||
WiFiSSID = secrets['ssid']
|
||||
WiFiPassword = secrets['password']
|
||||
|
||||
print(WiFiSSID)
|
||||
print(WiFiPassword)
|
28
picow-lab-code/Lab09Code/wifi_connect.py
Normal file
28
picow-lab-code/Lab09Code/wifi_connect.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import os
|
||||
import ipaddress
|
||||
import wifi
|
||||
import socketpool
|
||||
|
||||
print()
|
||||
print("Connecting to WiFi")
|
||||
|
||||
# connect to your SSID
|
||||
wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
|
||||
|
||||
print("Connected to WiFi")
|
||||
|
||||
pool = socketpool.SocketPool(wifi.radio)
|
||||
|
||||
# prints MAC address to REPL
|
||||
print("My MAC addr:", [hex(i) for i in wifi.radio.mac_address])
|
||||
|
||||
# prints IP address to REPL
|
||||
print("My IP address is", wifi.radio.ipv4_address)
|
||||
|
||||
# pings Google
|
||||
ipv4 = ipaddress.ip_address("8.8.4.4")
|
||||
print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
|
11
picow-lab-code/Lab09Code/wifi_scan.py
Normal file
11
picow-lab-code/Lab09Code/wifi_scan.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
import wifi
|
||||
|
||||
# https://learn.adafruit.com/todbot-circuitpython-tricks/networking
|
||||
|
||||
networks = []
|
||||
for network in wifi.radio.start_scanning_networks():
|
||||
networks.append(network)
|
||||
wifi.radio.stop_scanning_networks()
|
||||
networks = sorted(networks, key=lambda net: net.rssi, reverse=True)
|
||||
for network in networks:
|
||||
print("ssid:",network.ssid, "rssi:",network.rssi)
|
Loading…
Add table
Add a link
Reference in a new issue