From bec3d91d98e46e1e79122e30918f2f8c48de5546 Mon Sep 17 00:00:00 2001 From: pulipakaa24 Date: Sat, 10 Jan 2026 23:19:31 -0600 Subject: [PATCH] Add mac address and other info to BLE. --- include/BLE.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/BLE.cpp b/include/BLE.cpp index 713cf0e..d649eda 100644 --- a/include/BLE.cpp +++ b/include/BLE.cpp @@ -6,6 +6,7 @@ #include "defines.h" #include #include "bmHTTP.hpp" +#include "esp_mac.h" std::atomic flag_scan_requested{false}; std::atomic credsGiven{false}; @@ -28,6 +29,7 @@ std::atomic authConfirmChar = nullptr; std::atomic credsChar = nullptr; std::atomic tokenChar = nullptr; std::atomic ssidRefreshChar = nullptr; +std::atomic deviceInfoChar = nullptr; NimBLEAdvertising* initBLE() { finalAuth = false; @@ -93,6 +95,27 @@ NimBLEAdvertising* initBLE() { ); connectConfirmChar.load()->createDescriptor("2902"); // Add BLE2902 descriptor for notifications + // 0x0006 - Device Info (READ) - MAC address and other device details + deviceInfoChar = pService->createCharacteristic( + "0006", + NIMBLE_PROPERTY::READ + ); + // Build device info JSON with MAC address + uint8_t mac[6]; + esp_read_mac(mac, ESP_MAC_WIFI_STA); + char macStr[18]; + snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + cJSON *infoRoot = cJSON_CreateObject(); + cJSON_AddStringToObject(infoRoot, "mac", macStr); + cJSON_AddStringToObject(infoRoot, "firmware", "1.0.0"); + cJSON_AddStringToObject(infoRoot, "model", "BlindMaster-C6"); + char *infoJson = cJSON_PrintUnformatted(infoRoot); + deviceInfoChar.load()->setValue(std::string(infoJson)); + cJSON_Delete(infoRoot); + free(infoJson); + // Start pService->start();