Ich verwende Quellcode von: https://github.com/jegamboafuentes/Trai ... 25/current software.git und bin derzeit nicht in der Lage, einen Speicherzuordnungsfehler herauszufinden:
Die Anzeige auf dem seriellen Monitor ist:
Code: Select all
Adafruit CircuitPython 10.0.3 on 2025-10-17; Adafruit Matrix Portal M4 with samd51j19
>>>
soft reboot
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Warning: outlined_label.OutlinedLabel is deprecated, adafruit_display_text.bitmap_label.Label now supports outline functionality with the same API, it should be used instead.
Connecting to mywifi
Getting time from IP address
2025-12-29 15:32:05
Data source: https://www.mbta.com/schedules/finder_api/departures?id=Blue&stop=place-wondl&direction=0
Free memory before variable: 22304 bytes
Retrieving data...Reply is OK!
Traceback (most recent call last):
File "code.py", line 181, in
File "code.py", line 52, in get_arrival_times2
File "adafruit_portalbase/network.py", line 638, in fetch_data
File "adafruit_portalbase/network.py", line 670, in _parse_data
File "adafruit_portalbase/network.py", line 735, in process_json
MemoryError: memory allocation failed, allocating 680 bytes
Code done running.
Der Fehler wird innerhalb der Funktion get_arrival_times2( ) bei stop_trains = network.fetch_data(DATA_SOURCE2) ausgelöst
Es scheint, dass vor dem Abrufen der Daten genügend Speicher vorhanden ist die API??? Ich habe bereits versucht, einige gc.collect()-Anweisungen im gesamten Code einzufügen und alle nicht benötigten Bibliotheken und Bitmapdateien entfernt, um die auf dem Gerät gespeicherte Menge zu begrenzen....
Jeder Einblick, was hier vor sich geht und wie dieser Fehler umgangen werden kann, ist mir sehr willkommen!
Code: Select all
#August 25 2023
#V2
#Jorge Enrique Gamboa Fuentes
#Subway schedule board - single direction
#Data from: Boston - MBTA
# .l. - .l. - .l. - .l. - .l. - .l. - .l. - .l. - .l. - .l. - .l. - .l. - .l. - .l. - .l. - .l. -
import time
import microcontroller
from board import NEOPIXEL
import displayio
import adafruit_display_text.label
from adafruit_datetime import datetime
from adafruit_bitmap_font import bitmap_font
from adafruit_matrixportal.matrix import Matrix
from adafruit_matrixportal.network import Network
import json
import gc
#CONFIGURABLE PARAMETERS
#-*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*-
BOARD_TITLE = 'Bowdoin'
STOP_ID = 'place-wondl'
DIRECTION_ID = '0'
ROUTE = 'Blue'
BACKGROUND_IMAGE = 'Tred-dashboard.bmp'
PAGE_LIMIT = '3'
DATA_SOURCE = 'https://api-v3.mbta.com/predictions?filter%5Bstop%5D='+STOP_ID+'&filter%5Bdirection_id%5D='+DIRECTION_ID+'&page%5Blimit%5D='+PAGE_LIMIT+'&sort=departure_time'
DATA_SOURCE2 = 'https://www.mbta.com/schedules/finder_api/departures?id=Blue&stop=place-wondl&direction=0'
UPDATE_DELAY = 15
SYNC_TIME_DELAY = 30
MINIMUM_MINUTES_DISPLAY = 9
ERROR_RESET_THRESHOLD = 3
#-*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*--*-/-*-\-*-
def get_arrival_in_minutes_from_now(now, date_str):
train_date = datetime.fromisoformat(date_str).replace(tzinfo=None) # Remove tzinfo to be able to diff dates
return round((train_date-now).total_seconds()/60.0)
#New 8/25/23 - this function gets directly the time from the API
def get_arrival_times2():
now = datetime.now()
print(now)
print("Data source: "+DATA_SOURCE2)
print("Free memory before variable: {} bytes".format(gc.mem_free()))
stop_trains = network.fetch_data(DATA_SOURCE2)
print(stop_trains)
res = json.loads(stop_trains)
print(res)
times = []
for entry in res:
try:
time = entry['realtime']['prediction']['time']
print(entry['realtime']['prediction']['time'])
if time[0] == 'arriving':
times.append('brding')
else:
times.append("{:02}".format(int(time[0])) + ' ' + time[2])
except KeyError:
continue
if len(times) == 3:
break
return times
def text_formating(trainMinutes):
textFormated = ""
if(trainMinutes last_time_sync + SYNC_TIME_DELAY:
# Sync clock to minimize time drift
network.get_local_time()
last_time_sync = time.monotonic()
arrivals = get_arrival_times2()
update_text2(*arrivals)
except (ValueError, RuntimeError) as e:
print("Some error occured, retrying! -", e)
error_counter = error_counter + 1
if error_counter > ERROR_RESET_THRESHOLD:
microcontroller.reset()
time.sleep(UPDATE_DELAY)
Mobile version