4545#define HOMEKIT_SOCKET_KEEPALIVE_INTERVAL_SEC 30
4646// const int maxpkt = 4; /* Drop connection after 4 probes without response */
4747#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.
4949
5050// WiFiClient can not write big buff once.
5151// TCP_SND_BUF = (2 * TCP_MSS) = 1072. See lwipopts.h
@@ -562,7 +562,7 @@ int client_send_encrypted_(client_context_t *context,
562562 memset (nonce, 0 , sizeof (nonce));
563563
564564 byte encrypted[1024 + 18 ];
565- int payload_offset = 0 ;
565+ uint payload_offset = 0 ;
566566
567567 while (payload_offset < size) {
568568 size_t chunk_size = size - payload_offset;
@@ -1879,7 +1879,7 @@ void homekit_server_on_get_characteristics(client_context_t *context) {
18791879
18801880 query_param_t *qp = context->endpoint_params ;
18811881 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 );
18831883 qp = qp->next ;
18841884 }
18851885
@@ -2629,6 +2629,7 @@ void homekit_server_on_pairings(client_context_t *context, const byte *data, siz
26292629 INFO (" Last admin pairing was removed, enabling pair setup" );
26302630 context->server ->paired = false ;
26312631 // homekit_setup_mdns(context->server);
2632+ homekit_storage_reset_pairing_data ();
26322633 }
26332634 }
26342635 }
@@ -2763,7 +2764,7 @@ int homekit_server_on_url(http_parser *parser, const char *data, size_t length)
27632764}
27642765
27652766int 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);
27672768 client_context_t *context = (client_context_t *) parser->data ;
27682769 context->body = (char *) realloc (context->body , context->body_length + length + 1 );
27692770 memcpy (context->body + context->body_length , data, length);
@@ -2891,7 +2892,7 @@ void homekit_client_process(client_context_t *context) {
28912892 }
28922893 return ;
28932894 }
2894- CLIENT_DEBUG (context, " Got %d incomming data, encrypted is %s" ,
2895+ CLIENT_DEBUG (context, " Got %d incoming data, encrypted is %s" ,
28952896 data_len, context->encrypted ? " true" : " false" );
28962897 byte *payload = (byte*) context->data ;
28972898 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
29452946
29462947 if (context->socket ) {
29472948 context->socket ->stop ();
2948- CLIENT_DEBUG (context, " The sockect is stopped" );
2949+ CLIENT_DEBUG (context, " The socket is stopped" );
29492950 delete context->socket ;
29502951 context->socket = nullptr ;
29512952 }
@@ -3021,7 +3022,7 @@ client_context_t* homekit_server_accept_client(homekit_server_t *server) {
30213022void homekit_server_process_notifications (homekit_server_t *server) {
30223023 client_context_t *context = server->clients ;
30233024 // 把characteristic_event_t拼接成client_event_t链表
3024- // 按照Apple的规定,Nofiy消息需合并发送
3025+ // 按照Apple的规定,Notify消息需合并发送
30253026 while (context) {
30263027 if (context->step != HOMEKIT_CLIENT_STEP_PAIR_VERIFY_2OF2) {
30273028 // Do not send event when the client is not verify over.
@@ -3117,7 +3118,7 @@ void homekit_server_process(homekit_server_t *server) {
31173118}
31183119
31193120// =====================================================
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!
31213122// =====================================================
31223123bool homekit_mdns_started = false ;
31233124
@@ -3134,22 +3135,19 @@ void homekit_mdns_init(homekit_server_t *server) {
31343135 }
31353136
31363137 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);
31393139 if (!accessory_info) {
31403140 ERROR (" Invalid accessory declaration: no Accessory Information service" );
31413141 return ;
31423142 }
31433143
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);
31463145 if (!name) {
31473146 ERROR (" Invalid accessory declaration: " " no Name characteristic in AccessoryInfo service" );
31483147 return ;
31493148 }
31503149
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);
31533151 if (!model) {
31543152 ERROR (" Invalid accessory declaration: " " no Model characteristic in AccessoryInfo service" );
31553153 return ;
@@ -3169,8 +3167,7 @@ void homekit_mdns_init(homekit_server_t *server) {
31693167 MDNS.begin (name->value .string_value , staIP);
31703168 INFO (" MDNS begin: %s, IP: %s" , name->value .string_value , staIP.toString ().c_str ());
31713169
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);
31743171 // Set a service specific callback for dynamic service TXT items.
31753172 // The callback is called, whenever service TXT items are needed for the given service.
31763173 MDNS.setDynamicServiceTxtCallback (mdns_service,
@@ -3241,7 +3238,7 @@ void homekit_mdns_init(homekit_server_t *server) {
32413238
32423239 unsigned char encodedHash[9 ];
32433240 memset (encodedHash, 0 , sizeof (encodedHash));
3244- word32 len = sizeof (encodedHash);
3241+ // word32 len = sizeof(encodedHash);
32453242 base64_encode_ ((const unsigned char *) shaHash, 4 , encodedHash);
32463243 MDNS.addServiceTxt (mdns_service, " sh" , (char *) encodedHash);
32473244 }
@@ -3345,20 +3342,10 @@ void homekit_server_init(homekit_server_config_t *config) {
33453342 // homekit_server_task(server);
33463343 INFO (" Starting server" );
33473344
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+ ) {
33623349 homekit_accessory_id_generate (server->accessory_id );
33633350 homekit_storage_save_accessory_id (server->accessory_id );
33643351
@@ -3437,11 +3424,11 @@ int homekit_get_setup_uri(const homekit_server_config_t *config, char *buffer, s
34373424
34383425 if (!config->password )
34393426 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
34413428
34423429 if (!config->setupId )
34433430 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
34453432
34463433 homekit_accessory_t *accessory = homekit_accessory_by_id (config->accessories , 1 );
34473434 if (!accessory)
@@ -3483,8 +3470,8 @@ int homekit_get_setup_uri(const homekit_server_config_t *config, char *buffer, s
34833470 return 0 ;
34843471}
34853472
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.
34883475bool arduino_homekit_preinit (homekit_server_t *server) {
34893476 if (saved_preinit_pairing_context != nullptr ) {
34903477 return true ;
0 commit comments