pimoroni / enviro

MIT License
105 stars 85 forks source link

adafruit_io logging causing halt (in 0.0.8) #77

Closed retropangy closed 2 years ago

retropangy commented 2 years ago

adafruit_io upload appears to be causing my grow to halt with a red flashing light. Suspect for some reason it's not handling throttling at the adafruit end (it did before) and returning False, which means that

    if not enviro.upload_readings():
      enviro.halt("! reading upload failed")

in main.py is causing a halt. Could be wrong though!

lowfatcode commented 2 years ago

That's correct, it's alerting you that an error occurred. If it's throttling you need to either reduce your upload frequency, remove some readings, or pay for a Pro plan!

retropangy commented 2 years ago

It wasn't doing that before however - it was throttling, but it backed off and tried again rather than halting. It looks like the entire section to handle that situation has been removed;

        if result.status_code == 429:
          result.close()
          logging.info(f"  - rate limited, cooling off for thirty seconds")
          time.sleep(30)
          # try the request again
          result = urequests.post(url, json=payload, headers=headers)

and I think even if that failed it didn't halt.

I should probably point out that I'm using the provisioning defaults for the Grow at all points. I feel that it should be able to handle uploading to one of the default destinations at the defaults rates without having to have a pro plan - that's just going to put users off. I'm going to try reverting to the original adafruit_io.py in the meantime as at least it worked!

retropangy commented 2 years ago

@lowfatcode - just also noticed that it now causes a halt if it can't upload for any reason, e.g. the Pico W can't connect to wifi. Does a halt stop any further processing (i.e. does it wake up again in 15 minutes and try again or stay halted)? If so that could be a critical failure - if you're away for two weeks, the wifi glitches for a few minutes two days in and you've got dead plants on your return.

I have altered the new adafruit_io.py to try two more times with 60 seconds sleep inbetween which now seems to be keeping things stable (albeit with one further halt because it couldn't connect to wifi for some unknown reason) but I feel strongly that this should not be a closed issue - it just does not work as well as the previous version.

lowfatcode commented 2 years ago

Yes, it was backing off before but this isn't a viable solution when on battery power as it substantially increases the drain on the battery - the correct answer is to increase your upload frequency, remove some readings, or pay for pro!

A halt is really just a normal sleep with attached error log entry and blinking red LED to alert the user - so it wakes up again as normal and will actually clear the error (blinking LED) if everything goes OK.

retropangy commented 2 years ago

Good news on the halt being essentially cosmetic, that's reassuring! I appreciate that the battery usage of waiting and retrying is higher, but compared to over doubling the number of upload sessions it must be a close thing, especially as I imagine running the pumps is going to swamp usage to some degree . (And yes, there is Pro, but as I say it's a bit of an ask for casual users.)

Probably my best bet is to reduce the number of data points in general (e.g drop luminence and battery voltage, maybe pressure) and upload a little more frequently. Hopefully simple enough to do (he says, with little hope!)

retropangy commented 2 years ago

Of course, now I run into another problem which is that the RTC has drifted into the future so I'm getting errors coming back from adafruit.io because there is date being logged that is in the future as far as its concerned - the backing off hid that because by the time it actually uploaded it was in the past! More halts because of it. The ntp fetch is only done if the year has reset, so I've had to alter the code in enviro/init.py so that is_clock_set() only returns true if the year is above 2020 and it's not between midnight and half-past midnight - so hopefully it will sync once (or twice) a day.

RedDogUK commented 2 years ago

@lowfatcode, I think the Adafruit IO upload script needs to revert back to v0.0.2 (or a version similar to v0.0.2) where the script allows for pauses in the upload when reaching the upload limit of 30 data points per minute (for a free account).