From a4858015c459ab9f0e5d77abb440b62afec228d8 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Sat, 16 Oct 2021 13:40:03 -0700 Subject: [PATCH] Update rstp/rpc scripts to use standard network libraries --- ..._as_the_remote_device_for_your_computer.py | 28 +++---- ..._as_the_remote_device_for_your_computer.py | 28 +++---- ...e_transfer_raw_as_the_controller_device.py | 2 +- ...image_transfer_raw_as_the_remote_device.py | 2 +- .../popular_features_as_the_remote_device.py | 42 +++++----- .../36-Web-Servers/rtsp_video_server_lan.py | 79 +++++++++++++++++++ .../36-Web-Servers/rtsp_video_server_wlan.py | 79 +++++++++++++++++++ ..._as_the_remote_device_for_your_computer.py | 28 +++---- ..._as_the_remote_device_for_your_computer.py | 28 +++---- ...e_transfer_raw_as_the_controller_device.py | 2 +- ...image_transfer_raw_as_the_remote_device.py | 2 +- .../popular_features_as_the_remote_device.py | 28 +++---- ...deo_server.py => rtsp_video_server_lan.py} | 20 ++--- .../36-Web-Servers/rtsp_video_server_wlan.py} | 22 +++--- scripts/libraries/rpc.py | 28 ++----- scripts/libraries/rtsp.py | 12 +-- 16 files changed, 282 insertions(+), 148 deletions(-) create mode 100644 scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server_lan.py create mode 100644 scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server_wlan.py rename scripts/examples/OpenMV/36-Web-Servers/{rtsp_video_server.py => rtsp_video_server_lan.py} (82%) rename scripts/examples/{Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server.py => OpenMV/36-Web-Servers/rtsp_video_server_wlan.py} (82%) diff --git a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_jpg_as_the_remote_device_for_your_computer.py b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_jpg_as_the_remote_device_for_your_computer.py index 80f47b70a..9e4ffad60 100644 --- a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_jpg_as_the_remote_device_for_your_computer.py +++ b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_jpg_as_the_remote_device_for_your_computer.py @@ -20,7 +20,7 @@ sensor.skip_frames(time = 2000) omv.disable_fb(True) # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to be controlled over USB or WIFI. +# allowing your OpenMV Cam to be controlled over USB or LAN/WLAN. ################################################################ # Choose the interface you wish to control your OpenMV Cam over. @@ -30,21 +30,21 @@ omv.disable_fb(True) # interface = rpc.rpc_usb_vcp_slave() -# Uncomment the below line to setup your OpenMV Cam for control over WiFi. +# Uncomment the below line to setup your OpenMV Cam for control over the lan. # -# * ssid - WiFi network to connect to. -# * ssid_key - WiFi network password. -# * ssid_security - WiFi security. -# * port - Port to route traffic to. -# * mode - Regular or access-point mode. -# * static_ip - If not None then a tuple of the (IP Address, Subnet Mask, Gateway, DNS Address) +# network_if = network.LAN() +# network_if.active(True) +# network_if.ifconfig('dhcp') # -# interface = rpc.rpc_wifi_slave(ssid="", -# ssid_key="", -# ssid_security=network.WINC.WPA_PSK, -# port=0x1DBA, -# mode=network.WINC.MODE_STA, -# static_ip=None) +# interface = rpc.rpc_network_slave(network_if) + +# Uncomment the below line to setup your OpenMV Cam for control over the wlan. +# +# network_if = network.WLAN(network.STA_IF) +# network_if.active(True) +# network_if.connect('your-ssid', 'your-password') +# +# interface = rpc.rpc_network_slave(network_if) ################################################################ # Call Backs diff --git a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_jpg_streaming_as_the_remote_device_for_your_computer.py b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_jpg_streaming_as_the_remote_device_for_your_computer.py index 686ba22fd..3ac708df4 100644 --- a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_jpg_streaming_as_the_remote_device_for_your_computer.py +++ b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_jpg_streaming_as_the_remote_device_for_your_computer.py @@ -20,7 +20,7 @@ sensor.skip_frames(time = 2000) omv.disable_fb(True) # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to be controlled over USB or WIFI. +# allowing your OpenMV Cam to be controlled over USB or LAN/WLAN. ################################################################ # Choose the interface you wish to control your OpenMV Cam over. @@ -30,21 +30,21 @@ omv.disable_fb(True) # interface = rpc.rpc_usb_vcp_slave() -# Uncomment the below line to setup your OpenMV Cam for control over WiFi. +# Uncomment the below line to setup your OpenMV Cam for control over the lan. # -# * ssid - WiFi network to connect to. -# * ssid_key - WiFi network password. -# * ssid_security - WiFi security. -# * port - Port to route traffic to. -# * mode - Regular or access-point mode. -# * static_ip - If not None then a tuple of the (IP Address, Subnet Mask, Gateway, DNS Address) +# network_if = network.LAN() +# network_if.active(True) +# network_if.ifconfig('dhcp') # -# interface = rpc.rpc_wifi_slave(ssid="", -# ssid_key="", -# ssid_security=network.WINC.WPA_PSK, -# port=0x1DBA, -# mode=network.WINC.MODE_STA, -# static_ip=None) +# interface = rpc.rpc_network_slave(network_if) + +# Uncomment the below line to setup your OpenMV Cam for control over the wlan. +# +# network_if = network.WLAN(network.STA_IF) +# network_if.active(True) +# network_if.connect('your-ssid', 'your-password') +# +# interface = rpc.rpc_network_slave(network_if) ################################################################ # Call Backs diff --git a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_controller_device.py b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_controller_device.py index 20769d35b..f3b9d1a07 100644 --- a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_controller_device.py +++ b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_controller_device.py @@ -7,7 +7,7 @@ import image, network, omv, rpc, sensor, struct, time # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to control over CAN, I2C, SPI, UART, or WIFI. +# allowing your OpenMV Cam to control over CAN, I2C, SPI, UART, or LAN/WLAN. ############################################################## # Choose the interface you wish to control an OpenMV Cam over. diff --git a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_remote_device.py b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_remote_device.py index 5d2267370..c04ac7d66 100644 --- a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_remote_device.py +++ b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/image_transfer_raw_as_the_remote_device.py @@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to be controlled over CAN, I2C, SPI, UART, or WIFI. +# allowing your OpenMV Cam to be controlled over CAN, I2C, SPI, UART, or LAN/WLAN. ################################################################ # Choose the interface you wish to control your OpenMV Cam over. diff --git a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_remote_device.py b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_remote_device.py index 45a4091f2..500821e68 100644 --- a/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_remote_device.py +++ b/scripts/examples/Arduino/Portenta-H7/34-Remote-Control/popular_features_as_the_remote_device.py @@ -14,7 +14,7 @@ sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to be controlled over CAN, I2C, SPI, UART, USB VCP, or WiFi. +# allowing your OpenMV Cam to be controlled over CAN, I2C, SPI, UART, USB VCP, or LAN/WLAN. ################################################################ # Choose the interface you wish to control your OpenMV Cam over. @@ -64,21 +64,21 @@ interface = rpc.rpc_uart_slave(baudrate=115200) # # interface = rpc.rpc_usb_vcp_slave() -# Uncomment the below line to setup your OpenMV Cam for control over WiFi. +# Uncomment the below line to setup your OpenMV Cam for control over the lan. # -# * ssid - WiFi network to connect to. -# * ssid_key - WiFi network password. -# * ssid_security - WiFi security. -# * port - Port to route traffic to. -# * mode - Regular or access-point mode. -# * static_ip - If not None then a tuple of the (IP Address, Subnet Mask, Gateway, DNS Address) +# network_if = network.LAN() +# network_if.active(True) +# network_if.ifconfig('dhcp') # -# interface = rpc.rpc_wifi_slave(ssid="", -# ssid_key="", -# ssid_security=network.WINC.WPA_PSK, -# port=0x1DBA, -# mode=network.WINC.MODE_STA, -# static_ip=None) +# interface = rpc.rpc_network_slave(network_if) + +# Uncomment the below line to setup your OpenMV Cam for control over the wlan. +# +# network_if = network.WLAN(network.STA_IF) +# network_if.active(True) +# network_if.connect('your-ssid', 'your-password') +# +# interface = rpc.rpc_network_slave(network_if) ################################################################ # Call Backs @@ -127,7 +127,7 @@ def person_detection(data): # data is unused def qrcode_detection(data): sensor.set_pixformat(sensor.GRAYSCALE) - sensor.set_framesize(sensor.VGA) + sensor.set_framesize(sensor.QVGA) sensor.set_windowing((320, 240)) codes = sensor.snapshot().find_qrcodes() if not codes: return bytes() # No detections. @@ -139,7 +139,7 @@ def qrcode_detection(data): # data is unused def all_qrcode_detection(data): sensor.set_pixformat(sensor.GRAYSCALE) - sensor.set_framesize(sensor.VGA) + sensor.set_framesize(sensor.QVGA) sensor.set_windowing((320, 240)) codes = sensor.snapshot().find_qrcodes() if not codes: return bytes() # No detections. @@ -177,7 +177,7 @@ def all_apriltag_detection(data): # data is unused def datamatrix_detection(data): sensor.set_pixformat(sensor.GRAYSCALE) - sensor.set_framesize(sensor.VGA) + sensor.set_framesize(sensor.QVGA) sensor.set_windowing((320, 240)) codes = sensor.snapshot().find_datamatrices() if not codes: return bytes() # No detections. @@ -189,7 +189,7 @@ def datamatrix_detection(data): # data is unused def all_datamatrix_detection(data): sensor.set_pixformat(sensor.GRAYSCALE) - sensor.set_framesize(sensor.VGA) + sensor.set_framesize(sensor.QVGA) sensor.set_windowing((320, 240)) codes = sensor.snapshot().find_datamatrices() if not codes: return bytes() # No detections. @@ -202,7 +202,7 @@ def all_datamatrix_detection(data): # data is unused def barcode_detection(data): sensor.set_pixformat(sensor.GRAYSCALE) - sensor.set_framesize(sensor.VGA) + sensor.set_framesize(sensor.QVGA) sensor.set_windowing((sensor.width(), sensor.height()//8)) codes = sensor.snapshot().find_barcodes() if not codes: return bytes() # No detections. @@ -213,7 +213,7 @@ def barcode_detection(data): # data is unused def all_barcode_detection(data): sensor.set_pixformat(sensor.GRAYSCALE) - sensor.set_framesize(sensor.VGA) + sensor.set_framesize(sensor.QVGA) sensor.set_windowing((sensor.width(), sensor.height()//8)) codes = sensor.snapshot().find_barcodes() if not codes: return bytes() # No detections. @@ -244,7 +244,7 @@ def color_detection(data): # # data is unused def jpeg_snapshot(data): - sensor.set_pixformat(sensor.GRAYSCALE) + sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) return sensor.snapshot().compress(quality=90).bytearray() diff --git a/scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server_lan.py b/scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server_lan.py new file mode 100644 index 000000000..f047cdf02 --- /dev/null +++ b/scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server_lan.py @@ -0,0 +1,79 @@ +# RTSP Video Server +# +# This example shows off how to stream video over RTSP with your OpenMV Cam. +# +# You can use a program like VLC to view the video stream by connecting to the +# OpenMV Cam's IP address. + +import network, omv, rtsp, sensor, time + +# RTP MJPEG streaming works using JPEG images produced by the OV2640/OV5640 camera modules. +# Not all programs (e.g. VLC) implement the full JPEG standard for decoding any JPEG image +# in RTP packets. Images JPEG compressed by the OpenMV Cam internally may not display. + +# FFPLAY will correctly handle JPEGs produced by OpenMV software. + +sensor.reset() + +sensor.set_pixformat(sensor.GRAYSCALE) +sensor.set_framesize(sensor.QVGA) + +# Turn off the frame buffer connection to the IDE from the OpenMV Cam side. +# +# This needs to be done when manually compressing jpeg images at higher quality +# so that the OpenMV Cam does not try to stream them to the IDE using a fall back +# mechanism if the JPEG image is too large to fit in the IDE JPEG frame buffer on the OpenMV Cam. + +omv.disable_fb(True) + +# Setup Network Interface + +network_if = network.LAN() +network_if.active(True) +network_if.ifconfig('dhcp') + +# Setup RTSP Server + +server = rtsp.rtsp_server(network_if) + +# For the call back functions below: +# +# `pathname` is the name of the stream resource the client wants. You can ignore this if it's not +# needed. Otherwise, you can use it to determine what image object to return. By default the path +# name will be "/". +# +# `session` is random number that will change when a new connection is established. You can use +# session with a dictionary to differentiate different accesses to the same file name. + +def setup_callback(pathname, session): + print("Opening \"%s\" in session %d" % (pathname, session)) + +def play_callback(pathname, session): + print("Playing \"%s\" in session %d" % (pathname, session)) + +def pause_callback(pathname, session): # VLC only pauses locally. This is never called. + print("Pausing \"%s\" in session %d" % (pathname, session)) + +def teardown_callback(pathname, session): + print("Closing \"%s\" in session %d" % (pathname, session)) + +server.register_setup_cb(setup_callback) +server.register_play_cb(play_callback) +server.register_pause_cb(pause_callback) +server.register_teardown_cb(teardown_callback) + +# Track the current FPS. +clock = time.clock() + +# Called each time a new frame is needed. +def image_callback(pathname, session): + clock.tick() + img = sensor.snapshot() + # Markup image and/or do various things. + print(clock.fps()) + return img + +# Stream does not return. It will call `image_callback` when it needs to get an image object to send +# to the remote rtsp client connecting to the server. + +server.stream(image_callback) diff --git a/scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server_wlan.py b/scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server_wlan.py new file mode 100644 index 000000000..76908829d --- /dev/null +++ b/scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server_wlan.py @@ -0,0 +1,79 @@ +# RTSP Video Server +# +# This example shows off how to stream video over RTSP with your OpenMV Cam. +# +# You can use a program like VLC to view the video stream by connecting to the +# OpenMV Cam's IP address. + +import network, omv, rtsp, sensor, time + +# RTP MJPEG streaming works using JPEG images produced by the OV2640/OV5640 camera modules. +# Not all programs (e.g. VLC) implement the full JPEG standard for decoding any JPEG image +# in RTP packets. Images JPEG compressed by the OpenMV Cam internally may not display. + +# FFPLAY will correctly handle JPEGs produced by OpenMV software. + +sensor.reset() + +sensor.set_pixformat(sensor.GRAYSCALE) +sensor.set_framesize(sensor.QVGA) + +# Turn off the frame buffer connection to the IDE from the OpenMV Cam side. +# +# This needs to be done when manually compressing jpeg images at higher quality +# so that the OpenMV Cam does not try to stream them to the IDE using a fall back +# mechanism if the JPEG image is too large to fit in the IDE JPEG frame buffer on the OpenMV Cam. + +omv.disable_fb(True) + +# Setup Network Interface + +network_if = network.WLAN(network.STA_IF) +network_if.active(True) +network_if.connect('your-ssid', 'your-password') + +# Setup RTSP Server + +server = rtsp.rtsp_server(network_if) + +# For the call back functions below: +# +# `pathname` is the name of the stream resource the client wants. You can ignore this if it's not +# needed. Otherwise, you can use it to determine what image object to return. By default the path +# name will be "/". +# +# `session` is random number that will change when a new connection is established. You can use +# session with a dictionary to differentiate different accesses to the same file name. + +def setup_callback(pathname, session): + print("Opening \"%s\" in session %d" % (pathname, session)) + +def play_callback(pathname, session): + print("Playing \"%s\" in session %d" % (pathname, session)) + +def pause_callback(pathname, session): # VLC only pauses locally. This is never called. + print("Pausing \"%s\" in session %d" % (pathname, session)) + +def teardown_callback(pathname, session): + print("Closing \"%s\" in session %d" % (pathname, session)) + +server.register_setup_cb(setup_callback) +server.register_play_cb(play_callback) +server.register_pause_cb(pause_callback) +server.register_teardown_cb(teardown_callback) + +# Track the current FPS. +clock = time.clock() + +# Called each time a new frame is needed. +def image_callback(pathname, session): + clock.tick() + img = sensor.snapshot() + # Markup image and/or do various things. + print(clock.fps()) + return img + +# Stream does not return. It will call `image_callback` when it needs to get an image object to send +# to the remote rtsp client connecting to the server. + +server.stream(image_callback) diff --git a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_jpg_as_the_remote_device_for_your_computer.py b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_jpg_as_the_remote_device_for_your_computer.py index cf6baa5d1..6dd962dd7 100644 --- a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_jpg_as_the_remote_device_for_your_computer.py +++ b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_jpg_as_the_remote_device_for_your_computer.py @@ -20,7 +20,7 @@ sensor.skip_frames(time = 2000) omv.disable_fb(True) # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to be controlled over USB or WIFI. +# allowing your OpenMV Cam to be controlled over USB or LAN/WLAN. ################################################################ # Choose the interface you wish to control your OpenMV Cam over. @@ -30,21 +30,21 @@ omv.disable_fb(True) # interface = rpc.rpc_usb_vcp_slave() -# Uncomment the below line to setup your OpenMV Cam for control over WiFi. +# Uncomment the below line to setup your OpenMV Cam for control over the lan. # -# * ssid - WiFi network to connect to. -# * ssid_key - WiFi network password. -# * ssid_security - WiFi security. -# * port - Port to route traffic to. -# * mode - Regular or access-point mode. -# * static_ip - If not None then a tuple of the (IP Address, Subnet Mask, Gateway, DNS Address) +# network_if = network.LAN() +# network_if.active(True) +# network_if.ifconfig('dhcp') # -# interface = rpc.rpc_wifi_slave(ssid="", -# ssid_key="", -# ssid_security=network.WINC.WPA_PSK, -# port=0x1DBA, -# mode=network.WINC.MODE_STA, -# static_ip=None) +# interface = rpc.rpc_network_slave(network_if) + +# Uncomment the below line to setup your OpenMV Cam for control over the wlan. +# +# network_if = network.WLAN(network.STA_IF) +# network_if.active(True) +# network_if.connect('your-ssid', 'your-password') +# +# interface = rpc.rpc_network_slave(network_if) ################################################################ # Call Backs diff --git a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_jpg_streaming_as_the_remote_device_for_your_computer.py b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_jpg_streaming_as_the_remote_device_for_your_computer.py index 48f173b1c..a21c75b23 100644 --- a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_jpg_streaming_as_the_remote_device_for_your_computer.py +++ b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_jpg_streaming_as_the_remote_device_for_your_computer.py @@ -20,7 +20,7 @@ sensor.skip_frames(time = 2000) omv.disable_fb(True) # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to be controlled over USB or WIFI. +# allowing your OpenMV Cam to be controlled over USB or LAN/WLAN. ################################################################ # Choose the interface you wish to control your OpenMV Cam over. @@ -30,21 +30,21 @@ omv.disable_fb(True) # interface = rpc.rpc_usb_vcp_slave() -# Uncomment the below line to setup your OpenMV Cam for control over WiFi. +# Uncomment the below line to setup your OpenMV Cam for control over the lan. # -# * ssid - WiFi network to connect to. -# * ssid_key - WiFi network password. -# * ssid_security - WiFi security. -# * port - Port to route traffic to. -# * mode - Regular or access-point mode. -# * static_ip - If not None then a tuple of the (IP Address, Subnet Mask, Gateway, DNS Address) +# network_if = network.LAN() +# network_if.active(True) +# network_if.ifconfig('dhcp') # -# interface = rpc.rpc_wifi_slave(ssid="", -# ssid_key="", -# ssid_security=network.WINC.WPA_PSK, -# port=0x1DBA, -# mode=network.WINC.MODE_STA, -# static_ip=None) +# interface = rpc.rpc_network_slave(network_if) + +# Uncomment the below line to setup your OpenMV Cam for control over the wlan. +# +# network_if = network.WLAN(network.STA_IF) +# network_if.active(True) +# network_if.connect('your-ssid', 'your-password') +# +# interface = rpc.rpc_network_slave(network_if) ################################################################ # Call Backs diff --git a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_controller_device.py b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_controller_device.py index 20769d35b..f3b9d1a07 100644 --- a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_controller_device.py +++ b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_controller_device.py @@ -7,7 +7,7 @@ import image, network, omv, rpc, sensor, struct, time # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to control over CAN, I2C, SPI, UART, or WIFI. +# allowing your OpenMV Cam to control over CAN, I2C, SPI, UART, or LAN/WLAN. ############################################################## # Choose the interface you wish to control an OpenMV Cam over. diff --git a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_remote_device.py b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_remote_device.py index 84d691dfc..77c3cd499 100644 --- a/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_remote_device.py +++ b/scripts/examples/OpenMV/34-Remote-Control/image_transfer_raw_as_the_remote_device.py @@ -12,7 +12,7 @@ sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to be controlled over CAN, I2C, SPI, UART, or WIFI. +# allowing your OpenMV Cam to be controlled over CAN, I2C, SPI, UART, or LAN/WLAN. ################################################################ # Choose the interface you wish to control your OpenMV Cam over. diff --git a/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_remote_device.py b/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_remote_device.py index 5293c4150..aa163158a 100644 --- a/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_remote_device.py +++ b/scripts/examples/OpenMV/34-Remote-Control/popular_features_as_the_remote_device.py @@ -14,7 +14,7 @@ sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) # The RPC library above is installed on your OpenMV Cam and provides mutliple classes for -# allowing your OpenMV Cam to be controlled over CAN, I2C, SPI, UART, USB VCP, or WiFi. +# allowing your OpenMV Cam to be controlled over CAN, I2C, SPI, UART, USB VCP, or LAN/WLAN. ################################################################ # Choose the interface you wish to control your OpenMV Cam over. @@ -64,21 +64,21 @@ interface = rpc.rpc_uart_slave(baudrate=115200) # # interface = rpc.rpc_usb_vcp_slave() -# Uncomment the below line to setup your OpenMV Cam for control over WiFi. +# Uncomment the below line to setup your OpenMV Cam for control over the lan. # -# * ssid - WiFi network to connect to. -# * ssid_key - WiFi network password. -# * ssid_security - WiFi security. -# * port - Port to route traffic to. -# * mode - Regular or access-point mode. -# * static_ip - If not None then a tuple of the (IP Address, Subnet Mask, Gateway, DNS Address) +# network_if = network.LAN() +# network_if.active(True) +# network_if.ifconfig('dhcp') # -# interface = rpc.rpc_wifi_slave(ssid="", -# ssid_key="", -# ssid_security=network.WINC.WPA_PSK, -# port=0x1DBA, -# mode=network.WINC.MODE_STA, -# static_ip=None) +# interface = rpc.rpc_network_slave(network_if) + +# Uncomment the below line to setup your OpenMV Cam for control over the wlan. +# +# network_if = network.WLAN(network.STA_IF) +# network_if.active(True) +# network_if.connect('your-ssid', 'your-password') +# +# interface = rpc.rpc_network_slave(network_if) ################################################################ # Call Backs diff --git a/scripts/examples/OpenMV/36-Web-Servers/rtsp_video_server.py b/scripts/examples/OpenMV/36-Web-Servers/rtsp_video_server_lan.py similarity index 82% rename from scripts/examples/OpenMV/36-Web-Servers/rtsp_video_server.py rename to scripts/examples/OpenMV/36-Web-Servers/rtsp_video_server_lan.py index c91b60145..b98f52c64 100644 --- a/scripts/examples/OpenMV/36-Web-Servers/rtsp_video_server.py +++ b/scripts/examples/OpenMV/36-Web-Servers/rtsp_video_server_lan.py @@ -26,19 +26,15 @@ sensor.set_framesize(sensor.UXGA) omv.disable_fb(True) -# * ssid - WiFi network to connect to. -# * ssid_key - WiFi network password. -# * ssid_security - WiFi security. -# * port - Port to listen to (554). -# * mode - Regular or access-point mode. -# * static_ip - If not None then a tuple of the (IP Address, Subnet Mask, Gateway, DNS Address) +# Setup Network Interface -server = rtsp.rtsp_server(ssid="", - ssid_key="", - ssid_security=network.WINC.WPA_PSK, - port=554, - mode=network.WINC.MODE_STA, - static_ip=None) +network_if = network.LAN() +network_if.active(True) +network_if.ifconfig('dhcp') + +# Setup RTSP Server + +server = rtsp.rtsp_server(network_if) # For the call back functions below: # diff --git a/scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server.py b/scripts/examples/OpenMV/36-Web-Servers/rtsp_video_server_wlan.py similarity index 82% rename from scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server.py rename to scripts/examples/OpenMV/36-Web-Servers/rtsp_video_server_wlan.py index 8de8d8165..b38034e3c 100644 --- a/scripts/examples/Arduino/Portenta-H7/36-Web-Servers/rtsp_video_server.py +++ b/scripts/examples/OpenMV/36-Web-Servers/rtsp_video_server_wlan.py @@ -11,6 +11,8 @@ import network, omv, rtsp, sensor, time # Not all programs (e.g. VLC) implement the full JPEG standard for decoding any JPEG image # in RTP packets. Images JPEG compressed by the OpenMV Cam internally may not display. +# FFPLAY will correctly handle JPEGs produced by OpenMV software. + sensor.reset() sensor.set_pixformat(sensor.JPEG) # Only supported by the OV2640/OV5640. @@ -24,19 +26,15 @@ sensor.set_framesize(sensor.UXGA) omv.disable_fb(True) -# * ssid - WiFi network to connect to. -# * ssid_key - WiFi network password. -# * ssid_security - WiFi security. -# * port - Port to listen to (554). -# * mode - Regular or access-point mode. -# * static_ip - If not None then a tuple of the (IP Address, Subnet Mask, Gateway, DNS Address) +# Setup Network Interface -server = rtsp.rtsp_server(ssid="", - ssid_key="", - ssid_security=network.WINC.WPA_PSK, - port=554, - mode=network.WINC.MODE_STA, - static_ip=None) +network_if = network.WLAN(network.STA_IF) +network_if.active(True) +network_if.connect('your-ssid', 'your-password') + +# Setup RTSP Server + +server = rtsp.rtsp_server(network_if) # For the call back functions below: # diff --git a/scripts/libraries/rpc.py b/scripts/libraries/rpc.py index 8148a7d83..507933ef8 100644 --- a/scripts/libraries/rpc.py +++ b/scripts/libraries/rpc.py @@ -557,7 +557,7 @@ class rpc_usb_vcp_slave(rpc_slave): def put_bytes(self, data, timeout_ms): # protected self.__usb_vcp.send(data, timeout=timeout_ms) -class rpc_wifi_master(rpc_master): +class rpc_network_master(rpc_master): def __valid_tcp_socket(self): # private if self.__tcp__socket is None: @@ -587,17 +587,11 @@ class rpc_wifi_master(rpc_master): self.__udp__socket.close() self.__udp__socket = None - def __init__(self, ssid, ssid_key, ssid_security, ip, port=0x1DBA, mode=network.WINC.MODE_STA, static_ip=None): # private + def __init__(self, network_if, port=0x1DBA): # private self._udp_limit = 1400 self._timeout_scale = 10 - self.__winc = network.WINC(mode=mode) - if mode == network.WINC.MODE_STA: - if static_ip is not None: self.__winc.ifconfig(static_ip) - self.__winc.connect(ssid, key=ssid_key, security=ssid_security) - if not self.__winc.isconnected(): raise OSError("Failed to connect to network!") - elif mode == network.WINC.MODE_AP: self.__winc.start_ap(ssid, key=ssid_key, security=ssid_security) - else: raise ValueError("Invalid mode") - self.__myip = self.__winc.ifconfig()[0] + self.__network = network_if + self.__myip = self.__network.ifconfig()[0] self.__myaddr = (self.__myip, port) self.__slave_addr = (ip, port) self.__tcp__socket = None @@ -708,7 +702,7 @@ class rpc_wifi_master(rpc_master): except OSError: self.__close_tcp_socket() if l: raise OSError # Stop Stream. -class rpc_wifi_slave(rpc_slave): +class rpc_network_slave(rpc_slave): def __valid_tcp_socket(self): # private if self.__tcp__socket is None: @@ -734,17 +728,11 @@ class rpc_wifi_slave(rpc_slave): self.__udp__socket.close() self.__udp__socket = None - def __init__(self, ssid, ssid_key, ssid_security, port=0x1DBA, mode=network.WINC.MODE_STA, static_ip=None): # private + def __init__(self, network_if, port=0x1DBA): # private self._udp_limit = 1400 self._timeout_scale = 10 - self.__winc = network.WINC(mode=mode) - if mode == network.WINC.MODE_STA: - if static_ip is not None: self.__winc.ifconfig(static_ip) - self.__winc.connect(ssid, key=ssid_key, security=ssid_security) - if not self.__winc.isconnected(): raise OSError("Failed to connect to network!") - elif mode == network.WINC.MODE_AP: self.__winc.start_ap(ssid, key=ssid_key, security=ssid_security) - else: raise ValueError("Invalid mode") - self.__myip = self.__winc.ifconfig()[0] + self.__network = network_if + self.__myip = self.__network.ifconfig()[0] self.__myaddr = (self.__myip, port) self.__master_addr = None self.__tcp__socket = None diff --git a/scripts/libraries/rtsp.py b/scripts/libraries/rtsp.py index 70a1698f1..5a0b9d81c 100644 --- a/scripts/libraries/rtsp.py +++ b/scripts/libraries/rtsp.py @@ -37,15 +37,9 @@ class rtsp_server: self.__udp__socket.close() self.__udp__socket = None - def __init__(self, ssid, ssid_key, ssid_security, port=554, mode=network.WINC.MODE_STA, static_ip=None): # private - self.__winc = network.WINC(mode=mode) - if mode == network.WINC.MODE_STA: - if static_ip is not None: self.__winc.ifconfig(static_ip) - self.__winc.connect(ssid, key=ssid_key, security=ssid_security) - if not self.__winc.isconnected(): raise OSError("Failed to connect to network!") - elif mode == network.WINC.MODE_AP: self.__winc.start_ap(ssid, key=ssid_key, security=ssid_security) - else: raise ValueError("Invalid mode") - self.__myip = self.__winc.ifconfig()[0] + def __init__(self, network_if, port=554): # private + self.__network = network_if + self.__myip = self.__network.ifconfig()[0] self.__myaddr = (self.__myip, port) self.__tcp__socket = None self.__udp__socket = None