0

Hi I am controlling nest thermostat by Firebase SDK. We have big problem with Too many requests exception. I saw a few threads about that but without solution for that problem. So I would like to ask if someone managed to solve that problem?

user1442611
  • 21
  • 1
  • 4
  • Let me describe it in more details. Problem related with Too many requests is related always with changing something on the device. We do not have this problem in case of fetching device state. We are able to make 3-5 changes on the device and then we are exceeding the limit and have Too many requests exception. Then we have to wait some time and again we are able to make a few changes on device. – user1442611 Oct 09 '14 at 10:19

3 Answers3

1

From https://developer.nest.com/documentation/data-rate-limits:

To avoid errors, we recommend you limit requests to one call per minute, maximum.

From this, and from other posts on SO, I believe you can make 60 requests in any 60 minute window. But I think this is a Per Access Token limit. Nest say separately that they rate-limit writes to devices and structures - I haven't hit the write limit, but I don't do a lot of writing to the device.

thesimm
  • 774
  • 3
  • 12
1

In order to work around this limitation, I did the following:

  • When the user issues a command, don't send the command to Firebase immediately; just queue it and execute it after a constant delay, D
  • If the user issues another command within delay D, then de-queue the previous command and queue the most recent one.

With this strategy, the number of issues commands is at most one per D seconds.

Here is the code:

-(void) delayedSetValue:(NSArray *)valuesAndURL  {
NSDictionary *values = valuesAndURL[0];
NSString *URL = valuesAndURL[1];

if ([self.subscribedURLs objectForKey:URL]) {
    [[self.fireBi objectForKey:URL]  runTransactionBlock:^FTransactionResult *(FMutableData *currentData) {
        [currentData setValue:values];
        return [FTransactionResult successWithValue:currentData];
    } andCompletionBlock:^(NSError *error, BOOL committed, FDataSnapshot *snapshot) {
        if (error) {
            NSLog(@"Error: %@", error);
        }
    } withLocalEvents:NO];
}
}

/*
 * Sets the values for the given firebase URL.
 */
- (void)setValues:(NSDictionary *)values forURL:(NSString *)URL
{
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    NSArray *valuesAndURL = @[values, URL];
    [self performSelector:@selector(delayedSetValue:) withObject:valuesAndURL afterDelay:5.0f];
}
RawMean
  • 8,374
  • 6
  • 55
  • 82
0

I have had a similare issue. but it was only when I authenticated too much. I had to wait for a while to get the change to authenticate again. Now i got a websocket running to get the values and that gives no problems. Setting values is the next step i am going to do. So for that i dont know how much request you can send

RawMean
  • 8,374
  • 6
  • 55
  • 82
Roy du Crocq
  • 51
  • 1
  • 8
  • I am currently also working on writing data to the nest. And I have had the too many requets exception. this because i didn't use my timer right. just make sure you limit your data changes, every minuut is around the limit it seems. hope it helpt – Roy du Crocq Oct 13 '14 at 10:42