etwmc / Personal-HomeKit-HAP

This project will provide source code to build a HomeKit support accessories.
MIT License
236 stars 85 forks source link

Is this HomeKit-HAP not support for IOS10.3.3 ? #73

Open jabenwang opened 6 years ago

jabenwang commented 6 years ago

Hi @etwmc , I use your Personal-HomeKit-HAP to write a demo running on my openwrt , it works sucessfully! And I added two accessory, lightbule and a switch , which can be dicoveried by Apple homekit on my phone, but they all show as Not supported and needs to update by using the manufacturer's app. I have no idea why this show.

etwmc commented 6 years ago

Can you send me the code? Its hard to debug I have it running at my house, and I haven’t heard any complaint on unsupport yet, and I’m using the code to handle IP can setup right now, so I think it should be still compatible with iOS 10.3.3

Sent from my iPhone

On Oct 31, 2017, at 12:11 AM, jabenwang notifications@github.com wrote:

Hi @etwmc , I use your Personal-HomeKit-HAP to write a demo running on my openwrt , it works sucessfully! And I added two accessory, lightbule and a switch , which can be dicoveried by Apple homekit on my phone, but they all show as Not supported and needs to update by using the manufacturer's app. I have no idea why this show.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

jabenwang commented 6 years ago

Ok, this my accessory.cpp code , I also sent you an e-mail, please have a check,many thanks~

`/*

include "Accessory.h"

include "PHKAccessory.h"

include "PHKNetworkIP.h"

include

include

using namespace std;

pthread_mutex_t recordMutex;

set trackingUserList; set <connectionInfo*> activeUsers;

intCharacteristics *occupyState;

define userListAddr "./userList"

void _newConnection(connectionInfo* info) { printf("New connection %s\n", info->hostname.c_str()); pthread_mutex_lock(&recordMutex);

bool originalOutput = activeUsers.size() > 0;
if ( trackingUserList.count(info->hostname) > 0 )
    activeUsers.insert(info);

bool laterOutput = activeUsers.size() > 0;

pthread_mutex_unlock(&recordMutex);
if (originalOutput != laterOutput) {
    //Should notify
    printf("Changed\n");
    occupyState->notify();
}

}

void _deadConnection(connectionInfo *info) { pthread_mutex_lock(&recordMutex);

bool originalOutput = activeUsers.size() > 0;
activeUsers.erase(info);

bool laterOutput = activeUsers.size() > 0;

pthread_mutex_unlock(&recordMutex);
if (originalOutput != laterOutput) {
    //Should notify
    printf("Changed\n");
    occupyState->notify();
}

}

void loadUserList() { ifstream fs; fs.open(userListAddr, std::ifstream::in); char buffer[256]; bool isEmpty = fs.peek() == EOF; while (!isEmpty&&fs.is_open()&&fs.good()&&!fs.eof()) { fs.getline(buffer, 256); string s = string(buffer); trackingUserList.insert(s); } fs.close(); }

void saveUserList() { ofstream fs; fs.open(userListAddr, std::ifstream::out); for (set::iterator it = trackingUserList.begin(); it != trackingUserList.end(); it++) { fs << *it << "\n"; } fs.close(); }

string trackable(connectionInfo *sender) { pthread_mutex_lock(&recordMutex); string result = trackingUserList.count(sender->hostname) > 0? "1": "0"; pthread_mutex_unlock(&recordMutex); return result; }

string calculateOccupy(connectionInfo *sender) { pthread_mutex_lock(&recordMutex); string result = activeUsers.size() > 0? "1": "0"; pthread_mutex_unlock(&recordMutex); return result; }

void switchTrackable(bool oldValue, bool newValue, connectionInfo *sender) { if (newValue) { //Track this device trackingUserList.insert(sender->hostname); saveUserList(); //Update active list _newConnection(sender); } else { //Stop tracking trackingUserList.erase(sender->hostname); saveUserList(); //Update active list _deadConnection(sender); } }

void identity(bool oldValue, bool newValue, connectionInfo *sender) { printf("Identify\n"); }

void lightIdentify(bool oldValue, bool newValue,connectionInfo *sender) { printf("Start Identify Light\n"); }

AccessorySet *accSet;

void AddOccupySensor(){ Accessory *sensorAcc = new Accessory(); addInfoServiceToAccessory(sensorAcc, "Occupy Sensor", "ET", "Occupy Sensor v1", "12345678", &identity); accSet->addAccessory(sensorAcc);

Service *sensorService = new Service(serviceType_occupancySensor);
sensorAcc->addService(sensorService);

boolCharacteristics *trackableState = new boolCharacteristics(0x10000, premission_read|premission_write);
trackableState->characteristics::setValue("false");
trackableState->perUserQuery = &trackable;
trackableState->valueChangeFunctionCall = &switchTrackable;
sensorAcc->addCharacteristics(sensorService, trackableState);

occupyState = new intCharacteristics(charType_occupancyDetected, premission_read|premission_notify, 0, 1, 1, unit_none);
occupyState->characteristics::setValue("0");
occupyState->perUserQuery = &calculateOccupy;
sensorAcc->addCharacteristics(sensorService, occupyState);

}

void AddLight(){

Accessory *lightAcc = new Accessory();
addInfoServiceToAccessory(lightAcc, "Light 1", "ET", "Light v1", "12345678", &lightIdentify);
accSet->addAccessory(lightAcc);

Service *lightService = new Service(serviceType_lightBulb);
lightAcc->addService(lightService);

boolCharacteristics *powerState = new boolCharacteristics(charType_on, premission_read|premission_write);
powerState->characteristics::setValue("true");
lightAcc->addCharacteristics(lightService, powerState);

intCharacteristics *brightnessState = new intCharacteristics(charType_brightness, premission_read|premission_write, 0, 100, 1, unit_percentage);
brightnessState->characteristics::setValue("50");
lightAcc->addCharacteristics(lightService, brightnessState);

}

void AddSwitch(){

Accessory *switchAcc = new Accessory();
addInfoServiceToAccessory(switchAcc, "Switch 1", "ET", "Switch v1", "12345678", &lightIdentify);
accSet->addAccessory(switchAcc);

Service *switchService = new Service(serviceType_switch);
switchAcc->addService(switchService);

boolCharacteristics *powerState = new boolCharacteristics(charType_on, premission_read|premission_write);
powerState->characteristics::setValue("true");
switchAcc->addCharacteristics(switchService, powerState);

}

void initAccessorySet() {

newConnection = &_newConnection;
deadConnection = &_deadConnection;

loadUserList();

pthread_mutex_init(&recordMutex, NULL);

currentDeviceType = deviceType_bridge;

printf("Initial Accessory\n");
accSet = &AccessorySet::getInstance();

Accessory *bridge = new Accessory();
addInfoServiceToAccessory(bridge, "NDBJ", "ET", "Bridge", "12345678", &identity);
accSet->addAccessory(bridge);

AddLight();
AddOccupySensor();
AddSwitch();

};

`

etwmc commented 6 years ago

You need to add permission_notify to power state for both switch and light. It’s a new requirement in iOS 10.

Sent from my iPhone

On Oct 31, 2017, at 12:39 AM, jabenwang notifications@github.com wrote:

Ok, this my accessory.cpp code `/*

This accessory.cpp is configurated for light accessory */

include "Accessory.h"

include "PHKAccessory.h"

include "PHKNetworkIP.h"

include

include

using namespace std;

pthread_mutex_t recordMutex;

set trackingUserList; set <connectionInfo*> activeUsers;

intCharacteristics *occupyState;

define userListAddr "./userList"

void _newConnection(connectionInfo* info) { printf("New connection %s\n", info->hostname.c_str()); pthread_mutex_lock(&recordMutex);

bool originalOutput = activeUsers.size() > 0; if ( trackingUserList.count(info->hostname) > 0 ) activeUsers.insert(info);

bool laterOutput = activeUsers.size() > 0;

pthread_mutex_unlock(&recordMutex); if (originalOutput != laterOutput) { //Should notify printf("Changed\n"); occupyState->notify(); } }

void _deadConnection(connectionInfo *info) { pthread_mutex_lock(&recordMutex);

bool originalOutput = activeUsers.size() > 0; activeUsers.erase(info);

bool laterOutput = activeUsers.size() > 0;

pthread_mutex_unlock(&recordMutex); if (originalOutput != laterOutput) { //Should notify printf("Changed\n"); occupyState->notify(); } }

void loadUserList() { ifstream fs; fs.open(userListAddr, std::ifstream::in); char buffer[256]; bool isEmpty = fs.peek() == EOF; while (!isEmpty&&fs.is_open()&&fs.good()&&!fs.eof()) { fs.getline(buffer, 256); string s = string(buffer); trackingUserList.insert(s); } fs.close(); }

void saveUserList() { ofstream fs; fs.open(userListAddr, std::ifstream::out); for (set::iterator it = trackingUserList.begin(); it != trackingUserList.end(); it++) { fs << *it << "\n"; } fs.close(); }

string trackable(connectionInfo *sender) { pthread_mutex_lock(&recordMutex); string result = trackingUserList.count(sender->hostname) > 0? "1": "0"; pthread_mutex_unlock(&recordMutex); return result; }

string calculateOccupy(connectionInfo *sender) { pthread_mutex_lock(&recordMutex); string result = activeUsers.size() > 0? "1": "0"; pthread_mutex_unlock(&recordMutex); return result; }

void switchTrackable(bool oldValue, bool newValue, connectionInfo *sender) { if (newValue) { //Track this device trackingUserList.insert(sender->hostname); saveUserList(); //Update active list _newConnection(sender); } else { //Stop tracking trackingUserList.erase(sender->hostname); saveUserList(); //Update active list _deadConnection(sender); } }

void identity(bool oldValue, bool newValue, connectionInfo *sender) { printf("Identify\n"); }

void lightIdentify(bool oldValue, bool newValue,connectionInfo *sender) { printf("Start Identify Light\n"); }

AccessorySet *accSet;

void AddOccupySensor(){ Accessory *sensorAcc = new Accessory(); addInfoServiceToAccessory(sensorAcc, "Occupy Sensor", "ET", "Occupy Sensor v1", "12345678", &identity); accSet->addAccessory(sensorAcc);

Service *sensorService = new Service(serviceType_occupancySensor); sensorAcc->addService(sensorService);

boolCharacteristics *trackableState = new boolCharacteristics(0x10000, premission_read|premission_write); trackableState->characteristics::setValue("false"); trackableState->perUserQuery = &trackable; trackableState->valueChangeFunctionCall = &switchTrackable; sensorAcc->addCharacteristics(sensorService, trackableState);

occupyState = new intCharacteristics(charType_occupancyDetected, premission_read|premission_notify, 0, 1, 1, unit_none); occupyState->characteristics::setValue("0"); occupyState->perUserQuery = &calculateOccupy; sensorAcc->addCharacteristics(sensorService, occupyState); }

void AddLight(){

Accessory *lightAcc = new Accessory(); addInfoServiceToAccessory(lightAcc, "Light 1", "ET", "Light v1", "12345678", &lightIdentify); accSet->addAccessory(lightAcc);

Service *lightService = new Service(serviceType_lightBulb); lightAcc->addService(lightService);

boolCharacteristics *powerState = new boolCharacteristics(charType_on, premission_read|premission_write); powerState->characteristics::setValue("true"); lightAcc->addCharacteristics(lightService, powerState);

intCharacteristics *brightnessState = new intCharacteristics(charType_brightness, premission_read|premission_write, 0, 100, 1, unit_percentage); brightnessState->characteristics::setValue("50"); lightAcc->addCharacteristics(lightService, brightnessState); }

void AddSwitch(){

Accessory *switchAcc = new Accessory(); addInfoServiceToAccessory(switchAcc, "Switch 1", "ET", "Switch v1", "12345678", &lightIdentify); accSet->addAccessory(switchAcc);

Service *switchService = new Service(serviceType_switch); switchAcc->addService(switchService);

boolCharacteristics *powerState = new boolCharacteristics(charType_on, premission_read|premission_write); powerState->characteristics::setValue("true"); switchAcc->addCharacteristics(switchService, powerState); }

void initAccessorySet() {

newConnection = &_newConnection; deadConnection = &_deadConnection;

loadUserList();

pthread_mutex_init(&recordMutex, NULL);

currentDeviceType = deviceType_bridge;

printf("Initial Accessory\n"); accSet = &AccessorySet::getInstance();

Accessory *bridge = new Accessory(); addInfoServiceToAccessory(bridge, "NDBJ", "ET", "Bridge", "12345678", &identity); accSet->addAccessory(bridge);

AddLight(); AddOccupySensor(); AddSwitch(); };

`

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

jabenwang commented 6 years ago

Ok, thank you very much~