From 9137c5acb15654ac772b445647e009ca4be8bd3e Mon Sep 17 00:00:00 2001
From: Nic Limper
Date: Sat, 24 Feb 2024 14:01:27 +0100
Subject: [PATCH] add BLE to all ESP32-S3 based AP's (default disabled; enable
in the config screen if needed)
---
ESP32_AP-Flasher/include/tag_db.h | 1 +
ESP32_AP-Flasher/platformio.ini | 3 +++
ESP32_AP-Flasher/src/ble_writer.cpp | 1 +
ESP32_AP-Flasher/src/main.cpp | 4 +++-
ESP32_AP-Flasher/src/tag_db.cpp | 2 ++
ESP32_AP-Flasher/src/web.cpp | 8 ++++++++
ESP32_AP-Flasher/wwwroot/index.html | 7 +++++++
ESP32_AP-Flasher/wwwroot/main.js | 5 +++++
8 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/ESP32_AP-Flasher/include/tag_db.h b/ESP32_AP-Flasher/include/tag_db.h
index 910ad43c..a22458b6 100644
--- a/ESP32_AP-Flasher/include/tag_db.h
+++ b/ESP32_AP-Flasher/include/tag_db.h
@@ -67,6 +67,7 @@ struct Config {
char timeZone[52];
uint8_t sleepTime1;
uint8_t sleepTime2;
+ uint8_t ble;
String repo;
String env;
};
diff --git a/ESP32_AP-Flasher/platformio.ini b/ESP32_AP-Flasher/platformio.ini
index 1d2bf26a..fc1de726 100644
--- a/ESP32_AP-Flasher/platformio.ini
+++ b/ESP32_AP-Flasher/platformio.ini
@@ -137,6 +137,7 @@ build_flags =
-D CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
-D POWER_RAMPING
-D POWER_HIGH_SIDE_DRIVER
+ -D HAS_BLE_WRITER
-D FLASHER_AP_SS=4
-D FLASHER_AP_CLK=5
-D FLASHER_AP_MOSI=7
@@ -225,6 +226,7 @@ build_flags =
-D POWER_NO_SOFT_POWER
-D BOARD_HAS_PSRAM
-D CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
+ -D HAS_BLE_WRITER
-D FLASHER_AP_SS=-1
-D FLASHER_AP_CLK=-1
-D FLASHER_AP_MOSI=-1
@@ -385,6 +387,7 @@ build_flags =
-D POWER_RAMPING
-D POWER_HIGH_SIDE_DRIVER
-D CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y
+ -D HAS_BLE_WRITER
-D FLASHER_AP_SS=-1
-D FLASHER_AP_CLK=-1
-D FLASHER_AP_MOSI=-1
diff --git a/ESP32_AP-Flasher/src/ble_writer.cpp b/ESP32_AP-Flasher/src/ble_writer.cpp
index b42a9864..299e4a2d 100644
--- a/ESP32_AP-Flasher/src/ble_writer.cpp
+++ b/ESP32_AP-Flasher/src/ble_writer.cpp
@@ -147,6 +147,7 @@ void BLE_startScan(uint32_t timeout) {
void BLETask(void* parameter) {
vTaskDelay(5000 / portTICK_PERIOD_MS);
+ Serial.println("BLE task started");
BLEDevice::init("");
while (1) {
switch (ble_main_state) {
diff --git a/ESP32_AP-Flasher/src/main.cpp b/ESP32_AP-Flasher/src/main.cpp
index 9960e7ed..8ea93c83 100644
--- a/ESP32_AP-Flasher/src/main.cpp
+++ b/ESP32_AP-Flasher/src/main.cpp
@@ -139,7 +139,9 @@ void setup() {
vTaskDelay(10 / portTICK_PERIOD_MS);
#ifdef HAS_BLE_WRITER
- xTaskCreate(BLETask, "BLE Writer", 12000, NULL, 5, NULL);
+ if (config.ble) {
+ xTaskCreate(BLETask, "BLE Writer", 12000, NULL, 5, NULL);
+ }
#endif
#ifdef HAS_USB
diff --git a/ESP32_AP-Flasher/src/tag_db.cpp b/ESP32_AP-Flasher/src/tag_db.cpp
index a5234315..ef8aa815 100644
--- a/ESP32_AP-Flasher/src/tag_db.cpp
+++ b/ESP32_AP-Flasher/src/tag_db.cpp
@@ -325,6 +325,7 @@ void initAPconfig() {
config.lock = APconfig.containsKey("lock") ? APconfig["lock"] : 0;
config.sleepTime1 = APconfig.containsKey("sleeptime1") ? APconfig["sleeptime1"] : 0;
config.sleepTime2 = APconfig.containsKey("sleeptime2") ? APconfig["sleeptime2"] : 0;
+ config.ble = APconfig.containsKey("ble") ? APconfig["ble"] : 0;
// default wifi power 8.5 dbM
// see https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/src/WiFiGeneric.h#L111
config.wifiPower = APconfig.containsKey("wifipower") ? APconfig["wifipower"] : 34;
@@ -354,6 +355,7 @@ void saveAPconfig() {
APconfig["timezone"] = config.timeZone;
APconfig["sleeptime1"] = config.sleepTime1;
APconfig["sleeptime2"] = config.sleepTime2;
+ APconfig["ble"] = config.ble;
APconfig["repo"] = config.repo;
APconfig["env"] = config.env;
serializeJsonPretty(APconfig, configFile);
diff --git a/ESP32_AP-Flasher/src/web.cpp b/ESP32_AP-Flasher/src/web.cpp
index c98bbc68..2a1dffae 100644
--- a/ESP32_AP-Flasher/src/web.cpp
+++ b/ESP32_AP-Flasher/src/web.cpp
@@ -503,6 +503,11 @@ void init_web() {
response->print("\"hasFlasher\": \"1\", ");
#else
response->print("\"hasFlasher\": \"0\", ");
+#endif
+#ifdef HAS_BLE_WRITER
+ response->print("\"hasBLE\": \"1\", ");
+#else
+ response->print("\"hasBLE\": \"0\", ");
#endif
response->print("\"apstate\": \"" + String(apInfo.state) + "\"");
@@ -561,6 +566,9 @@ void init_web() {
if (request->hasParam("lock", true)) {
config.lock = static_cast(request->getParam("lock", true)->value().toInt());
}
+ if (request->hasParam("ble", true)) {
+ config.ble = static_cast(request->getParam("ble", true)->value().toInt());
+ }
if (request->hasParam("sleeptime1", true)) {
config.sleepTime1 = static_cast(request->getParam("sleeptime1", true)->value().toInt());
config.sleepTime2 = static_cast(request->getParam("sleeptime2", true)->value().toInt());
diff --git a/ESP32_AP-Flasher/wwwroot/index.html b/ESP32_AP-Flasher/wwwroot/index.html
index a8b1dabe..937e1795 100644
--- a/ESP32_AP-Flasher/wwwroot/index.html
+++ b/ESP32_AP-Flasher/wwwroot/index.html
@@ -289,6 +289,13 @@ options:
+
+
+
+