circuitpython: MagTag Vaccination tracker crash in magtag.network.connect() between 7alpha3 and 7alpha4

CircuitPython version

Adafruit CircuitPython 7.0.0-alpha.4 on 2021-07-08; Adafruit MagTag with ESP32S2

Code/REPL

Demo code can be fetched from here: https://learn.adafruit.com/adafruit-magtag-covid-vaccination-percent-tracker/code-the-vaccination-tracker

Behavior

MagTag Vaccination tracker crash in magtag.network.connect() between 7alpha3 and 7alpha4

I tested MagTag Covid percentage tracker with 7.0.0-alpha.3 and 7.0.0-alpha.4.

Somewhere in between the two it crash in loop in magtag.network.connect()

With Adafruit CircuitPython 7.0.0-alpha.3 on 2021-06-03; Adafruit MagTag with ESP32S2

It kind of work, it does not display the properly, but the progress bar are there and the network fetch work:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable. code.py output: Connecting to AP NEO Retrieving data…Reply is OK! Response is [‘United States’, ‘2021-07-18’, ‘"Johnson&Johnson’, ’ Moderna’, ’ Pfizer/BioNTech"', ‘https://covid.cdc.gov/covid-data-tracker/COVIDData/getAjaxData?id=vaccination_data’, ‘337740358’, ‘186038501’, ‘161232483’] Sleeping for 86400 seconds

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload. Pretending to deep sleep until alarm, CTRL-C or file write.

With Adafruit CircuitPython 7.0.0-alpha.4 on 2021-07-08; Adafruit MagTag with ESP32S2 it bootloop in

It reset/boot in loop somewhere inside magtag.network.connect():

soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable. code.py output: Connecting to AP NEO

^^^ And here bootlook reseting the serial ^^^

So somewhere between 7.0.0-alpha.3 and 7.0.0-alpha.4 the network call of

I guess I need to bisec and find where it stated to behave like that.

Demo code can be fetched from here: https://learn.adafruit.com/adafruit-magtag-covid-vaccination-percent-tracker/code-the-vaccination-tracker

Description

No response

Additional information

This test is done with the learn guide library… except for manual update to the latest version from GIT of:

  • adafruit_portalbase
  • adafruit_magtag

Using the py (not mpy) version of those library (in an attempt to debug that further).

This is also mean using https://github.com/adafruit/Adafruit_CircuitPython_MagTag/pull/63 that I was trying to validate.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@jfurcean Thanks for the minimal example! We used it to debug.

It must be some kind of object that is moved but can’t be moved safely, making this change causes the crash to go away for me:

--- a/py/gc.c
+++ b/py/gc.c
@@ -780,6 +780,7 @@ bool gc_has_finaliser(const void *ptr) {
 }
 
 void *gc_make_long_lived(void *old_ptr) {
+    return old_ptr;
     // If its already in the long lived section then don't bother moving it.
     if (old_ptr >= MP_STATE_MEM(gc_lowest_long_lived_ptr)) {
         return old_ptr;

Commenting out the gc.collect() line in network.py of adafruit_circuitpython_portalbase allows the shortened example to work. The longer example still doesn’t work. I think there is some interaction with gc.collect() and the network connection.

I tested this with the simple magtag example in adafruit_circuitpython_magtag and added magtag.network.connnect(). It would crash unless I also commented out the gc.collect() in add_text and set_text in __init__.py in adafruit_circuitpython_portalbase.

Adafruit CircuitPython 7.0.0-beta.0 on 2021-08-24; Adafruit MagTag with ESP32S2
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import terminalio
from adafruit_magtag.magtag import MagTag

magtag = MagTag()

# added this line to the example
magtag.network.connect()

magtag.add_text(
    text_font=terminalio.FONT,
    text_position=(
        50,
        (magtag.graphics.display.height // 2) - 1,
    ),
    text_scale=3,
)

magtag.set_text("Hello World")

buttons = magtag.peripherals.buttons
button_colors = ((255, 0, 0), (255, 150, 0), (0, 255, 255), (180, 0, 255))
button_tones = (1047, 1318, 1568, 2093)
timestamp = time.monotonic()

while True:
    for i, b in enumerate(buttons):
        if not b.value:
            print("Button %c pressed" % chr((ord("A") + i)))
            magtag.peripherals.neopixel_disable = False
            magtag.peripherals.neopixels.fill(button_colors[i])
            magtag.peripherals.play_tone(button_tones[i], 0.25)
            break
    else:
        magtag.peripherals.neopixel_disable = True
    time.sleep(0.01)