diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/connect.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/connect.py deleted file mode 100644 index b4b26d9b4..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/connect.py +++ /dev/null @@ -1,21 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Connect Example -# -# This example shows how to connect your OpenMV Cam with a WiFi shield to the net. - -import network - -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/dns.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/dns.py deleted file mode 100644 index c1b19c9f8..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/dns.py +++ /dev/null @@ -1,24 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# DNS Example -# -# This example shows how to get the IP address for websites via DNS. - -import network -import usocket - -# AP info -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) -print(usocket.getaddrinfo("www.google.com", 80)[0][4]) diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/http_client.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/http_client.py deleted file mode 100644 index 2d471fe62..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/http_client.py +++ /dev/null @@ -1,42 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Simple HTTP client example. - -import network -import usocket - -# AP info -SSID = "" # Network SSID -KEY = "" # Network key - -PORT = 80 -HOST = "www.google.com" - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -# Get addr info via DNS -addr = usocket.getaddrinfo(HOST, PORT)[0][4] -print(addr) - -# Create a new socket and connect to addr -client = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) -client.connect(addr) - -# Set timeout -client.settimeout(3.0) - -# Send HTTP request and recv response -client.send("GET / HTTP/1.1\r\nHost: %s\r\n\r\n" % (HOST)) -print(client.recv(1024)) - -# Close socket -client.close() diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/http_client_ssl.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/http_client_ssl.py deleted file mode 100644 index 64a9667b7..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/http_client_ssl.py +++ /dev/null @@ -1,54 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Simple HTTPS client example. - -import network -import usocket -import ussl - -# AP info -SSID = "" # Network SSID -KEY = "" # Network key - -PORT = 443 -HOST = "www.google.com" - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -# Get addr info via DNS -addr = usocket.getaddrinfo(HOST, PORT)[0][4] -print(addr) - -# Create a new socket and connect to addr -client = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) - -client.connect(addr) - -# Set timeout -client.settimeout(3.0) - -client = ussl.wrap_socket(client, server_hostname=HOST) - -# Send HTTP request and recv response -request = "GET / HTTP/1.1\r\n" -request += "HOST: %s\r\n" -request += "User-Agent: Mozilla/5.0\r\n" -request += "Connection: keep-alive\r\n\r\n" -# Add more headers if needed. -client.write(request % (HOST) + "\r\n") - -response = client.read(1024) -for l in response.split(b"\r\n"): - print(l.decode()) - -# Close socket -client.close() diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/http_post.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/http_post.py deleted file mode 100644 index c91af5878..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/http_post.py +++ /dev/null @@ -1,52 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Post files with HTTP/Post urequests module example -import network -import urequests - -# AP info -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -url = "http://website.com/upload.php/" -# Or /:port -# url = 'http://website.com:80/upload.php/' -# SSL is supported. -# url = 'https://192.168.1.102:443/upload.php/' - -headers = { - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0", - # Add more headers if needed -} - -# Send some files -files = { - "image1": ("example1.jpg", open("example1.jpg", "rb")), - "image2": ("example2.jpg", open("example2.jpg", "rb")), -} - -# Post a request -if True: - # Send some files - r = urequests.post( - url, files=files, headers=headers - ) # Can add auth=('username', 'password') if needed -else: - # Or send some JSON data - r = urequests.post( - url, json={"some": "data"}, headers=headers - ) # Can add auth=('username', 'password') if needed - -print(r.status_code, r.reason) -print(r.headers, r.content) diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mjpeg_streamer.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mjpeg_streamer.py deleted file mode 100644 index e6a000d3e..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mjpeg_streamer.py +++ /dev/null @@ -1,90 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# MJPEG Streaming -# -# This example shows off how to do MJPEG streaming to a FIREFOX webrowser -# Chrome, Firefox and MJpegViewer App on Android have been tested. -# Connect to the IP address/port printed out from ifconfig to view the stream. - -import sensor -import time -import network -import usocket - -SSID = "" # Network SSID -KEY = "" # Network key -HOST = "" # Use first available interface -PORT = 8080 # Arbitrary non-privileged port - -# Reset sensor -sensor.reset() -sensor.set_framesize(sensor.QQVGA) -sensor.set_pixformat(sensor.GRAYSCALE) - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -# Create server socket -s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) -s.setsockopt(usocket.SOL_SOCKET, usocket.SO_REUSEADDR, True) - -# Bind and listen -s.bind([HOST, PORT]) -s.listen(5) - -# Set server socket to blocking -s.setblocking(True) - - -def start_streaming(s): - print("Waiting for connections..") - client, addr = s.accept() - # set client socket timeout to 2s - client.settimeout(2.0) - print("Connected to " + addr[0] + ":" + str(addr[1])) - - # Read request from client - data = client.recv(1024) - # Should parse client request here - - # Send multipart header - client.sendall( - "HTTP/1.1 200 OK\r\n" - "Server: OpenMV\r\n" - "Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" - "Cache-Control: no-cache\r\n" - "Pragma: no-cache\r\n\r\n" - ) - - # FPS clock - clock = time.clock() - - # Start streaming images - # NOTE: Disable IDE preview to increase streaming FPS. - while True: - clock.tick() # Track elapsed milliseconds between snapshots(). - frame = sensor.snapshot() - cframe = frame.compressed(quality=35) - header = ( - "\r\n--openmv\r\n" - "Content-Type: image/jpeg\r\n" - "Content-Length:" + str(cframe.size()) + "\r\n\r\n" - ) - client.sendall(header) - client.sendall(cframe) - print(clock.fps()) - - -while True: - try: - start_streaming(s) - except OSError as e: - print("socket error: ", e) - # sys.print_exception(e) diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mjpeg_streamer_fir.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mjpeg_streamer_fir.py deleted file mode 100644 index 7fcfb1678..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mjpeg_streamer_fir.py +++ /dev/null @@ -1,95 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# MJPEG Streaming with FIR -# -# This example shows off how to do MJPEG streaming to a FIREFOX webrowser -# (IE and Chrome do not work). Just input your network SSID and KEY and then -# connect to the IP address/port printed out from ifconfig. - -import sensor -import network -import usocket -import fir - -SSID = "" # Network SSID -KEY = "" # Network key -HOST = "" # Use first available interface -PORT = 8000 # Arbitrary non-privileged port - -# Reset sensor -sensor.reset() -sensor.set_framesize(sensor.QQVGA) -sensor.set_pixformat(sensor.RGB565) - -# Initialize the thermal sensor -fir.init() - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -# Create server socket -s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) - -# Bind and listen -s.bind((HOST, PORT)) -s.listen(5) - -# Set server socket to blocking -s.setblocking(True) - -# Set timeout to 1s -s.settimeout(1.0) - -print("Waiting for connections..") -client, addr = s.accept() -print("Connected to " + addr[0] + ":" + str(addr[1])) - -# Read request from client -data = client.recv(1024) - -# Should parse client request here - -# Send multipart header -client.send( - "HTTP/1.1 200 OK\r\n" - "Server: OpenMV\r\n" - "Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" - "Cache-Control: no-cache\r\n" - "Pragma: no-cache\r\n\r\n" -) - -# Start streaming images -while True: - image = sensor.snapshot() - - # Capture FIR data - # ta: Ambient temperature - # ir: Object temperatures (IR array) - # to_min: Minimum object temperature - # to_max: Maximum object temperature - ta, ir, to_min, to_max = fir.read_ir() - - # Scale the image and belnd it with the framebuffer - fir.draw_ir(image, ir) - - # Draw ambient, min and max temperatures. - image.draw_string(0, 0, "Ta: %0.2f" % ta, color=(0xFF, 0x00, 0x00)) - image.draw_string(0, 8, "To min: %0.2f" % to_min, color=(0xFF, 0x00, 0x00)) - image.draw_string(0, 16, "To max: %0.2f" % to_max, color=(0xFF, 0x00, 0x00)) - - cimage = image.compressed(quality=90) - client.sendall( - "\r\n--openmv\r\n" - "Content-Type: image/jpeg\r\n" - "Content-Length:" + str(cimage.size()) + "\r\n\r\n" - ) - client.sendall(cimage) - -client.close() diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mqtt_pub.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mqtt_pub.py deleted file mode 100644 index 34498cd01..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mqtt_pub.py +++ /dev/null @@ -1,35 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# MQTT Example. -# This example shows how to use the MQTT library to publish to a topic. -# -# 1) Copy the mqtt.py library to OpenMV storage. -# 2) Run this script on the OpenMV camera. -# 3) Install the mosquitto client on PC and run the following command: -# mosquitto_sub -h test.mosquitto.org -t "openmv/test" -v -# -# NOTE: If the mosquitto broker is unreachable, try another broker (For example: broker.hivemq.com) -import time -import network -from mqtt import MQTTClient - -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -client = MQTTClient("openmv", "test.mosquitto.org", port=1883) -client.connect() - -while True: - client.publish("openmv/test", "Hello World!") - time.sleep_ms(1000) diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mqtt_sub.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mqtt_sub.py deleted file mode 100644 index b1cc2d9b6..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mqtt_sub.py +++ /dev/null @@ -1,44 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# MQTT Example. -# This example shows how to use the MQTT library to subscribe to a topic. -# -# 1) Copy the mqtt.py library to OpenMV storage. -# 2) Run this script on the OpenMV camera. -# 3) Install the mosquitto client on PC and run the following command: -# mosquitto_pub -t "openmv/test" -m "Hello World!" -h test.mosquitto.org -p 1883 -# -# NOTE: If the mosquitto broker is unreachable, try another broker (For example: broker.hivemq.com) -import time -import network -from mqtt import MQTTClient - -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -client = MQTTClient("openmv", "test.mosquitto.org", port=1883) -client.connect() - - -def callback(topic, msg): - print(topic, msg) - - -# must set callback first -client.set_callback(callback) -client.subscribe("openmv/test") - -while True: - client.check_msg() # poll for messages. - time.sleep_ms(1000) diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/ntp.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/ntp.py deleted file mode 100644 index df89c055e..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/ntp.py +++ /dev/null @@ -1,40 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# NTP Example -# -# This example shows how to get the current time using NTP with the WiFi shield. - -import network -import usocket -import ustruct -import utime - -SSID = "" # Network SSID -KEY = "" # Network key - -TIMESTAMP = 2208988800 + 946684800 - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WINC() -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -# Create new socket -client = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM) - -# Get addr info via DNS -addr = usocket.getaddrinfo("pool.ntp.org", 123)[0][4] - -# Send query -client.sendto("\x1b" + 47 * "\0", addr) -data, address = client.recvfrom(1024) - -# Print time -t = ustruct.unpack(">IIIIIIIIIIII", data)[10] - TIMESTAMP -print("Year:%d Month:%d Day:%d Time: %d:%d:%d" % (utime.localtime(t)[0:6])) diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/scan.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/scan.py deleted file mode 100644 index 6582753a2..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/scan.py +++ /dev/null @@ -1,20 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Scan Example -# -# This example shows how to scan for networks with the WiFi shield. - -import time -import network - -wlan = network.WINC() -print("\nFirmware version:", wlan.fw_version()) - -while True: - scan_result = wlan.scan() - for ap in scan_result: - print("Channel:%d RSSI:%d Auth:%d BSSID:%s SSID:%s" % (ap)) - print() - time.sleep_ms(1000) diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/static_ip.py b/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/static_ip.py deleted file mode 100644 index 44ec4cb7f..000000000 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/static_ip.py +++ /dev/null @@ -1,39 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# NTP Example using static IP. -# -# This example shows how to get the current time using NTP with the WiFi shield. - -import network -import usocket -import ustruct -import utime - -SSID = "" # Network SSID -KEY = "" # Network key - -TIMESTAMP = 2208988800 + 946684800 - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WINC() -# 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=KEY, security=wlan.WPA_PSK) - -# Create new socket -client = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM) - -# Get addr info via DNS -addr = usocket.getaddrinfo("pool.ntp.org", 123)[0][4] - -# Send query -client.sendto("\x1b" + 47 * "\0", addr) -data, address = client.recvfrom(1024) - -# Print time -t = ustruct.unpack(">IIIIIIIIIIII", data)[10] - TIMESTAMP -print("Year:%d Month:%d Day:%d Time: %d:%d:%d" % (utime.localtime(t)[0:6])) diff --git a/scripts/examples/09-WiFi/WINC1500/fw_dump.py b/scripts/examples/09-WiFi/WINC1500/fw_dump.py new file mode 100644 index 000000000..81ac1c9e8 --- /dev/null +++ b/scripts/examples/09-WiFi/WINC1500/fw_dump.py @@ -0,0 +1,12 @@ +# This work is licensed under the MIT license. +# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. +# https://github.com/openmv/openmv/blob/master/LICENSE +# +# Atmel WINC1500 Firmware dump. + +import network + +wlan = network.WINC(mode=network.WINC.MODE_FIRMWARE) + +# For ATWINC1500-MR210PB only. +wlan.fw_dump("/winc_19_7_6.bin") diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/fw_update.py b/scripts/examples/09-WiFi/WINC1500/fw_update.py similarity index 96% rename from scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/fw_update.py rename to scripts/examples/09-WiFi/WINC1500/fw_update.py index 8fa2f9ce9..48c9bd4a4 100644 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/fw_update.py +++ b/scripts/examples/09-WiFi/WINC1500/fw_update.py @@ -2,7 +2,7 @@ # Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. # https://github.com/openmv/openmv/blob/master/LICENSE # -# WINC Firmware Update Script. +# Atmel WINC1500 Firmware Update. # # This script updates the ATWINC1500 WiFi module firmware. # 1) Copy the firmware image to a FAT32/exFAT SD card. diff --git a/scripts/examples/09-WiFi/WINC1500/fw_version.py b/scripts/examples/09-WiFi/WINC1500/fw_version.py new file mode 100644 index 000000000..fde65dc57 --- /dev/null +++ b/scripts/examples/09-WiFi/WINC1500/fw_version.py @@ -0,0 +1,10 @@ +# This work is licensed under the MIT license. +# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. +# https://github.com/openmv/openmv/blob/master/LICENSE +# +# Atmel WINC1500 firmware version. + +import network + +wlan = network.WINC() +print("\nFirmware version:", wlan.fw_version()) diff --git a/scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/ap_mode.py b/scripts/examples/09-WiFi/ap_mode.py similarity index 100% rename from scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/ap_mode.py rename to scripts/examples/09-WiFi/ap_mode.py diff --git a/scripts/examples/10-Arduino-Boards/Portenta-H7/02-WiFi/connect.py b/scripts/examples/09-WiFi/connect.py similarity index 87% rename from scripts/examples/10-Arduino-Boards/Portenta-H7/02-WiFi/connect.py rename to scripts/examples/09-WiFi/connect.py index 3dc503e53..2d1994c91 100644 --- a/scripts/examples/10-Arduino-Boards/Portenta-H7/02-WiFi/connect.py +++ b/scripts/examples/09-WiFi/connect.py @@ -4,7 +4,7 @@ # # Connect Example # -# This example shows how to connect your OpenMV Cam with a WiFi shield to the net. +# This example shows how to connect to a WiFi network. import network import time diff --git a/scripts/examples/10-Arduino-Boards/Portenta-H7/02-WiFi/dns.py b/scripts/examples/09-WiFi/dns.py similarity index 90% rename from scripts/examples/10-Arduino-Boards/Portenta-H7/02-WiFi/dns.py rename to scripts/examples/09-WiFi/dns.py index 3dada792c..50569b14e 100644 --- a/scripts/examples/10-Arduino-Boards/Portenta-H7/02-WiFi/dns.py +++ b/scripts/examples/09-WiFi/dns.py @@ -8,6 +8,7 @@ import network import time +import socket SSID = "" # Network SSID KEY = "" # Network key @@ -23,4 +24,4 @@ while not wlan.isconnected(): # We should have a valid IP now via DHCP print("WiFi Connected ", wlan.ifconfig()) -print(usocket.getaddrinfo("www.google.com", 80)[0][4]) +print(socket.getaddrinfo("www.google.com", 80)[0][4]) diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/http_client.py b/scripts/examples/09-WiFi/http_client.py similarity index 100% rename from scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/http_client.py rename to scripts/examples/09-WiFi/http_client.py diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/http_client_ssl.py b/scripts/examples/09-WiFi/http_client_ssl.py similarity index 99% rename from scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/http_client_ssl.py rename to scripts/examples/09-WiFi/http_client_ssl.py index 57137bae1..4f5268ac4 100644 --- a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/http_client_ssl.py +++ b/scripts/examples/09-WiFi/http_client_ssl.py @@ -3,6 +3,7 @@ # https://github.com/openmv/openmv/blob/master/LICENSE # # Simple HTTPS client example. + import network import socket import ssl diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/mjpeg_streamer.py b/scripts/examples/09-WiFi/mjpeg_streamer.py similarity index 99% rename from scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/mjpeg_streamer.py rename to scripts/examples/09-WiFi/mjpeg_streamer.py index d09e9dc59..a1e7b5a19 100644 --- a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/mjpeg_streamer.py +++ b/scripts/examples/09-WiFi/mjpeg_streamer.py @@ -7,6 +7,7 @@ # This example shows off how to do MJPEG streaming to a FIREFOX webrowser # Chrome, Firefox and MJpegViewer App on Android have been tested. # Connect to the IP address/port printed out from ifconfig to view the stream. + import sensor import time import network diff --git a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mjpeg_streamer_ap.py b/scripts/examples/09-WiFi/mjpeg_streamer_ap.py similarity index 66% rename from scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mjpeg_streamer_ap.py rename to scripts/examples/09-WiFi/mjpeg_streamer_ap.py index 0efb5aac5..b8359fcdf 100644 --- a/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/mjpeg_streamer_ap.py +++ b/scripts/examples/09-WiFi/mjpeg_streamer_ap.py @@ -11,7 +11,7 @@ import sensor import time import network -import usocket +import socket SSID = "OPENMV_AP" # Network SSID KEY = "1234567890" # Network key (must be 10 chars) @@ -24,21 +24,17 @@ sensor.set_framesize(sensor.QQVGA) sensor.set_pixformat(sensor.GRAYSCALE) # Init wlan module in AP mode. -wlan = network.WINC(mode=network.WINC.MODE_AP) -wlan.start_ap(SSID, key=KEY, security=wlan.WEP, channel=2) +wlan = network.WLAN(network.AP_IF) +wlan.active(True) +# Note some WiFi modules only support WEP in AP mode. +wlan.config(ssid=SSID, key=KEY, channel=2) # security=wlan.WEP print("AP mode started. SSID: {} IP: {}".format(SSID, wlan.ifconfig()[0])) # You can block waiting for client to connect -# print(wlan.wait_for_sta(10000)) +# print(wlan.wait_for_sta(100000)) -def start_streaming(s): - print("Waiting for connections..") - client, addr = s.accept() - # set client socket timeout to 2s - client.settimeout(2.0) - print("Connected to " + addr[0] + ":" + str(addr[1])) - +def start_streaming(client): # Read request from client data = client.recv(1024) # Should parse client request here @@ -71,23 +67,34 @@ def start_streaming(s): print(clock.fps()) -while True: - # Create server socket - s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM) - s.setsockopt(usocket.SOL_SOCKET, usocket.SO_REUSEADDR, True) - try: - # Bind and listen - s.bind([HOST, PORT]) - s.listen(5) - # Set server socket to blocking - s.setblocking(True) +server = None - # Set server socket timeout - # NOTE: Due to a WINC FW bug, the server socket must be closed and reopened if - # the client disconnects. Use a timeout here to close and re-create the socket. - s.settimeout(3) - start_streaming(s) +while True: + if server is None: + # Create server socket + server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) + # Bind and listen + server.bind([HOST, PORT]) + server.listen(5) + # Set server socket to blocking + server.setblocking(True) + + try: + print("Waiting for connections..") + client, addr = server.accept() except OSError as e: - s.close() - print("socket error: ", e) + server.close() + server = None + print("server socket error:", e) + continue + + try: + # set client socket timeout to 2s + client.settimeout(5.0) + print("Connected to " + addr[0] + ":" + str(addr[1])) + start_streaming(client) + except OSError as e: + client.close() + print("client socket error:", e) # sys.print_exception(e) diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/mqtt_pub.py b/scripts/examples/09-WiFi/mqtt_pub.py similarity index 99% rename from scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/mqtt_pub.py rename to scripts/examples/09-WiFi/mqtt_pub.py index 2d484b1a7..e400e4294 100644 --- a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/mqtt_pub.py +++ b/scripts/examples/09-WiFi/mqtt_pub.py @@ -11,6 +11,7 @@ # mosquitto_sub -h test.mosquitto.org -t "openmv/test" -v # # NOTE: If the mosquitto broker is unreachable, try another broker (For example: broker.hivemq.com) + import time import network from mqtt import MQTTClient diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/mqtt_sub.py b/scripts/examples/09-WiFi/mqtt_sub.py similarity index 99% rename from scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/mqtt_sub.py rename to scripts/examples/09-WiFi/mqtt_sub.py index 91fd0bad9..861666634 100644 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/mqtt_sub.py +++ b/scripts/examples/09-WiFi/mqtt_sub.py @@ -11,6 +11,7 @@ # mosquitto_pub -t "openmv/test" -m "Hello World!" -h test.mosquitto.org -p 1883 # # NOTE: If the mosquitto broker is unreachable, try another broker (For example: broker.hivemq.com) + import time import network from mqtt import MQTTClient diff --git a/scripts/examples/10-Arduino-Boards/Portenta-H7/02-WiFi/ntp.py b/scripts/examples/09-WiFi/ntp.py similarity index 88% rename from scripts/examples/10-Arduino-Boards/Portenta-H7/02-WiFi/ntp.py rename to scripts/examples/09-WiFi/ntp.py index 8546b8ff9..17ce6e5a2 100644 --- a/scripts/examples/10-Arduino-Boards/Portenta-H7/02-WiFi/ntp.py +++ b/scripts/examples/09-WiFi/ntp.py @@ -4,7 +4,7 @@ # # NTP Example # -# This example shows how to get the current time using NTP with the WiFi shield. +# This example shows how to get the current time using NTP. import network import socket @@ -14,7 +14,10 @@ import time SSID = "" # Network SSID KEY = "" # Network key -TIMESTAMP = 2208988800 + 946684800 +TIMESTAMP = 2208988800 + +if time.gmtime(0)[0] == 2000: + TIMESTAMP += 946684800 # Init wlan module and connect to network print("Trying to connect... (This may take a while)...") diff --git a/scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/scan.py b/scripts/examples/09-WiFi/scan.py similarity index 100% rename from scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/scan.py rename to scripts/examples/09-WiFi/scan.py diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/static_ip.py b/scripts/examples/09-WiFi/static_ip.py similarity index 93% rename from scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/static_ip.py rename to scripts/examples/09-WiFi/static_ip.py index 1422951e1..755e3d13b 100644 --- a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/static_ip.py +++ b/scripts/examples/09-WiFi/static_ip.py @@ -4,7 +4,7 @@ # # NTP Example using static IP. # -# This example shows how to get the current time using NTP with the WiFi shield. +# This example shows how to set a static IP config. import network import socket diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/connect.py b/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/connect.py deleted file mode 100644 index 3dc503e53..000000000 --- a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/connect.py +++ /dev/null @@ -1,25 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Connect Example -# -# This example shows how to connect your OpenMV Cam with a WiFi shield to the net. - -import network -import time - -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -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()) diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/dns.py b/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/dns.py deleted file mode 100644 index 3dada792c..000000000 --- a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/dns.py +++ /dev/null @@ -1,26 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# DNS Example -# -# This example shows how to get the IP address for websites via DNS. - -import network -import time - -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -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()) -print(usocket.getaddrinfo("www.google.com", 80)[0][4]) diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/mqtt_sub.py b/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/mqtt_sub.py deleted file mode 100644 index 91fd0bad9..000000000 --- a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/mqtt_sub.py +++ /dev/null @@ -1,47 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# MQTT Example. -# This example shows how to use the MQTT library to subscribe to a topic. -# -# 1) Copy the mqtt.py library to OpenMV storage. -# 2) Run this script on the OpenMV camera. -# 3) Install the mosquitto client on PC and run the following command: -# mosquitto_pub -t "openmv/test" -m "Hello World!" -h test.mosquitto.org -p 1883 -# -# NOTE: If the mosquitto broker is unreachable, try another broker (For example: broker.hivemq.com) -import time -import network -from mqtt import MQTTClient - -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -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()) - -client = MQTTClient("openmv", "test.mosquitto.org", port=1883) -client.connect() - - -def callback(topic, msg): - print(topic, msg) - - -# must set callback first -client.set_callback(callback) -client.subscribe("openmv/test") - -while True: - client.check_msg() # poll for messages. - time.sleep_ms(1000) diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/ntp.py b/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/ntp.py deleted file mode 100644 index 8546b8ff9..000000000 --- a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/ntp.py +++ /dev/null @@ -1,44 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# NTP Example -# -# This example shows how to get the current time using NTP with the WiFi shield. - -import network -import socket -import struct -import time - -SSID = "" # Network SSID -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.active(True) -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()) - -# Create new socket -client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - -# Get addr info via DNS -addr = socket.getaddrinfo("pool.ntp.org", 123)[0][4] - -# Send query -client.sendto("\x1b" + 47 * "\0", addr) -data, address = client.recvfrom(1024) - -# Print time -t = struct.unpack(">IIIIIIIIIIII", data)[10] - TIMESTAMP -print("Year:%d Month:%d Day:%d Time: %d:%d:%d" % (time.localtime(t)[0:6])) diff --git a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/scan.py b/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/scan.py deleted file mode 100644 index 6cadbaa4f..000000000 --- a/scripts/examples/10-Arduino-Boards/Giga-H7/03-WiFi/scan.py +++ /dev/null @@ -1,24 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Scan Example -# -# This example shows how to scan for networks with the WiFi shield. - -import time -import network - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -print("Scanning...") -while True: - scan_result = wlan.scan() - for ap in scan_result: - print( - "SSID: %s BSSID: %s Channel: %d RSSI: %d Auth: %d" - % (ap[0], ":".join(["%X" % i for i in ap[1]]), ap[2], ap[3], ap[4]) - ) - print() - time.sleep_ms(1000) diff --git a/scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/http_client.py b/scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/http_client.py deleted file mode 100644 index afcd1acb8..000000000 --- a/scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/http_client.py +++ /dev/null @@ -1,43 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Simple HTTP client example. - -import network -import socket - -# AP info -SSID = "" # Network SSID -KEY = "" # Network key - -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.active(True) -wlan.connect(SSID, KEY) - -# We should have a valid IP now via DHCP -print("WiFi Connected ", wlan.ifconfig()) - -# Get addr info via DNS -addr = socket.getaddrinfo(HOST, PORT)[0][4] -print(addr) - -# Create a new socket and connect to addr -client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -client.connect(addr) - -# Set timeout -client.settimeout(3.0) - -# Send HTTP request and recv response -client.send("GET / HTTP/1.1\r\nHost: %s\r\n\r\n" % (HOST)) -print(client.recv(1024)) - -# Close socket -client.close() diff --git a/scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/ntp.py b/scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/ntp.py deleted file mode 100644 index 51a74f004..000000000 --- a/scripts/examples/10-Arduino-Boards/Nano-RP2040/03-WiFi/ntp.py +++ /dev/null @@ -1,44 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# NTP Example -# -# This example shows how to get the current time using NTP with the WiFi shield. - -import network -import usocket -import ustruct -import utime - -# AP info -SSID = "" # Network SSID -KEY = "" # Network key - -TIMESTAMP = 2208988800 - -# Init wlan module and connect to network -print("Trying to connect... (may take a while)...") - -wlan = network.WLAN() -wlan.active(True) -wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK) - -# We should have a valid IP now via DHCP -print(wlan.ifconfig()) - -# Create new socket -client = usocket.socket(usocket.AF_INET, usocket.SOCK_DGRAM) -client.bind(("", 8080)) -# client.settimeout(3.0) - -# Get addr info via DNS -addr = usocket.getaddrinfo("pool.ntp.org", 123)[0][4] - -# Send query -client.sendto("\x1b" + 47 * "\0", addr) -data, address = client.recvfrom(1024) - -# Print time -t = ustruct.unpack(">IIIIIIIIIIII", data)[10] - TIMESTAMP -print("Year:%d Month:%d Day:%d Time: %d:%d:%d" % (utime.localtime(t)[0:6])) diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/connect.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/connect.py deleted file mode 100644 index 3dc503e53..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/connect.py +++ /dev/null @@ -1,25 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Connect Example -# -# This example shows how to connect your OpenMV Cam with a WiFi shield to the net. - -import network -import time - -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -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()) diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/dns.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/dns.py deleted file mode 100644 index 3dada792c..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/dns.py +++ /dev/null @@ -1,26 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# DNS Example -# -# This example shows how to get the IP address for websites via DNS. - -import network -import time - -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -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()) -print(usocket.getaddrinfo("www.google.com", 80)[0][4]) diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/http_client.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/http_client.py deleted file mode 100644 index aab7b0c39..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/http_client.py +++ /dev/null @@ -1,46 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Simple HTTP client example. - -import network -import socket -import time - -# AP info -SSID = "" # Network SSID -KEY = "" # Network key - -PORT = 80 -HOST = "www.google.com" - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -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()) - -# Get addr info via DNS -addr = socket.getaddrinfo(HOST, PORT)[0][4] -print(addr) - -# Create a new socket and connect to addr -client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -client.connect(addr) - -# Set timeout -client.settimeout(3.0) - -# Send HTTP request and recv response -client.send("GET / HTTP/1.1\r\nHost: %s\r\n\r\n" % (HOST)) -print(client.recv(1024)) - -# Close socket -client.close() diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/http_client_ssl.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/http_client_ssl.py deleted file mode 100644 index 57137bae1..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/http_client_ssl.py +++ /dev/null @@ -1,57 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Simple HTTPS client example. -import network -import socket -import ssl -import time - -# AP info -SSID = "" # Network SSID -KEY = "" # Network key - -PORT = 443 -HOST = "www.google.com" - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -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()) - -# Get addr info via DNS -addr = socket.getaddrinfo(HOST, PORT)[0][4] -print(addr) - -# Create a new socket and connect to addr -client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - -client.connect(addr) - -# Set timeout -client.settimeout(3.0) - -client = ssl.wrap_socket(client, server_hostname=HOST) - -# Send HTTP request and recv response -request = "GET / HTTP/1.1\r\n" -request += "HOST: %s\r\n" -request += "User-Agent: Mozilla/5.0\r\n" -request += "Connection: keep-alive\r\n\r\n" -# Add more headers if needed. -client.write(request % (HOST) + "\r\n") - -response = client.read(1024) -for l in response.split(b"\r\n"): - print(l.decode()) - -# Close socket -client.close() diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/mjpeg_streamer.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/mjpeg_streamer.py deleted file mode 100644 index d09e9dc59..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/mjpeg_streamer.py +++ /dev/null @@ -1,93 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# MJPEG Streaming -# -# This example shows off how to do MJPEG streaming to a FIREFOX webrowser -# Chrome, Firefox and MJpegViewer App on Android have been tested. -# Connect to the IP address/port printed out from ifconfig to view the stream. -import sensor -import time -import network -import socket - -SSID = "" # Network SSID -KEY = "" # Network key -HOST = "" # Use first available interface -PORT = 8080 # Arbitrary non-privileged port - -# Init sensor -sensor.reset() -sensor.set_framesize(sensor.QVGA) -sensor.set_pixformat(sensor.RGB565) - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -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()) - -# Create server socket -s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) - -# Bind and listen -s.bind([HOST, PORT]) -s.listen(5) - -# Set server socket to blocking -s.setblocking(True) - - -def start_streaming(s): - print("Waiting for connections..") - client, addr = s.accept() - # set client socket timeout to 5s - client.settimeout(5.0) - print("Connected to " + addr[0] + ":" + str(addr[1])) - - # Read request from client - data = client.recv(1024) - # Should parse client request here - - # Send multipart header - client.sendall( - "HTTP/1.1 200 OK\r\n" - "Server: OpenMV\r\n" - "Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" - "Cache-Control: no-cache\r\n" - "Pragma: no-cache\r\n\r\n" - ) - - # FPS clock - clock = time.clock() - - # Start streaming images - # NOTE: Disable IDE preview to increase streaming FPS. - while True: - clock.tick() # Track elapsed milliseconds between snapshots(). - frame = sensor.snapshot() - cframe = frame.compressed(quality=35) - header = ( - "\r\n--openmv\r\n" - "Content-Type: image/jpeg\r\n" - "Content-Length:" + str(cframe.size()) + "\r\n\r\n" - ) - client.sendall(header) - client.sendall(cframe) - print(clock.fps()) - - -while True: - try: - start_streaming(s) - except OSError as e: - print("socket error: ", e) - # sys.print_exception(e) diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/mqtt_pub.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/mqtt_pub.py deleted file mode 100644 index 2d484b1a7..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/mqtt_pub.py +++ /dev/null @@ -1,38 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# MQTT Example. -# This example shows how to use the MQTT library to publish to a topic. -# -# 1) Copy the mqtt.py library to OpenMV storage. -# 2) Run this script on the OpenMV camera. -# 3) Install the mosquitto client on PC and run the following command: -# mosquitto_sub -h test.mosquitto.org -t "openmv/test" -v -# -# NOTE: If the mosquitto broker is unreachable, try another broker (For example: broker.hivemq.com) -import time -import network -from mqtt import MQTTClient - -SSID = "" # Network SSID -KEY = "" # Network key - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -wlan.active(True) -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()) - -client = MQTTClient("openmv", "test.mosquitto.org", port=1883) -client.connect() - -while True: - client.publish("openmv/test", "Hello World!") - time.sleep_ms(1000) diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/ntp.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/ntp.py deleted file mode 100644 index 8546b8ff9..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/ntp.py +++ /dev/null @@ -1,44 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# NTP Example -# -# This example shows how to get the current time using NTP with the WiFi shield. - -import network -import socket -import struct -import time - -SSID = "" # Network SSID -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.active(True) -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()) - -# Create new socket -client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - -# Get addr info via DNS -addr = socket.getaddrinfo("pool.ntp.org", 123)[0][4] - -# Send query -client.sendto("\x1b" + 47 * "\0", addr) -data, address = client.recvfrom(1024) - -# Print time -t = struct.unpack(">IIIIIIIIIIII", data)[10] - TIMESTAMP -print("Year:%d Month:%d Day:%d Time: %d:%d:%d" % (time.localtime(t)[0:6])) diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/scan.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/scan.py deleted file mode 100644 index 6cadbaa4f..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/scan.py +++ /dev/null @@ -1,24 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Scan Example -# -# This example shows how to scan for networks with the WiFi shield. - -import time -import network - -wlan = network.WLAN(network.STA_IF) -wlan.active(True) - -print("Scanning...") -while True: - scan_result = wlan.scan() - for ap in scan_result: - print( - "SSID: %s BSSID: %s Channel: %d RSSI: %d Auth: %d" - % (ap[0], ":".join(["%X" % i for i in ap[1]]), ap[2], ap[3], ap[4]) - ) - print() - time.sleep_ms(1000) diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/static_ip.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/static_ip.py deleted file mode 100644 index 1422951e1..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/03-WiFi/static_ip.py +++ /dev/null @@ -1,43 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# NTP Example using static IP. -# -# This example shows how to get the current time using NTP with the WiFi shield. - -import network -import socket -import struct -import time - -SSID = "" # Network SSID -KEY = "" # Network key - -TIMESTAMP = 2208988800 + 946684800 - -# Init wlan module and connect to network -wlan = network.WLAN(network.STA_IF) -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) - -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) - -# Get addr info via DNS -addr = socket.getaddrinfo("pool.ntp.org", 123)[0][4] - -# Send query -client.sendto("\x1b" + 47 * "\0", addr) -data, address = client.recvfrom(1024) - -# Print time -t = struct.unpack(">IIIIIIIIIIII", data)[10] - TIMESTAMP -print("Year:%d Month:%d Day:%d Time: %d:%d:%d" % (time.localtime(t)[0:6])) diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/04-Bluetooth/ble_blinky.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/04-Bluetooth/ble_blinky.py deleted file mode 100644 index 3877e219c..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/04-Bluetooth/ble_blinky.py +++ /dev/null @@ -1,65 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Bluetooth Blinky Example -# -# Use nRFConnect app from the App store, connect to the Nano and write 1/0 to control the LED. - -import bluetooth -import time -from ble_advertising import advertising_payload -from machine import LED -from micropython import const - -_IRQ_CENTRAL_CONNECT = const(1) -_IRQ_CENTRAL_DISCONNECT = const(2) -_IRQ_GATTS_WRITE = const(3) - -_FLAG_READ = const(0x0002) -_FLAG_WRITE = const(0x0008) -_FLAG_NOTIFY = const(0x0010) -_FLAG_INDICATE = const(0x0020) - -_SERVICE_UUID = bluetooth.UUID(0x1523) -_LED_CHAR_UUID = (bluetooth.UUID(0x1525), _FLAG_WRITE) -_LED_SERVICE = ( - _SERVICE_UUID, - (_LED_CHAR_UUID,), -) - - -class BLETemperature: - def __init__(self, ble, name="Nicla-Vision"): - self._ble = ble - self._ble.active(True) - self._ble.irq(self._irq) - ((self._handle,),) = self._ble.gatts_register_services((_LED_SERVICE,)) - self._connections = set() - self._payload = advertising_payload(name=name, services=[_SERVICE_UUID]) - self._advertise() - self.led = LED("LED_BLUE") - - def _irq(self, event, data): - # Track connections so we can send notifications. - if event == _IRQ_CENTRAL_CONNECT: - conn_handle, _, _ = data - self._connections.add(conn_handle) - elif event == _IRQ_CENTRAL_DISCONNECT: - conn_handle, _, _ = data - self._connections.remove(conn_handle) - # Start advertising again to allow a new connection. - self._advertise() - elif event == _IRQ_GATTS_WRITE: - self.led.value(self._ble.gatts_read(data[-1])[0]) - - def _advertise(self, interval_us=500000): - self._ble.gap_advertise(interval_us, adv_data=self._payload) - - -if __name__ == "__main__": - ble = bluetooth.BLE() - temp = BLETemperature(ble) - - while True: - time.sleep_ms(1000) diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/04-Bluetooth/ble_temperature.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/04-Bluetooth/ble_temperature.py deleted file mode 100644 index 121a40a1e..000000000 --- a/scripts/examples/10-Arduino-Boards/Nicla-Vision/04-Bluetooth/ble_temperature.py +++ /dev/null @@ -1,102 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# This example demonstrates a simple temperature sensor peripheral. -# -# The sensor's local value updates every second, and it will notify -# any connected central every 10 seconds. - -import bluetooth -import random -import struct -import time -from ble_advertising import advertising_payload -from machine import LED -from micropython import const - -_IRQ_CENTRAL_CONNECT = const(1) -_IRQ_CENTRAL_DISCONNECT = const(2) -_IRQ_GATTS_INDICATE_DONE = const(20) - -_FLAG_READ = const(0x0002) -_FLAG_NOTIFY = const(0x0010) -_FLAG_INDICATE = const(0x0020) - -# org.bluetooth.service.environmental_sensing -_ENV_SENSE_UUID = bluetooth.UUID(0x181A) -# org.bluetooth.characteristic.temperature -_TEMP_CHAR = ( - bluetooth.UUID(0x2A6E), - _FLAG_READ | _FLAG_NOTIFY | _FLAG_INDICATE, -) -_ENV_SENSE_SERVICE = ( - _ENV_SENSE_UUID, - (_TEMP_CHAR,), -) - -# org.bluetooth.characteristic.gap.appearance.xml -_ADV_APPEARANCE_GENERIC_THERMOMETER = const(768) - - -class BLETemperature: - def __init__(self, ble, name="Nicla-Vision"): - self._ble = ble - self._ble.active(True) - self._ble.irq(self._irq) - ((self._handle,),) = self._ble.gatts_register_services((_ENV_SENSE_SERVICE,)) - self._connections = set() - self._payload = advertising_payload( - name=name, - services=[_ENV_SENSE_UUID], - appearance=_ADV_APPEARANCE_GENERIC_THERMOMETER, - ) - self._advertise() - self.led = LED("LED_BLUE") - - def _irq(self, event, data): - # Track connections so we can send notifications. - if event == _IRQ_CENTRAL_CONNECT: - conn_handle, _, _ = data - self._connections.add(conn_handle) - self.led.on() - elif event == _IRQ_CENTRAL_DISCONNECT: - conn_handle, _, _ = data - self._connections.remove(conn_handle) - # Start advertising again to allow a new connection. - self._advertise() - self.led.off() - elif event == _IRQ_GATTS_INDICATE_DONE: - conn_handle, value_handle, status = data - - def set_temperature(self, temp_deg_c, notify=False, indicate=False): - # Data is sint16 in degrees Celsius with a resolution of 0.01 degrees Celsius. - # Write the local value, ready for a central to read. - self._ble.gatts_write(self._handle, struct.pack("IIIIIIIIIIII", data)[10] - TIMESTAMP -print("Year:%d Month:%d Day:%d Time: %d:%d:%d" % (time.localtime(t)[0:6])) diff --git a/scripts/examples/10-Arduino-Boards/Portenta-H7/03-Bluetooth/ble_blinky.py b/scripts/examples/10-Arduino-Boards/Portenta-H7/03-Bluetooth/ble_blinky.py deleted file mode 100644 index 3c013398d..000000000 --- a/scripts/examples/10-Arduino-Boards/Portenta-H7/03-Bluetooth/ble_blinky.py +++ /dev/null @@ -1,65 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# Bluetooth Blinky Example -# -# Use nRFConnect app from the App store, connect to the Nano and write 1/0 to control the LED. - -import bluetooth -import time -from ble_advertising import advertising_payload -from machine import LED -from micropython import const - -_IRQ_CENTRAL_CONNECT = const(1) -_IRQ_CENTRAL_DISCONNECT = const(2) -_IRQ_GATTS_WRITE = const(3) - -_FLAG_READ = const(0x0002) -_FLAG_WRITE = const(0x0008) -_FLAG_NOTIFY = const(0x0010) -_FLAG_INDICATE = const(0x0020) - -_SERVICE_UUID = bluetooth.UUID(0x1523) -_LED_CHAR_UUID = (bluetooth.UUID(0x1525), _FLAG_WRITE) -_LED_SERVICE = ( - _SERVICE_UUID, - (_LED_CHAR_UUID,), -) - - -class BLETemperature: - def __init__(self, ble, name="Portenta-H7"): - self._ble = ble - self._ble.active(True) - self._ble.irq(self._irq) - ((self._handle,),) = self._ble.gatts_register_services((_LED_SERVICE,)) - self._connections = set() - self._payload = advertising_payload(name=name, services=[_SERVICE_UUID]) - self._advertise() - self.led = LED("LED_BLUE") - - def _irq(self, event, data): - # Track connections so we can send notifications. - if event == _IRQ_CENTRAL_CONNECT: - conn_handle, _, _ = data - self._connections.add(conn_handle) - elif event == _IRQ_CENTRAL_DISCONNECT: - conn_handle, _, _ = data - self._connections.remove(conn_handle) - # Start advertising again to allow a new connection. - self._advertise() - elif event == _IRQ_GATTS_WRITE: - self.led.value(self._ble.gatts_read(data[-1])[0]) - - def _advertise(self, interval_us=500000): - self._ble.gap_advertise(interval_us, adv_data=self._payload) - - -if __name__ == "__main__": - ble = bluetooth.BLE() - temp = BLETemperature(ble) - - while True: - time.sleep_ms(1000) diff --git a/scripts/examples/10-Arduino-Boards/Portenta-H7/03-Bluetooth/ble_temperature.py b/scripts/examples/10-Arduino-Boards/Portenta-H7/03-Bluetooth/ble_temperature.py deleted file mode 100644 index e70c1a4c3..000000000 --- a/scripts/examples/10-Arduino-Boards/Portenta-H7/03-Bluetooth/ble_temperature.py +++ /dev/null @@ -1,102 +0,0 @@ -# This work is licensed under the MIT license. -# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved. -# https://github.com/openmv/openmv/blob/master/LICENSE -# -# This example demonstrates a simple temperature sensor peripheral. -# -# The sensor's local value updates every second, and it will notify -# any connected central every 10 seconds. - -import bluetooth -import random -import struct -import time -from ble_advertising import advertising_payload -from machine import LED -from micropython import const - -_IRQ_CENTRAL_CONNECT = const(1) -_IRQ_CENTRAL_DISCONNECT = const(2) -_IRQ_GATTS_INDICATE_DONE = const(20) - -_FLAG_READ = const(0x0002) -_FLAG_NOTIFY = const(0x0010) -_FLAG_INDICATE = const(0x0020) - -# org.bluetooth.service.environmental_sensing -_ENV_SENSE_UUID = bluetooth.UUID(0x181A) -# org.bluetooth.characteristic.temperature -_TEMP_CHAR = ( - bluetooth.UUID(0x2A6E), - _FLAG_READ | _FLAG_NOTIFY | _FLAG_INDICATE, -) -_ENV_SENSE_SERVICE = ( - _ENV_SENSE_UUID, - (_TEMP_CHAR,), -) - -# org.bluetooth.characteristic.gap.appearance.xml -_ADV_APPEARANCE_GENERIC_THERMOMETER = const(768) - - -class BLETemperature: - def __init__(self, ble, name="Portenta-H7"): - self._ble = ble - self._ble.active(True) - self._ble.irq(self._irq) - ((self._handle,),) = self._ble.gatts_register_services((_ENV_SENSE_SERVICE,)) - self._connections = set() - self._payload = advertising_payload( - name=name, - services=[_ENV_SENSE_UUID], - appearance=_ADV_APPEARANCE_GENERIC_THERMOMETER, - ) - self._advertise() - self.led = LED("LED_BLUE") - - def _irq(self, event, data): - # Track connections so we can send notifications. - if event == _IRQ_CENTRAL_CONNECT: - conn_handle, _, _ = data - self._connections.add(conn_handle) - self.led.on() - elif event == _IRQ_CENTRAL_DISCONNECT: - conn_handle, _, _ = data - self._connections.remove(conn_handle) - # Start advertising again to allow a new connection. - self._advertise() - self.led.off() - elif event == _IRQ_GATTS_INDICATE_DONE: - conn_handle, value_handle, status = data - - def set_temperature(self, temp_deg_c, notify=False, indicate=False): - # Data is sint16 in degrees Celsius with a resolution of 0.01 degrees Celsius. - # Write the local value, ready for a central to read. - self._ble.gatts_write(self._handle, struct.pack("