From 9ad65d69c1af586b2d07573aba4bb644f6cb1221 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 3 Aug 2018 12:25:37 +0100 Subject: uni-init BLE before sleeping --- sensor/Makefile | 2 +- sensor/patchedBLE/src/BLEDevice.cpp | 8 ++++++++ sensor/patchedBLE/src/BLEDevice.h | 1 + sensor/thermostat.ino | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sensor/Makefile b/sensor/Makefile index 68ba91f..085e162 100644 --- a/sensor/Makefile +++ b/sensor/Makefile @@ -1,5 +1,5 @@ SKETCH = thermostat.ino -CUSTOM_LIBS = DHTesp esp8266-oled-ssd1306 +CUSTOM_LIBS = DHTesp esp8266-oled-ssd1306 patchedBLE UPLOAD_PORT = /dev/ttyUSB0 BOARD = lolin32 diff --git a/sensor/patchedBLE/src/BLEDevice.cpp b/sensor/patchedBLE/src/BLEDevice.cpp index a7db454..3f31ace 100644 --- a/sensor/patchedBLE/src/BLEDevice.cpp +++ b/sensor/patchedBLE/src/BLEDevice.cpp @@ -426,6 +426,14 @@ uint16_t BLEDevice::m_localMTU = 23; vTaskDelay(200/portTICK_PERIOD_MS); // Delay for 200 msecs as a workaround to an apparent Arduino environment issue. } // init +void BLEDevice::uninit() { + if (initialized) { + initialized = false; + esp_bluedroid_disable(); + esp_bt_controller_disable(); + esp_bt_controller_deinit(); + } +} /** * @brief Set the transmission power. diff --git a/sensor/patchedBLE/src/BLEDevice.h b/sensor/patchedBLE/src/BLEDevice.h index 7a1b833..16c323c 100644 --- a/sensor/patchedBLE/src/BLEDevice.h +++ b/sensor/patchedBLE/src/BLEDevice.h @@ -33,6 +33,7 @@ public: static BLEScan* getScan(); // Get the scan object static std::string getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID); // Get the value of a characteristic of a service on a server. static void init(std::string deviceName); // Initialize the local BLE environment. + static void uninit(); static void setPower(esp_power_level_t powerLevel); // Set our power level. static void setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value); // Set the value of a characteristic on a service on a server. static std::string toString(); // Return a string representation of our device. diff --git a/sensor/thermostat.ino b/sensor/thermostat.ino index 4ab3833..23bc610 100644 --- a/sensor/thermostat.ino +++ b/sensor/thermostat.ino @@ -138,7 +138,7 @@ void setup() { void teardown_and_sleep(int next_time) { enable_sensor(false); - //BLEDevice::uninit(); + BLEDevice::uninit(); //esp_wifi_stop(); delay(2000); esp_sleep_enable_timer_wakeup(next_time * uS_TO_S_FACTOR); -- cgit v1.2.3