From 02a99f6e53110db85be01e6b2b3a8e5690660f7e Mon Sep 17 00:00:00 2001 From: David Edwards Date: Tue, 13 Dec 2022 12:15:50 +0000 Subject: [PATCH] Attempt to upload cached files when low disk space In the event of low disk space caused by previous cache upload failures, dont take more readings and just try to upload. related to issue #126 --- main.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 13c17a0..95eff3b 100644 --- a/main.py +++ b/main.py @@ -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() @@ -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(".")