Troubleshooting multiple compilation errors in an ESP32 HomeKit project, with missing library files in the Arduino IDE

Hello, I’m working on a HomeKit Light Control project with an ESP32 board and coding in the Arduino IDE, but I’ve been facing persistent compilation errors for over a week. The main issue started with an error indicating “esp32-crypt.h” was missing (fatal error: soc/cpu.h: No such file or directory).

I attempted to resolve it by downloading esp32-crypt.h separately and adding it to my libraries, but this only led to further errors. After replacing the file from Google again, I encountered a new error:

error: 'WC_ESP32SHA' does not name a type

134 | WC_ESP32SHA ctx;

| ^~~~~~~~~~~

The errors are increasing, and I’m unable to compile successfully. My code setup involves three main files: Watertest.ino, my_accessory.c, and wifi_info.h. I’m using the Arduino-HomeKit-ESP32 library from Mixiaoxiao’s GitHub(GitHub - Mixiaoxiao/Arduino-HomeKit-ESP32: [Deprecated] Native Apple HomeKit accessory implementation for the ESP32 Arduino core.). This project is for controlling lights via HomeKit, and I would greatly appreciate any help to troubleshoot these errors!

I’ve successfully run the Switch example from the HomeKit ESP8266 library on my ESP8266 board without issues. However, when trying to run the same code on my ESP32 board, I’m encountering more errors. I need to run the HomeKit code on the ESP32 to control my lights for better performance.

So, I would request any professionals to understand my situation and help me to fix it.

Hardware - Esp-32
Software- Homekit libraries by Mixiaoxiao’s(GitHub - Mixiaoxiao/Arduino-HomeKit-ESP32: [Deprecated] Native Apple HomeKit accessory implementation for the ESP32 Arduino core.)
Examples- Done from the Esp8266 Switch examples by Mixiaoxiao's(GitHub - Mixiaoxiao/Arduino-HomeKit-ESP8266: Native Apple HomeKit accessory implementation for the ESP8266 Arduino core.)

Welcome to the forum

Please clarify whether you are using a Nano ESP32 board or a generic ESP32 board, bearing in mind the forum category that you posted in

Please do not post pictures of code

Please post your full sketches, using code tags when you do. This prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

You are doing the wrong thing. If you are missing libraries, use the Library Manager to install the Library, do NOT grab random files from the internet. Post your original source code in code tags here and I will have a look at what is needed.

Do you see Deprecated? This code likely no longer works.

Did you not see that the libraries are now officially supported by Espressif? The library name is esp-apple-homekit-adp Standard zip install method under Sketch/Include / Add Zip library
pic 1 is doc re no longer supported


pic 2 is steps to install official library

Using Generic Esp32 Board

THE CODE:
**WaterTest.ino:**

#include <Arduino.h>
#include <arduino_homekit_server.h>
#include "wifi_info.h"

#define LOG_D(fmt, ...) printf_P(PSTR(fmt "\n"), ##__VA_ARGS__);

void setup() {
  Serial.begin(115200);
  wifi_connect();  // in wifi_info.h
  //homekit_storage_reset(); // to remove the previous HomeKit pairing storage when you first run this new HomeKit example
  my_homekit_setup();
}

void loop() {
  my_homekit_loop();
  delay(10);
}

//==============================
// HomeKit setup and loop
//==============================

// access your HomeKit characteristics defined in my_accessory.c
extern "C" homekit_server_config_t config;
extern "C" homekit_characteristic_t cha_switch_on;
extern "C" homekit_characteristic_t cha_switch_on2;
extern "C" homekit_characteristic_t cha_switch_on3;
extern "C" homekit_characteristic_t cha_switch_on4;

static uint32_t next_heap_millis = 0;

#define PIN_SWITCH 5
#define PIN_SWITCH2 2
#define PIN_SWITCH3 14
#define PIN_SWITCH4 12

//Called when the switch value is changed by iOS Home APP
void cha_switch_on_setter(const homekit_value_t value) {
  bool on = value.bool_value;
  cha_switch_on.value.bool_value = on;  //sync the value
  LOG_D("Switch: %s", on ? "ON" : "OFF");
  digitalWrite(PIN_SWITCH, on ? LOW : HIGH);
}
void cha_switch_on_setter2(const homekit_value_t value) {
  bool on = value.bool_value;
  cha_switch_on2.value.bool_value = on;  //sync the value
  LOG_D("Switch: %s", on ? "ON" : "OFF");
  digitalWrite(PIN_SWITCH2, on ? LOW : HIGH);
}
void cha_switch_on_setter3(const homekit_value_t value) {
  bool on = value.bool_value;
  cha_switch_on3.value.bool_value = on;  //sync the value
  LOG_D("Switch: %s", on ? "ON" : "OFF");
  digitalWrite(PIN_SWITCH3, on ? LOW : HIGH);
}
void cha_switch_on_setter4(const homekit_value_t value) {
  bool on = value.bool_value;
  cha_switch_on4.value.bool_value = on;  //sync the value
  LOG_D("Switch: %s", on ? "ON" : "OFF");
  digitalWrite(PIN_SWITCH4, on ? LOW : HIGH);
}

void my_homekit_setup() {
  pinMode(PIN_SWITCH, OUTPUT);
  digitalWrite(PIN_SWITCH, HIGH);
  pinMode(PIN_SWITCH2, OUTPUT);
  digitalWrite(PIN_SWITCH2, HIGH);
  pinMode(PIN_SWITCH3, OUTPUT);
  digitalWrite(PIN_SWITCH3, HIGH);
  pinMode(PIN_SWITCH4, OUTPUT);
  digitalWrite(PIN_SWITCH4, HIGH);

  //Add the .setter function to get the switch-event sent from iOS Home APP.
  //The .setter should be added before arduino_homekit_setup.
  //HomeKit sever uses the .setter_ex internally, see homekit_accessories_init function.
  //Maybe this is a legacy design issue in the original esp-homekit library,
  //and I have no reason to modify this "feature".
  cha_switch_on.setter = cha_switch_on_setter;
  cha_switch_on2.setter = cha_switch_on_setter2;
  cha_switch_on3.setter = cha_switch_on_setter3;
  cha_switch_on4.setter = cha_switch_on_setter4;
  arduino_homekit_setup(&config);

  //report the switch value to HomeKit if it is changed (e.g. by a physical button)
  //bool switch_is_on = true/false;
  //cha_switch_on.value.bool_value = switch_is_on;
  //homekit_characteristic_notify(&cha_switch_on, cha_switch_on.value);
}

void my_homekit_loop() {
  arduino_homekit_loop();
  const uint32_t t = millis();
  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());
  }
}

> my_accessory.c

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

// Define characteristics for each switch
homekit_characteristic_t cha_switch_on = HOMEKIT_CHARACTERISTIC_(ON, false);
homekit_characteristic_t cha_switch_on2 = HOMEKIT_CHARACTERISTIC_(ON, false);
homekit_characteristic_t cha_switch_on3 = HOMEKIT_CHARACTERISTIC_(ON, false);
homekit_characteristic_t cha_switch_on4 = HOMEKIT_CHARACTERISTIC_(ON, false);

// Define the accessory information
homekit_characteristic_t name = HOMEKIT_CHARACTERISTIC_(NAME, "ESP32 Light Controller");
homekit_characteristic_t serial_number = HOMEKIT_CHARACTERISTIC_(SERIAL_NUMBER, "0123456");
homekit_characteristic_t manufacturer = HOMEKIT_CHARACTERISTIC_(MANUFACTURER, "Custom");
homekit_characteristic_t model = HOMEKIT_CHARACTERISTIC_(MODEL, "ESP32-Light");
homekit_characteristic_t firmware_revision = HOMEKIT_CHARACTERISTIC_(FIRMWARE_REVISION, "1.0");

// Accessory identification function
void accessory_identify(homekit_value_t _value) {
  printf("Accessory identified\n");
}

// Define the accessory and its services
homekit_accessory_t *accessories[] = {
  HOMEKIT_ACCESSORY(
      .id = 1,
      .category = homekit_accessory_category_switch,
      .services = (homekit_service_t *[]){
        HOMEKIT_SERVICE(
          ACCESSORY_INFORMATION,
          .characteristics = (homekit_characteristic_t *[]){
            &name,
            &manufacturer,
            &serial_number,
            &model,
            &firmware_revision,
            HOMEKIT_CHARACTERISTIC(IDENTIFY, accessory_identify),
            NULL }),
        HOMEKIT_SERVICE(SWITCH, .primary = true, .characteristics = (homekit_characteristic_t *[]){ HOMEKIT_CHARACTERISTIC(NAME, "Switch 1"), &cha_switch_on, NULL }), HOMEKIT_SERVICE(SWITCH, .characteristics = (homekit_characteristic_t *[]){ HOMEKIT_CHARACTERISTIC(NAME, "Switch 2"), &cha_switch_on2, NULL }), HOMEKIT_SERVICE(SWITCH, .characteristics = (homekit_characteristic_t *[]){ HOMEKIT_CHARACTERISTIC(NAME, "Switch 3"), &cha_switch_on3, NULL }), HOMEKIT_SERVICE(SWITCH, .characteristics = (homekit_characteristic_t *[]){ HOMEKIT_CHARACTERISTIC(NAME, "Switch 4"), &cha_switch_on4, NULL }), NULL }),
  NULL
};

// Configuration for the accessory
homekit_server_config_t config = {
  .accessories = accessories,
  .password = "111-11-111"  // Replace with your desired pairing code
};

wifi_info.h

/*
 * wifi_info.h
 *
 * Manages WiFi connection setup for the ESP32
 */

#ifndef WIFI_INFO_H_
#define WIFI_INFO_H_

#include <WiFi.h>

// Replace these with your WiFi credentials
const char *ssid = "Airtel_Zerotouch";
const char *password = "Airtel@123";

void wifi_connect() {
  WiFi.mode(WIFI_STA);          // Set the ESP32 to station mode
  WiFi.setAutoReconnect(true);  // Enable auto-reconnect
  WiFi.begin(ssid, password);   // Connect to WiFi

  Serial.println("Connecting to WiFi...");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);  // Wait for connection
    Serial.print(".");
  }

  Serial.println("\nWiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  // Print the local IP address
}

#endif /* WIFI_INFO_H_ */

Topic moved to a more generic forum category to avoid confusion

I've tried with that library. But still errors are popping out !!

/Users/jacobsamuel/Documents/Arduino/WaterTest/WaterTest.ino:2:10: fatal error: arduino_homekit_server.h: No such file or directory
2 | #include <arduino_homekit_server.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: arduino_homekit_server.h: No such file or directory

As far as I can tell, that 'kit' requires the IDF professional tool chain, NOT the hobbyist IDE. The instructions for how to install and use the library are there in the readme files and online in the github.
You should contact the people who sold you the kit for IDE instructions.

Yes, there is NO arduino_homekit_server.h in the new library. Contact the creator of your kit for new updated software that works with esp_apple_homekit

Can you guide me on how to get support or contact the creator for fixing this issue?

No, you bought it so you have the info to contact the creator. I mis-spoke when I said Arduino support.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.