From 9d9b2bed85560848dbe4d970c63bd1189f9170a9 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 27 Nov 2020 19:51:09 +0200 Subject: [PATCH] PORTENTA: Enable Ethernet. --- .../Arduino/38-Ethernet/http_client.py | 30 ++++++++++++++ .../Arduino/38-Ethernet/http_client_ssl.py | 39 +++++++++++++++++++ .../Arduino/38-Ethernet/peer_to_peer.py | 15 +++++++ src/Makefile | 4 +- src/micropython | 2 +- src/omv/boards/PORTENTA/omv_boardconfig.h | 2 +- 6 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 scripts/examples/Arduino/38-Ethernet/http_client.py create mode 100644 scripts/examples/Arduino/38-Ethernet/http_client_ssl.py create mode 100644 scripts/examples/Arduino/38-Ethernet/peer_to_peer.py diff --git a/scripts/examples/Arduino/38-Ethernet/http_client.py b/scripts/examples/Arduino/38-Ethernet/http_client.py new file mode 100644 index 000000000..1caf93408 --- /dev/null +++ b/scripts/examples/Arduino/38-Ethernet/http_client.py @@ -0,0 +1,30 @@ +# Ethernet LAN HTTP client example. +import network, usocket + +PORT = 80 +HOST = "www.google.com" + +lan = network.LAN() +lan.active(True) +lan.ifconfig('dhcp') + +# We should have a valid IP now via DHCP +print(lan.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/Arduino/38-Ethernet/http_client_ssl.py b/scripts/examples/Arduino/38-Ethernet/http_client_ssl.py new file mode 100644 index 000000000..b33da5e01 --- /dev/null +++ b/scripts/examples/Arduino/38-Ethernet/http_client_ssl.py @@ -0,0 +1,39 @@ +# Ethernet LAN HTTP client example. +import network, usocket, ussl + +PORT = 443 +HOST = "www.google.com" + +lan = network.LAN() +lan.active(True) +lan.ifconfig('dhcp') + +# We should have a valid IP now via DHCP +print(lan.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/Arduino/38-Ethernet/peer_to_peer.py b/scripts/examples/Arduino/38-Ethernet/peer_to_peer.py new file mode 100644 index 000000000..6328c27d9 --- /dev/null +++ b/scripts/examples/Arduino/38-Ethernet/peer_to_peer.py @@ -0,0 +1,15 @@ +# Ethernet LAN Peer to Peer example. +# On the PC try the following: +# +# $> sudo ifconfig eth0 192.168.1.102 up +# $> ping 192.168.1.102 + +import network, time + +lan = network.LAN() +lan.active(True) +lan.ifconfig(('192.168.1.100', '255.255.255.0', '192.168.1.1', '192.168.1.1')) + +while (True): + # Nothing else to do. + time.sleep(1.0) diff --git a/src/Makefile b/src/Makefile index 31dbcb116..f39906ea3 100755 --- a/src/Makefile +++ b/src/Makefile @@ -347,6 +347,7 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\ pendsv.o \ bufhelper.o \ usb.o \ + eth.o \ gccollect.o \ help.o \ flash.o \ @@ -388,6 +389,7 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\ moduos.o \ modutime.o \ modusocket.o \ + network_lan.o \ modnetwork.o \ modmachine.o \ machine_i2c.o \ @@ -400,7 +402,7 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\ posix_helpers.o \ softtimer.o \ mbedtls/mbedtls_port.o \ - frozen_content.o \ + frozen_content.o \ ) # board object files diff --git a/src/micropython b/src/micropython index 07aaa0cc4..64655f149 160000 --- a/src/micropython +++ b/src/micropython @@ -1 +1 @@ -Subproject commit 07aaa0cc42dd11e1eba7e749d4e4f9063deb444f +Subproject commit 64655f1492b42a650bb01077fea7b6ee757764e5 diff --git a/src/omv/boards/PORTENTA/omv_boardconfig.h b/src/omv/boards/PORTENTA/omv_boardconfig.h index 80b557ac2..659ad7fb7 100644 --- a/src/omv/boards/PORTENTA/omv_boardconfig.h +++ b/src/omv/boards/PORTENTA/omv_boardconfig.h @@ -145,7 +145,7 @@ #define OMV_FB_SIZE (4M) // FB memory: header + VGA/GS image #define OMV_FB_ALLOC_SIZE (3M) // minimum fb alloc size #define OMV_STACK_SIZE (32K) -#define OMV_HEAP_SIZE (210K) +#define OMV_HEAP_SIZE (182K) #define OMV_SDRAM_SIZE (8 * 1024 * 1024) // This needs to be here for UVC firmware. #define OMV_LINE_BUF_SIZE (11 * 1024) // Image line buffer round(2592 * 2BPP * 2 buffers).