[BT] Add gateway deactivation/activation command (#1821)
This commit is contained in:
1 parent
771b792484
commit
7f9f042f7c
6 files changed
+103
-45
No files matched your search
@@ -26,6 +26,16 @@ With the ability to monitor and analyze data such as temperature, humidity, mois
|
|||||||
Support the project by purchasing the [Theengs plug](https://shop.theengs.io/products/theengs-plug-smart-plug-ble-gateway-and-energy-consumption)
|
Support the project by purchasing the [Theengs plug](https://shop.theengs.io/products/theengs-plug-smart-plug-ble-gateway-and-energy-consumption)
|
||||||
The plug is available in North America only, other regions are planned.
|
The plug is available in North America only, other regions are planned.
|
||||||
|
|
||||||
|
## Disable or enable the BLE gateway (default: true, available with HA discovery)
|
||||||
|
|
||||||
|
If you want to deactivate the BLE gateway:
|
||||||
|
|
||||||
|
`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"enabled":false}'`
|
||||||
|
|
||||||
|
If you want to activate the BLE gateway:
|
||||||
|
|
||||||
|
`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/config -m '{"enabled":true}'`
|
||||||
|
|
||||||
## Receiving signals from [compatible BLE sensors](https://decoder.theengs.io/devices/devices_by_brand.html) to publish it to an MQTT broker.
|
## Receiving signals from [compatible BLE sensors](https://decoder.theengs.io/devices/devices_by_brand.html) to publish it to an MQTT broker.
|
||||||
To receive data from BLE sensors you can use an ESP32-based device with a programming USB port or use a Serial adapter.
|
To receive data from BLE sensors you can use an ESP32-based device with a programming USB port or use a Serial adapter.
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -6,7 +6,7 @@
|
|||||||
# include "ZgatewayBLEConnect.h"
|
# include "ZgatewayBLEConnect.h"
|
||||||
# define convertTemp_CtoF(c) ((c * 1.8) + 32)
|
# define convertTemp_CtoF(c) ((c * 1.8) + 32)
|
||||||
|
|
||||||
extern bool ProcessLock;
|
extern bool BTProcessLock;
|
||||||
extern std::vector<BLEdevice*> devices;
|
extern std::vector<BLEdevice*> devices;
|
||||||
|
|
||||||
NimBLERemoteCharacteristic* zBLEConnect::getCharacteristic(const NimBLEUUID& service,
|
NimBLERemoteCharacteristic* zBLEConnect::getCharacteristic(const NimBLEUUID& service,
|
||||||
@@ -135,7 +135,7 @@ void LYWSD03MMC_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pD
|
|||||||
if (m_taskHandle == nullptr) {
|
if (m_taskHandle == nullptr) {
|
||||||
return; // unexpected notification
|
return; // unexpected notification
|
||||||
}
|
}
|
||||||
if (!ProcessLock) {
|
if (!BTProcessLock) {
|
||||||
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
||||||
|
|
||||||
if (length == 5) {
|
if (length == 5) {
|
||||||
@@ -167,7 +167,7 @@ void LYWSD03MMC_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pD
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.trace(F("Callback process canceled by processLock" CR));
|
Log.trace(F("Callback process canceled by BTProcessLock" CR));
|
||||||
}
|
}
|
||||||
|
|
||||||
xTaskNotifyGive(m_taskHandle);
|
xTaskNotifyGive(m_taskHandle);
|
||||||
@@ -199,7 +199,7 @@ void DT24_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, s
|
|||||||
return; // unexpected notification
|
return; // unexpected notification
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ProcessLock) {
|
if (!BTProcessLock) {
|
||||||
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
||||||
if (length == 20) {
|
if (length == 20) {
|
||||||
m_data.assign(pData, pData + length);
|
m_data.assign(pData, pData + length);
|
||||||
@@ -232,7 +232,7 @@ void DT24_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, s
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.trace(F("Callback process canceled by processLock" CR));
|
Log.trace(F("Callback process canceled by BTProcessLock" CR));
|
||||||
}
|
}
|
||||||
|
|
||||||
xTaskNotifyGive(m_taskHandle);
|
xTaskNotifyGive(m_taskHandle);
|
||||||
@@ -264,7 +264,7 @@ void BM2_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, si
|
|||||||
return; // unexpected notification
|
return; // unexpected notification
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ProcessLock) {
|
if (!BTProcessLock) {
|
||||||
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
||||||
if (length == 16) {
|
if (length == 16) {
|
||||||
Log.trace(F("Device identified creating BLE buffer" CR));
|
Log.trace(F("Device identified creating BLE buffer" CR));
|
||||||
@@ -309,7 +309,7 @@ void BM2_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, si
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.trace(F("Callback process canceled by processLock" CR));
|
Log.trace(F("Callback process canceled by BTProcessLock" CR));
|
||||||
}
|
}
|
||||||
|
|
||||||
xTaskNotifyGive(m_taskHandle);
|
xTaskNotifyGive(m_taskHandle);
|
||||||
@@ -375,7 +375,7 @@ void XMWSDJ04MMC_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* p
|
|||||||
if (m_taskHandle == nullptr) {
|
if (m_taskHandle == nullptr) {
|
||||||
return; // unexpected notification
|
return; // unexpected notification
|
||||||
}
|
}
|
||||||
if (!ProcessLock) {
|
if (!BTProcessLock) {
|
||||||
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
||||||
|
|
||||||
if (length == 6) {
|
if (length == 6) {
|
||||||
@@ -399,7 +399,7 @@ void XMWSDJ04MMC_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* p
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.trace(F("Callback process canceled by processLock" CR));
|
Log.trace(F("Callback process canceled by BTProcessLock" CR));
|
||||||
}
|
}
|
||||||
|
|
||||||
xTaskNotifyGive(m_taskHandle);
|
xTaskNotifyGive(m_taskHandle);
|
||||||
@@ -430,7 +430,7 @@ void SBS1_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, s
|
|||||||
if (m_taskHandle == nullptr) {
|
if (m_taskHandle == nullptr) {
|
||||||
return; // unexpected notification
|
return; // unexpected notification
|
||||||
}
|
}
|
||||||
if (!ProcessLock) {
|
if (!BTProcessLock) {
|
||||||
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
Log.trace(F("Callback from %s characteristic" CR), pChar->getUUID().toString().c_str());
|
||||||
|
|
||||||
if (length) {
|
if (length) {
|
||||||
@@ -440,7 +440,7 @@ void SBS1_connect::notifyCB(NimBLERemoteCharacteristic* pChar, uint8_t* pData, s
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.trace(F("Callback process canceled by processLock" CR));
|
Log.trace(F("Callback process canceled by BTProcessLock" CR));
|
||||||
}
|
}
|
||||||
|
|
||||||
xTaskNotifyGive(m_taskHandle);
|
xTaskNotifyGive(m_taskHandle);
|
||||||
|
|||||||
+47
-25
@@ -104,6 +104,7 @@ void BTConfig_init() {
|
|||||||
BTConfig.presenceAwayTimer = PresenceAwayTimer;
|
BTConfig.presenceAwayTimer = PresenceAwayTimer;
|
||||||
BTConfig.movingTimer = MovingTimer;
|
BTConfig.movingTimer = MovingTimer;
|
||||||
BTConfig.forcePassiveScan = false;
|
BTConfig.forcePassiveScan = false;
|
||||||
|
BTConfig.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long timeBetweenConnect = 0;
|
unsigned long timeBetweenConnect = 0;
|
||||||
@@ -133,6 +134,7 @@ String stateBTMeasures(bool start) {
|
|||||||
jo["presenceawaytimer"] = BTConfig.presenceAwayTimer;
|
jo["presenceawaytimer"] = BTConfig.presenceAwayTimer;
|
||||||
jo["movingtimer"] = BTConfig.movingTimer;
|
jo["movingtimer"] = BTConfig.movingTimer;
|
||||||
jo["forcepassivescan"] = BTConfig.forcePassiveScan;
|
jo["forcepassivescan"] = BTConfig.forcePassiveScan;
|
||||||
|
jo["enabled"] = BTConfig.enabled;
|
||||||
jo["bletaskstack"] = uxTaskGetStackHighWaterMark(xProcBLETaskHandle);
|
jo["bletaskstack"] = uxTaskGetStackHighWaterMark(xProcBLETaskHandle);
|
||||||
jo["blecoretaskstack"] = uxTaskGetStackHighWaterMark(xCoreTaskHandle);
|
jo["blecoretaskstack"] = uxTaskGetStackHighWaterMark(xCoreTaskHandle);
|
||||||
|
|
||||||
@@ -178,6 +180,13 @@ void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) {
|
|||||||
eraseTopic("number", (char*)getUniqueId("intervalacts", "").c_str());
|
eraseTopic("number", (char*)getUniqueId("intervalacts", "").c_str());
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
// Identify if the gateway is enabled or not and stop start accordingly
|
||||||
|
if (BTdata.containsKey("enabled") && BTdata["enabled"] == false && BTConfig.enabled == true) {
|
||||||
|
stopProcessing();
|
||||||
|
} else if (BTdata.containsKey("enabled") && BTdata["enabled"] == true && BTConfig.enabled == false) {
|
||||||
|
BTProcessLock = false;
|
||||||
|
setupBTTasksAndBLE();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Config_update(BTdata, "adaptivescan", BTConfig.adaptiveScan);
|
Config_update(BTdata, "adaptivescan", BTConfig.adaptiveScan);
|
||||||
// Home Assistant presence message
|
// Home Assistant presence message
|
||||||
@@ -225,6 +234,8 @@ void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) {
|
|||||||
Config_update(BTdata, "pubBeaconUuidForTopic", BTConfig.pubBeaconUuidForTopic);
|
Config_update(BTdata, "pubBeaconUuidForTopic", BTConfig.pubBeaconUuidForTopic);
|
||||||
// Disable Whitelist & Blacklist
|
// Disable Whitelist & Blacklist
|
||||||
Config_update(BTdata, "ignoreWBlist", (BTConfig.ignoreWBlist));
|
Config_update(BTdata, "ignoreWBlist", (BTConfig.ignoreWBlist));
|
||||||
|
// Enable or disable the BT gateway
|
||||||
|
Config_update(BTdata, "enabled", BTConfig.enabled);
|
||||||
|
|
||||||
stateBTMeasures(startup);
|
stateBTMeasures(startup);
|
||||||
|
|
||||||
@@ -266,6 +277,7 @@ void BTConfig_fromJson(JsonObject& BTdata, bool startup = false) {
|
|||||||
jo["presenceawaytimer"] = BTConfig.presenceAwayTimer;
|
jo["presenceawaytimer"] = BTConfig.presenceAwayTimer;
|
||||||
jo["movingtimer"] = BTConfig.movingTimer;
|
jo["movingtimer"] = BTConfig.movingTimer;
|
||||||
jo["forcepassivescan"] = BTConfig.forcePassiveScan;
|
jo["forcepassivescan"] = BTConfig.forcePassiveScan;
|
||||||
|
jo["enabled"] = BTConfig.enabled;
|
||||||
// Save config into NVS (non-volatile storage)
|
// Save config into NVS (non-volatile storage)
|
||||||
String conf = "";
|
String conf = "";
|
||||||
serializeJson(jsonBuffer, conf);
|
serializeJson(jsonBuffer, conf);
|
||||||
@@ -580,7 +592,7 @@ void procBLETask(void* pvParameters) {
|
|||||||
xQueueReceive(BLEQueue, &advertisedDevice, portMAX_DELAY);
|
xQueueReceive(BLEQueue, &advertisedDevice, portMAX_DELAY);
|
||||||
// Feed the watchdog
|
// Feed the watchdog
|
||||||
//esp_task_wdt_reset();
|
//esp_task_wdt_reset();
|
||||||
if (!ProcessLock) {
|
if (!BTProcessLock) {
|
||||||
Log.trace(F("Creating BLE buffer" CR));
|
Log.trace(F("Creating BLE buffer" CR));
|
||||||
StaticJsonDocument<JSON_MSG_BUFFER> BLEdataBuffer;
|
StaticJsonDocument<JSON_MSG_BUFFER> BLEdataBuffer;
|
||||||
JsonObject BLEdata = BLEdataBuffer.to<JsonObject>();
|
JsonObject BLEdata = BLEdataBuffer.to<JsonObject>();
|
||||||
@@ -675,7 +687,7 @@ void BLEscan() {
|
|||||||
* Connect to BLE devices and initiate the callbacks with a service/characteristic request
|
* Connect to BLE devices and initiate the callbacks with a service/characteristic request
|
||||||
*/
|
*/
|
||||||
void BLEconnect() {
|
void BLEconnect() {
|
||||||
if (!ProcessLock) {
|
if (!BTProcessLock) {
|
||||||
Log.notice(F("BLE Connect begin" CR));
|
Log.notice(F("BLE Connect begin" CR));
|
||||||
do {
|
do {
|
||||||
for (vector<BLEdevice*>::iterator it = devices.begin(); it != devices.end(); ++it) {
|
for (vector<BLEdevice*>::iterator it = devices.begin(); it != devices.end(); ++it) {
|
||||||
@@ -742,33 +754,39 @@ void BLEconnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stopProcessing() {
|
void stopProcessing() {
|
||||||
ProcessLock = true;
|
if (BTConfig.enabled) {
|
||||||
// We stop the scan
|
BTProcessLock = true;
|
||||||
Log.notice(F("Stopping BLE scan" CR));
|
// We stop the scan
|
||||||
BLEScan* pBLEScan = BLEDevice::getScan();
|
Log.notice(F("Stopping BLE scan" CR));
|
||||||
if (pBLEScan->isScanning()) {
|
BLEScan* pBLEScan = BLEDevice::getScan();
|
||||||
pBLEScan->stop();
|
if (pBLEScan->isScanning()) {
|
||||||
|
pBLEScan->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xSemaphoreTake(semaphoreBLEOperation, pdMS_TO_TICKS(5000)) == pdTRUE) {
|
||||||
|
Log.notice(F("Stopping BLE tasks" CR));
|
||||||
|
//Suspending, deleting tasks and stopping BT to free memory
|
||||||
|
vTaskSuspend(xCoreTaskHandle);
|
||||||
|
vTaskDelete(xCoreTaskHandle);
|
||||||
|
vTaskSuspend(xProcBLETaskHandle);
|
||||||
|
vTaskDelete(xProcBLETaskHandle);
|
||||||
|
xSemaphoreGive(semaphoreBLEOperation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Log.notice(F("Stopping BLE tasks" CR));
|
|
||||||
//Suspending, deleting tasks and stopping BT to free memory
|
|
||||||
vTaskSuspend(xCoreTaskHandle);
|
|
||||||
vTaskDelete(xCoreTaskHandle);
|
|
||||||
vTaskSuspend(xProcBLETaskHandle);
|
|
||||||
vTaskDelete(xProcBLETaskHandle);
|
|
||||||
Log.notice(F("BLE gateway stopped %T, free heap: %d" CR), ESP.getFreeHeap());
|
Log.notice(F("BLE gateway stopped %T, free heap: %d" CR), ESP.getFreeHeap());
|
||||||
}
|
}
|
||||||
|
|
||||||
void coreTask(void* pvParameters) {
|
void coreTask(void* pvParameters) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!ProcessLock) {
|
if (!BTProcessLock) {
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (client.state() != 0 && n <= InitialMQTTConnectionTimeout && !ProcessLock) {
|
while (client.state() != 0 && n <= InitialMQTTConnectionTimeout && !BTProcessLock) {
|
||||||
n++;
|
n++;
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
if (client.state() != 0) {
|
if (client.state() != 0) {
|
||||||
Log.warning(F("MQTT client disconnected no BLE scan" CR));
|
Log.warning(F("MQTT client disconnected no BLE scan" CR));
|
||||||
} else if (!ProcessLock) {
|
} else if (!BTProcessLock) {
|
||||||
if (xSemaphoreTake(semaphoreBLEOperation, pdMS_TO_TICKS(30000)) == pdTRUE) {
|
if (xSemaphoreTake(semaphoreBLEOperation, pdMS_TO_TICKS(30000)) == pdTRUE) {
|
||||||
BLEscan();
|
BLEscan();
|
||||||
// Launching a connect every TimeBtwConnect
|
// Launching a connect every TimeBtwConnect
|
||||||
@@ -813,6 +831,7 @@ void deepSleep(uint64_t time_in_us) {
|
|||||||
|
|
||||||
Log.trace(F("Deactivating ESP32 components" CR));
|
Log.trace(F("Deactivating ESP32 components" CR));
|
||||||
stopProcessing();
|
stopProcessing();
|
||||||
|
ProcessLock = true;
|
||||||
// Ignore the deprecated warning, this call is necessary here.
|
// Ignore the deprecated warning, this call is necessary here.
|
||||||
# pragma GCC diagnostic push
|
# pragma GCC diagnostic push
|
||||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
@@ -891,6 +910,7 @@ void setupBT() {
|
|||||||
Log.notice(F("Presence Away Timer: %d" CR), BTConfig.presenceAwayTimer);
|
Log.notice(F("Presence Away Timer: %d" CR), BTConfig.presenceAwayTimer);
|
||||||
Log.notice(F("Moving Timer: %d" CR), BTConfig.movingTimer);
|
Log.notice(F("Moving Timer: %d" CR), BTConfig.movingTimer);
|
||||||
Log.notice(F("Force passive scan: %T" CR), BTConfig.forcePassiveScan);
|
Log.notice(F("Force passive scan: %T" CR), BTConfig.forcePassiveScan);
|
||||||
|
Log.notice(F("Enabled BLE: %T" CR), BTConfig.enabled);
|
||||||
|
|
||||||
atomic_init(&forceBTScan, 0); // in theory, we don't need this
|
atomic_init(&forceBTScan, 0); // in theory, we don't need this
|
||||||
|
|
||||||
@@ -901,10 +921,12 @@ void setupBT() {
|
|||||||
xSemaphoreGive(semaphoreBLEOperation);
|
xSemaphoreGive(semaphoreBLEOperation);
|
||||||
|
|
||||||
BLEQueue = xQueueCreate(QueueSize, sizeof(NimBLEAdvertisedDevice*));
|
BLEQueue = xQueueCreate(QueueSize, sizeof(NimBLEAdvertisedDevice*));
|
||||||
|
if (BTConfig.enabled) {
|
||||||
setupBTTasksAndBLE();
|
setupBTTasksAndBLE();
|
||||||
|
Log.notice(F("ZgatewayBT multicore ESP32 setup done" CR));
|
||||||
Log.trace(F("ZgatewayBT multicore ESP32 setup done " CR));
|
} else {
|
||||||
|
Log.notice(F("ZgatewayBT multicore ESP32 setup disabled" CR));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BTtoMQTT() { // for on demand BLE scans
|
bool BTtoMQTT() { // for on demand BLE scans
|
||||||
@@ -1230,7 +1252,7 @@ void hass_presence(JsonObject& HomePresence) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BTforceScan() {
|
void BTforceScan() {
|
||||||
if (!ProcessLock) {
|
if (!BTProcessLock) {
|
||||||
BTtoMQTT();
|
BTtoMQTT();
|
||||||
Log.trace(F("Scan done" CR));
|
Log.trace(F("Scan done" CR));
|
||||||
if (BTConfig.bleConnect)
|
if (BTConfig.bleConnect)
|
||||||
@@ -1243,7 +1265,7 @@ void BTforceScan() {
|
|||||||
void immediateBTAction(void* pvParameters) {
|
void immediateBTAction(void* pvParameters) {
|
||||||
if (BLEactions.size()) {
|
if (BLEactions.size()) {
|
||||||
// Immediate action; we need to prevent the normal connection action and stop scanning
|
// Immediate action; we need to prevent the normal connection action and stop scanning
|
||||||
ProcessLock = true;
|
BTProcessLock = true;
|
||||||
NimBLEScan* pScan = NimBLEDevice::getScan();
|
NimBLEScan* pScan = NimBLEDevice::getScan();
|
||||||
if (pScan->isScanning()) {
|
if (pScan->isScanning()) {
|
||||||
pScan->stop();
|
pScan->stop();
|
||||||
@@ -1261,7 +1283,7 @@ void immediateBTAction(void* pvParameters) {
|
|||||||
std::swap(BLEactions, act_swap);
|
std::swap(BLEactions, act_swap);
|
||||||
|
|
||||||
// Unlock here to allow the action to be performed
|
// Unlock here to allow the action to be performed
|
||||||
ProcessLock = false;
|
BTProcessLock = false;
|
||||||
BLEconnect();
|
BLEconnect();
|
||||||
// back to normal
|
// back to normal
|
||||||
std::swap(devices, dev_swap);
|
std::swap(devices, dev_swap);
|
||||||
@@ -1282,7 +1304,7 @@ void immediateBTAction(void* pvParameters) {
|
|||||||
buildTopicFromId(BLEdata, subjectBTtoMQTT);
|
buildTopicFromId(BLEdata, subjectBTtoMQTT);
|
||||||
handleJsonEnqueue(BLEdata, QueueSemaphoreTimeOutTask);
|
handleJsonEnqueue(BLEdata, QueueSemaphoreTimeOutTask);
|
||||||
BLEactions.pop_back();
|
BLEactions.pop_back();
|
||||||
ProcessLock = false;
|
BTProcessLock = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
|
|||||||
@@ -1216,6 +1216,16 @@ void pubMqttDiscovery() {
|
|||||||
stateClassNone, //State Class
|
stateClassNone, //State Class
|
||||||
"false", "true" //state_off, state_on
|
"false", "true" //state_off, state_on
|
||||||
);
|
);
|
||||||
|
createDiscovery("switch", //set Type
|
||||||
|
subjectBTtoMQTT, "BT: Enabled", (char*)getUniqueId("enabled", "").c_str(), //set state_topic,name,uniqueId
|
||||||
|
will_Topic, "", "{{ value_json.enabled }}", //set availability_topic,device_class,value_template,
|
||||||
|
"{\"enabled\":true,\"save\":true}", "{\"enabled\":false,\"save\":true}", "", //set,payload_on,payload_off,unit_of_meas,
|
||||||
|
0, //set off_delay
|
||||||
|
Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoBTset, //set,payload_available,payload_not available ,is a gateway entity, command topic
|
||||||
|
"", "", "", "", false, // device name, device manufacturer, device model, device MAC, retain
|
||||||
|
stateClassNone, //State Class
|
||||||
|
"false", "true" //state_off, state_on
|
||||||
|
);
|
||||||
|
|
||||||
# define EntitiesCount 8
|
# define EntitiesCount 8
|
||||||
const char* obsoleteEntities[EntitiesCount][2] = {
|
const char* obsoleteEntities[EntitiesCount][2] = {
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ struct BTConfig_s {
|
|||||||
unsigned long presenceAwayTimer; //Timer that trigger a tracker/PIR state as offline/off if not seen
|
unsigned long presenceAwayTimer; //Timer that trigger a tracker/PIR state as offline/off if not seen
|
||||||
unsigned long movingTimer; //Timer that trigger a moving sensor state as offline if not seen
|
unsigned long movingTimer; //Timer that trigger a moving sensor state as offline if not seen
|
||||||
bool forcePassiveScan; //Force passive scan
|
bool forcePassiveScan; //Force passive scan
|
||||||
|
bool enabled; // Enable or disable the BT gateway
|
||||||
};
|
};
|
||||||
|
|
||||||
// Global struct to store live BT configuration data
|
// Global struct to store live BT configuration data
|
||||||
|
|||||||
+24
-9
@@ -273,7 +273,9 @@ static String ota_server_cert = "";
|
|||||||
# include <nvs.h>
|
# include <nvs.h>
|
||||||
# include <nvs_flash.h>
|
# include <nvs_flash.h>
|
||||||
|
|
||||||
bool ProcessLock = true; // Process lock when we want to use a critical function like OTA for example, at start to true so as to wait for critical functions to be performed before BLE start
|
bool BTProcessLock = true; // Process lock when we want to use a critical function like OTA for example, at start to true so as to wait for critical functions to be performed before BLE start
|
||||||
|
bool ProcessLock = false; // Process lock when we want to use a critical function like OTA for example
|
||||||
|
|
||||||
# if !defined(NO_INT_TEMP_READING)
|
# if !defined(NO_INT_TEMP_READING)
|
||||||
// ESP32 internal temperature reading
|
// ESP32 internal temperature reading
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
@@ -1398,8 +1400,11 @@ void setOTA() {
|
|||||||
ErrorIndicatorON();
|
ErrorIndicatorON();
|
||||||
SendReceiveIndicatorON();
|
SendReceiveIndicatorON();
|
||||||
last_ota_activity_millis = millis();
|
last_ota_activity_millis = millis();
|
||||||
# if defined(ZgatewayBT) && defined(ESP32)
|
# ifdef ESP32
|
||||||
|
ProcessLock = true;
|
||||||
|
# ifdef ZgatewayBT
|
||||||
stopProcessing();
|
stopProcessing();
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
lpDisplayPrint("OTA in progress");
|
lpDisplayPrint("OTA in progress");
|
||||||
});
|
});
|
||||||
@@ -2099,7 +2104,7 @@ void loop() {
|
|||||||
checkForUpdates();
|
checkForUpdates();
|
||||||
# endif
|
# endif
|
||||||
# ifdef ZgatewayBT
|
# ifdef ZgatewayBT
|
||||||
ProcessLock = false; // Release BLE processes at start
|
BTProcessLock = !BTConfig.enabled; // Release BLE processes at start if enabled
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2744,11 +2749,12 @@ void MQTTHttpsFWUpdate(char* topicOri, JsonObject& HttpsFwUpdateData) {
|
|||||||
Log.error(F("Invalid URL" CR));
|
Log.error(F("Invalid URL" CR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
# if defined(ZgatewayBT)
|
|
||||||
stopProcessing();
|
|
||||||
# endif
|
|
||||||
# ifdef ESP32
|
# ifdef ESP32
|
||||||
|
ProcessLock = true;
|
||||||
//esp_task_wdt_delete(NULL); // Stop task watchdog during update
|
//esp_task_wdt_delete(NULL); // Stop task watchdog during update
|
||||||
|
# ifdef ZgatewayBT
|
||||||
|
stopProcessing();
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
Log.warning(F("Starting firmware update" CR));
|
Log.warning(F("Starting firmware update" CR));
|
||||||
|
|
||||||
@@ -2885,8 +2891,11 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
if (SYSdata.containsKey("wifi_ssid") && SYSdata.containsKey("wifi_pass")) {
|
if (SYSdata.containsKey("wifi_ssid") && SYSdata.containsKey("wifi_pass")) {
|
||||||
# if defined(ZgatewayBT) && defined(ESP32)
|
# ifdef ESP32
|
||||||
|
ProcessLock = true;
|
||||||
|
# ifdef ZgatewayBT
|
||||||
stopProcessing();
|
stopProcessing();
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
String prev_ssid = WiFi.SSID();
|
String prev_ssid = WiFi.SSID();
|
||||||
String prev_pass = WiFi.psk();
|
String prev_pass = WiFi.psk();
|
||||||
@@ -2953,8 +2962,11 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if defined(ZgatewayBT) && defined(ESP32)
|
# ifdef ESP32
|
||||||
|
ProcessLock = true;
|
||||||
|
# ifdef ZgatewayBT
|
||||||
stopProcessing();
|
stopProcessing();
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
disconnectClient = false;
|
disconnectClient = false;
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
@@ -2977,8 +2989,11 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
|||||||
|
|
||||||
client.setServer(SYSdata["mqtt_server"].as<const char*>(), SYSdata["mqtt_port"].as<unsigned int>());
|
client.setServer(SYSdata["mqtt_server"].as<const char*>(), SYSdata["mqtt_port"].as<unsigned int>());
|
||||||
} else {
|
} else {
|
||||||
# if defined(ZgatewayBT) && defined(ESP32)
|
# ifdef ESP32
|
||||||
|
ProcessLock = true;
|
||||||
|
# ifdef ZgatewayBT
|
||||||
stopProcessing();
|
stopProcessing();
|
||||||
|
# endif
|
||||||
# endif
|
# endif
|
||||||
disconnectClient = false;
|
disconnectClient = false;
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
|
|||||||
Reference in new issue
Block a user