diff --git a/docker/README.md b/docker/README.md index bc633f3e8..e643f3fce 100644 --- a/docker/README.md +++ b/docker/README.md @@ -29,7 +29,7 @@ user: admin password: testadmin ``` -Examples for post requests can be found at `scripts/examples/OpenMV/14-WiFi-Shield/http_post.py`. +Examples for post requests can be found at `scripts/examples/09-WiFi/http_post.py`. ## GET Requests diff --git a/scripts/examples/07-Interface-Library/00-Arduino/arduino_i2c_slave.py b/scripts/examples/07-Interface-Library/00-Arduino/arduino_i2c_slave.py index 5957c5b6c..5879f1a60 100644 --- a/scripts/examples/07-Interface-Library/00-Arduino/arduino_i2c_slave.py +++ b/scripts/examples/07-Interface-Library/00-Arduino/arduino_i2c_slave.py @@ -11,11 +11,11 @@ # OpenMV Cam Ground - Arduino Ground import pyb -import ustruct +import struct text = "Hello World!\n" -data = ustruct.pack("<%ds" % len(text), text) -# Use "ustruct" to build data packets to send. +data = struct.pack("<%ds" % len(text), text) +# Use "struct" to build data packets to send. # "<" puts the data in the struct in little endian order. # "%ds" puts a string in the data stream. E.g. "13s" for "Hello World!\n" (13 chars). # See https://docs.python.org/3/library/struct.html @@ -42,7 +42,7 @@ print("Waiting for Arduino...") while True: try: bus.send( - ustruct.pack(" # License: MIT +import time +import select +import socket +import struct +import random +import uctypes # Internet Checksum Algorithm @@ -22,13 +28,6 @@ def checksum(data): def ping(host, count=4, timeout=5000, interval=10, quiet=False, size=64): - import utime - import uselect - import uctypes - import usocket - import ustruct - import urandom - # prepare packet assert size >= 16, "pkt size too small" pkt = b"Q" * size @@ -44,14 +43,14 @@ def ping(host, count=4, timeout=5000, interval=10, quiet=False, size=64): h.type = 8 # ICMP_ECHO_REQUEST h.code = 0 h.checksum = 0 - h.id = urandom.randint(0, 65535) + h.id = random.randint(0, 65535) h.seq = 1 # init socket - sock = usocket.socket(usocket.AF_INET, usocket.SOCK_RAW, 1) + sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, 1) sock.setblocking(0) sock.settimeout(timeout / 1000) - addr = usocket.getaddrinfo(host, 1)[0][-1][0] # ip address + addr = socket.getaddrinfo(host, 1)[0][-1][0] # ip address sock.connect((addr, 1)) not quiet and print("PING %s (%s): %u data bytes" % (host, addr, len(pkt))) @@ -66,7 +65,7 @@ def ping(host, count=4, timeout=5000, interval=10, quiet=False, size=64): # send packet h.checksum = 0 h.seq = c - h.timestamp = utime.ticks_us() + h.timestamp = time.ticks_us() h.checksum = checksum(pkt) if sock.send(pkt) == size: n_trans += 1 @@ -77,7 +76,7 @@ def ping(host, count=4, timeout=5000, interval=10, quiet=False, size=64): # recv packet while 1: - socks, _, _ = uselect.select([sock], [], [], 0) + socks, _, _ = select.select([sock], [], [], 0) if socks: resp = socks[0].recv(4096) resp_mv = memoryview(resp) @@ -85,8 +84,8 @@ def ping(host, count=4, timeout=5000, interval=10, quiet=False, size=64): # TODO: validate checksum (optional) seq = h2.seq if h2.type == 0 and h2.id == h.id and (seq in seqs): # 0: ICMP_ECHO_REPLY - t_elasped = (utime.ticks_us() - h2.timestamp) / 1000 - ttl = ustruct.unpack("!B", resp_mv[8:9])[0] # time-to-live + t_elasped = (time.ticks_us() - h2.timestamp) / 1000 + ttl = struct.unpack("!B", resp_mv[8:9])[0] # time-to-live n_recv += 1 not quiet and print( "%u bytes from %s: icmp_seq=%u, ttl=%u, time=%f ms" @@ -102,7 +101,7 @@ def ping(host, count=4, timeout=5000, interval=10, quiet=False, size=64): if finish: break - utime.sleep_ms(1) + time.sleep_ms(1) t += 1 # close diff --git a/scripts/libraries/utelnet.py b/scripts/libraries/utelnet.py index 9fbf71880..2625c19cf 100644 --- a/scripts/libraries/utelnet.py +++ b/scripts/libraries/utelnet.py @@ -3,9 +3,9 @@ import socket import network -import uos +import os import errno -from uio import IOBase +from io import IOBase last_client_socket = None server_socket = None @@ -73,24 +73,24 @@ def accept_telnet_connect(telnet_server): if last_client_socket: # close any previous clients - uos.dupterm(None) + os.dupterm(None) last_client_socket.close() last_client_socket, remote_addr = telnet_server.accept() print("Telnet connection from:", remote_addr) last_client_socket.setblocking(False) # dupterm_notify() not available under MicroPython v1.1 - # last_client_socket.setsockopt(socket.SOL_SOCKET, 20, uos.dupterm_notify) + # last_client_socket.setsockopt(socket.SOL_SOCKET, 20, os.dupterm_notify) last_client_socket.sendall(bytes([255, 252, 34])) # dont allow line mode last_client_socket.sendall(bytes([255, 251, 1])) # turn off local echo - uos.dupterm(TelnetWrapper(last_client_socket)) + os.dupterm(TelnetWrapper(last_client_socket)) def stop(): global server_socket, last_client_socket - uos.dupterm(None) + os.dupterm(None) if server_socket: server_socket.close() if last_client_socket: