Comments (8)
I will look into implementing this
from esp-homekit.
Hey, did you find any way to solve this issue? I kind of came across the same. :)
from esp-homekit.
Nope
from esp-homekit.
I made a few changes to the server.c file and now there is a function which returns the status of pair. Please note that my experience with C and homekit is minimum so I'm not sure if the following changes are acceptable in principal or not. If anyone has any suggestion on the proposed changes, please make it. It will be very welcome.
Here is what I did in the server.c:
//declare a local variable that will hold pair status.
static bool _ispaired = false;
then, within "homekit_server_task" function find the following code and add the marked line:
if (pairing) {
INFO("Found admin pairing with %s, disabling pair setup", pairing->device_id);
_ispaired = true; // <-- Add this line
pairing_free(pairing);
server->paired = true;
} else { //<-- Add this line
_ispaired = false; //<-- Add this line
}
Then add the following function and you should be good to go.
bool homekit_is_paired()
{
return _ispaired;
}
You can call "homekit_is_paired()" from anywhere in your code and it will return the status of pair.
I don't know how to make a PR. If the above changes are acceptable, then give it a try.
from esp-homekit.
Here is a more concrete implementation of the changes required to get pairing status;
All the below changes should be applied to server.c
- Definition of a local variable holding the pairing status
//declare a local variable that will hold pair status.
static bool _ispaired = false;
- Make changes in code so that local variable _ispaired is in sync with pairing status:
void homekit_server_on_pair_setup(client_context_t *context, const byte *data, size_t size) {
//....other code....
tlv_values_t *response = tlv_new();
tlv_add_integer_value(response, TLVType_State, 1, 6);
tlv_add_value(response, TLVType_EncryptedData,
encrypted_response_data, encrypted_response_data_size);
free(encrypted_response_data);
send_tlv_response(context, response);
pairing_context_free(context->server->pairing_context);
context->server->pairing_context = NULL;
context->server->paired = 1;
homekit_setup_mdns(context->server);
_ispaired = true; //--------> Add this line
CLIENT_INFO(context, "Successfully paired");
break;
}
default: {
CLIENT_ERROR(context, "Unknown state: %d",
tlv_get_integer_value(message, TLVType_State, -1));
}
}
also here:
void homekit_server_on_pair_verify(client_context_t *context, const byte *data, size_t size) {
//....other code....
if (!pairing) {
CLIENT_ERROR(context, "No pairing for %s found", device_id);
_ispaired = false; //--------> Add this line
free(device_id);
tlv_free(decrypted_message);
pair_verify_context_free(context->verify_context);
context->verify_context = NULL;
send_tlv_error_response(context, 4, TLVError_Authentication);
break;
}
_ispaired = true; //--------> Add this line
CLIENT_INFO(context, "Found pairing with %s", device_id);
free(device_id);
//....other code....
}
also here:
void homekit_server_on_pairings(client_context_t *context, const byte *data, size_t size) {
homekit_storage_pairing_iterator_free(pairing_it);
if (!pairing) {
// No admins left, enable pairing again
_ispaired = false; //--------> Add this line
INFO("Last admin pairing was removed, resetting accessory");
homekit_server_on_reset(context);
/*
INFO("Last admin pairing was removed, enabling pair setup");
context->server->paired = false;
homekit_setup_mdns(context->server);
*/
} else {
pairing_free(pairing);
}
}
here:
void homekit_server_task(void *args) {
if (pairing) {
_ispaired = true; //--------> Add this line
INFO("Found admin pairing with %s, disabling pair setup", pairing->device_id);
pairing_free(pairing);
server->paired = true;
}else{ //--------> Add this line
_ispaired = false; //--------> Add this line
}
}
- Finally, implement function homekit_is_paired() which will return status of pairing :
bool homekit_is_paired()
{
return _ispaired;
}
@maximkulkin Do you think the above code changes are possible to be implemented from your side?
Many Thanks,
from esp-homekit.
Thank you! Looking forward to read your code and see your approach :)
from esp-homekit.
For now you can implement this in your own init code, just use startup code from homekit_server_init
to access server
structure
from esp-homekit.
I have added support for tracking some homekit internal state through events. Check out led_status example.
from esp-homekit.
Related Issues (20)
- Read HC-SR501- infrared detector module HOT 6
- Cannot find device after removing it. HOT 1
- QUESTION : Dynamic "name" after init_accessory - without esp restart HOT 3
- Server limited to 25 characteristics HOT 4
- How to use ESP8266 as AccessPoint
- 'Hidden' Flag Doesn't Work?
- Separate Accessories - Causes Intermittent 'No Response' HOT 6
- Performance on iOS 16 beta HOT 1
- HOMEKIT_SERVICE_DOORBELL not found
- Can this be used as a proxy for the Level Lock? HOT 1
- Request pairing on demand by variable HOT 3
- Failed to dump SPR public key (code -199) HOT 3
- How to install in ESPhome running on Home Assistant HOT 1
- HOMEKIT_SERVICE_HUMIDIFIER_DEHUMIDIFIER
- wifi:bcn_timeout,ap_probe_send_start HOT 2
- Question: arduino as esp-idf component HOT 1
- Question: esp-idf v5.0
- Reason using PORT 5556 HOT 3
- ESP8266 not reachable after MDNS restart HOT 7
- ESP8266 Accessory No Response HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp-homekit.