Life expectancy with Micropython

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
thalesmaoa
Posts: 35
Joined: Thu Feb 13, 2020 10:10 pm

Life expectancy with Micropython

Post by thalesmaoa » Wed Nov 17, 2021 12:22 pm

Does anyone think that is possible that micropython reduces ESP32 life expectancy?

Ok, this an odd question...

Context:
I have 5 ESP8266 running C++ code with an total uptime of 3 years and a half. However, I have an application that uses an ESP32 - Micropython that has failed 2 times in the last year and a half. It starts with Wifi intermittence. After that, the period between reconnection starts to grow. Minutes trying to reconnect... After some time, it can't connect any more.

Does anyone have a Micropython ESP32 - Wifi 24/7 uptime for more than a year?

My theory: depending on memory technology, it has a limited amount of writing cycles. Is it possible that micropython loops between writing cycles? I constantly use gc.collect.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Life expectancy with Micropython

Post by pythoncoder » Thu Nov 18, 2021 12:59 pm

gc affects only RAM which has no limit on write cycles. Flash does have a limit which could be reached if your application repeatedly writes to the filesystem - typically on the order of 10K sector erases. Flash read cycles are unlimited, so unless your application performs explicit file writes there should be no limit to ESP32 life.

When your boards fail, can you still access the REPL?
Peter Hinch
Index to my micropython libraries.

thalesmaoa
Posts: 35
Joined: Thu Feb 13, 2020 10:10 pm

Re: Life expectancy with Micropython

Post by thalesmaoa » Thu Nov 18, 2021 3:22 pm

Yes. I can. Wifi starts to fail, apparently, that's all.

I'm sure that my code doesn't write into the flash.

Bellow are the imports that I'm using, but I'm not sure if they use flash.

Code: Select all

from machine import UART
from machine import Pin
from machine import PWM
from machine import WDT
import esp32
import machine
import time
from time import sleep
import ubinascii
import micropython
import network
import esp
esp.osdebug(None)
import gc
gc.collect()
from mqtt_as import MQTTClient
from config import config
import uasyncio as asyncio

wdt = WDT(timeout=15000)  # enable it with a timeout of 15s
The main piece of code:

Code: Select all

async def main(client):
    asyncio.create_task( verifica_rfid() )
    await client.connect()
    asyncio.create_task( door_check() )
    while True:
        await client.publish("portao/social/led", "idle")
        await client.publish("portao/social/temp", str( (esp32.raw_temperature()-32)*5/9 ) )
        await asyncio.sleep(15)

config['subs_cb'] = callback
config['connect_coro'] = conn_han
config['server'] = SERVER

# Attach Interrupt
rfid_in_interrup.irq(trigger=Pin.IRQ_FALLING, handler=read_rfid_in)
rfid_out_interrup.irq(trigger=Pin.IRQ_FALLING, handler=read_rfid_out)

MQTTClient.DEBUG = False  # Optional: print diagnostic messages
client = MQTTClient(config)
try:
    asyncio.run(main(client))
finally:
    client.close()  # Prevent LmacRxBlk:1 errors

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Life expectancy with Micropython

Post by pythoncoder » Fri Nov 19, 2021 9:54 am

One of the advantages of the ESP32 is that it doesn't write to flash when it initialises WiFi (the ESP8266 stores credentials with an effect on Flash lifetime). Aside from highly specialised register level coding MicroPython only writes to Flash with explicit filesystem writes. There should be no flash wear. In any event, if Flash did wear, I'd struggle to see why only WiFi performance would be affected.

I can't explain this dropoff in WiFi performance at all.
Peter Hinch
Index to my micropython libraries.

thalesmaoa
Posts: 35
Joined: Thu Feb 13, 2020 10:10 pm

Re: Life expectancy with Micropython

Post by thalesmaoa » Fri Nov 19, 2021 11:15 am

Thanks, at least I know that it can't be flash.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Life expectancy with Micropython

Post by pythoncoder » Sat Nov 20, 2021 10:14 am

If you find out what is going on, please report it here so others can benefit.
Peter Hinch
Index to my micropython libraries.

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: Life expectancy with Micropython

Post by scruss » Sat Nov 20, 2021 7:52 pm

How are you powering the ESP32?

I've got an inexpensive ESP32 board that will flash and work fine with the REPL, but its wifi performance is terrible when powered via USB. It's now in an application where it's powered by a decent regulator via the pins, and wifi is fine. Perhaps the power circuit you're using is not quite providing the power the ESP32 needs to run wifi reliably?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Life expectancy with Micropython

Post by pythoncoder » Sun Nov 21, 2021 10:25 am

Good point. I've had problems with voltage drop on long USB leads. Current goes up substantially when WiFi is active.
Peter Hinch
Index to my micropython libraries.

Post Reply