You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After the firmware and connection. Homekit shows a constant update of the device. The port monitor does not display any changes. Where did I make a mistake?
#include<Arduino.h>
#include<arduino_homekit_server.h>
#include"wifi_info.h"//include the Arduino library for your real sensor here, e.g. <DHT.h>
#defineLOG_D(fmt, ...) printf_P(PSTR(fmt "\n") , ##__VA_ARGS__);
voidsetup() {
Serial.begin(115200);
wifi_connect(); // in wifi_info.h//homekit_storage_reset();my_homekit_setup();
}
voidloop() {
my_homekit_loop();
delay(10);
}
//==============================// Homekit setup and loop//==============================// access your homekit characteristics defined in my_accessory.cextern"C"homekit_server_config_t config;
extern"C"homekit_characteristic_t cha_current_humidity;
extern"C"homekit_characteristic_t cha_current_humidity_cur;
extern"C"homekit_characteristic_t cha_current_humidity_tar;
extern"C"homekit_characteristic_t cha_current_humidity_rel;
staticuint32_t next_heap_millis = 0;
staticuint32_t next_report_millis = 0;
#definePIN_SWITCH2voidstate(consthomekit_value_t value){
uint8_t state = value.float_value;
cha_current_humidity_tar.value.float_value = 0;
cha_current_humidity_tar.value.float_value = state;
Serial.print("1: ");
Serial.println(state);
}
voidstate_cur(consthomekit_value_t value){
uint8_t state_cur = value.float_value;
cha_current_humidity_cur.value.float_value = state_cur;
Serial.print("2: ");
Serial.println(state_cur);
}
voidrel(consthomekit_value_t value){
uint8_t rel = value.float_value;
cha_current_humidity_cur.value.float_value = rel;
Serial.print("3: ");
Serial.println(rel);
}
voidmy_homekit_setup() {
cha_current_humidity_tar.setter = state;
cha_current_humidity_cur.setter = state_cur;
cha_current_humidity_rel.setter = rel;
arduino_homekit_setup(&config);
}
voidmy_homekit_loop() {
arduino_homekit_loop();
constuint32_t t = millis();
if (t > next_report_millis) {
// report sensor values every 10 seconds
next_report_millis = t + 10 * 1000;
my_homekit_report();
}
if (t > next_heap_millis) {
// show heap info every 5 seconds
next_heap_millis = t + 5 * 1000;
LOG_D("Free heap: %d, HomeKit clients: %d",
ESP.getFreeHeap(), arduino_homekit_connected_clients_count());
}
}
voidmy_homekit_report() {
cha_current_humidity.value.float_value = 50.0;
homekit_characteristic_notify(&cha_current_humidity, cha_current_humidity.value);
}
Accessory:
/* * my_accessory.c * Define the accessory in C language using the Macro in characteristics.h * * Created on: 2020-05-15 * Author: Mixiaoxiao (Wang Bin)*/
#include<homekit/homekit.h>
#include<homekit/characteristics.h>// Called to identify this accessory. See HAP section 6.7.6 Identify Routine// Generally this is called when paired successfully or click the "Identify Accessory" button in Home APP.voidmy_accessory_identify(homekit_value_t _value) {
printf("accessory identify\n");
}
// (required) format: float; HAP section 9.35; min 0, max 100, step 0.1, unit celsiushomekit_characteristic_t cha_current_humidity = HOMEKIT_CHARACTERISTIC_(CURRENT_RELATIVE_HUMIDITY, 0);
homekit_characteristic_t cha_current_humidity_cur = HOMEKIT_CHARACTERISTIC_(CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE, 0);
homekit_characteristic_t cha_current_humidity_tar = HOMEKIT_CHARACTERISTIC_(TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE, 0);
homekit_characteristic_t cha_current_humidity_rel = HOMEKIT_CHARACTERISTIC_(RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD, 0);
// (optional) format: string; HAP section 9.62; max length 64homekit_characteristic_t cha_name = HOMEKIT_CHARACTERISTIC_(NAME, "Humidifiers");
homekit_accessory_t *accessories[] = {
HOMEKIT_ACCESSORY(.id=1, .category=homekit_accessory_category_sensor, .services=(homekit_service_t*[]) {
HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics=(homekit_characteristic_t*[]) {
HOMEKIT_CHARACTERISTIC(NAME, "Humidifiers"),
HOMEKIT_CHARACTERISTIC(MANUFACTURER, "Arduino HomeKit"),
HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "0123456"),
HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266/ESP32"),
HOMEKIT_CHARACTERISTIC(FIRMWARE_REVISION, "1.0"),
HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify),
NULL
}),
HOMEKIT_SERVICE(HUMIDIFIER_DEHUMIDIFIER, .primary=true, .characteristics=(homekit_characteristic_t*[]) {
&cha_current_humidity,
&cha_name,//optional
&cha_current_humidity_cur,
&cha_current_humidity_tar,
&cha_current_humidity_rel,
NULL
}),
NULL
}),
NULL
};
homekit_server_config_t config = {
.accessories = accessories,
.password = "111-11-111"
};
The text was updated successfully, but these errors were encountered:
After the firmware and connection. Homekit shows a constant update of the device. The port monitor does not display any changes. Where did I make a mistake?
Accessory:
The text was updated successfully, but these errors were encountered: