examples: Update all networking scripts.

* Remove non-standard timeout arg and use isconnected.
This commit is contained in:
iabdalkader 2023-06-28 17:16:27 +02:00
parent 5e8ba825ed
commit 11194954cb
20 changed files with 94 additions and 67 deletions

View File

@ -8,12 +8,13 @@ SSID='' # Network SSID
KEY='' # Network key
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -8,12 +8,13 @@ SSID='' # Network SSID
KEY='' # Network key
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -10,12 +10,13 @@ PORT = 80
HOST = "www.google.com"
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -9,12 +9,13 @@ PORT = 443
HOST = "www.google.com"
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -16,11 +16,13 @@ sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.RGB565)
# Init wlan module and connect to network
print("Trying to connect... (This may take a while)...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -14,12 +14,13 @@ SSID='' # Network SSID
KEY='' # Network key
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -14,12 +14,13 @@ SSID='' # Network SSID
KEY='' # Network key
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -12,9 +12,13 @@ TIMESTAMP = 2208988800+946684800
# Init wlan module and connect to network
print("Trying to connect... (This may take a while)...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -5,7 +5,6 @@
import time, network
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
print("Scanning...")

View File

@ -10,13 +10,16 @@ KEY='' # Network key
TIMESTAMP = 2208988800+946684800
# Init wlan module and connect to network
print("Trying to connect... (This may take a while)...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
# ifconfig must be called before connect()
wlan.ifconfig(('192.168.1.200', '255.255.255.0', '192.168.1.1', '192.168.1.1'))
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# Create new socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

View File

@ -8,12 +8,13 @@ SSID='' # Network SSID
KEY='' # Network key
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -8,12 +8,13 @@ SSID='' # Network SSID
KEY='' # Network key
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -10,12 +10,13 @@ PORT = 80
HOST = "www.google.com"
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -9,12 +9,13 @@ PORT = 443
HOST = "www.google.com"
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -16,11 +16,13 @@ sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
# Init wlan module and connect to network
print("Trying to connect... (This may take a while)...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -14,12 +14,13 @@ SSID='' # Network SSID
KEY='' # Network key
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -14,12 +14,13 @@ SSID='' # Network SSID
KEY='' # Network key
# Init wlan module and connect to network
print("Trying to connect. Note this may take a while...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -10,11 +10,14 @@ KEY='' # Network key
TIMESTAMP = 2208988800+946684800
# Init wlan module and connect to network
print("Trying to connect... (This may take a while)...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())

View File

@ -5,7 +5,6 @@
import time, network
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
print("Scanning...")

View File

@ -10,13 +10,16 @@ KEY='' # Network key
TIMESTAMP = 2208988800+946684800
# Init wlan module and connect to network
print("Trying to connect... (This may take a while)...")
wlan = network.WLAN(network.STA_IF)
wlan.deinit()
wlan.active(True)
# ifconfig must be called before connect()
wlan.ifconfig(('192.168.1.200', '255.255.255.0', '192.168.1.1', '192.168.1.1'))
wlan.connect(SSID, KEY, timeout=30000)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print("Trying to connect to \"{:s}\"...".format(SSID))
time.sleep_ms(1000)
# Create new socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)