MicroPython: Various networking fixes to code & examples.
Replaces https://github.com/pimoroni/pimoroni-pico/pull/712, https://github.com/pimoroni/pimoroni-pico/pull/632 and https://github.com/pimoroni/pimoroni-pico/pull/630 Co-authored-by: ben4github <ben4github@users.noreply.github.com> Co-authored-by: Alexander Gee <bostwickenator@gmail.com>
This commit is contained in:
parent
aa70394495
commit
0d0dc6a781
|
@ -40,7 +40,7 @@ try:
|
|||
|
||||
except ImportError:
|
||||
# WIFI settings
|
||||
WIFI_COUNTRY = "GB" # Changeme!
|
||||
WIFI_COUNTRY = "GB" # Change to your local two-letter ISO 3166-1 country code
|
||||
network_manager = NetworkManager(WIFI_COUNTRY, status_handler=status_handler)
|
||||
uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK))
|
||||
# Install missing module
|
||||
|
@ -60,7 +60,7 @@ else:
|
|||
html_file = open('index.html', 'r')
|
||||
|
||||
# WIFI settings
|
||||
WIFI_COUNTRY = "GB" # Changeme!
|
||||
WIFI_COUNTRY = "GB" # Change to your local two-letter ISO 3166-1 country code
|
||||
|
||||
|
||||
class LEDs:
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
SSID = ""
|
||||
PSK = ""
|
||||
COUNTRY = ""
|
||||
COUNTRY = "" # Change to your local two-letter ISO 3166-1 country code
|
||||
|
|
|
@ -7,7 +7,7 @@ import uasyncio
|
|||
class NetworkManager:
|
||||
_ifname = ("Client", "Access Point")
|
||||
|
||||
def __init__(self, country="GB", client_timeout=30, access_point_timeout=5, status_handler=None, error_handler=None):
|
||||
def __init__(self, country="GB", client_timeout=60, access_point_timeout=5, status_handler=None, error_handler=None):
|
||||
rp2.country(country)
|
||||
self._ap_if = network.WLAN(network.AP_IF)
|
||||
self._sta_if = network.WLAN(network.STA_IF)
|
||||
|
@ -74,8 +74,8 @@ class NetworkManager:
|
|||
self._ap_if.active(False)
|
||||
|
||||
self._sta_if.active(True)
|
||||
self._sta_if.connect(ssid, psk)
|
||||
self._sta_if.config(pm=0xa11140)
|
||||
self._sta_if.connect(ssid, psk)
|
||||
|
||||
try:
|
||||
await uasyncio.wait_for(self.wait(network.STA_IF), self._client_timeout)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
SSID = "YOUR_WIFI_SSID"
|
||||
PSK = "YOUR_WIFI_PASSWORD"
|
||||
COUNTRY = "YOUR_COUNTRY_CODE"
|
||||
COUNTRY = "YOUR_COUNTRY_CODE" # Change to your local two-letter ISO 3166-1 country code
|
||||
|
|
|
@ -7,7 +7,7 @@ import uasyncio
|
|||
class NetworkManager:
|
||||
_ifname = ("Client", "Access Point")
|
||||
|
||||
def __init__(self, country="GB", client_timeout=30, access_point_timeout=5, status_handler=None, error_handler=None):
|
||||
def __init__(self, country="GB", client_timeout=60, access_point_timeout=5, status_handler=None, error_handler=None):
|
||||
rp2.country(country)
|
||||
self._ap_if = network.WLAN(network.AP_IF)
|
||||
self._sta_if = network.WLAN(network.STA_IF)
|
||||
|
@ -74,6 +74,7 @@ class NetworkManager:
|
|||
self._ap_if.active(False)
|
||||
|
||||
self._sta_if.active(True)
|
||||
self._sta_if.config(pm=0xa11140)
|
||||
self._sta_if.connect(ssid, psk)
|
||||
|
||||
try:
|
||||
|
|
|
@ -67,7 +67,7 @@ app = webserver()
|
|||
html_file = open('index.html', 'r')
|
||||
|
||||
# WIFI settings
|
||||
WIFI_COUNTRY = "GB" # Changeme!
|
||||
WIFI_COUNTRY = "GB" # Change to your local two-letter ISO 3166-1 country code
|
||||
|
||||
|
||||
# Index page
|
||||
|
|
|
@ -36,6 +36,7 @@ def network_connect(SSID, PSK):
|
|||
|
||||
# Sets the Wireless LED pulsing and attempts to connect to your local network.
|
||||
print("connecting...")
|
||||
wlan.config(pm=0xa11140) # Turn WiFi power saving off for some slow APs
|
||||
wlan.connect(SSID, PSK)
|
||||
|
||||
while max_wait > 0:
|
||||
|
|
|
@ -44,6 +44,7 @@ def network_connect(SSID, PSK):
|
|||
|
||||
# Sets the Wireless LED pulsing and attempts to connect to your local network.
|
||||
print("connecting...")
|
||||
wlan.config(pm=0xa11140) # Turn WiFi power saving off for some slow APs
|
||||
wlan.connect(SSID, PSK)
|
||||
|
||||
while max_wait > 0:
|
||||
|
|
|
@ -119,6 +119,7 @@ def sync_time():
|
|||
# Start connection
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
wlan.config(pm=0xa11140) # Turn WiFi power saving off for some slow APs
|
||||
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
|
||||
|
||||
# Wait for connect success or failure
|
||||
|
|
|
@ -93,6 +93,7 @@ def network_connect(SSID, PSK):
|
|||
|
||||
# Sets the Wireless LED pulsing and attempts to connect to your local network.
|
||||
pulse_network_led()
|
||||
wlan.config(pm=0xa11140) # Turn WiFi power saving off for some slow APs
|
||||
wlan.connect(SSID, PSK)
|
||||
|
||||
while max_wait > 0:
|
||||
|
|
|
@ -115,6 +115,7 @@ def sync_time():
|
|||
# Start connection
|
||||
wlan = network.WLAN(network.STA_IF)
|
||||
wlan.active(True)
|
||||
wlan.config(pm=0xa11140) # Turn WiFi power saving off for some slow APs
|
||||
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
|
||||
|
||||
# Wait for connect success or failure
|
||||
|
|
Loading…
Reference in New Issue