Wiznet makers

viktor

Published September 26, 2022 ©

79 UCC

14 WCC

33 VAR

0 Contests

0 Followers

0 Following

Original Link

Raspberry Pi Pico robustness with MicroPython and Ethernet (W5100S-EVB-Pico)

Raspberry Pi Pico robustness with MicroPython and Ethernet (W5100S-EVB-Pico)

COMPONENTS Hardware components

WIZnet - W5100S-EVB-Pico

x 1


PROJECT DESCRIPTION

In My Humble Opinion (IMHO), when a cabled infrastructure is available, an Ethernet connection is much better than Wifi for fixed IoT applications. However, I missed a good cost-benefit solution for DIY enthusiasts. Wiznet W5100S-EVB-Pico (Raspberry Pi Pico with Ethernet) was the answer to what I wanted. I got some as soon as they were available, but the firmware was unstable.

But now we have the official MicroPython support for the W5100S Ethernet chipset on the Pi Pico! And it works great! I downloaded the firmware (v1.19.1 (2022-06-18) .uf2) from https://micropython.org/download/W5100S_EVB_PICO/ and installed it on the board, by simply “dragging and dropping” the downloaded file to the Pi Pico USB Disk!

Tests performed on the Pi Pico with Ethernet (W5100S-EVB-Pico)

Init network:

from machine import Pin,SPI
spi0=SPI(0,2_000_000, mosi=Pin(19),miso=Pin(16),sck=Pin(18))
nic = network.WIZNET5K(machine.SPI(0), machine.Pin(17), machine.Pin(20))
nic.active(True)
nic.ifconfig()

DHCP over Ethernet works nicely!

Test 1 – MQTT with BIPES

Test took 7 hours. Here is the program used:

No data was lost – all data sent was received! on the server

 

BIPES Console:

EasyMQTT Publish - Session: 5y927 Topic: Test Value: 25193
Uptime: 25573.52
EasyMQTT Publish - Session: 5y927 Topic: Test Value: 25194
Uptime: 25574.52
EasyMQTT Publish - Session: 5y927 Topic: Test Value: 25195
Uptime: 25575.52

During all the tests, a ping flood was running against the Pi Pico board!

0% packet loss

rafael@vaio:~$ time sudo ping -f 192.168.88.234
[sudo] password for rafael: 
PING 192.168.88.234 (192.168.88.234) 56(84) bytes of data.
....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................^C  
--- 192.168.88.234 ping statistics ---
1884598 packets transmitted, 1884068 received, 0% packet loss, time 25303297ms
rtt min/avg/max/mdev = 2.326/29.941/74.117/20.287 ms, pipe 5, ipg/ewma 13.426/28.825 ms

real	421m47,266s
user	1m1,598s
sys	5m7,648s

Test 2 – MQTT and HTTP simultaneously

A more complete test, using MQTT and HTTP at the same time! With and without ping flood during the tests.

Up to now, tests were done with the board connected to a PC. After some time, on some cases, running the MicroPython garbage collector (gc) is a good idea:

import gc
gc.collect()
gc.mem_free()

For the curios, here is the code automatically generated by BIPES and uploaded to the board to perform the test mentioned:

>>> 
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import umqtt.robust
=== from machine import ADC
=== from machine import Pin
=== import time
=== import urequests
=== 
=== mqtt_error = None
=== mqtt_sent = None
=== http_error = None
=== http_sent = None
=== adc = None
=== temperature = None
=== uptime_seconds = None
=== R = None
=== 
=== adc4=ADC(4)
=== 
=== 
=== easymqtt_session = "5y927";
=== easymqtt_client = umqtt.robust.MQTTClient("umqtt_client", server = "bipes.net.br", port = 1883, user = "bipes", password = "m8YLUr5uW3T");
=== easymqtt_client.connect()
=== print("EasyMQTT connected")
=== mqtt_error = 0
=== mqtt_sent = 0
=== http_error = 0
=== http_sent = 0
=== while True:
===   adc = (adc4.read_u16()) * 0.00005035477225909819
===   temperature = 27 - (adc - 0.706) / 0.001721
===   uptime_seconds = (time.ticks_ms()
===   ) / 1000
===   print(''.join([str(x) for x in ['Uptime: ', uptime_seconds, ' | Temperature: ', temperature, ' | HTTP Sent:', http_sent, ' | HTTP Errors: ', http_error, ' | MQTT Sent:', mqtt_sent, ' | MQTT Errors:', mqtt_error]]))
===   print('Trying to publish to the MQTT server...')
===   try:
===     easymqtt_client.publish(easymqtt_session + "/" + 'uptime', str(uptime_seconds))
===     print("EasyMQTT Publish - Session:",easymqtt_session,"Topic:",'uptime',"Value:",str(uptime_seconds))
===     easymqtt_client.publish(easymqtt_session + "/" + 'temperature', str(temperature))
===     print("EasyMQTT Publish - Session:",easymqtt_session,"Topic:",'temperature',"Value:",str(temperature))
===     mqtt_sent = (mqtt_sent if isinstance(mqtt_sent, int) else 0) + 1
=== 
===   except:
===     print('Error sending MQTT data. Network may be down.')
===     mqtt_error = (mqtt_error if isinstance(mqtt_error, int) else 0) + 1
===   print('Trying to make HTTP GET Request...')
===   try:
===     R = urequests.get('http://bipes.net.br/date-time-test.php')
=== 
===     print(R.text)
===     http_sent = (http_sent if isinstance(http_sent, int) else 0) + 1
=== 
===   except:
===     print('Error sending HTTP data. Network may be down.')
===     http_error = (http_error if isinstance(http_error, int) else 0) + 1
===   time.sleep(1)
=== 
=== 
=== 
0
EasyMQTT connected
Uptime: 28137.88 | Temperature: 28.91677 | HTTP Sent:0 | HTTP Errors: 0 | MQTT Sent:0 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28137.88
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 28.91677
Trying to make HTTP GET Request...
2022-09-08 04:36:27pm
Uptime: 28139.38 | Temperature: 32.66196 | HTTP Sent:1 | HTTP Errors: 0 | MQTT Sent:1 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28139.38
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 32.66196
Trying to make HTTP GET Request...
2022-09-08 04:36:29pm
Uptime: 28140.89 | Temperature: 31.72567 | HTTP Sent:2 | HTTP Errors: 0 | MQTT Sent:2 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28140.89
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 31.72567
Trying to make HTTP GET Request...
2022-09-08 04:36:30pm
Uptime: 28142.39 | Temperature: 31.72567 | HTTP Sent:3 | HTTP Errors: 0 | MQTT Sent:3 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28142.39
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 31.72567
Trying to make HTTP GET Request...
2022-09-08 04:36:32pm
Uptime: 28143.89 | Temperature: 31.72567 | HTTP Sent:4 | HTTP Errors: 0 | MQTT Sent:4 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28143.89
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 31.72567
Trying to make HTTP GET Request...
2022-09-08 04:36:33pm
Uptime: 28145.4 | Temperature: 32.19381 | HTTP Sent:5 | HTTP Errors: 0 | MQTT Sent:5 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28145.4
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 32.19381
Trying to make HTTP GET Request...
2022-09-08 04:36:35pm
Uptime: 28146.9 | Temperature: 31.72567 | HTTP Sent:6 | HTTP Errors: 0 | MQTT Sent:6 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28146.9
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 31.72567
Trying to make HTTP GET Request...
2022-09-08 04:36:36pm
Uptime: 28148.41 | Temperature: 32.19381 | HTTP Sent:7 | HTTP Errors: 0 | MQTT Sent:7 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28148.41
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 32.19381
Trying to make HTTP GET Request...
2022-09-08 04:36:38pm
Uptime: 28149.91 | Temperature: 31.25752 | HTTP Sent:8 | HTTP Errors: 0 | MQTT Sent:8 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28149.91
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 31.25752
Trying to make HTTP GET Request...
2022-09-08 04:36:39pm
Uptime: 28151.41 | Temperature: 32.19381 | HTTP Sent:9 | HTTP Errors: 0 | MQTT Sent:9 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28151.41
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 32.19381
Trying to make HTTP GET Request...
2022-09-08 04:36:41pm
Uptime: 28152.91 | Temperature: 30.78938 | HTTP Sent:10 | HTTP Errors: 0 | MQTT Sent:10 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28152.91
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 30.78938
Trying to make HTTP GET Request...
2022-09-08 04:36:42pm
Uptime: 28154.42 | Temperature: 32.66196 | HTTP Sent:11 | HTTP Errors: 0 | MQTT Sent:11 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28154.42
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 32.66196
Trying to make HTTP GET Request...
2022-09-08 04:36:44pm
Uptime: 28155.91 | Temperature: 32.66196 | HTTP Sent:12 | HTTP Errors: 0 | MQTT Sent:12 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28155.91
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 32.66196
Trying to make HTTP GET Request...
2022-09-08 04:36:45pm
Uptime: 28157.42 | Temperature: 32.66196 | HTTP Sent:13 | HTTP Errors: 0 | MQTT Sent:13 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 28157.42
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 32.66196
Trying to make HTTP GET Request...
2022-09-08 04:36:47pm
Uptime: 28158.91 | Temperature: 32.19381 | HTTP Sent:14 | HTTP Error

And here is the result of the ping flood executed while the test was running. Again, 0% packet loss.

rafael@vaio:~$ time sudo ping -f 192.168.88.234
PING 192.168.88.234 (192.168.88.234) 56(84) bytes of data.
........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................^C
--- 192.168.88.234 ping statistics ---
1644217 packets transmitted, 1643682 received, 0% packet loss, time 21810566ms
rtt min/avg/max/mdev = 2.374/29.950/71.460/20.327 ms, pipe 5, ipg/ewma 13.265/30.199 ms

real	363m30,596s
user	0m44,335s
sys	3m39,977s

Again, for the curious and interested in doing the same test, here is the source code used on the server side (date-time-test.php) and the number of lines of the log file date-time-test-log.txt.

root@bipes-1:/var/www/html# cat date-time-test.php 
<?php
$d=date("Y-m-d h:i:sa");
echo $d;
file_put_contents('/var/www/html/date-time-test-log.txt', $d . "\r\n", FILE_APPEND | LOCK_EX);
?>

root@bipes-1:/var/www/html# cat date-time-test-log.txt  |wc -l
14134

Additionaly, take a look at the last lines shown on the console tab. Ctrl+C was sent at the end of the console view to stop the program/test.

Uptime: 49970.19 | Temperature: 34.53454 | HTTP Sent:14133 | HTTP Errors: 0 | MQTT Sent:14133 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 49970.19
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 34.53454
Trying to make HTTP GET Request...
2022-09-08 10:40:19pm
Uptime: 49971.72 | Temperature: 34.53454 | HTTP Sent:14134 | HTTP Errors: 0 | MQTT Sent:14134 | MQTT Errors:0
Trying to publish to the MQTT server...
EasyMQTT Publish - Session: 5y927 Topic: uptime Value: 49971.72
EasyMQTT Publish - Session: 5y927 Topic: temperature Value: 34.53454
Trying to make HTTP GET Request...
2022-09-08 10:40:20pm
Traceback (most recent call last):
  File "<stdin>", line 54, in <module>
KeyboardInterrupt: 
>>> 

This last test took about 14 hours. Following figure shows the temperature log (BIPES EasyMQTT Tab) stable about 34 degrees Celcius during all the tests with ping flood running!

Test 3 – Same code, but stand alone operation

Now, the same tests, but without the USB port connected to a PC. Main program was saved as main.py using BIPES and executed directly on boot, using a 1 Amp power supply, without PC USB port.

The code and results (EasyMQTT tab) can be seen at:

https://bipes.net.br/ide/#xgpana

After a few days:

root@bipes-1:/var/www/html# cat date-time-test-log.txt |wc -l
438654

And here is the view of EasyMQTT tab:

For this last test, ping foold was not executed during all the test period. But, as a matter of curiosity, ping flood was executed at the end of the test to check if the board / MicroPython was still reliable handling incoming packets while sending HTTP and MQTT messages. Again, 0% packet loss!

rafael@vaio:~$ time sudo ping -f 192.168.88.234
PING 192.168.88.234 (192.168.88.234) 56(84) bytes of data.
.............................................^C 
--- 192.168.88.234 ping statistics ---
149836 packets transmitted, 149791 received, 0% packet loss, time 2004086ms
rtt min/avg/max/mdev = 2.331/29.901/69.679/20.265 ms, pipe 5, ipg/ewma 13.375/29.506 ms

real	33m24,115s
user	0m3,943s
sys	0m19,998s

Well, the conclusion is:

IMHO, W5100S-EVB-Pico with MicroPython is good to go!

Documents
Comments Write