Skip to content

Hard fault after 1.5 hours of co2 monitoring #10612

@tudorapo

Description

@tudorapo

CircuitPython version and board name

Adafruit CircuitPython 9.2.8 on 2025-05-28; Raspberry Pi Pico W with rp2040
Board ID:raspberry_pi_pico_w
UID:E6632C85930F4136
MAC:2C:CF:67:08:08:49

Code/REPL

import time
import board
import busio
import wifi
import sys
import gc
import supervisor
import traceback
import adafruit_scd4x
import adafruit_requests
import adafruit_connection_manager
from os import getenv

i2c0 = busio.I2C(board.GP17, board.GP16)
scd4x = adafruit_scd4x.SCD4X(i2c0)
scd4x.start_periodic_measurement()

print("wifi")
wifi.radio.hostname="co2"
try:
    wifi.radio.connect(ssid=getenv("WIFI"), password=getenv("PASS"))
except OSError as e:
    print(f"wifi: {e}")
radio = wifi.radio

if not radio.connected:
    print("No wifi, sad.")
    time.sleep(5)
    supervisor.reload()

pool = adafruit_connection_manager.get_radio_socketpool(radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(radio)
requests = adafruit_requests.Session(pool, ssl_context)

print("Waiting for first measurement....")
while True:
    while not scd4x.data_ready:
        time.sleep(0.1)
    co2 = scd4x.CO2
    temp = scd4x.temperature
    hum = scd4x.relative_humidity
    urls = []
    urls.append(f'http://{getenv("SERV")}/templog/add/{getenv("NAME")}/co2/{co2}')
    urls.append(f'http://{getenv("SERV")}/templog/add/{getenv("NAME")}/temp/{temp}')
    urls.append(f'http://{getenv("SERV")}/templog/add/{getenv("NAME")}/hum/{hum}')
    for url in urls:
        try:
            r = requests.get(url, timeout=15)
        except Exception as e:
            print("Unexpected error:", traceback.format_exception(e))
            time.sleep(5)
            supervisor.reload()
        else:
            print(r.status_code)
    del urls
    msg = f"CO2: {co2:d} ppm\n"
    msg += f"Temp: {temp:.1f}C\n"
    msg += f"Humidity: {hum:.0f}%"
    print(msg)
    del msg
    print(gc.mem_free())
    time.sleep(30)

Behavior

It works quite well for 1.5 hours, and then:

CO2: 2226 ppm
Temp: 25.1C
Humidity: 62%
171120
200
200
200
CO2: 2223 ppm
Temp: 25.0C
Humidity: 63%
169504
200
200
Unexpected error: ['Traceback (most recent call last):\r\n  File "code.py", line 48, in <module>\r\n  File "adafruit_requests.py", line 721, in get\r\n  File "adafruit_requests.py", line 649, in request\r\n  File "adafruit_connection_manager.py", line 331, in get_socket\r\n  File "adafruit_connection_manager.py", line 248, in _get_connected_socket\r\nOSError: [Errno 119] EINPROGRESS\n']

Code done running.

[15:42:49.153] Disconnected
[15:42:50.154] Warning: Could not open /dev/ttyACM0 (No such file or directory)
[15:42:50.154] Waiting for tty device..
[15:42:52.158] Connected to /dev/ttyACM0
Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Hard fault: memory access or instruction error.
Please file an issue with your program at github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 9.2.8 on 2025-05-28; Raspberry Pi Pico W with rp2040

Description

I added some dels and gc info to the output hoping that its a problem of running out of memory, but no.

After I remove the usb and plug it back it comes back in firmware load mode, ie. the RPI-RP2 disk is mounted.

Tried it with the 10.0.0.beta3 too, same problem.

Additional information

It said that I have to open this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrp2Both RP2 microcontrollers

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions