pimoroni / enviro

MIT License
105 stars 85 forks source link

Add code to retry sending results to adafruit with a delay when rate limited #64

Closed sgtwilko closed 2 years ago

sgtwilko commented 2 years ago

This solves the issue where your board stops because Ada Fruit has rate limited the uploads.

My board ran the battery down to flat, probably because it was stuck trying to upload values.

This PR adds some debug so you can see from the console what the return status is, and also will retry the request after 30 seconds if the response is 429 - Rate limited.

lowfatcode commented 2 years ago

We actually used to have something like this in the code but I removed it - the issue is it keeps the board awake for much longer than is needed and therefore drains the battery very quickly.

There are a couple of options though:

Basically what's happening is logical based on the setup of the system so it doesn't seem like something to work around?

sgtwilko commented 2 years ago

Hiya,

Interesting. I would have thought bringing WiFi up more often (to upload more often) would have caused a larger power drain as it has to go through the entire handshake each time.

As it uses most power when transmitting, having to go through that initially WiFi setup more often would surely drain it quicker than pausing when it's not deliberately transmitting.

Would be interested to know how this was measured.

Anyway, you asked if this was something to work around. I think it is, based on the current behaviour where by default you cannot upload the results if you received the 429.

429 may also be returned even if you're on a paid plan as we have no knowledge of what other feeds the user has going into Adafruit.

If they approach the 60 values per minute of the paid plan, then the enviro board will still spam all the values up as fast as it can and it will still receive the 429.

In this instance I would have thought it's got to be better to back off and retry, rather than leave the board flashing red with results stuck?