Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jabenwang opened this issue Oct 31, 2017 · 4 comments
Open

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

jabenwang opened this issue Oct 31, 2017 · 4 comments

Comments

@jabenwang
Copy link

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
Copy link
Owner

etwmc commented Oct 31, 2017 via email

@jabenwang
Copy link
Author

jabenwang commented Oct 31, 2017

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

`/*

  • 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();

};

`

@etwmc
Copy link
Owner

etwmc commented Oct 31, 2017 via email

@jabenwang
Copy link
Author

Ok, thank you very much~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants