Repeated failures with Adafruit ESP32-S2 TFT Feather

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
sromanos
 
Posts: 10
Joined: Sun Dec 18, 2022 3:54 pm

Repeated failures with Adafruit ESP32-S2 TFT Feather

Post by sromanos »

I recently purchased this snazzy little Adafruit ESP32-S2 TFT Feather for use with a BME688 to collect and send temperature data to a raspberry pi over wifi.

I'm using the modified code.py file from the "Getting Started with Microsoft Azure and CircuitPython" project. Essentially I've replaced the calls to Azure with a simple http connection to my local raspberry pi (I don't need the sensor data to leave my network).

The code works on boot, and displays the temp and graphics just fine. However, the ESP32 is unstable and crashes with various errors.
- First, it could only send a few http requests before it would fail due to a sockets problem. After looking around, I found a comment about how the wifi code doesn't properly manage sockets and runs out. So I added "requests._free_sockets()" after each requests.get() call. Fine, fixed that problem.

- Then, after 30 minutes or so, it would consistently fail with a TIMEOUT error after calling ntp = adafruit_ntp.NTP() in the early lines of the program. So fine, I replaced adafruit_ntp.mpy from the /lib directory on the device with the current adafruit_ntp.py file on github. Same problem. Then I replaced the ntp server from that file ""0.adafruit.pool.ntp.org" with a google time server, time3.google.com. That seemed to fix this problem. However, every once in a while it crashes with an NTP timeout, which is quite strange, given that there is only one NTP call in the program.

- But at least it lasts for a day or so (instead of minutes) before crashing with nondescript errors like "Unknown failure 15." Google searches haven't revealed much in the way of the cause, or solution.

Has anyone experienced this before, or have an idea how to fix it. Or more importantly, is this a sign of a defective unit, or just something to be expected?

Thanks.

Note, I've tried both CircuitPython 7.3.3, and 8.0.0-beta.5 and I believe that yes, the code matches the proper version of circuitpython.

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Repeated failures with Adafruit ESP32-S2 TFT Feather

Post by mikeysklar »

NTP is based on UDP packets so it is not a particularly reliable protocol to begin with.

Here are some things to try:

1) adjust the socket timeout when calling NTP

Code: Select all

ntp = adafruit_ntp.NTP(socket_timeout=100) 
2) try / except logic to catch the error rather than error out of the program and then retry the ntp request.

Code: Select all

try:
    ntp = adafruit_ntp.NTP() 
    except (ValueError, RuntimeError, ConnectionError, OSError) as e:
        print("Failed to get data, retrying...\n", e)
        continue
3) free up sockets

Code: Select all

requests._free_sockets()
4) reset the network device ( a little bit extreme, but might be necessary)

Code: Select all

wifi.radio.stop_station()
wifi.radio.connect(ssid, pass)

User avatar
sromanos
 
Posts: 10
Joined: Sun Dec 18, 2022 3:54 pm

Re: Repeated failures with Adafruit ESP32-S2 TFT Feather

Post by sromanos »

Thanks for the tips. I added all the error catching, but actually, a strange thing happened.

The device had been set up outside on my deck, underneath a table, to protect it from rain. And this is where it kept rebooting. And it was largely shielded from the elements.

But then after a big rain, I needed to dry it off, and finally covered it properly in a ziplock bag. That was weeks ago, and it's been running perfectly fine since. I can't explain it. It wasn't getting consistently wet outside, but something about covering it completely in a bag seemed to make all the difference. Go figure.

User avatar
sromanos
 
Posts: 10
Joined: Sun Dec 18, 2022 3:54 pm

Re: Repeated failures with Adafruit ESP32-S2 TFT Feather

Post by sromanos »

Actually, I take that back.

I now have two of these ESP32-S2 TFT feathers (running latest circuit python, etc), one that's outside, sending wifi through a window about 20ft to my Pi4, and another that is inside the house, also about 20 feet from the Pi. Both TFTs are sending sensor data (Co2, temp, etc) to the Pi as an HTTP request.

But both TFTs fail intermittently with networking errors. Sometimes it's a failure to authenticate, other times it's some other networking error. But the errors change, as does the time to failure. The TFT inside is slightly more reliable than the one outside. The inside one maybe lasts a week or so before failure, while the outside one seems to fail every 2-3 days.

I don't know if this is a software or hardware problem, but this is starting to become a problem enough that I would mostly like to throw these in the garbage and replace them with something more stable. All I need is something to capture sensor data and send the data over wifi. If anyone has any recommendations for something to replace the TFTs, that would be lovely.

FWIW, the relevant networking code is:

import time
import board
import busio
import adafruit_sgp30
import displayio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import bitmap_label, wrap_text_to_lines
import vectorio
import adafruit_requests
import wifi
import socketpool

try:
from secrets import secrets
except ImportError:
print("WiFi secrets are kept in secrets.py, please add them there!")
raise

print("Connecting to WiFi...")
wifi.radio.connect(secrets["ssid"], secrets["password"])
print("Connected to WiFi!")
pool = socketpool.SocketPool(wifi.radio)
print("My IP address is", wifi.radio.ipv4_address)

# Create library object on our I2C port
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)

sgp30.set_iaq_baseline(0x8973, 0x8AAE)
sgp30.set_iaq_relative_humidity(celsius=22.1, relative_humidity=44)

...

while True:
eco2, tvoc = sgp30.iaq_measure()

eco2_text.text = "Co2 %d ppm" % eco2
tvoc_text.text = "VOC %d ppb" % tvoc

message = str(eco2) +","+ str(tvoc)
sensorURL = "http://192.168.1.200:88/cgi/moxData.py?" + message

try:
requests = adafruit_requests.Session(pool)
response = requests.get(sensorURL)
response.close()
requests._free_sockets()
except BaseException as error:
print('Error sending msg to Pi: {}'.format(error))

time.sleep(60)

User avatar
mikeysklar
 
Posts: 13824
Joined: Mon Aug 01, 2016 8:10 pm

Re: Repeated failures with Adafruit ESP32-S2 TFT Feather

Post by mikeysklar »

Have you been able to catch the network error messages? That will be critical to resolving this.

User avatar
sromanos
 
Posts: 10
Joined: Sun Dec 18, 2022 3:54 pm

Re: Repeated failures with Adafruit ESP32-S2 TFT Feather

Post by sromanos »

You would think, but like I said, the errors vary, even when nothing else about the device has changed. But sure, I'll catalogue all the failures.

Frankly, I'm pretty disappointed in these. Again, I don't know if it's a software or hardware issue. But regardless, it all seems very fickle and is becoming less and less worth it.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”