45
45
#define HOMEKIT_SOCKET_KEEPALIVE_INTERVAL_SEC 30
46
46
// const int maxpkt = 4; /* Drop connection after 4 probes without response */
47
47
#define HOMEKIT_SOCKET_KEEPALIVE_IDLE_COUNT 4
48
- // if 180 + 30 * 4 = 300 sec without socket response, disconected it.
48
+ // if 180 + 30 * 4 = 300 sec without socket response, disconnected it.
49
49
50
50
// WiFiClient can not write big buff once.
51
51
// TCP_SND_BUF = (2 * TCP_MSS) = 1072. See lwipopts.h
@@ -118,10 +118,10 @@ void server_free(homekit_server_t *server) {
118
118
}
119
119
120
120
void tlv_debug (const tlv_values_t *values) {
121
- DEBUG (" Got following TLV values:" );
121
+ printf (" Got following TLV values:\n " );
122
122
for (tlv_t *t = values->head ; t; t = t->next ) {
123
123
char *escaped_payload = binary_to_string (t->value , t->size );
124
- DEBUG ( " Type %d value (%d bytes): %s" , t->type , t->size , escaped_payload);
124
+ printf ( " \t Type %d value (%d bytes): %s\n " , t->type , t->size , escaped_payload);
125
125
free (escaped_payload);
126
126
}
127
127
}
@@ -562,7 +562,7 @@ int client_send_encrypted_(client_context_t *context,
562
562
memset (nonce, 0 , sizeof (nonce));
563
563
564
564
byte encrypted[1024 + 18 ];
565
- int payload_offset = 0 ;
565
+ uint payload_offset = 0 ;
566
566
567
567
while (payload_offset < size) {
568
568
size_t chunk_size = size - payload_offset;
@@ -1879,7 +1879,7 @@ void homekit_server_on_get_characteristics(client_context_t *context) {
1879
1879
1880
1880
query_param_t *qp = context->endpoint_params ;
1881
1881
while (qp) {
1882
- CLIENT_DEBUG (context, " Query paramter %s = %s" , qp->name , qp->value );
1882
+ CLIENT_DEBUG (context, " Query parameter %s = %s" , qp->name , qp->value );
1883
1883
qp = qp->next ;
1884
1884
}
1885
1885
@@ -2629,6 +2629,7 @@ void homekit_server_on_pairings(client_context_t *context, const byte *data, siz
2629
2629
INFO (" Last admin pairing was removed, enabling pair setup" );
2630
2630
context->server ->paired = false ;
2631
2631
// homekit_setup_mdns(context->server);
2632
+ homekit_storage_reset_pairing_data ();
2632
2633
}
2633
2634
}
2634
2635
}
@@ -2760,7 +2761,7 @@ int homekit_server_on_url(http_parser *parser, const char *data, size_t length)
2760
2761
}
2761
2762
2762
2763
int homekit_server_on_body (http_parser *parser, const char *data, size_t length) {
2763
- DEBUG (" http_parser lenght =%d" , length);
2764
+ DEBUG (" http_parser length =%d" , length);
2764
2765
client_context_t *context = (client_context_t *) parser->data ;
2765
2766
context->body = (char *) realloc (context->body , context->body_length + length + 1 );
2766
2767
memcpy (context->body + context->body_length , data, length);
@@ -2888,7 +2889,7 @@ void homekit_client_process(client_context_t *context) {
2888
2889
}
2889
2890
return ;
2890
2891
}
2891
- CLIENT_DEBUG (context, " Got %d incomming data, encrypted is %s" ,
2892
+ CLIENT_DEBUG (context, " Got %d incoming data, encrypted is %s" ,
2892
2893
data_len, context->encrypted ? " true" : " false" );
2893
2894
byte *payload = (byte*) context->data ;
2894
2895
size_t payload_size = (size_t ) data_len;
@@ -2942,7 +2943,7 @@ void homekit_server_close_client(homekit_server_t *server, client_context_t *con
2942
2943
2943
2944
if (context->socket ) {
2944
2945
context->socket ->stop ();
2945
- CLIENT_DEBUG (context, " The sockect is stopped" );
2946
+ CLIENT_DEBUG (context, " The socket is stopped" );
2946
2947
delete context->socket ;
2947
2948
context->socket = nullptr ;
2948
2949
}
@@ -2979,7 +2980,7 @@ client_context_t* homekit_server_accept_client(homekit_server_t *server) {
2979
2980
WiFiClient *wifiClient = nullptr ;
2980
2981
2981
2982
if (server->wifi_server ->hasClient ()) {
2982
- wifiClient = new WiFiClient (server->wifi_server ->available ());
2983
+ wifiClient = new WiFiClient (server->wifi_server ->accept ());
2983
2984
if (server->nfds >= HOMEKIT_MAX_CLIENTS) {
2984
2985
INFO (" No more room for client connections (max %d)" , HOMEKIT_MAX_CLIENTS);
2985
2986
wifiClient->stop ();
@@ -2990,7 +2991,8 @@ client_context_t* homekit_server_accept_client(homekit_server_t *server) {
2990
2991
return NULL ;
2991
2992
}
2992
2993
2993
- INFO (" Got new client: local %s:%d, remote %s:%d" ,
2994
+ INFO (" Got new client %d: local %s:%d, remote %s:%d" ,
2995
+ wifiClient,
2994
2996
wifiClient->localIP ().toString ().c_str (), wifiClient->localPort (),
2995
2997
wifiClient->remoteIP ().toString ().c_str (), wifiClient->remotePort ());
2996
2998
@@ -3018,7 +3020,7 @@ client_context_t* homekit_server_accept_client(homekit_server_t *server) {
3018
3020
void homekit_server_process_notifications (homekit_server_t *server) {
3019
3021
client_context_t *context = server->clients ;
3020
3022
// 把characteristic_event_t拼接成client_event_t链表
3021
- // 按照Apple的规定,Nofiy消息需合并发送
3023
+ // 按照Apple的规定,Notify消息需合并发送
3022
3024
while (context) {
3023
3025
if (context->step != HOMEKIT_CLIENT_STEP_PAIR_VERIFY_2OF2) {
3024
3026
// Do not send event when the client is not verify over.
@@ -3114,7 +3116,7 @@ void homekit_server_process(homekit_server_t *server) {
3114
3116
}
3115
3117
3116
3118
// =====================================================
3117
- // Arduino ESP8266 MDNS: call this funciton only once when WiFi STA is connected!
3119
+ // Arduino ESP8266 MDNS: call this function only once when WiFi STA is connected!
3118
3120
// =====================================================
3119
3121
bool homekit_mdns_started = false ;
3120
3122
@@ -3145,7 +3147,7 @@ void homekit_mdns_init(homekit_server_t *server) {
3145
3147
ERROR (" Invalid accessory declaration: " " no Name characteristic in AccessoryInfo service" );
3146
3148
return ;
3147
3149
}
3148
-
3150
+
3149
3151
homekit_characteristic_t *model = homekit_service_characteristic_by_type (accessory_info,
3150
3152
HOMEKIT_CHARACTERISTIC_MODEL);
3151
3153
@@ -3215,7 +3217,6 @@ void homekit_mdns_init(homekit_server_t *server) {
3215
3217
3216
3218
unsigned char encodedHash[9 ];
3217
3219
memset (encodedHash, 0 , sizeof (encodedHash));
3218
- word32 len = sizeof (encodedHash);
3219
3220
base64_encode_ ((const unsigned char *) shaHash, 4 , encodedHash);
3220
3221
MDNS.addServiceTxt (mdns_service, " sh" , (char *) encodedHash);
3221
3222
}
@@ -3317,7 +3318,7 @@ void homekit_server_init(homekit_server_config_t *config) {
3317
3318
// homekit_server_task(server);
3318
3319
INFO (" Starting server" );
3319
3320
3320
- if (homekit_storage_init () != 0 ||
3321
+ if (homekit_storage_init (false ) != 0 ||
3321
3322
homekit_storage_load_accessory_id (server->accessory_id ) != 0 ||
3322
3323
homekit_storage_load_accessory_key (&server->accessory_key ) != 0 ) {
3323
3324
@@ -3399,11 +3400,11 @@ int homekit_get_setup_uri(const homekit_server_config_t *config, char *buffer, s
3399
3400
3400
3401
if (!config->password )
3401
3402
return -1 ;
3402
- // TODO: validate password in case it is run beffore server is started
3403
+ // TODO: validate password in case it is run before server is started
3403
3404
3404
3405
if (!config->setupId )
3405
3406
return -1 ;
3406
- // TODO: validate setupID in case it is run beffore server is started
3407
+ // TODO: validate setupID in case it is run before server is started
3407
3408
3408
3409
homekit_accessory_t *accessory = homekit_accessory_by_id (config->accessories , 1 );
3409
3410
if (!accessory)
@@ -3445,8 +3446,8 @@ int homekit_get_setup_uri(const homekit_server_config_t *config, char *buffer, s
3445
3446
return 0 ;
3446
3447
}
3447
3448
3448
- // Pre-initialize the pairing_context used in Pair-Setep 1/3
3449
- // For avoiding timeout caused sockect disconnection from iOS device.
3449
+ // Pre-initialize the pairing_context used in Pair-Setup 1/3
3450
+ // For avoiding timeout caused socket disconnection from iOS device.
3450
3451
bool arduino_homekit_preinit (homekit_server_t *server) {
3451
3452
if (saved_preinit_pairing_context != nullptr ) {
3452
3453
return true ;
0 commit comments