diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..1e3f52b Binary files /dev/null and b/.DS_Store differ diff --git a/lib/esp_ibeacon/esp_ibeacon_api.cpp b/lib/esp_ibeacon/esp_ibeacon_api.cpp deleted file mode 100644 index 0f58782..0000000 --- a/lib/esp_ibeacon/esp_ibeacon_api.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ - - - -/**************************************************************************** -* -* This file is for iBeacon APIs. It supports both iBeacon encode and decode. -* -* iBeacon is a trademark of Apple Inc. Before building devices which use iBeacon technology, -* visit https://developer.apple.com/ibeacon/ to obtain a license. -* -****************************************************************************/ - -#include -#include -#include -#include - -#include "esp_gap_ble_api.h" -#include "esp_ibeacon_api.hpp" - - -const uint8_t uuid_zeros[ESP_UUID_LEN_128] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - -/* For iBeacon packet format, please refer to Apple "Proximity Beacon Specification" doc */ -/* Constant part of iBeacon data */ -esp_ble_ibeacon_head_t ibeacon_common_head = { - .flags = {0x02, 0x01, 0x06}, - .length = 0x1A, - .type = 0xFF, - .company_id = 0x004C, - .beacon_type = 0x1502 -}; - -/* Vendor part of iBeacon data*/ -esp_ble_ibeacon_vendor_t vendor_config = { - .proximity_uuid = ESP_UUID, - .major = ENDIAN_CHANGE_U16(ESP_MAJOR), //Major=ESP_MAJOR - .minor = ENDIAN_CHANGE_U16(ESP_MINOR), //Minor=ESP_MINOR - .measured_power = static_cast(0xC5) -}; - -bool esp_ble_is_ibeacon_packet (uint8_t *adv_data, uint8_t adv_data_len){ - bool result = false; - - if ((adv_data != NULL) && (adv_data_len == 0x1E)){ - if (!memcmp(adv_data, (uint8_t*)&ibeacon_common_head, sizeof(ibeacon_common_head))){ - result = true; - } - } - - return result; -} - -esp_err_t esp_ble_config_ibeacon_data (esp_ble_ibeacon_vendor_t *vendor_config, esp_ble_ibeacon_t *ibeacon_adv_data){ - if ((vendor_config == NULL) || (ibeacon_adv_data == NULL) || (!memcmp(vendor_config->proximity_uuid, uuid_zeros, sizeof(uuid_zeros)))){ - return ESP_ERR_INVALID_ARG; - } - - memcpy(&ibeacon_adv_data->ibeacon_head, &ibeacon_common_head, sizeof(esp_ble_ibeacon_head_t)); - memcpy(&ibeacon_adv_data->ibeacon_vendor, vendor_config, sizeof(esp_ble_ibeacon_vendor_t)); - - return ESP_OK; -} diff --git a/lib/esp_ibeacon/esp_ibeacon_api.hpp b/lib/esp_ibeacon/esp_ibeacon_api.hpp deleted file mode 100644 index c4ce409..0000000 --- a/lib/esp_ibeacon/esp_ibeacon_api.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ - - -/**************************************************************************** -* -* This file is for iBeacon definitions. It supports both iBeacon sender and receiver -* which is distinguished by macros IBEACON_SENDER and IBEACON_RECEIVER, -* -* iBeacon is a trademark of Apple Inc. Before building devices which use iBeacon technology, -* visit https://developer.apple.com/ibeacon/ to obtain a license. -* -****************************************************************************/ - -#include -#include -#include -#include - -#include "esp_gap_ble_api.h" -#include "esp_gattc_api.h" - -#define IBEACON_SENDER 0 -#define IBEACON_RECEIVER 1 -#define IBEACON_MODE CONFIG_IBEACON_MODE - -/* Major and Minor part are stored in big endian mode in iBeacon packet, - * need to use this macro to transfer while creating or processing - * iBeacon data */ -#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00)>>8) + (((x)&0xFF)<<8)) - -/* Espressif WeChat official account can be found using WeChat "Yao Yi Yao Zhou Bian", - * if device advertises using ESP defined UUID. - * Please refer to http://zb.weixin.qq.com for further information. */ -#define ESP_UUID {0xFD, 0xA5, 0x06, 0x93, 0xA4, 0xE2, 0x4F, 0xB1, 0xAF, 0xCF, 0xC6, 0xEB, 0x07, 0x64, 0x78, 0x25} -#define ESP_MAJOR 10167 -#define ESP_MINOR 61958 - - -typedef struct { - uint8_t flags[3]; - uint8_t length; - uint8_t type; - uint16_t company_id; - uint16_t beacon_type; -}__attribute__((packed)) esp_ble_ibeacon_head_t; - -typedef struct { - uint8_t proximity_uuid[16]; - uint16_t major; - uint16_t minor; - int8_t measured_power; -}__attribute__((packed)) esp_ble_ibeacon_vendor_t; - - -typedef struct { - esp_ble_ibeacon_head_t ibeacon_head; - esp_ble_ibeacon_vendor_t ibeacon_vendor; -}__attribute__((packed)) esp_ble_ibeacon_t; - - -/* For iBeacon packet format, please refer to Apple "Proximity Beacon Specification" doc */ -/* Constant part of iBeacon data */ -extern esp_ble_ibeacon_head_t ibeacon_common_head; - -bool esp_ble_is_ibeacon_packet (uint8_t *adv_data, uint8_t adv_data_len); - -esp_err_t esp_ble_config_ibeacon_data (esp_ble_ibeacon_vendor_t *vendor_config, esp_ble_ibeacon_t *ibeacon_adv_data); diff --git a/platformio.ini b/platformio.ini index 568f6c2..b27d08c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,21 +9,23 @@ ; https://docs.platformio.org/page/projectconf.html ; Ducted A/C Variant -[env:ducted] +[env:satitm-ducted] platform = espressif32 board = wt32-eth01 framework = arduino lib_deps = siwats/ESPMegaPROR3@^2.9.4 monitor_speed = 115200 board_build.partitions = partitions_custom.csv -build_flags = -DCORE_DEBUG_LEVEL=0 -DSW_VERSION='"cud-ibeacon-duct"' -DBOARD_MODEL='"ESPMegaPRO R3.3c"' -DAC_TYPE=AC_TYPE_DUCTED +board_upload.flash_size = 4MB +build_flags = -DCORE_DEBUG_LEVEL=0 -DSW_VERSION='"cud-dev-duct"' -DBOARD_MODEL='"ESPMegaPRO R3.3c"' -DAC_TYPE=AC_TYPE_DUCTED ; Ceiling A/C Variant (and newer ducted models) -[env:ceiling] +[env:satitm-ceiling] platform = espressif32 board = wt32-eth01 framework = arduino lib_deps = siwats/ESPMegaPROR3@^2.9.4 monitor_speed = 115200 board_build.partitions = partitions_custom.csv -build_flags = -DCORE_DEBUG_LEVEL=0 -DSW_VERSION='"cud-ibeacon-ceiling"' -DBOARD_MODEL='"ESPMegaPRO R3.3c"' -DAC_TYPE=AC_TYPE_CEILING \ No newline at end of file +board_upload.flash_size = 4MB +build_flags = -DCORE_DEBUG_LEVEL=0 -DSW_VERSION='"cud-dev-ceiling"' -DBOARD_MODEL='"ESPMegaPRO R3.3c"' -DAC_TYPE=AC_TYPE_CEILING \ No newline at end of file diff --git a/src/config.hpp b/src/config.hpp index f680ba7..26e4348 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -25,14 +25,6 @@ #define MOSQUITO_ZAPPER_PIN 8 // There are one power relay for the socket #define SOCKET_CONTACTOR_PIN 9 - -/*********************************************** - * iBeacon Settings * - ***********************************************/ -#define ESP_MAJOR 10167 -#define ESP_MINOR 61958 -// UUID is now dynamically generated per device from MAC address - /*********************************************** * Air Conditioner * ***********************************************/ @@ -96,4 +88,4 @@ #define AQI_REQUEST_TOPIC "/iqair/request" #define AC_LOCK_RELATIVE_TOPIC "/ac/lock" #define AC_TEMP_LOWER_BOUND_RELATIVE_TOPIC "/ac/temp_bound/lower" -#define AC_TEMP_UPPER_BOUND_RELATIVE_TOPIC "/ac/temp_bound/upper" \ No newline at end of file +#define AC_TEMP_UPPER_BOUND_RELATIVE_TOPIC "/ac/temp_bound/upper" diff --git a/src/main.cpp b/src/main.cpp index 9c0a1d2..1521d55 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,46 +36,10 @@ CUDDisplay cudDisplay = CUDDisplay(&cud_display_conf); ESPMegaDisplayOTA cudDisplayOTA = ESPMegaDisplayOTA(); ESPMegaDisplayOTA internalDisplayOTA = ESPMegaDisplayOTA(); -// iBeacon configuration -static esp_ble_adv_params_t ble_adv_params = { - .adv_int_min = 0x20, - .adv_int_max = 0x40, - .adv_type = ADV_TYPE_NONCONN_IND, - .own_addr_type = BLE_ADDR_TYPE_PUBLIC, - .channel_map = ADV_CHNL_ALL, - .adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY, -}; - -esp_ble_ibeacon_vendor_t vendor_config_custom; - /************************************************ * End of Global Variables * ************************************************/ -/** - * Generate a unique UUID based on ESP32's chip ID - * @param uuid Output buffer for the UUID (16 bytes) - */ -void generate_unique_uuid(uint8_t *uuid) { - // Get ESP32 chip ID (6 bytes) - uint8_t mac[6]; - esp_efuse_mac_get_default(mac); - - // Use a fixed prefix (8 bytes) - static const uint8_t prefix[8] = {0xFD, 0xA5, 0x06, 0x93, 0xA4, 0xE2, 0x4F, 0xB1}; - - // Copy prefix to first 8 bytes of UUID - memcpy(uuid, prefix, 8); - - // Copy MAC address to next 6 bytes - memcpy(uuid + 8, mac, 6); - - // Fill the remaining 2 bytes with a hash of the MAC - uint16_t hash = mac[0] + (mac[1] << 8) + mac[2] + (mac[3] << 8) + mac[4] + (mac[5] << 8); - uuid[14] = hash & 0xFF; - uuid[15] = (hash >> 8) & 0xFF; -} - void setup() { // Initialize both displayports @@ -158,30 +122,6 @@ void setup() espmega.iot->registerMqttCallback(handle_mqtt_message); cudDisplayOTA.begin("/cuddisp", &cudDisplay, espmega.webServer); internalDisplayOTA.begin("/intdisp", espmega.display, espmega.webServer); - - // Initialize iBeacon with unique UUID - ESP_LOGV("CUD IoT OS", "Initializing iBeacon"); - esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); - esp_bt_controller_init(&bt_cfg); - esp_bt_controller_enable(ESP_BT_MODE_BLE); - esp_bluedroid_init(); - esp_bluedroid_enable(); - esp_ble_gap_register_callback(esp_gap_cb); - - // Generate unique UUID for this device - uint8_t uuid[16]; - generate_unique_uuid(uuid); - - // Configure iBeacon with unique UUID - memcpy(vendor_config_custom.proximity_uuid, uuid, sizeof(uuid)); - vendor_config_custom.major = ENDIAN_CHANGE_U16(ESP_MAJOR); - vendor_config_custom.minor = ENDIAN_CHANGE_U16(ESP_MINOR); - vendor_config_custom.measured_power = static_cast(0xC5); - - esp_ble_ibeacon_t ibeacon_adv_data; - esp_ble_config_ibeacon_data(&vendor_config_custom, &ibeacon_adv_data); - esp_ble_gap_config_adv_data_raw((uint8_t *)&ibeacon_adv_data, sizeof(ibeacon_adv_data)); - #ifdef TAMPER_DETECTION espmega.display->registerPageChangeCallback(pageChangeCallback); espmega.display->registerTouchCallback(touchCallback); @@ -216,35 +156,6 @@ void handle_mqtt_message(char *topic, char *payload) ESP_LOGD("CUD IoT OS", "MQTT Message Received: %s, %s", topic, payload); } -static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) -{ - esp_err_t err; - - switch (event) { - case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: { - esp_ble_gap_start_advertising(&ble_adv_params); - break; - } - case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: - // adv start complete event to indicate adv start successfully or failed - if ((err = param->adv_start_cmpl.status) != ESP_BT_STATUS_SUCCESS) { - ESP_LOGE("iBeacon", "Advertising start failed, error %s", esp_err_to_name(err)); - } else { - ESP_LOGI("iBeacon", "Advertising start successfully"); - } - break; - case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: - if ((err = param->adv_stop_cmpl.status) != ESP_BT_STATUS_SUCCESS) { - ESP_LOGE("iBeacon", "Advertising stop failed, error %s", esp_err_to_name(err)); - } else { - ESP_LOGI("iBeacon", "Advertising stop successfully"); - } - break; - default: - break; - } -} - #ifdef TAMPER_DETECTION void pageChangeCallback(uint8_t page) { diff --git a/src/main.hpp b/src/main.hpp index 5ed5d98..3495415 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -14,10 +14,6 @@ #include #include #include -#include -#include -#include -#include #include "lcd_elements.hpp" #include "ir_codes.hpp" #include "display.hpp" @@ -31,7 +27,6 @@ void loop(); void send_stop_bytes(HardwareSerial &uart); void handle_input_change(uint8_t pin, bool state); void handle_mqtt_message(char *topic, char *payload); -static void esp_gap_cb(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param); #ifdef TAMPER_DETECTION void pageChangeCallback(uint8_t page);