Yurik72 / ESPHap

ESP32/ESP8266 Arduino library for native Apple Homekit Accessory Protocol (HAP)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Naming Issue on Multiple Accessories

matrixall opened this issue · comments

I want to setup 3 accessories on single ESP12F Module. However after successful pairing, the name of the first accessory shows (LB-XXXX) instead of (1st) and the name (LB) appears for the others instead of (2nd) & (3rd). I noticed that if I delete the name text I see (1st, 2nd & 3rd) as placeholders.

Here is the code i used:

// GPIO Pins
const int TPIN1 = 5;
const int TPIN2 = 14;
const int TPIN3 = 13;

homekit_service_t* hapservice1={0};
homekit_service_t* hapservice2={0};
homekit_service_t* hapservice3={0};
homekit_characteristic_t *ch;

homekit_characteristic_t * ch1;
homekit_characteristic_t * ch2;
homekit_characteristic_t * ch3;

hap_initbase_accessory_service("LB","Yurik72","0","EspHapLed","1.0");

hapservice1= hap_add_lightbulb_service("1st",led_callback,(void*)&TPIN1);
hapservice2= hap_add_lightbulb_service_as_accessory (homekit_accessory_category_lightbulb,"2nd",led_callback,(void*)&TPIN2);
hapservice3= hap_add_lightbulb_service_as_accessory (homekit_accessory_category_lightbulb,"3rd",led_callback,(void*)&TPIN3);

hap_setinitial_characteristic_bool_value(hapservice1,HOMEKIT_CHARACTERISTIC_ON,false);
hap_setinitial_characteristic_bool_value(hapservice2,HOMEKIT_CHARACTERISTIC_ON,false);
hap_setinitial_characteristic_bool_value(hapservice3,HOMEKIT_CHARACTERISTIC_ON,false);

ch1= homekit_service_characteristic_by_type(hapservice1, HOMEKIT_CHARACTERISTIC_ON);
ch2= homekit_service_characteristic_by_type(hapservice2, HOMEKIT_CHARACTERISTIC_ON);
ch3= homekit_service_characteristic_by_type(hapservice3, HOMEKIT_CHARACTERISTIC_ON);

void led_callback(homekit_characteristic_t *ch, homekit_value_t value, void *context) {
if ( ch == ch1 ) { set_led(TPIN1, ch1->value.bool_value); }
if ( ch == ch2 ) { set_led(TPIN2, ch2->value.bool_value); }
if ( ch == ch3 ) { set_led(TPIN3, ch3->value.bool_value); }
}

void set_led(int GPIOPin, bool val){
digitalWrite(GPIOPin, val?HIGH:LOW);
}