Mixiaoxiao / Arduino-HomeKit-ESP8266

Native Apple HomeKit accessory implementation for the ESP8266 Arduino core.
MIT License
1.48k stars 278 forks source link

Device name + mac address #158

Open askarkurymbayev opened 2 years ago

askarkurymbayev commented 2 years ago

Kind time of the day friends, I can not solve the problem with the automatic name of devices in the line homekit_characteristic_t cha_name = HOMEKITCHARACTERISTIC (NAME, "name" + MAC address); can't bind

what i tried to do int name_len = snprintf (NULL, 0, "Outlet-% 02X% 02X% 02X", macaddr [3], macaddr [4], macaddr [5]); char * name_value = malloc (name_len + 1); snprintf (name_value, name_len + 1, "Outlet-% 02X% 02X% 02X", macaddr [3], macaddr [4], macaddr [5]); HOMEKITCHARACTERISTIC (NAME, name_value);

hitenlulla commented 2 years ago

Did you solve it?

ruleechen commented 2 years ago

My solution is to change the value of cha_name during arduino setup.

String hostName;

extern "C" homekit_characteristic_t cha_name;

void setup(void) {
  hostName = WiFi.macAddress();
  cha_name.value.string_value = const_cast<char*>(hostName.c_str());
}

void loop(void) { }
LouisLee985 commented 2 years ago

Kind time of the day friends, I can not solve the problem with the automatic name of devices in the line homekit_characteristic_t cha_name = HOMEKITCHARACTERISTIC (NAME, "name" + MAC address); can't bind

what i tried to do int name_len = snprintf (NULL, 0, "Outlet-% 02X% 02X% 02X", macaddr [3], macaddr [4], macaddr [5]); char * name_value = malloc (name_len + 1); snprintf (name_value, name_len + 1, "Outlet-% 02X% 02X% 02X", macaddr [3], macaddr [4], macaddr [5]); HOMEKITCHARACTERISTIC (NAME, name_value);

try this:

extern "C" homekit_characteristic_t cha_name;
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.macAddress(mac);
sprintf(cha_name.value.string_value, "Outlet-%02X%02X%02X", mac[3], mac[4], mac[5]);