MagTag Covid Tracking waking up every hour

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
rgbailey
 
Posts: 17
Joined: Mon Jun 16, 2014 9:08 am

MagTag Covid Tracking waking up every hour

Post by rgbailey »

I have setup the Covid tracker and it is waking up every hour and updating.

Below is the code I am running and the time zone is America/Los_Angeles

Code: Select all

# SPDX-FileCopyrightText: 2020 ladyada, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import alarm
import supervisor
import alarm
from adafruit_magtag.magtag import MagTag

# Change this to the hour you want to check the data at, for us its 8pm
# local time (eastern), which is 20:00 hrs
DAILY_UPDATE_HOUR = 20

# Set up where we'll be fetching data from
DATA_SOURCE = "https://api.covidtracking.com/v1/us/current.json"
DATE_LOCATION = [0, 'dateChecked']
NEWPOS_LOCATION = [0, 'positiveIncrease']
CURRHOSP_LOCATION = [0, 'hospitalizedCurrently']
NEWHOSP_LOCATION = [0, 'hospitalizedIncrease']
ALLDEATH_LOCATION = [0, 'death']
NEWDEATH_LOCATION = [0, 'deathIncrease']

magtag = MagTag(
    url=DATA_SOURCE,
    json_path=(DATE_LOCATION, NEWPOS_LOCATION,
               CURRHOSP_LOCATION, NEWHOSP_LOCATION,
               ALLDEATH_LOCATION, NEWDEATH_LOCATION),
)


# Date stamp of info
magtag.add_text(
    text_font="Arial-Bold-12.pcf",
    text_position=(10, 15),
    text_transform=lambda x: "Date: {}".format(x[0:10]),
)
# Positive increase
magtag.add_text(
    text_font="Arial-Bold-12.pcf",
    text_position=(10, 35),
    text_transform=lambda x: "New positive:   {:,}".format(x),
)
# Curr hospitalized
magtag.add_text(
    text_font="Arial-Bold-12.pcf",
    text_position=(10, 55),
    text_transform=lambda x: "Current Hospital:   {:,}".format(x),
)
# Change in hospitalized
magtag.add_text(
    text_font="Arial-Bold-12.pcf",
    text_position=(10, 75),
    text_transform=lambda x: "Change in Hospital:   {:,}".format(x),
)
# All deaths
magtag.add_text(
    text_font="Arial-Bold-12.pcf",
    text_position=(10, 95),
    text_transform=lambda x: "Total deaths:   {:,}".format(x),
)
# new deaths
magtag.add_text(
    text_font="Arial-Bold-12.pcf",
    text_position=(10, 115),
    text_transform=lambda x: "New deaths:   {:,}".format(x),
)

# updated time
magtag.add_text(
    text_font="Arial-Bold-12.pcf",
    text_position=(245, 30),
    line_spacing=0.75,
    is_data=False
)

magtag.graphics.qrcode(b"https://covidtracking.com/data",
                       qr_size=2, x=240, y=70)

magtag.peripherals.neopixels.brightness = 0.1
magtag.peripherals.neopixel_disable = False # turn on lights
magtag.peripherals.neopixels.fill(0x0F0000) # red!

magtag.get_local_time()
try:
    now = time.localtime()
    print("Now: ", now)

    # display the current time since its the last-update
    updated_at = "%d/%d\n%d:%02d" % now[1:5]
    magtag.set_text(updated_at, 6, False)

    # get data from the Covid Tracking Project
    value = magtag.fetch()
    print("Response is", value)

    # OK we're done!
    magtag.peripherals.neopixels.fill(0x000F00) # greten
except (ValueError, RuntimeError) as e:
    print("Some error occured, trying again later -", e)

time.sleep(2) # let screen finish updating

# we only wanna wake up once a day, around the event update time:
event_time = time.struct_time((now[0], now[1], now[2],
                               DAILY_UPDATE_HOUR, 0, 0,
                               -1, -1, now[8]))
# how long is that from now?
remaining = time.mktime(event_time) - time.mktime(now)
if remaining < 0:             # ah its aready happened today...
    remaining += 24 * 60 * 60 # wrap around to the next day
remaining_hrs = remaining // 3660
remaining_min = (remaining % 3600) // 60
print("Gonna zzz for %d hours, %d minutes" % (remaining_hrs, remaining_min))

# Turn it all off and go to bed till the next update time
magtag.exit_and_deep_sleep(remaining)

User avatar
rgbailey
 
Posts: 17
Joined: Mon Jun 16, 2014 9:08 am

Re: MagTag Covid Tracking waking up every hour

Post by rgbailey »

Here is the serial output for several hours

Code: Select all


Code done running. Waiting for reload.
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
Traceback (most recent call last):
  File "code.py", line 116, in <module>
  File "adafruit_magtag/magtag.py", line 120, in exit_and_deep_sleep
  File "adafruit_portalbase/__init__.py", line 315, in exit_and_deep_sleep
KeyboardInterrupt: 

Press any key to enter the REPL. Use CTRL-D to reload.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 asgard
Getting time for timezone America/Los_Angeles
Now:  struct_time(tm_year=2020, tm_mon=12, tm_mday=22, tm_hour=11, tm_min=5, tm_sec=6, tm_wday=1, tm_yday=357, tm_isdst=-1)
Retrieving data...Reply is OK!
Response is ['2020-12-21T24:00:00Z', 178191, 115351, 3214, 310968, 1485]
Gonna zzz for 8 hours, 54 minutes
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 asgard
Getting time for timezone America/Los_Angeles
Now:  struct_time(tm_year=2020, tm_mon=12, tm_mday=22, tm_hour=11, tm_min=50, tm_sec=58, tm_wday=1, tm_yday=357, tm_isdst=-1)
Retrieving data...Reply is OK!
Response is ['2020-12-21T24:00:00Z', 178191, 115351, 3214, 310968, 1485]
Gonna zzz for 8 hours, 9 minutes
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 asgard
Getting time for timezone America/Los_Angeles
Now:  struct_time(tm_year=2020, tm_mon=12, tm_mday=22, tm_hour=13, tm_min=0, tm_sec=53, tm_wday=1, tm_yday=357, tm_isdst=-1)
Retrieving data...Reply is OK!
Response is ['2020-12-21T24:00:00Z', 178191, 115351, 3214, 310968, 1485]
Gonna zzz for 6 hours, 59 minutes
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 asgard
Getting time for timezone America/Los_Angeles
Now:  struct_time(tm_year=2020, tm_mon=12, tm_mday=22, tm_hour=14, tm_min=10, tm_sec=46, tm_wday=1, tm_yday=357, tm_isdst=-1)
Retrieving data...Reply is OK!
Response is ['2020-12-21T24:00:00Z', 178191, 115351, 3214, 310968, 1485]
Gonna zzz for 5 hours, 49 minutes
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 asgard
Getting time for timezone America/Los_Angeles
Now:  struct_time(tm_year=2020, tm_mon=12, tm_mday=22, tm_hour=15, tm_min=20, tm_sec=41, tm_wday=1, tm_yday=357, tm_isdst=-1)
Retrieving data...Reply is OK!
Response is ['2020-12-21T24:00:00Z', 178191, 115351, 3214, 310968, 1485]
Gonna zzz for 4 hours, 39 minutes



User avatar
jay0lee
 
Posts: 12
Joined: Wed Oct 21, 2020 11:03 am

Re: MagTag Covid Tracking waking up every hour

Post by jay0lee »

I'm seeing similar issues. I suspect the Circuit Python 6.1 beta is buggy and crashing after an hour.

User avatar
rgbailey
 
Posts: 17
Joined: Mon Jun 16, 2014 9:08 am

Re: MagTag Covid Tracking waking up every hour

Post by rgbailey »

The soft reboots were happening for me every 70 minutes.

I resolved it by loading the absolute latest build. (bleeding edge code)

This is the one I used.

https://adafruit-circuit-python.s3.amaz ... b03951.uf2

Other related builds are here.
https://adafruit-circuit-python.s3.amaz ... ale/en_US/

User avatar
jay0lee
 
Posts: 12
Joined: Wed Oct 21, 2020 11:03 am

Re: MagTag Covid Tracking waking up every hour

Post by jay0lee »

Confirmed daily resolved that issue but like a daily build often does it proved unstable in other areas. I'm now on beta3 released just today and hopefully it's overall stable:

https://circuitpython.org/board/adafrui ... grayscale/

User avatar
rgbailey
 
Posts: 17
Joined: Mon Jun 16, 2014 9:08 am

Re: MagTag Covid Tracking waking up every hour

Post by rgbailey »

I need to update as well, I noticed that the daily that I am running reboots about every 12 hours and the battery lasts about 36-48 hours.

Locked
Please be positive and constructive with your questions and comments.

Return to “AdaBox! Show us what you made!”