Giter VIP home page Giter VIP logo

Comments (8)

maximkulkin avatar maximkulkin commented on August 16, 2024 1

I will look into implementing this

from esp-homekit.

peros550 avatar peros550 commented on August 16, 2024

Hey, did you find any way to solve this issue? I kind of came across the same. :)

from esp-homekit.

ruudk avatar ruudk commented on August 16, 2024

Nope

from esp-homekit.

peros550 avatar peros550 commented on August 16, 2024

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.

peros550 avatar peros550 commented on August 16, 2024

Here is a more concrete implementation of the changes required to get pairing status;

All the below changes should be applied to server.c

  1. Definition of a local variable holding the pairing status
//declare a local variable that will hold pair status. 
static bool _ispaired = false;

  1. 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
    }
}
  1. 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.

peros550 avatar peros550 commented on August 16, 2024

Thank you! Looking forward to read your code and see your approach :)

from esp-homekit.

Roman1us avatar Roman1us commented on August 16, 2024

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.

maximkulkin avatar maximkulkin commented on August 16, 2024

I have added support for tracking some homekit internal state through events. Check out led_status example.

from esp-homekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.