Skip to content

Flash Corrupted After Deep Sleep / Post Data Script On Feather S2 #10398

Open

Description

@FoamyGuy
Adafruit CircuitPython 10.0.0-alpha.6 on 2025-05-17; Adafruit Feather ESP32S2 with ESP32S2

Reproducer code:


import alarm
import board
import digitalio
import neopixel
from os import getenv
import random
import time
import adafruit_connection_manager
import adafruit_requests
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
import wifi


# On MagTag, enable power to NeoPixels.
# Remove these two lines on boards without board.NEOPIXEL_POWER.
np_power = digitalio.DigitalInOut(board.NEOPIXEL_POWER)
np_power.switch_to_output(value=True)

builtin_led = digitalio.DigitalInOut(board.LED)
builtin_led.switch_to_output(value=True)

status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.1, pixel_order=neopixel.GRB, auto_write=True)
status_pixel[0] = 0xff0000
status_pixel[0] = 0xffff00

# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
ssid = getenv("WIFI_SSID")
password = getenv("WIFI_PASSWORD")
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
aio_key = getenv("ADAFRUIT_AIO_KEY")

print("Connecting to %s" % ssid)
wifi.radio.connect(ssid, password)
print("Connected to %s!" % ssid)

pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
requests = adafruit_requests.Session(pool, ssl_context)
# Initialize an Adafruit IO HTTP API object
io = IO_HTTP(aio_username, aio_key, requests)

status_pixel[0] = 0x00ff00

try:

    random_feed = io.get_feed("random")
    io.send_data(random_feed["key"], random.randint(0,9999))

except AdafruitIO_RequestError as e:
    print(e)
    #print("You must create feeds on AdafruitIO for: temperature, humidity, and pressure")
except OSError as e:
    print(e)

np_power.value = False
builtin_led.value = False

# Create a an alarm that will trigger 20 seconds from now.
# time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + (5 * 60))
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 60)
# Exit the program, and then deep sleep until the alarm wakes us.
alarm.exit_and_deep_sleep_until_alarms(time_alarm)
# Does not return, so we never get here.

I ran this code on a Feather S2 powered by a 3.7v battery connected to the JST port. After running for "a while" and then unplugging the battery and plugging the feather back in to the computer the flash storage shows signs of corruption.

Most of the times that I've seen it happen it creates a file with a weird four character filename:

Image

The file does not always have the same name, but it is often similar. Here is another one:

Image

One time instead of creating a file like this there were a few characters within the code.py that got corrupted instead leading to syntax error when it tried to run.

After having the corrupted file appear I have been using storage.erase_filesystem() in the REPL to format the flash and get back to a clean state before starting the next trial.

Often times the code seems to keep running seemingly successfully, the neopixel blinks yellow and green during successful wake up / network connect / post data and I've seen that it has continued doing that but after "a while" when I switched to the PC I found the corrupted file.

I tested 9.2.8 and never had the same issue occur. I've also tested 10 alpha 6 with code that only joins the WIFI network and does not POST data, and I did not have the issue occur under that code either.

"a while" seems to be anywhere from a few minutes to an hour or two. On the trials where it did not occur I left them running for 8+ hours and never saw the issue come up.

I will test on USB power from a wall adapter next to try to remove the JST connected battery from the equation.

Activity

  1. added this to the 10.0.0 milestone on Jun 2, 2025
  2. FoamyGuy commented on Jun 2, 2025

    @FoamyGuy
    CollaboratorAuthor

    Maybe the last 3 characters in the filename are consistent. Looking back at screenshots from when it occurred before I found a third instance with a different filename but only the first character differs between all 3 of them. I believe the other times the file appeared matched this pattern as well but I don't have screenshots of any others.

    Image

  3. FoamyGuy commented on Jun 2, 2025

    @FoamyGuy
    CollaboratorAuthor

    Just had this issue occur on USB power from a wall adapter instead of battery via JST. This time it repeated one of the prior weird filenames instead of being unique áy■?

  4. FoamyGuy commented on Jun 4, 2025

    @FoamyGuy
    CollaboratorAuthor

    I have tested this under 10 alpha 6 with two new variations and neither have gotten corrupted after running several hours each.

    • sending a GET request to the adafruit wifi test page http://wifitest.adafruit.com/testwifi/index.html
    • sending a POST request to a local http server running on a rpi on the local network.
  5. dhalbert commented on Jun 4, 2025

    @dhalbert
    Collaborator

    Is Adafruit_IO_HTTP using https or http?

  6. FoamyGuy commented on Jun 4, 2025

    @FoamyGuy
    CollaboratorAuthor

    It's using https. https://github.com/adafruit/Adafruit_CircuitPython_AdafruitIO/blob/d570eebcfd63f7dabf837e2e7d653a06ea0c2ade/adafruit_io/adafruit_io.py#L537

    I could start a new trial with it POST'ing to something else that uses https instead of my local http webserver on the same network. Or a GET request that uses https as now I notice the wifi test doesn't

  7. FoamyGuy commented on Jun 4, 2025

    @FoamyGuy
    CollaboratorAuthor

    HTTPS being involved is looking like a promising theory. I also think that I've narrowed down to POST specifically, I've yet to see it occur with a GET request, and I did run a test with GET requests to an HTTPS URL for a while.

    In my latest test I had this corruption occur with this code that makes a POST to httpbin.org:

    
    import alarm
    import board
    import digitalio
    import neopixel
    from os import getenv
    
    import time
    import adafruit_connection_manager
    import adafruit_requests
    
    import wifi
    
    
    # On MagTag, enable power to NeoPixels.
    # Remove these two lines on boards without board.NEOPIXEL_POWER.
    np_power = digitalio.DigitalInOut(board.NEOPIXEL_POWER)
    np_power.switch_to_output(value=True)
    
    builtin_led = digitalio.DigitalInOut(board.LED)
    builtin_led.switch_to_output(value=True)
    
    status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.1, pixel_order=neopixel.GRB, auto_write=True)
    status_pixel[0] = 0xff0000
    status_pixel[0] = 0xffff00
    
    # battery_monitor = adafruit_max1704x.MAX17048(board.I2C())
    # battery_percentage = battery_monitor.cell_percent
    # print(f"Battery %: {battery_percentage}")
    
    # Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
    # (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
    ssid = getenv("WIFI_SSID")
    password = getenv("WIFI_PASSWORD")
    
    
    print("Connecting to %s" % ssid)
    wifi.radio.connect(ssid, password)
    print("Connected to %s!" % ssid)
    
    pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
    ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
    requests = adafruit_requests.Session(pool, ssl_context)
    
    status_pixel[0] = 0x00ff00
    
    JSON_POST_URL = "https://httpbin.org/post"
    
    # Initalize Wifi, Socket Pool, Request Session
    pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
    ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
    requests = adafruit_requests.Session(pool, ssl_context)
    rssi = wifi.radio.ap_info.rssi
    
    print(f"\nConnecting to {ssid}...")
    print(f"Signal Strength: {rssi}")
    try:
        # Connect to the Wi-Fi network
        wifi.radio.connect(ssid, password)
    except OSError as e:
        print(f"❌ OSError: {e}")
    print("✅ Wifi!")
    
    json_data = {"Date": "January 1, 1970"}
    print(f" | ✅ JSON 'key':'value' POST Test: {JSON_POST_URL} {json_data}")
    with requests.post(JSON_POST_URL, json=json_data) as response:
        json_resp = response.json()
        # Parse out the 'json' key from json_resp dict.
        print(f" | ✅ JSON 'key':'value' Response: {json_resp['json']}")
    print("-" * 80)
    
    print("Finished!")
    
    np_power.value = False
    builtin_led.value = False
    
    # Create a an alarm that will trigger 20 seconds from now.
    # time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + (5 * 60))
    time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 30)
    # Exit the program, and then deep sleep until the alarm wakes us.
    alarm.exit_and_deep_sleep_until_alarms(time_alarm)
    # Does not return, so we never get here.
    
    

    I got this corrupted file created while running this script:

    Image

    Again the same pattern with the final characters of the filename.

    This removes Adafruit IO from the equation entirely. It is feeling like somehow this is tied to HTTPS and specifically POST'ing data.

  8. dhalbert commented on Jul 29, 2025

    @dhalbert
    Collaborator

    See a similar report of random overwrites of files in https://forums.adafruit.com/viewtopic.php?t=219390.

  9. dhalbert commented on Jul 30, 2025

    @dhalbert
    Collaborator

    @FoamyGuy have you seen this at all on anything after 10.0.0-alpha.6? https://forums.adafruit.com/viewtopic.php?t=219390 does report file corruption in 10.0.0-beta.0, apparently.

  10. dhalbert commented on Aug 7, 2025

    @dhalbert
    Collaborator

    I have been unable to reproduce this on 10.0.0-beta.2, on a Feather ESP32-S2. I was doing HTTP (not HTTPS) POST's to httpbin.org, and then doing HTTP GET's to a local server. I'm powering it with a power-only USB cable. I don't see stray directory entries. I sped up the sleep a lot so it's waking up after 5 seconds. I believe you saw this, but I'm not sure how to reproduce. This could be some kind of brownout issue with the flash, since there's otherwise no writing of the flash going on. The fact that it's directory entries makes me suspicious it's in the first block of flash.

  11. FoamyGuy commented on Aug 8, 2025

    @FoamyGuy
    CollaboratorAuthor

    I updated to Adafruit CircuitPython 10.0.0-beta.2 on 2025-07-31; Adafruit Feather ESP32S2 with ESP32S2 and started up the reproducer script again today and had this corruption happen again.

    Image

    It was running for 2-3 hours powered by a USB C cable connected to a wall adapter before it crashed and then had the corrupted file on the drive when I plugged it in to a computer afterward.

    The cable itself supports both data and power, but the wall adapter it is connected to should be power only.

  12. modified the milestones: 10.0.0, 10.x.x on Sep 10, 2025
  13. modified the milestones: 10.x.x, 11.0.0 on Sep 28, 2026
  14. dhalbert commented on Nov 14, 2026

    @dhalbert
    Collaborator

    @FoamyGuy Have you seen this in recent builds? If not I'll close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions