UniversalDevicesInc-PG3 / udi-poly-Airthings-Consumer

Polyglot V3 Node Server for Airthings Consumer API
0 stars 0 forks source link

Check why rate limit is being hit #13

Open jimboca opened 2 years ago

jimboca commented 2 years ago

Looks like it's calling update for each sensor? Need to confirm: https://forum.universal-devices.com/topic/36297-airthings-api-now-available-for-their-consumer-products/?do=findComment&comment=343669

jimboca commented 2 years ago

And properly catch this error: 2022-07-16 00:03:04,512 Thread-16889 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2930024519/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070}

From: https://forum.universal-devices.com/topic/36297-airthings-api-now-available-for-their-consumer-products/?do=findComment&comment=343651

jimboca commented 2 years ago

You can only poll a sensor, there is no API method to grab them all. I asked the Vendor if it could be done and they said only for Business products.

So user must set short poll to: 30 * number of sensors.

Need to look into automatically adjusting the short poll interval.

macjeff commented 1 year ago

I have 4 decvices (5 nodes- so 4 sensors). I have it set to 120 and still getting this in the logs. I am going to keep going up and see what happens. (restarting nodeserver each time)

2022-10-06 12:26:47,693 Thread-24 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2920014538/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070} 2022-10-06 12:26:47,694 Thread-24 udi_interface ERROR pgSession:response: Check AirThings system status 2022-10-06 12:32:48,299 Thread-29 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2920014538/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070} 2022-10-06 12:32:48,300 Thread-29 udi_interface ERROR pgSession:response: Check AirThings system status 2022-10-06 13:38:47,206 Thread-78 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2930024519/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070} 2022-10-06 13:38:47,207 Thread-78 udi_interface ERROR pgSession:response: Check AirThings system status 2022-10-06 14:44:47,308 Thread-128 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2930024519/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070} 2022-10-06 14:44:47,309 Thread-128 udi_interface ERROR pgSession:response: Check AirThings system status 2022-10-06 15:50:47,479 Thread-177 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2930024519/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070} 2022-10-06 15:50:47,481 Thread-177 udi_interface ERROR pgSession:response: Check AirThings system status 2022-10-06 16:56:47,707 Thread-227 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2930024519/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070} 2022-10-06 16:56:47,708 Thread-227 udi_interface ERROR pgSession:response: Check AirThings system status 2022-10-06 18:02:47,991 Thread-276 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2930024519/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070} 2022-10-06 18:02:47,992 Thread-276 udi_interface ERROR pgSession:response: Check AirThings system status 2022-10-06 19:08:48,230 Thread-326 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2930024519/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070} 2022-10-06 19:08:48,231 Thread-326 udi_interface ERROR pgSession:response: Check AirThings system status

jimboca commented 1 year ago

@macjeff 120 should be fine since that will not hit the rate limit https://developer.airthings.com/docs/api-rate-limit#airthings-consumer But try increasing some more to see what happens.

macjeff commented 1 year ago

its been on 120 for a while. Now I am on 180. Restarted and within a couple minutes

2022-10-06 20:12:53,991 Thread-29 udi_interface ERROR pgSession:response: Unknown response 429: https://ext-api.airthings.com/v1//devices/2930008704/latest-samples {"error":"TOO_MANY_REQUESTS","error_description":"Rate limit on API exceeded","error_code":1070}

jimboca commented 1 year ago

Did it have any successful updates? If you already hit the rate limit and just restarted then you will still be hitting the rate limit.

macjeff commented 1 year ago

when I look that was my last error so I guess its working now. Just restarted and its ok. I am on 180 and will leave it there.

JayTeeHardAtWork commented 1 year ago

If you do automate the shortpoll value (which would be a good idea, IMO), here's a table I believe represents what the max shortpoll should be for each Airthings hub/API based on number of devices linked to it since it seems each device (rather than the hub) is considered a separate API request.

Devices Calls per hour Delay in mins 10 12.0 5 9 13.3 4.5 8 15.0 4 7 17.1 3.5 6 20.0 3 5 24.0 2.5 4 30.0 2 3 40.0 1.5 2 60.0 1 1 120.0 0.5

I can confirm that 5 mins has been working with 9 devices. I didn't test 4.5 mins but I think 4 mins was working when I had 8 devices. It's worth noting that the devices themselves only update the cloud every 5 mins or so anyway (and I'm sure I've seen longer times between updates).

Also worth noting that a restart will result in an extra set of set of API requests being made. In my case while 5 mins is fine in general, if I do a restart I blow the API rate limit because of the extra calls due to the restart.

jimboca commented 1 year ago

This is not possible until PG3 supports it https://github.com/UniversalDevicesInc/udi_python_interface/issues/26

jimboca commented 1 year ago

For now we will just notify the user with a warning in the log and a message in the PG3 UI if their value is to low.

jimboca commented 4 months ago

I've Pinged https://github.com/UniversalDevicesInc/udi_python_interface/issues/26 to see if this can be added.