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
@@ -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
}
@@ -2763,7 +2764,7 @@ int homekit_server_on_url(http_parser *parser, const char *data, size_t length)
2763
2764
}
2764
2765
2765
2766
int homekit_server_on_body (http_parser *parser, const char *data, size_t length) {
2766
- DEBUG (" http_parser lenght =%d" , length);
2767
+ DEBUG (" http_parser length =%d" , length);
2767
2768
client_context_t *context = (client_context_t *) parser->data ;
2768
2769
context->body = (char *) realloc (context->body , context->body_length + length + 1 );
2769
2770
memcpy (context->body + context->body_length , data, length);
@@ -2891,7 +2892,7 @@ void homekit_client_process(client_context_t *context) {
2891
2892
}
2892
2893
return ;
2893
2894
}
2894
- CLIENT_DEBUG (context, " Got %d incomming data, encrypted is %s" ,
2895
+ CLIENT_DEBUG (context, " Got %d incoming data, encrypted is %s" ,
2895
2896
data_len, context->encrypted ? " true" : " false" );
2896
2897
byte *payload = (byte*) context->data ;
2897
2898
size_t payload_size = (size_t ) data_len;
@@ -2945,7 +2946,7 @@ void homekit_server_close_client(homekit_server_t *server, client_context_t *con
2945
2946
2946
2947
if (context->socket ) {
2947
2948
context->socket ->stop ();
2948
- CLIENT_DEBUG (context, " The sockect is stopped" );
2949
+ CLIENT_DEBUG (context, " The socket is stopped" );
2949
2950
delete context->socket ;
2950
2951
context->socket = nullptr ;
2951
2952
}
@@ -3021,7 +3022,7 @@ client_context_t* homekit_server_accept_client(homekit_server_t *server) {
3021
3022
void homekit_server_process_notifications (homekit_server_t *server) {
3022
3023
client_context_t *context = server->clients ;
3023
3024
// 把characteristic_event_t拼接成client_event_t链表
3024
- // 按照Apple的规定,Nofiy消息需合并发送
3025
+ // 按照Apple的规定,Notify消息需合并发送
3025
3026
while (context) {
3026
3027
if (context->step != HOMEKIT_CLIENT_STEP_PAIR_VERIFY_2OF2) {
3027
3028
// Do not send event when the client is not verify over.
@@ -3117,7 +3118,7 @@ void homekit_server_process(homekit_server_t *server) {
3117
3118
}
3118
3119
3119
3120
// =====================================================
3120
- // Arduino ESP8266 MDNS: call this funciton only once when WiFi STA is connected!
3121
+ // Arduino ESP8266 MDNS: call this function only once when WiFi STA is connected!
3121
3122
// =====================================================
3122
3123
bool homekit_mdns_started = false ;
3123
3124
@@ -3134,22 +3135,19 @@ void homekit_mdns_init(homekit_server_t *server) {
3134
3135
}
3135
3136
3136
3137
homekit_accessory_t *accessory = server->config ->accessories [0 ];
3137
- homekit_service_t *accessory_info = homekit_service_by_type (accessory,
3138
- HOMEKIT_SERVICE_ACCESSORY_INFORMATION);
3138
+ homekit_service_t *accessory_info = homekit_service_by_type (accessory, HOMEKIT_SERVICE_ACCESSORY_INFORMATION);
3139
3139
if (!accessory_info) {
3140
3140
ERROR (" Invalid accessory declaration: no Accessory Information service" );
3141
3141
return ;
3142
3142
}
3143
3143
3144
- homekit_characteristic_t *name = homekit_service_characteristic_by_type (accessory_info,
3145
- HOMEKIT_CHARACTERISTIC_NAME);
3144
+ homekit_characteristic_t *name = homekit_service_characteristic_by_type (accessory_info, HOMEKIT_CHARACTERISTIC_NAME);
3146
3145
if (!name) {
3147
3146
ERROR (" Invalid accessory declaration: " " no Name characteristic in AccessoryInfo service" );
3148
3147
return ;
3149
3148
}
3150
3149
3151
- homekit_characteristic_t *model = homekit_service_characteristic_by_type (accessory_info,
3152
- HOMEKIT_CHARACTERISTIC_MODEL);
3150
+ homekit_characteristic_t *model = homekit_service_characteristic_by_type (accessory_info, HOMEKIT_CHARACTERISTIC_MODEL);
3153
3151
if (!model) {
3154
3152
ERROR (" Invalid accessory declaration: " " no Model characteristic in AccessoryInfo service" );
3155
3153
return ;
@@ -3169,8 +3167,7 @@ void homekit_mdns_init(homekit_server_t *server) {
3169
3167
MDNS.begin (name->value .string_value , staIP);
3170
3168
INFO (" MDNS begin: %s, IP: %s" , name->value .string_value , staIP.toString ().c_str ());
3171
3169
3172
- MDNSResponder::hMDNSService mdns_service = MDNS.addService (name->value .string_value ,
3173
- HOMEKIT_MDNS_SERVICE, HOMEKIT_MDNS_PROTO, HOMEKIT_SERVER_PORT);
3170
+ MDNSResponder::hMDNSService mdns_service = MDNS.addService (name->value .string_value , HOMEKIT_MDNS_SERVICE, HOMEKIT_MDNS_PROTO, HOMEKIT_SERVER_PORT);
3174
3171
// Set a service specific callback for dynamic service TXT items.
3175
3172
// The callback is called, whenever service TXT items are needed for the given service.
3176
3173
MDNS.setDynamicServiceTxtCallback (mdns_service,
@@ -3241,7 +3238,7 @@ void homekit_mdns_init(homekit_server_t *server) {
3241
3238
3242
3239
unsigned char encodedHash[9 ];
3243
3240
memset (encodedHash, 0 , sizeof (encodedHash));
3244
- word32 len = sizeof (encodedHash);
3241
+ // word32 len = sizeof(encodedHash);
3245
3242
base64_encode_ ((const unsigned char *) shaHash, 4 , encodedHash);
3246
3243
MDNS.addServiceTxt (mdns_service, " sh" , (char *) encodedHash);
3247
3244
}
@@ -3345,20 +3342,10 @@ void homekit_server_init(homekit_server_config_t *config) {
3345
3342
// homekit_server_task(server);
3346
3343
INFO (" Starting server" );
3347
3344
3348
- int r = homekit_storage_init ();
3349
- if (r == 0 ) {
3350
- r = homekit_storage_load_accessory_id (server->accessory_id );
3351
-
3352
- if (!r)
3353
- r = homekit_storage_load_accessory_key (&server->accessory_key );
3354
- }
3355
-
3356
- if (r) {
3357
- if (r < 0 ) {
3358
- INFO (" Resetting HomeKit storage" );
3359
- homekit_storage_reset ();
3360
- }
3361
-
3345
+ if (homekit_storage_init (false ) != 0 ||
3346
+ homekit_storage_load_accessory_id (server->accessory_id ) != 0 ||
3347
+ homekit_storage_load_accessory_key (&server->accessory_key ) != 0
3348
+ ) {
3362
3349
homekit_accessory_id_generate (server->accessory_id );
3363
3350
homekit_storage_save_accessory_id (server->accessory_id );
3364
3351
@@ -3437,11 +3424,11 @@ int homekit_get_setup_uri(const homekit_server_config_t *config, char *buffer, s
3437
3424
3438
3425
if (!config->password )
3439
3426
return -1 ;
3440
- // TODO: validate password in case it is run beffore server is started
3427
+ // TODO: validate password in case it is run before server is started
3441
3428
3442
3429
if (!config->setupId )
3443
3430
return -1 ;
3444
- // TODO: validate setupID in case it is run beffore server is started
3431
+ // TODO: validate setupID in case it is run before server is started
3445
3432
3446
3433
homekit_accessory_t *accessory = homekit_accessory_by_id (config->accessories , 1 );
3447
3434
if (!accessory)
@@ -3483,8 +3470,8 @@ int homekit_get_setup_uri(const homekit_server_config_t *config, char *buffer, s
3483
3470
return 0 ;
3484
3471
}
3485
3472
3486
- // Pre-initialize the pairing_context used in Pair-Setep 1/3
3487
- // For avoiding timeout caused sockect disconnection from iOS device.
3473
+ // Pre-initialize the pairing_context used in Pair-Setup 1/3
3474
+ // For avoiding timeout caused socket disconnection from iOS device.
3488
3475
bool arduino_homekit_preinit (homekit_server_t *server) {
3489
3476
if (saved_preinit_pairing_context != nullptr ) {
3490
3477
return true ;
0 commit comments