Skip to content

Commit

Permalink
On Low disk space try to upload readings. Plus sleep on boot
Browse files Browse the repository at this point in the history
When low disk space detected try to upload the readings to free up the disk space.  On Boot sleep for 0.5 seconds at start.
  • Loading branch information
dave-ct committed Dec 11, 2022
1 parent a1e2454 commit c902806
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
# from phew import logging
# logging.disable_logging_types(logging.LOG_DEBUG)

# Issue #117 where neeed to sleep on startup otherwis emight not boot
from time import sleep
sleep(0.5)

# import enviro firmware, this will trigger provisioning if needed
import enviro
import os


try:
# initialise enviro
enviro.startup()
Expand All @@ -42,7 +47,19 @@
if enviro.low_disk_space():
# less than 10% of diskspace left, this probably means cached results
# are not getting uploaded so warn the user and halt with an error
enviro.halt("! low disk space")

# Issue #126 to try and upload if disk space is low
# is an upload destination set?
if enviro.config.destination:
enviro.logging.error("! low disk space. Attempting to upload file(s)")

# if we have enough cached uploads...
enviro.logging.info(f"> {enviro.cached_upload_count()} cache file(s) need uploading")
if not enviro.upload_readings():
enviro.halt("! reading upload failed")
else:
# no destination so go to sleep
enviro.halt("! low disk space")

# TODO this seems to be useful to keep around?
filesystem_stats = os.statvfs(".")
Expand Down

0 comments on commit c902806

Please sign in to comment.