Skip to content

Commit

Permalink
Merge branch 'delay-close'
Browse files Browse the repository at this point in the history
  • Loading branch information
mash committed Apr 11, 2014
2 parents 9fa03a5 + 1ef3028 commit 1a6210c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions firmware/src/IRKit/IRKit.ino
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ void process_commands() {
case COMMAND_START_POLLING:
irkit_httpclient_start_polling( 0 );
break;
case COMMAND_POST_DOOR:
irkit_httpclient_post_door();
break;
default:
break;
}
Expand Down
21 changes: 12 additions & 9 deletions firmware/src/IRKit/IRKitHTTPHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern struct RingBuffer commands;
extern void on_ir_xmit();
extern void on_irkit_ready();
extern void wifi_hardware_reset();
extern void software_reset();
extern volatile char sharedbuffer[];

// if we have recently received GET or POST /messages request,
Expand Down Expand Up @@ -118,20 +119,20 @@ static int8_t on_post_door_response(int8_t cid, uint16_t status_code, GSwifi::GS
break;
case 401:
case HTTP_STATUSCODE_CLIENT_TIMEOUT:
// keys have expired, we have to start from morse sequence again
ring_put( &commands, COMMAND_CLOSE );
ring_put( &commands, cid );
// keys have expired, we have to start listening for POST /wifi again
keys.clear();
keys.save();
software_reset();

break;
case 400: // must be program bug, happens when there's no hostname parameter
case 408:
case 503: // heroku responds with 503 if longer than 30sec
default:
// try again
// TODO send this to next loop
gs.close(cid);
irkit_httpclient_post_door();
// retry again on next loop
ring_put( &commands, COMMAND_CLOSE );
ring_put( &commands, cid );
ring_put( &commands, COMMAND_POST_DOOR );
break;
}

Expand Down Expand Up @@ -172,7 +173,8 @@ static int8_t on_get_messages_response(int8_t cid, uint16_t status_code, GSwifi:
break;
case HTTP_STATUSCODE_CLIENT_TIMEOUT:
polling_cid = CID_UNDEFINED;
gs.close(cid);
ring_put( &commands, COMMAND_CLOSE );
ring_put( &commands, cid );
irkit_httpclient_start_polling( 5 );
break;
case HTTP_STATUSCODE_DISCONNECT:
Expand All @@ -184,7 +186,8 @@ static int8_t on_get_messages_response(int8_t cid, uint16_t status_code, GSwifi:
case 503:
default:
if (state == GSwifi::GSREQUESTSTATE_RECEIVED) {
gs.close(cid);
ring_put( &commands, COMMAND_CLOSE );
ring_put( &commands, cid );
irkit_httpclient_start_polling( 5 );
}
break;
Expand Down
1 change: 1 addition & 0 deletions firmware/src/IRKit/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define COMMAND_CONNECT 3
#define COMMAND_CLOSE 4
#define COMMAND_START_POLLING 5
#define COMMAND_POST_DOOR 6

#define COMMAND_QUEUE_SIZE 8

Expand Down

0 comments on commit 1a6210c

Please sign in to comment.