Git Product home page Git Product logo

arduino-homekit-esp8266's Introduction

Arduino HomeKit ESP8266

中文说明 | Português Brasileiro | Русский

Apple HomeKit accessory server library for ESP8266 Arduino

This Arduino library is a native Apple HomeKit accessory implementation for the ESP8266 Arduino core, and works without any additional bridges.

This project is mainly based on esp-homekit for ESP-OPEN-RTOS.

I ported the RTOS-based implementation of esp-homekit to the pure Arduino environment, aimed at easy and fast building project using Arduino IDE (or Eclipse with sloeber, PlatformIO).

Enjoy the "one-key" build, "one-key" upload, and work to link various other Arduino libraries with Apple HomeKit!

Here is a discussion about the RTOS is required for running Apple HomeKit, and this project is a proof of concept that Apple HomeKit can be implemented and work fine without the RTOS.

This library is built with ESP8266 Arduino Core 2.6.3. Lower versions may compile with errors.

For ESP32, see Arduino-HomeKit-ESP32. The HomeKit running on ESP32 has a GREAT PERFORMANCE which is 10x faster than ESP8266.

Preview

Preview

Setup code of the example sketch

111-11-111

Usage

  1. Define your accessory in a .c file to enjoy the convenient "Macro" style declaration. You can also define your accessory in a .ino file using C++ code.
    	homekit_accessory_t *accessories[] = ...
    	homekit_server_config_t config = {
    		.accessories = accessories,
    		.password = "111-11-111",
    		//.on_event = on_homekit_event, //optional
    		//.setupId = "ABCD" //optional
    	};
  2. In your sketch
    	#include <arduino_homekit_server.h>;
    	
    	//access the config defined in C code
    	extern "C" homekit_server_config_t config; 
    	
    	void setup() {
    		WiFi.begin(ssid, password);
    		arduino_homekit_setup(&config);
    	}
    	
    	void loop() {
    		arduino_homekit_loop();
    	}

Done.

Performance

Notice: You should set the ESP8266 CPU to run at 160MHz (at least during the pairing process), to avoid the tcp-socket disconnection from iOS device caused by timeout.

  • Preinit: ~9.1s (You can see the accessory on your iOS HOME app after Preinit)
  • Pair Setup Step 1/3: ~0s (The heavy crypto computation is done in Preinit)
  • Pair Setup Step 2/3: ~12.1s
  • Pair Setup Step 3/3: ~0.8s (The pair-setup is only processed when first paired with iOS device)
  • Pair Verify Step 1/2: ~0.3s
  • Pair Verify Step 2/2: ~0.8s (The Verify Step is required every time iOS connects or reconnects to ESP8266 to establish secure session)

All pairing process takes ~14s after you input the setup-code on your iPhone. Notice that Preinit require ~9s before you can start to pair.

Heap (memory)

The heap is critical for ESP8266 with full TCP/IP support. ESP8266 easily crashes when the memory is lower than ~5000.

I tried to make WolfSSL crypto work safely on ESP8266 with better performance and lower memory or a trade-off. See details in next section.

Here are the free heap values of running the example sketch:

  • Boot: ~26000
  • Preinit over: ~22000
  • Pairing: ~17000 (or even low when crypto computing)
  • Paired and connected with one iOS device: ~21700
  • Paired and no iOS device connected: ~23400

After memory optimization in v1.1.0:

  • Boot: ~46000
  • Preinit over: ~41000
  • Pairing: ~37000 (or even low when crypto computing)
  • Paired and connected with one iOS device: ~41700
  • Paired and no iOS device connected: ~43000

WolfSSL

  • Based on wolfssl-3.13.0-stable.
  • Clean source code: the unused files are removed.
  • CURVE25519_SMALL and ED25519_SMALL: ESP8266 can not directly run without SMALL defined since the memory is not sufficient. But the NO SMALL version is faster. I mark the big ge_precomp base[32][8] with PROGMEM to store it in Flash (around 70KB). Also the ge_double_scalarmult_vartime can not run caused by lack of heap. I define ESP_GE_DOUBLE_SCALARMULT_VARTIME_LOWMEM in user_settings.h to use LOWMEM version of ge_double_scalarmult_vartime in ge_low_mem.c. This is a trade-off of performance and memory. If you want more Flash space, you should define CURVE25519_SMALL and ED25519_SMALL and undefine ESP_GE_DOUBLE_SCALARMULT_VARTIME_LOWMEM in user_settings.h (this will lead the Pair Verify Steps to take 1.2s + 0.9s).
  • integer.c(big integer operations): MP_16BIT and ESP_FORCE_S_MP_EXPTMOD are defined for better performance in ESP8266. ESP_INTEGER_WINSIZE (value is 3) is defined to avoid crash caused by memory exhaust and the values of {3, 4, 5} are of similar performance.

Storage

  • The pairing data is stored in the EEPROM address in ESP8266 Arduino core.
  • This project does not use the EEPROM library with data-cache to reduce memory use (directly call flash_read and write).
  • The EEPROM is 4096B in ESP8266, this project uses max [0, 1408B).
  • See the comments in storge.c and ESP8266-EEPROM-doc.
  • EEPROM of [1408, 4096) is safe for you to use.
  • This project do NOT use FS(file system), so you can use FS freely.

WatchDog

  • There are software and hardware watchdogs in ESP8266 Arduino core. The heavy crypto computing will lead to watchdog reset.
  • There are disable/enable api of software-watchdog in ESP8266 Arduino core.
  • I found the esp_hw_wdt to disable/enable the hardware-watchdog.
  • The two watchdogs are disabled while Preinit and Pair Setup Step 2/3.

Recommended settings in IDE

  • Module: Generic ESP8266 Module (to enable full settings)
  • FlashSize: at least 470KB for sketch (see WolfSSL section if you want a smaller sketch)
  • LwIP Variant: v2 Lower Memory (for lower memory use)
  • Debug Level: None (for lower memory use)
  • Espressif FW: nonos-sdk 2.2.1+119(191122) (which I used to build this project)
  • SSL Support: Basic SSL ciphers (lower ROM use)
  • VTables: Flash (does not matter maybe)
  • Erase Flash: select All Flash Contents when you first upload
  • CPU Frequency: 160MHz (must)

Arduino port

  • ESP8266WiFi (WiFiServer and WiFiClient) is used for tcp connection.
  • ESP8266mDNS is used for advertising (Bonjour)

Troubleshooting

Change Log

v1.4.0

  • Add yield() while crypto computing, to prevent WiFi disconnection. The idea is from BbIKTOP-issues80
  • One new example.

v1.3.0

  • Small improvements.

v1.2.0

  • New examples.

v1.1.0

  • Memory optimization: moved String/byte constants as much as possible to Flash. The RODATA section of bin is only 4672. Extra ~20K free-heap is available compared with v1.0.1.
  • Upload ESP8266WiFi_nossl_noleak, a nossl and noleak version of the official ESP8266WiFi library of Arduino Core 2.6.3. Removed all codes of SSL to save memory (extra ~3K) since the HomeKit does not require SSL. Fix the memory-leak in WiFiClinet.stop() by adding tcp_abandon(_pcb, 0) in stop(), based on the idea of esp8266/Arduino/pull/2767.

v1.0.1

  • Reduce winsize from 3 to 2(same performance) to lower the heap required. Pairing can be done with low free-heap of ~14000.
  • Specify the MDNS runs on the IPAddress of STA to ensure the HomeKit can work with some SoftAP-based WiFi-Config libraries.
  • Rename the HTTP_METHOD(s) in http_parser.h to avoid multi-definition errors when using ESP8266WebServer together.

Thanks

arduino-homekit-esp8266's People

Contributors

brencerddwr avatar dsbaha avatar euler271 avatar jayfidev avatar jmbcpi avatar me-cooper avatar micampe avatar mixiaoxiao avatar ph4nt0m7 avatar rodolfovieira95 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-homekit-esp8266's Issues

Example03 and Example04 not Pairing

Hi Mixiaoxiao,

You have done amazing work with this library. First and foremost, thank you.
Example01 and Example02 sketches work great when flashed on my ESP8266.

I am having difficulty pairing with my ESP8266 when flashed with Example03 and Example04.

Here are the serial logs:
Example03
NOTE: It appears that it attempts to pair twice.

`WiFi connecting...
.......................................
WiFi connected, IP: 192.168.0.130

[ 4799] HomeKit: Starting server
[ 4805] HomeKit: Using existing accessory ID: FF:CF:78:7A:AA:A4
[ 4811] HomeKit: Preiniting pairing context
[ 4816] HomeKit: Using user-specified password: 111-11-111
[ 4837] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6
[ 10904] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5
[ 14023] HomeKit: Preinit pairing context success
[ 14028] HomeKit: Configuring MDNS
[ 14033] HomeKit: MDNS.begin: Stateless Programmable Switch, IP: 192.168.0.130
[ 14042] HomeKit: Init server over
Free heap: 41632, HomeKit clients: 0
Free heap: 42200, HomeKit clients: 0
Free heap: 41848, HomeKit clients: 0
Free heap: 42168, HomeKit clients: 0
Free heap: 42200, HomeKit clients: 0
Free heap: 42168, HomeKit clients: 0
Free heap: 41848, HomeKit clients: 0
[ 46647] HomeKit: Got new client: local 192.168.0.130:5556, remote 192.168.0.228:49758
[ 46657] HomeKit: [Client 1073682612] Pair Setup Step 1/3
Free heap: 40584, HomeKit clients: 1
[ 50178] HomeKit: [Client 1073682612] Pair Setup Step 2/3
[ 50190] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6
[ 58947] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5
Free heap: 40224, HomeKit clients: 1
[ 63575] HomeKit: [Client 1073682612] Pair Setup Step 3/3
[ 63605] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
[ 64357] HomeKit: Added pairing with 0C73D7AF-93CA-425E-A190-9DA038331F4A
[ 64433] HomeKit: Free saved_preinit_pairing_context
[ 64438] HomeKit: [Client 1073682612] Successfully paired
[ 64475] HomeKit: [Client 1073682612] Disconnected!
[ 64480] HomeKit: [Client 1073682612] Closing client connection
[ 64617] HomeKit: Got new client: local 192.168.0.130:5556, remote 192.168.0.228:49759
[ 64638] HomeKit: [Client 1073682940] Pair Verify Step 1/2
[ 64962] HomeKit: Free heap: 42344
[ 65089] HomeKit: [Client 1073682940] Pair Verify Step 2/2
[ 65095] HomeKit: [Client 1073682940] Found pairing with 0C73D7AF-93CA-425E-A190-9DA038331F4A
[ 65119] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
[ 65883] HomeKit: [Client 1073682940] Verification successful, secure session established
[ 65891] HomeKit: Free heap: 42456
[ 65958] HomeKit: [Client 1073682940] Get Accessories
[ 66035] HomeKit: [Client 1073682940] Remove Pairing
[ 66040] HomeKit: Removed pairing with 0C73D7AF-93CA-425E-A190-9DA038331F4A
[ 66048] HomeKit: Last admin pairing was removed, enabling pair setup
[ 66069] HomeKit: Preiniting pairing context
[ 66073] HomeKit: Using user-specified password: 111-11-111
[ 66095] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6
[ 72119] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5
[ 75205] HomeKit: Preinit pairing context success
[ 75212] HomeKit: [Client 1073682940] Disconnected!
[ 75218] HomeKit: [Client 1073682940] Closing client connection
Free heap: 41504, HomeKit clients: 0
Free heap: 41944, HomeKit clients: 0
Free heap: 41624, HomeKit clients: 0
Free heap: 41624, HomeKit clients: 0`

Example04
NOTE: Device is discoverable as "Multiple Sensors", and lets me type the 111-11-111 pairing code, but it doesn't pair successfully. It appears that the pairing process doesn't start according to this log...

`WiFi connecting...
.................................................
WiFi connected, IP: 192.168.0.130

[ 5946] HomeKit: Starting server
[ 5952] HomeKit: Formatting HomeKit storage at 0xfb000
[ 5958] HomeKit: Generated new accessory ID: AE:9B:49:9C:E2:28
[ 6019] HomeKit: Generated new accessory key
[ 6024] HomeKit: Preiniting pairing context
[ 6029] HomeKit: Using user-specified password: 111-11-112
[ 6050] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6
[ 12073] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5
[ 15191] HomeKit: Preinit pairing context success
[ 15196] HomeKit: Configuring MDNS
[ 15202] HomeKit: MDNS.begin: Multiple Sensors, IP: 192.168.0.130
[ 15209] HomeKit: Init server over
t 11.0, h 57.0, l 3446.0, c 1, m 0, o 1
Free heap: 37912, HomeKit clients: 0
Free heap: 38288, HomeKit clients: 0
t 19.0, h 39.0, l 9947.0, c 0, m 1, o 1
Free heap: 38128, HomeKit clients: 0
Free heap: 38448, HomeKit clients: 0
t 24.0, h 49.0, l 8718.0, c 1, m 0, o 1
Free heap: 38128, HomeKit clients: 0
Free heap: 38448, HomeKit clients: 0
t 11.0, h 30.0, l 6588.0, c 0, m 1, o 1
Free heap: 38448, HomeKit clients: 0
Free heap: 38456, HomeKit clients: 0
t 28.0, h 59.0, l 5009.0, c 0, m 1, o 0
Free heap: 38448, HomeKit clients: 0
Free heap: 38128, HomeKit clients: 0
t 16.0, h 55.0, l 7712.0, c 1, m 0, o 1
Free heap: 38448, HomeKit clients: 0
Free heap: 38448, HomeKit clients: 0
t 20.0, h 34.0, l 7964.0, c 0, m 0, o 0
Free heap: 38272, HomeKit clients: 0
Free heap: 38272, HomeKit clients: 0
t 18.0, h 33.0, l 2112.0, c 1, m 1, o 0
Free heap: 38448, HomeKit clients: 0
Free heap: 37848, HomeKit clients: 0`

Accessory not ready

Hi,

Thanks for your work on this awesome library!

I'm trying to create a HomeKit-enabled IR remote for my A/C. Converting the simplest_led sample to a simple on/off IR controller worked wonderfully. So far so good. Then I tried to implement a heater-cooler service and at this point the pairing just stopped working. I made sure to have every mandatory characteristic implemented (haven't added the optional ones yet though), erased flash, dialled the CPU frequency up – no luck, as soon as I enter the password HomeKit goes "Accessory not ready, please reboot blah blah" and drops the connection. Here's what it looks like in the serial:

>>> [  40117] HomeKit: heap: 41384, sockets: 0
>>> [  44548] HomeKit: Got new client: local 192.168.0.199:5556, remote 192.168.0.181:60329
>>> [  44558] HomeKit: [Client 1073682004] Pair Setup Step 1/3
>>> [  45121] HomeKit: heap: 39864, sockets: 1
>>> [  50123] HomeKit: heap: 39864, sockets: 1
>>> [  55126] HomeKit: heap: 39696, sockets: 1
>>> [  60130] HomeKit: heap: 39648, sockets: 1
>>> [  64411] HomeKit: [Client 1073682004] Disconnected!
>>> [  64416] HomeKit: [Client 1073682004] Closing client connection
>>> [  64422] HomeKit: Free saved_preinit_pairing_context
>>> [  64427] HomeKit: [Client 0] Clear the pairing context
>>> [  64437] HomeKit: Preiniting pairing context
>>> [  64442] HomeKit: Using user-specified password: 111-11-111
>>> [  64463] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6
>>> [  70509] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5
>>> [  73631] HomeKit: Preinit pairing context success
>>> [  73638] HomeKit: heap: 40352, sockets: 0
>>> [  78643] HomeKit: heap: 40792, sockets: 0
>>> [  83647] HomeKit: heap: 40960, sockets: 0
>>> [  88650] HomeKit: heap: 41288, sockets: 0

I understand that I've probably messed up the accessory definition, but I have no idea even where to start looking. Does this normally happen when the HomeKit is unhappy about the characteristics? Is it possible that a more complex (more chars etc) accessory is too much for the esp8266 to handle in a timely matter?

Any pointers would be much appreciated.

Conflicting base64 files name

Hey, first of all I just want to say what a great project this is.
I also want to suggest changing the name of the files "base64.h" and "base64.cpp", as they already exist in the espressif8266 framework. I have been having some problems because of it, and I imagine other people may as well have.
If that's not a good idea, how could I choose which file to include? I'm using PlatformIO in my project.

if i reboot the device it looses connection

when turn off and on the device, it looses teh connection to homekit and im not able to see the data anymore, its a temperature sensor, also im using a wifi manager library called iotwebconfig and when homekit library is enabled, it also erase all data in eeprom from that library.

Crash on my_homekit_setup()

Hi,
first, thanks a lot for your work. This library is great!

I had a working example which ran fine. Recently, after some changes, when running on my Arduino I get the following error in line my_homekit_setup()

https://pastebin.com/aRhvsqdK

I can't really make anything from it, and don't understand why this is happening now. This is my code:

https://pastebin.com/CPX8CBdp

and my_accesory.c

https://pastebin.com/7vPGKu0F

Do you have any idea what could be the issue? Thank you so much

提供一个修改建议

我发现,在使用您的temperature example的时候,第一次上传ESP8266一切正常,Homekit也可以pairing. 但是在手机上删除此元件后,再次重启ESP8266, 再想去pair,再也搜索不到。我为了绕过这个,就直接comment掉server->paired = true

while (!homekit_storage_next_pairing(&pairing_it, &pairing)) { if (pairing.permissions & pairing_permissions_admin) { //INFO("Found admin pairing with %s, disabling pair setup", pairing.device_id); INFO("XXXXXXXXXX"); // server->paired = true; break; } }
为了永久的解决这个问题,whileloop里面是不是可以加一个flag,可以让user选择force paring。 可以避免这个问题。应为再homekit删除后, 直接force server->paired = true 就跳过了新的pairing机会。

这只是我想的一个办法,您看您有什么更好的办法解决这个问题也可以。
我想说您写的这个库真的很厉害,真的很帮助到我! 感谢

PSA: Use 2.4Ghz for adding devices

Not a bug with your library but I wanted to highlight an issue I was having.

I was adding this library to some old projects I have and slowly building it up ensuring it was working. Everything was going smoothly until I came back to it a day later and I was having huge issues successfully adding my ESP device. After many wasted hours debugging I narrowed it down to the fact I have a dual band router and my iOS device was connected to 5Ghz.

I created a guest network (with password) on my router (with sufficient access to my network) and ensured it was 2.4Ghz. As long as I kept my iPhone connected to the 2.4Ghz network, adding my device worked flawlessly.

I just wanted to highlight the issue for any others who may go near crazy. It might be worth adding to the readme?!

Keep up the great work!

I am unable to understand the examples.

Hi, i have compiled the simplest_led example, it works and all.

But now i want to implement it into my own stuff, i could not understand how the you define an accessories using homekit_accessory_t *accessories[] = ...

And how you define what functions get called when the button is on/off, in the example there is a function called led_toggle(); but i cant find where in the code you define it to run..

anyways the examples are very messy, there are not much comments on the code.

Hope someone can help me out here.

How to read pwm (led eg) in loop() ?

Hello,
I am noob kind-of, I uploaded the LED sketch example and it works fine, but i need to do stuff in loop() for the value of pwm written or given through the Home app.
I wanted to run infrared signal "code" through an IRLed, when i set led pwm to 20, will send code 20 "IRSend library" to air-conditioner.
the issue is I cant get to read the pwm in loop (main tab called led) , neither can use the library or send the code in (my_accessory.h tab)
I tried Serial.println(led_bri.value.int_value); but always gives me same value 6510
I was able to get the ON/OFF state, but not the pwm value.
I know im missing something
i tried many things but all lead to fail.
thank you for your time.

Multiple HomeKit Device pairing issue

Hey!

Again awesome work on the library!
So far I had only one device in my network. When I try to add a different one I am not able due to the warning message: Found admin pairing with 6AE7DA31-6F0A-4B0F-9E81-FECEBC2F6FA4, disabling pair setup

Full Print:

>>> [   4341] HomeKit: Update the CPU to run at 160MHz
>>> [   4346] HomeKit: Starting server
>>> [   4349] HomeKit: Using existing accessory ID: FC:FA:56:16:CA:F8
>>> [   4356] HomeKit: Found admin pairing with 6AE7DA31-6F0A-4B0F-9E81-FECEBC2F6FA4, disabling pair setup
>>> [   4365] HomeKit: Configuring MDNS
>>> [   4370] HomeKit: MDNS.begin: Rise Wecker_E14627, IP: 192.168.0.145
>>> [   4380] HomeKit: Init server over
>>> [   4384] HomeKit: Free heap: 43744

Seems like both my devices have the same device id. How is this possible?
How can I change the device ID for the second ESP?
I do have two physically different devices so this confuses me.

Cheers,
Ferdinand

Soft WDT reset

Hello now im getting this problem and it restarts.

the stack trace says.

0x4023c698: _vfprintf_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 531
0x4023bf06: vprintf at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/vprintf.c line 40
>>> >> [  65629] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
>>> [  67145] HomeKit: [Client 1073688468] Verification successful, secure session established
>>> [  67154] HomeKit: Free heap: 28760
>>> [  67158] HomeKit: [Client 1073688436] Pair Verify Step 2/2
>>> [  67165] HomeKit: [Client 1073688436] Found pairing with 
>>> [  67199] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
Soft WDT reset

>>>stack>>>

ctx: cont

part of the code

void loop() {
    // -- doLoop should be called as frequently as possible.
    iotWebConf.doLoop();
    arduino_homekit_loop();

    // Only needed in forced mode! In normal mode, you can remove the next line.
    bme.takeForcedMeasurement(); // has no effect in normal mode

    if (iotWebConf.getState() == IOTWEBCONF_STATE_ONLINE && strlen(serialNumberValue) != 0) {
        if (delay_check(HomeKit.last, HomeKit.refresh)) { // update battery voltage if timer has elapsed
            my_homekit_report();
            HomeKit.last = millis(); // update structure variable to current time
        }
    }

    delay(10);
}

extern "C" homekit_server_config_t config;
extern "C" homekit_characteristic_t cha_current_temperature;
extern "C" homekit_characteristic_t cha_humidity;
extern "C" homekit_characteristic_t cha_status_active;

static uint32_t next_heap_millis = 0;
static uint32_t next_report_millis = 0;

void my_homekit_setup() {
    arduino_homekit_setup(&config);
}

void my_homekit_report() {
    //Serial.println("Inicia report");
    cha_current_temperature.value.float_value = temp;
    cha_humidity.value.float_value = hum;
    cha_status_active.value.bool_value = true;
    //LOG_D("Current temperature: %.1f", temperature_value);
    //Serial.print("Current temperature: %.1f");
    //Serial.println(temp);
    homekit_characteristic_notify(&cha_current_temperature, cha_current_temperature.value);
    homekit_characteristic_notify(&cha_humidity, cha_humidity.value);
    homekit_characteristic_notify(&cha_status_active, cha_status_active.value);
    //Serial.println("Termina report");
}

Cannot open header "windows.h" and "winsock2.h" while I'm trying to build on VSCode.

I have succeed performer examples on my Nodemcu & iPhone and it totally works. But problem occured while Im trying to build on VSCode. I searched my C:\ fully but can not find these two file.
Why it all worked on ArduinoIDE even without these two files? Am i the only one trying to build on VSCode?

.vscode/c_cpp_properties.json is as follows:
{ "configurations": [ { "name": "Win32", "includePath": [ "C:\\Users\\Administrator\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**", "D:\\Documents\\Arduino\\libraries\\**", "C:\\Users\\Administrator\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.7.2\\**" ], "forcedInclude": [], "intelliSenseMode": "msvc-x64" } ], "version": 4 }

Fan service stuck in loading state

I created a Fan service like this:

homekit_characteristic_t ch_fan_active = HOMEKIT_CHARACTERISTIC_(ACTIVE, FAN_INACTIVE);
homekit_characteristic_t ch_fan_rotation_speed = HOMEKIT_CHARACTERISTIC_(ROTATION_SPEED, 10.0);
homekit_characteristic_t ch_fan_swing_mode = HOMEKIT_CHARACTERISTIC_(SWING_MODE, FAN_SWING_DISABLED);

homekit_service_t fan_service = HOMEKIT_SERVICE_(FAN, .primary = true,
    .characteristics = (homekit_characteristic_t *[]) {
        HOMEKIT_CHARACTERISTIC(NAME, "Fan"),
        &ch_fan_active,
        &ch_fan_rotation_speed,
        &ch_fan_swing_mode,
        NULL
    });

and the tile in the Home app is stuck in the “Loading” state and tapping it doesn't toggle the fan on.

If I expand the tile and toggle the big switch, the tile shows “On” and “Off” correctly, but it is still grey instead of highlighted with the spinning fan.

I have other services in the same accessory and those work as expected. Removing all the other services and just making a fan accessory has the same issue; removing all the characteristics except for active (the only required one) also stays stuck in “Loading”.

In my investigation I noticed that the #define HOMEKIT_DECLARE_CHARACTERISTIC_ROTATION_SPEED is not initialising the .value field (which seems a bug in itself, same issue for _ROTATION_DIRECTION), but adding that doesn't seem to fix the problem.

I believe I tried all the combinations and I’m now out of ideas. Let me know how I can assist in debugging this.

I get an error while compiling

where do you think there is an error?
11k
22k
33k
44k
I'm a little new at this, sorry :/
If you can shoot a short video while compiling, I can see where I did wrong. Thanks
Good Works.

No yield()

Thank you very much for the library.
Have you tried to put yield() after every SrpHashUpdate() call inside the most painful functions like wolfcrypt::wc_SrpComputeKey() ?
It should solve watchdog issues and improve connection stability

Random connection loss

Hi,

First of all thanks for this porting! I tried the original esp-homekit but your work here made the use of this library much more simple!

I noticed that sometime all of my devices (not always at the same time) show that they aren't reachable. I was able to reproduce the behavior with you simple led example, and here the logs:

16:40:10.599 > >>> [ 748449] HomeKit: [Client 1073683172] Found pairing with C494D193-4EBE-47CB-8422-5E03001BDBC1
16:40:10.615 > >>> [ 748477] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
16:40:10.641 > >>> [ 749247] HomeKit: [Client 1073683172] Verification successful, secure session established
16:40:11.411 > >>> [ 749260] HomeKit: Free heap: 35512
16:40:11.419 > >>> [ 749274] HomeKit: [Client 1073683172] Get Accessories
16:40:11.435 > heap: 36752, sockets: 4
16:40:14.012 > heap: 36752, sockets: 4
16:40:19.013 > heap: 36752, sockets: 4
16:40:24.014 > heap: 36752, sockets: 4
16:40:29.015 > heap: 36752, sockets: 4
16:40:34.016 > heap: 36752, sockets: 4
16:40:39.017 > heap: 36752, sockets: 4
16:40:44.018 > heap: 37088, sockets: 4
16:40:49.019 > >>> [ 788020] HomeKit: [Client 1073683380] Get Characteristics
16:40:50.182 > heap: 36752, sockets: 4
16:40:54.020 > heap: 36944, sockets: 4
16:40:59.021 > heap: 37088, sockets: 4
16:41:04.022 > heap: 36752, sockets: 4
16:41:09.023 > heap: 36752, sockets: 4
16:41:14.024 > heap: 37096, sockets: 4
16:41:19.025 > heap: 36752, sockets: 4
16:41:24.026 > heap: 36752, sockets: 4
16:41:29.028 > >>> [ 827280] HomeKit: [Client 1073679716] Disconnected!
16:41:29.441 > >>> [ 827288] HomeKit: [Client 1073679716] Closing client connection
16:41:29.451 > heap: 38368, sockets: 3
16:41:34.028 > >>> [ 836298] HomeKit: [Client 1073683380] Disconnected!
16:41:38.459 > >>> [ 836306] HomeKit: [Client 1073683380] Closing client connection
16:41:38.469 > heap: 39936, sockets: 2
16:41:39.030 > >>> [ 838861] HomeKit: [Client 1073683172] Disconnected!
16:41:41.022 > >>> [ 838869] HomeKit: [Client 1073683172] Closing client connection
16:41:41.032 > >>> [ 840085] HomeKit: [Client 1073683212] Disconnected!
16:41:42.245 > >>> [ 840092] HomeKit: [Client 1073683212] Closing client connection
16:41:42.255 > heap: 43096, sockets: 0
16:41:44.031 > heap: 43440, sockets: 0
16:41:49.032 > heap: 43440, sockets: 0
16:41:54.033 > heap: 43440, sockets: 0
16:41:59.034 > heap: 43440, sockets: 0
16:42:04.035 > heap: 43440, sockets: 0
16:42:09.036 > heap: 43096, sockets: 0
16:42:14.037 > heap: 43096, sockets: 0
16:42:19.038 > heap: 43096, sockets: 0
16:42:24.039 > heap: 43096, sockets: 0
16:42:29.040 > heap: 43096, sockets: 0
16:42:34.041 > heap: 43096, sockets: 0
16:42:39.042 > heap: 43096, sockets: 0
16:42:44.043 > heap: 43096, sockets: 0
16:42:49.044 > heap: 43096, sockets: 0
16:42:54.045 > heap: 43096, sockets: 0
16:42:59.046 > heap: 43096, sockets: 0
16:43:04.047 > heap: 43096, sockets: 0
16:43:09.048 > >>> [ 928082] HomeKit: Got new client: local 192.168.1.60:5556, remote 192.168.1.43:51900
16:43:10.250 > >>> [ 928096] HomeKit: [Client 1073683380] Pair Verify Step 1/2
16:43:10.259 > >>> [ 928423] HomeKit: Free heap: 40120
16:43:10.583 > >>> [ 928458] HomeKit: [Client 1073683380] Pair Verify Step 2/2
16:43:10.619 > >>> [ 928468] HomeKit: [Client 1073683380] Found pairing with C494D193-4EBE-47CB-8422-5E03001BDBC1
16:43:10.636 > >>> [ 928496] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
16:43:10.661 > >>> [ 929266] HomeKit: [Client 1073683380] Verification successful, secure session established
16:43:11.432 > >>> [ 929279] HomeKit: Free heap: 40912
16:43:11.439 > >>> [ 929296] HomeKit: [Client 1073683380] Get Accessories
16:43:11.458 > >>> [ 929344] HomeKit: Got new client: local 192.168.1.60:5556, remote 192.168.1.53:49812
16:43:11.511 > >>> [ 929357] HomeKit: [Client 1073682268] Pair Verify Step 1/2
16:43:11.521 > >>> [ 929684] HomeKit: Free heap: 36032
16:43:11.845 > >>> [ 929714] HomeKit: [Client 1073682268] Pair Verify Step 2/2
16:43:11.876 > >>> [ 929724] HomeKit: [Client 1073682268] Found pairing with C494D193-4EBE-47CB-8422-5E03001BDBC1
16:43:11.892 > >>> [ 929752] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
16:43:11.917 > >>> [ 930522] HomeKit: [Client 1073682268] Verification successful, secure session established
16:43:12.688 > >>> [ 930535] HomeKit: Free heap: 38832
16:43:12.695 > >>> [ 930582] HomeKit: [Client 1073682268] Get Accessories
16:43:12.744 > >>> [ 930675] HomeKit: [Client 1073682268] Update Characteristics
16:43:12.838 > >>> [ 931430] HomeKit: Got new client: local 192.168.1.60:5556, remote 192.168.1.12:56080
16:43:13.597 > >>> [ 931444] HomeKit: Got new client: local 192.168.1.60:5556, remote 192.168.1.19:62318
16:43:13.611 > >>> [ 931457] HomeKit: [Client 1073687620] Pair Verify Step 1/2
16:43:13.620 > >>> [ 931784] HomeKit: Free heap: 34200
16:43:13.946 > >>> [ 931790] HomeKit: [Client 1073682300] Pair Verify Step 1/2
16:43:13.953 > >>> [ 932117] HomeKit: Free heap: 33576
16:43:14.277 > heap: 34336, sockets: 4
16:43:14.284 > >>> [ 932254] HomeKit: [Client 1073682300] Pair Verify Step 2/2
16:43:14.415 > >>> [ 932264] HomeKit: [Client 1073682300] Found pairing with C494D193-4EBE-47CB-8422-5E03001BDBC1
16:43:14.432 > >>> [ 932291] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
16:43:14.457 > >>> [ 933062] HomeKit: [Client 1073682300] Verification successful, secure session established
16:43:15.227 > >>> [ 933075] HomeKit: Free heap: 34400
16:43:15.235 > >>> [ 933175] HomeKit: [Client 1073682300] Get Accessories
16:43:15.337 > >>> [ 933679] HomeKit: [Client 1073683380] Update Characteristics
16:43:15.843 > >>> [ 935625] HomeKit: [Client 1073687620] Pair Verify Step 2/2
16:43:17.787 > >>> [ 935635] HomeKit: [Client 1073687620] Found pairing with C494D193-4EBE-47CB-8422-5E03001BDBC1
16:43:17.803 > >>> [ 935663] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
16:43:17.828 > >>> [ 936433] HomeKit: [Client 1073687620] Verification successful, secure session established
16:43:18.599 > >>> [ 936446] HomeKit: Free heap: 35896
16:43:18.606 > >>> [ 936647] HomeKit: [Client 1073687620] Get Accessories
16:43:18.810 > heap: 36704, sockets: 4

It seems that suddenly the device lost all the connected clients. It is something you have seen before? Any idea of what could cause this?

Thanks,

The future work about HomeKit on ESP8266 and ESP32

I notice that Espressif has published its official HomeKit library in this month, available on Espressif's GitHub repository esp-apple-homekit-adk.
This official HomeKit library based on ESP-IDF is for ESP32 and ESP32-S2 only.
Maybe I will do something to make this official HomeKit library work in Arduino environment.
And I would no longer maintain the HomeKit library for ESP32 based on the unofficial project esp-homekit.

Push button switch.

Hello.

Thanks for project Arduino-HomeKit-ESP8266.
I would need to create a push button switch. I have been trying the switch example, it works fine.
I need to automate a door opening by pressing it for about 3 seconds.
The problem with the example is that there are only two On/Off potions. I would need after about 3 seconds to go from the on state to the off state.

Thank you very much.

Unable to use this library for ESP32

This looks like an awesome project, and would be exactly what I need. However; I'm having some issues getting this to work on my ESP32 board. The issue is probably a case of me not understanding the structure in your repo, and/or not understanding how to properly use an external library.

Here is what i have done:

  1. download the repo as a zip
  2. added the zip as a library in the arduino IDE
  3. replace the src folder (Sketches/MyProject/libraries/Arduino-HomeKit-ESP8266-master/src) with the one in the ESP32 HomeKit folder.
  4. copy the example files from the ESP32 HomeKit into MyProject
  5. try to compile

Since my hypothesis is that I'm setting this up wrong, I won't bother you with the weird error messages I'm getting. Could you give me some pointers as to how to get this running on my ESP32? I'd be happy to help you describe the workflow in the readme, once I have gotten it running!

Error homekit_value_t: "sorry, unimplemented non-trivial designated initializers not supported"

When trying to instantiate HOMEKIT_BOOL(true) I get the compile error sorry, unimplemented non-trivial designated initializers not supported.

The error is given for all #defines to help the initialization of homekit_value_t in types.h, the lines are:

#define HOMEKIT_BOOL_(value, ...) \
    {.format=homekit_format_bool, .bool_value=(value), ##__VA_ARGS__}
#define HOMEKIT_BOOL(value, ...) (homekit_value_t) HOMEKIT_BOOL_(value, __VA_ARGS__)

Seems like the error is given because the initialization of the homekit_value_t struct is not given all variables. But maybe not (I do not have profound understanding of C++) I cannot get it to work defining homekit_value_t by my self neither with all variables.

If I make any progress I will keep the thread updated.

Thank you


Awesome library btw

你好,我想知道关于配网的方法

我尝试使用WiFiManager进行web配网,第一次可以正常接入,但是 在8266重启之后 保存wifi与密码功能不能使用,又得从新进行配网,我该怎么办,或许请告诉我更好的配网方式,谢谢

temperature value error

Hi, I use DS1820 temperature sensor, when temperature_value = -1, -2, -3...... and 100, 101, 102....... accessory starting not to response,
so accessory works only with values from 0 to 100

in my .c file code:
float temperature_value = -10;
temperature.value.float_value = temperature_value;
homekit_characteristic_notify(&temperature, HOMEKIT_FLOAT(temperature_value));

any thoughts?
Full example you can find on my github
And thank you for your library very much

Unable to pair with garage characteristic

Hi,

great library first of all. I tried to make an garage opener with current_state, target_state, obstruction_detected, current_lock and target_lock as described in the library. But I can not connect to the device.

The messages I get from the controller seem to look successful, but on the phone I get the Couldn't add Device Home couldn't connect to this accessory..

>>> [  37600] HomeKit: [Client 1073682956] Pair Setup Step 1/3
Free heap: 40648, HomeKit clients: 1
Report!
Free heap: 40584, HomeKit clients: 1
Free heap: 40536, HomeKit clients: 1
>>> [  51412] HomeKit: [Client 1073682956] Pair Setup Step 2/3
>>> [  51428] HomeKit: Call s_mp_exptmod in integer.c, original winsize 6
>>> [  68754] HomeKit: Call s_mp_exptmod in integer.c, original winsize 5
Free heap: 40184, HomeKit clients: 1
Report!
>>> [  77643] HomeKit: [Client 1073682956] Pair Setup Step 3/3
>>> [  77693] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
>>> [  79191] HomeKit: Added pairing with 9530CB6F-DC47-47BE-8DA3-A19A2CEEC876
>>> [  79310] HomeKit: Free saved_preinit_pairing_context
>>> [  79315] HomeKit: [Client 1073682956] Successfully paired
>>> [  79382] HomeKit: [Client 1073682956] Disconnected!
>>> [  79387] HomeKit: [Client 1073682956] Closing client connection
>>> [  79434] HomeKit: Got new client: local 192.168.178.24:5556, remote 192.168.178.31:62810
>>> [  79444] HomeKit: [Client 1073678596] Pair Verify Step 1/2
>>> [  80062] HomeKit: Free heap: 42304
>>> [  80137] HomeKit: [Client 1073678596] Pair Verify Step 2/2
>>> [  80144] HomeKit: [Client 1073678596] Found pairing with 9530CB6F-DC47-47BE-8DA3-A19A2CEEC876
>>> [  80179] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
>>> [  81695] HomeKit: [Client 1073678596] Verification successful, secure session established
>>> [  81704] HomeKit: Free heap: 42416
>>> [  81820] HomeKit: [Client 1073678596] Get Accessories
>>> [  81947] HomeKit: [Client 1073678596] Disconnected!
>>> [  81953] HomeKit: [Client 1073678596] Closing client connection

Here is my accessory file, maybe there is some issues with that:

#include <homekit/homekit.h>
#include <homekit/characteristics.h>

void my_accessory_identify(homekit_value_t _value)
{
    printf("accessory identify\n");
}

homekit_characteristic_t cha_garage_name = HOMEKIT_CHARACTERISTIC_(NAME, "Garage");
homekit_characteristic_t cha_garage_current_state = HOMEKIT_CHARACTERISTIC_(CURRENT_DOOR_STATE, 0);
homekit_characteristic_t cha_garage_target_state = HOMEKIT_CHARACTERISTIC_(TARGET_DOOR_STATE, 0);
homekit_characteristic_t cha_garage_obstruction = HOMEKIT_CHARACTERISTIC_(OBSTRUCTION_DETECTED, false);
homekit_characteristic_t cha_lock_current_state = HOMEKIT_CHARACTERISTIC_(LOCK_CURRENT_STATE, 0);
homekit_characteristic_t cha_lock_target_state = HOMEKIT_CHARACTERISTIC_(LOCK_TARGET_STATE, 0);

homekit_accessory_t *accessories[] = {
    HOMEKIT_ACCESSORY(
            .id = 2, .category = homekit_accessory_category_garage, .services = (homekit_service_t *[]){
                HOMEKIT_SERVICE(ACCESSORY_INFORMATION, .characteristics = (homekit_characteristic_t *[]){
                    HOMEKIT_CHARACTERISTIC(NAME, "Garage"), 
                    HOMEKIT_CHARACTERISTIC(MANUFACTURER, "com.de"), 
                    HOMEKIT_CHARACTERISTIC(SERIAL_NUMBER, "0000002"), 
                    HOMEKIT_CHARACTERISTIC(MODEL, "ESP8266"), 
                    HOMEKIT_CHARACTERISTIC(IDENTIFY, my_accessory_identify), 
                    NULL}), 
                HOMEKIT_SERVICE(GARAGE_DOOR_OPENER, .primary = true, .characteristics = (homekit_characteristic_t *[]){
                    &cha_garage_current_state, 
                    &cha_garage_target_state, 
                    &cha_garage_obstruction, 
                    &cha_garage_name, 
                    &cha_lock_current_state, 
                    &cha_lock_target_state, 
                    NULL}), 
                NULL}),
    NULL};

homekit_server_config_t config = {
    .accessories = accessories,
    .password = "111-11-111"};

Any ideas? Please let me know how and if you need more detailed log files.

使用esp-01s出现连接失败

使用esp-01s编译示例进去,出现了错误!
[ 112] HomeKit: Starting server
!!! [ 116] HomeKit: Failed to read HomeKit storage magic

[ 121] HomeKit: Formatting HomeKit storage at 0x3fb000
!!! [ 126] HomeKit: Failed to erase HomeKit storage
[ 131] HomeKit: Resetting HomeKit storage
!!! [ 136] HomeKit: Failed to reset HomeKit storage
[ 141] HomeKit: Generated new accessory ID: 2D:C4:6B:9E:03:41
!!! [ 147] HomeKit: Failed to write accessory ID to HomeKit storage
[ 205] HomeKit: Generated new accessory key
!!! [ 210] HomeKit: Failed to write accessory key to HomeKit storage
[ 217] HomeKit: Preiniting pairing context
使用iphone连接是否出现的错误!
!!! [ 39382] HomeKit: Failed to compact HomeKit storage: sector data read error
!!! [ 39389] HomeKit: Failed to write pairing info to HomeKit storage: max number of pairings
!!! [ 39397] HomeKit: [Client 1073682852] Failed to store pairing (code -2)
[ 39634] HomeKit: [Client 1073682852] Disconnected!

求解决办法,谢谢!

Problem with connecting to the esp

HI,
I’m Having trouble with connecting to my ESP 32, I uploaded the switch example sketch provided,
but on the phone, it doesn’t show up to select to pair with it. (I also tried it with the Temperature sensor and it didn’t work either)
these are the messages I get from the ESP,
image

it worked a few times before until I uncomment the command; homekit_storage_reset() and uploadet it.
In the message >>> [ 343] HomeKit: Found admin pairing with A1D6497F-4683-49CF-935B-2321A9ABB508, disabling pair setup
it says disabling pair setup I don’t know if that does mean anything but it doesn’t sound right to me that early.

Cannot add accessory based on ESP32

I was experimenting and I made a mistake in the homekit_accessory_t *accessories[] and Apple disconnected from the accessory when I tried to activate a switch. I corrected the error but now I cannot find the accessory anymore after inserting the "8-digit homekit setup code". Do you know how can I recover it?

HomeKit breaks NeoPixel Support

Hey!

Love the library! It works like a charm on its own. Really loving it this far!

However I’ve tried connecting a neopixel and running it through the Adafruit library. Somehow, the setup of HomeKit breaks the neopixel library. The LEDs don’t get the right signals and flicker in weird colors and brightness.

Do you think there is a way to make them both work in one sketch?

Interpreting negative integer values

I'm getting unexpected values when HomeKit is supposedly sending me a negative integer. I am building a window covering that supports a horizontal tilt angle of between -90 and +90 degrees; when the values are positive, the values are correct, but when the values are supposed to be negative, they are working down from 255.

This strikes me as a two's complement conversion problem, but I can't figure out where the error is introduced, and I'm not sure whether I can deal with it in my code.

In my .getter function in the .ino file, I have this:

// Called when setting horizontal tilt position
void cha_target_horizontal_tilt_angle_setter(const homekit_value_t value) {
	int angle = value.int_value;
	cha_target_horizontal_tilt_angle.value.int_value = angle;
	LOG_D("Window covering horizontal tilt angle: %i (%i)", angle, value.format);

	// tell the servo (range 0 to 180) to go to the requested angle (range -90 to 90)
	angle = map(angle, -90, 90, 0, 180);
	LOG_D("Window covering horizontal tilt mapped angle: %i", angle);
	tiltServo.write(angle); 
}

But here's what I see in my logs when that function runs and I start moving the control slider to the left, which is supposedly sending negative values:

>>> [  38883] HomeKit: [Client 1073679940] Update Characteristics
Window covering horizontal tilt angle: 253 (5)
Window covering horizontal tilt mapped angle: 343

One of the relevant characteristics is HOMEKIT_CHARACTERISTIC_TARGET_HORIZONTAL_TILT_ANGLE in characteristics.h at line 1510, but the .format is int, which is expected.

#define HOMEKIT_CHARACTERISTIC_TARGET_HORIZONTAL_TILT_ANGLE HOMEKIT_APPLE_UUID2("7B")
#define HOMEKIT_DECLARE_CHARACTERISTIC_TARGET_HORIZONTAL_TILT_ANGLE(_value, ...) \
    .type = HOMEKIT_CHARACTERISTIC_TARGET_HORIZONTAL_TILT_ANGLE, \
    .description = "Target Horizontal Tilt Angle", \
    .format = homekit_format_int, \
    .unit = homekit_unit_arcdegrees, \
    .permissions = homekit_permissions_paired_read \
                 | homekit_permissions_paired_write \
                 | homekit_permissions_notify, \
    .min_value = (float[]) {-90}, \
    .max_value = (float[]) {90}, \
    .min_step = (float[]) {1}, \
    .value = HOMEKIT_INT_(_value), \
    ##__VA_ARGS__

And in arduino_homekit_server.cpp, starting at line 303, it appears to be correctly formatting the json string from the iOS device into an int:

...
		case homekit_format_int:
			format_str = "int";
			break;
...
		if (format_str) {
			json_string(json, "format");
			json_string(json, format_str);
		}

And in the homekit_value_copy function from accessories.c, at line 73, it seems to be just copying the int value…

            case homekit_format_int:
                dst->int_value = src->int_value;
                break;

But I'm coming to this for the first time, and so I'm not sure I'm even on the right path.

I'm also not sure this isn't something to do with ESP8266 handling signed integers. I don't know much about its internals. The board I'm on is a LoLin NodeMCU.

Any help would be appreciated… and I am likewise happy to help any way I can.

TV Example

Hello, I create simple program to start and stop my TV using IR and simple switch button. I want to make more functions and looking for TV buttons example. Great library! Thanks!

HOMEKIT_MAX_CLIENTS - why 8?

Why is the default HOMEKIT_MAX_CLIENTS set to 8? It would be helpful to increase this, in homes with lots of Apple devices.

Unpredictable pairing with Homekit

Dear Mixiaoxiao, dear all,

First of all, thanks Mixiaoxiao for your work porting Homekit to ESP8266. This is a fantastic help for DIY hobbyists.

I am using your library ([email protected]) with an ESP8266 on a NodeMCU V3 board and I ‘m having some problems.

Sorry to bother with what might be a trivial problem.

For the sake of understanding, I'm using the temperature_sensor example you have provided.

The process of pairing seems very unpredictable. I could pair the device only once in 20 or 30 attempts.

Most of the time, the process stops at Pair setup step 2 / 3 with a message
`

[ 99510] pair_setup took 26664ms
homekit_client_process: [Client 1073682684] Finished processing
Current temperature: 19.0
Free heap: 39560, HomeKit clients: 1
operator(): MDNS call DynamicServiceTxtCallback
[ 99852] HomeKit: [Client 1073682684] Disconnected!
[ 99857] HomeKit: [Client 1073682684] Closing client connection
homekit_server_close_client: [Client 1073682684] The sockect is stopped
`
Sometimes, the log show that the device is paired :

`>>> [ 66273] HomeKit: [Client 1073678340] Pair Verify Step 2/2

homekit_server_on_pair_verify: [Client 1073678340] Decrypting payload
homekit_server_on_pair_verify: [Client 1073678340] Searching pairing with 37150F9A-FBD7-447C-8D2D-ED50E86365B8
[ 66296] HomeKit: [Client 1073678340] Found pairing with 37150F9A-FBD7-447C-8D2D-ED50E86365B8
homekit_server_on_pair_verify: [Client 1073678340] Verifying device signature
[ 66338] HomeKit: Call ge_double_scalarmult_vartime_lowmem in ge_low_mem.c
send_tlv_response: [Client 1073678340] Sending TLV response
client_send: [Client 1073678340] send data size=105, encrypted=false
write: [Client 1073678340] Sending data of size 105
[ 67871] HomeKit: [Client 1073678340] Verification successful, secure session established
[ 67879] pair_verify took 1606ms
[ 67883] HomeKit: Free heap: 41728
homekit_client_process: [Client 1073678340] Finished processing
[ 67903] HomeKit: [Client 1073678340] Disconnected!
[ 67908] HomeKit: [Client 1073678340] Closing client connection
homekit_server_close_client: [Client 1073678340] The sockect is stopped
operator(): MDNS call DynamicServiceTxtCallback`

But in reality, the HomeKit hub was not able to pair with the accessory.
My iPhone (iOS 13.5.1) shows "unable to add ... Could not connect to the accessory" (translated from French).

It looks like the connection was somehow broken. Have you ever encountered something like this ? Am I the one one having this problem ?

Thanks in advance for sharing your experience.
Regards

GarageDoor Example ?

Just wondering if there is any chance you could do a garage door opener example?

P.S. Loving your work!

Dimmable Lights

Hello, again thank you for your amazing work. I was wondering if you have some guidelines for how to control a dimmable light?

Error platformio

Good afternoon, I really like Your library on the Arduino IDE everything was fine, but I decided to use VSC. My code is the same as Yours with minor changes. Please help me. I can't compile the project in VSC PlatformIO. The compiler outputs the following errors:

My settings in platform.ini:


[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
; Using a library HomeKit-ESP8266 (7045)
;Using a library name ESP8266FtpServer (992)
;Using a library name DHT sensor library (19)
lib_deps =
7045
992
19
; set CPU frequency to 160MHz, to 80-Mhz 80000000L
board_build.f_cpu = 160000000L
; set FLASH frequency to 80MHz
board_build.f_flash = 80000000L
; set FLASH mode (qio, qoutm dio, dout)
board_build.flash_mode = qio
; Reset Method (ck, wifio, nodemcu)
upload_resetmethod = ck
; Flash Size https://github.com/esp8266/Arduino/tree/master/tools/sdk/ld
board_build.ldscript = eagle.flash.1m64.ld
;Upload Speed
upload_speed = 115200
;lwIP Variant
build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -D PIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK221 -D BEARSSL_SSL_BASIC -DNDEBUG -DVTABLES_IN_FLASH


Executing task in folder esp8266DHT21: C:\Users\rzhig.platformio\penv\Scripts\platformio.exe run <

Processing esp01_1m (platform: espressif8266; board: esp01_1m; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/esp01_1m.html
PLATFORM: Espressif 8266 2.6.2 > Espressif Generic ESP8266 ESP-01 1M
HARDWARE: ESP8266 160MHz, 80KB RAM, 1MB Flash
PACKAGES:

  • framework-arduinoespressif8266 3.20704.0 (2.7.4)
  • tool-esptool 1.413.0 (4.13)
  • tool-esptoolpy 1.20800.0 (2.8.0)
  • toolchain-xtensa 2.40802.200502 (4.8.2)
    LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    LibraryManager: Installing id=7045
    Using cache: C:\Users\rzhig.platformio.cache\2e\dd4ad81979d9bc876509cca35a118f2e
    HomeKit-ESP8266 @ 1.2.0 has been successfully installed!
    LibraryManager: Installing id=992
    Using cache: C:\Users\rzhig.platformio.cache\da\d16f40f3b4c5f862ad6f7d70c5cf71da
    esp8266FTPServer @ 1.0.1 has been successfully installed!
    LibraryManager: Installing id=19
    Using cache: C:\Users\rzhig.platformio.cache\bd\834944ae942986fabd8560ee9995cdbd
    DHT sensor library @ 1.3.10 has been successfully installed!
    Installing dependencies
    Looking for Adafruit Unified Sensor library in registry
    Found: https://platformio.org/lib/show/31/Adafruit Unified Sensor
    LibraryManager: Installing id=31
    Using cache: C:\Users\rzhig.platformio.cache\0b\e5cb7d3f156b54236879ddb31efac40b
    Adafruit Unified Sensor @ 1.1.4 has been successfully installed!
    Found 33 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- 1.2.0
    | |-- 1.0
    | |-- 1.2
    | | |-- 1.0
    |-- 1.3.10
    | |-- 1.1.4
    |-- 1.0.1
    | |-- 1.0
    |-- 1.0
    |-- 1.0
    | |-- 1.0
    Building in release mode
    Linking .pio\build\esp01_1m\firmware.elf
    c:/users/rzhig/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01_1m\src\main.cpp.o:(.text._Z16my_homekit_setupv+0x0): undefined reference to config' c:/users/rzhig/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01_1m\src\main.cpp.o:(.text._Z17my_homekit_reportv+0x8): undefined reference to cha_temperature'
    c:/users/rzhig/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01_1m\src\main.cpp.o:(.text._Z17my_homekit_reportv+0xc): undefined reference to cha_status_temp_active' c:/users/rzhig/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01_1m\src\main.cpp.o:(.text._Z17my_homekit_reportv+0x10): undefined reference to cha_status_temp_fault'
    c:/users/rzhig/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01_1m\src\main.cpp.o:(.text._Z17my_homekit_reportv+0x18): undefined reference to cha_humidity' c:/users/rzhig/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01_1m\src\main.cpp.o:(.text._Z17my_homekit_reportv+0x1c): undefined reference to cha_status_humi_active'
    c:/users/rzhig/.platformio/packages/toolchain-xtensa/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld.exe: .pio\build\esp01_1m\src\main.cpp.o:(.text._Z17my_homekit_reportv+0x20): undefined reference to `cha_status_humi_fault'
    collect2.exe: error: ld returned 1 exit status
    *** [.pio\build\esp01_1m\firmware.elf] Error 1
    ======================================================================================================== [FAILED] Took 5.11 seconds ========================================================================================================
    The terminal process "C:\Users\rzhig.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.


{
"resource": "/c:/Users/rzhig/Documents/PlatformIO/Projects/esp8266DHT21/include/my_accessory.h",
"owner": "C/C++",
"severity": 8,
"message": "a value of type "int" cannot be used to initialize an entity of type "homekit_permissions_t"",
"startLineNumber": 25,
"startColumn": 44,
"endLineNumber": 25,
"endColumn": 67
}
{
"resource": "/c:/Users/rzhig/Documents/PlatformIO/Projects/esp8266DHT21/include/my_accessory.h",
"owner": "C/C++",
"severity": 8,
"message": "a designator for an anonymous union member can only appear within braces corresponding to that anonymous union",
"startLineNumber": 57,
"startColumn": 5,
"endLineNumber": 57,
"endColumn": 22
}

Adding more lights with buttons

Hi! First thank you for your work, it's amazing!

I'm trying to understand how to control up to 3 lights with buttons (like you can do in the simple led example, which has a bug, when you turn off the light from the HomeKit app then you have to press twice the button to turn it on, but I don't care about that issue), the problem is to add more lights with a button for each one, I don't see how the code works and I tried every sketch I found online but everyone is using a different approach so it gets more and more confusing.

On the switch example (which works great) there is no button, I saw you comment "/report the switch value to HomeKit if it is changed (e.g. by a physical button)", but again I tried many things and I couldn't make it work.

Do you have an example to see how it would work? The final idea of the project is being able to control 3 lights with one button each. I always ended up with a problem identifying each button for each HomeKit service in my accessory.

Thank you so much!

More examples on the way

Hello
do you think you will release more example with more accessories?
Anyway, great job, I'll try to build my project with it (Motion sensor + sht30 sensor)

Arduino cannot execute

excuse me. I encountered a problem while testing the example. Aruino IDE tells me:
homekit/types.h: No such file or directory
homekit/homekit.h: No such file or directory
homekit/characteristics.h: No such file or directory

I installed through the management library

Question about delay() in the main loop...

If I understand correctly - delay in main loop is needed for the correct work of RTOS.
Can I use Ticker, or millisecond around all my functions in the loop instead of delay () to let RTOS to work 5, 10 ms, and use other timers in parallel with a interval longer then 5, 10 ms? Or are they anyway mix with each other and there may be problems?

simple_led_accessory.c:2:27: fatal error: homekit/types.h: No such file or directory

我用的终端编译提示无法找到types.h
库已放在/home/ubuntu/Arduino/libraries/HomeKit_ESP8266
并且在Arduino软件下也放了arduino/libraries/HomeKit_ESP8266
请教下是哪出了错误
ubuntu@VM-0-13-ubuntu:~/demo/WS2812B_Color_LED$ sudo arduino --board esp8266com:esp8266:generic --pref build.path=./bin --verify ws2812b.ino
Picked up JAVA_TOOL_OPTIONS:
Loading configuration...
Initializing packages...
Preparing boards...
Invalid library found in /opt/arduino/hardware/esp8266com/esp8266/libraries/SoftwareSerial: no headers files (.h) found in /opt/arduino/hardware/esp8266com/esp8266/libraries/SoftwareSerial
Invalid library found in /opt/arduino/hardware/esp8266com/esp8266/libraries/ESP8266SdFat: no headers files (.h) found in /opt/arduino/hardware/esp8266com/esp8266/libraries/ESP8266SdFat
Invalid library found in /opt/arduino/hardware/esp8266com/esp8266/libraries/SoftwareSerial: no headers files (.h) found in /opt/arduino/hardware/esp8266com/esp8266/libraries/SoftwareSerial
Invalid library found in /opt/arduino/hardware/esp8266com/esp8266/libraries/ESP8266SdFat: no headers files (.h) found in /opt/arduino/hardware/esp8266com/esp8266/libraries/ESP8266SdFat
Verifying...
simple_led_accessory.c:2:27: fatal error: homekit/types.h: No such file or directory
#include <homekit/types.h>
^
compilation terminated.
exit status 1

Using an Led Strip with this?

Sorry, I know that this is probably pretty basic, but what wondering how you would go about using an RGB strip with this. I have tried some others but this is the only one that I can actually get to show up on my phone as a device.

Matt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.