From b9f8d0b104893cb8d8d2e1004f483ba697f477bb Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 21 Apr 2020 11:06:30 +0200 Subject: [PATCH] Restrict use of HM10 driver to ESP8266 only --- tasmota/my_user_config.h | 10 ++----- tasmota/tasmota_configurations.h | 12 +++++--- tasmota/tasmota_globals.h | 41 ++++++++++++++++++---------- tasmota/xsns_62_MI_ESP32.ino | 47 +++++++++++++++++--------------- tasmota/xsns_62_MI_HM10.ino | 35 +++++++++++++----------- 5 files changed, 80 insertions(+), 65 deletions(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index c6bfdc57b..5d9dee34e 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -566,16 +566,10 @@ //#define USE_IBEACON // Add support for bluetooth LE passive scan of ibeacon devices (uses HM17 module) //#define USE_GPS // Add support for GPS and NTP Server for becoming Stratus 1 Time Source (+3k1 code, +132 bytes RAM) // #define USE_FLOG // Add support for GPS logging in OTA's Flash (Experimental) (+2k9 code, +8 bytes RAM) -#ifdef ESP8266 -// #define USE_HM10 // Add support for HM-10 as a BLE-bridge (+9k3 code) -#endif // ESP8266 +//#define USE_HM10 // (ESP8266 only) Add support for HM-10 as a BLE-bridge (+9k3 code) +//#define USE_MI_ESP32 // (ESP32 only) Add support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) //#define USE_HRXL // Add support for MaxBotix HRXL-MaxSonar ultrasonic range finders (+0k7) -// -- built-in BLE of the ESP32 -------------------- -#ifdef ESP32 -// #define USE_MI_ESP32 // Add support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) -#endif // ESP8266 - // -- Power monitoring sensors -------------------- #define USE_ENERGY_MARGIN_DETECTION // Add support for Energy Margin detection (+1k6 code) #define USE_ENERGY_POWER_LIMIT // Add additional support for Energy Power Limit detection (+1k2 code) diff --git a/tasmota/tasmota_configurations.h b/tasmota/tasmota_configurations.h index f99d15af9..dfb2434e3 100644 --- a/tasmota/tasmota_configurations.h +++ b/tasmota/tasmota_configurations.h @@ -146,7 +146,8 @@ #define USE_RDM6300 // Add support for RDM6300 125kHz RFID Reader (+0k8) #define USE_IBEACON // Add support for bluetooth LE passive scan of ibeacon devices (uses HM17 module) //#define USE_GPS // Add support for GPS and NTP Server for becoming Stratus 1 Time Source (+ 3.1kb flash, +132 bytes RAM) -#define USE_HM10 // Add support for HM-10 as a BLE-bridge for the LYWSD03 (+5k1 code) +#define USE_HM10 // (ESP8266 only) Add support for HM-10 as a BLE-bridge for the LYWSD03 (+5k1 code) +//#define USE_MI_ESP32 // (ESP32 only) Add support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) #define USE_HRXL // Add support for MaxBotix HRXL-MaxSonar ultrasonic range finders (+0k7) #define USE_ENERGY_SENSOR // Add energy sensors (-14k code) @@ -367,7 +368,8 @@ #undef USE_RDM6300 // Disable support for RDM6300 125kHz RFID Reader (+0k8) #undef USE_IBEACON // Disable support for bluetooth LE passive scan of ibeacon devices (uses HM17 module) #undef USE_GPS // Disable support for GPS and NTP Server for becoming Stratus 1 Time Source (+ 3.1kb flash, +132 bytes RAM) -#undef USE_HM10 // Disable support for HM-10 as a BLE-bridge for the LYWSD03 (+5k1 code) +#undef USE_HM10 // (ESP8266 only) Disable support for HM-10 as a BLE-bridge for the LYWSD03 (+5k1 code) +#undef USE_MI_ESP32 // (ESP32 only) Disable support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) #undef USE_HRXL // Disable support for MaxBotix HRXL-MaxSonar ultrasonic range finders (+0k7) //#define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor @@ -467,7 +469,8 @@ #undef USE_RDM6300 // Disable support for RDM6300 125kHz RFID Reader (+0k8) #undef USE_IBEACON // Disable support for bluetooth LE passive scan of ibeacon devices (uses HM17 module) #undef USE_GPS // Disable support for GPS and NTP Server for becoming Stratus 1 Time Source (+ 3.1kb flash, +132 bytes RAM) -#undef USE_HM10 // Disable support for HM-10 as a BLE-bridge for the LYWSD03 (+5k1 code) +#undef USE_HM10 // (ESP8266 only) Disable support for HM-10 as a BLE-bridge for the LYWSD03 (+5k1 code) +#undef USE_MI_ESP32 // (ESP32 only) Disable support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) #undef USE_HRXL // Disable support for MaxBotix HRXL-MaxSonar ultrasonic range finders (+0k7) //#undef USE_ENERGY_SENSOR // Disable energy sensors @@ -589,7 +592,8 @@ #undef USE_RDM6300 // Disable support for RDM6300 125kHz RFID Reader (+0k8) #undef USE_IBEACON // Disable support for bluetooth LE passive scan of ibeacon devices (uses HM17 module) #undef USE_GPS // Disable support for GPS and NTP Server for becoming Stratus 1 Time Source (+ 3.1kb flash, +132 bytes RAM) -#undef USE_HM10 // Disable support for HM-10 as a BLE-bridge for the LYWSD03 (+5k1 code) +#undef USE_HM10 // (ESP8266 only) Disable support for HM-10 as a BLE-bridge for the LYWSD03 (+5k1 code) +#undef USE_MI_ESP32 // (ESP32 only) Disable support for ESP32 as a BLE-bridge (+9k2 mem, +292k flash) #undef USE_HRXL // Disable support for MaxBotix HRXL-MaxSonar ultrasonic range finders (+0k7) #undef USE_ENERGY_SENSOR // Disable energy sensors diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index 9c5cbd8c3..2a1af58a3 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -117,21 +117,6 @@ extern "C" void resetPins(); #define MESSZ (MQTT_MAX_PACKET_SIZE -TOPSZ -7) // Max number of characters in JSON message string #endif -#ifdef ESP8266 -#ifndef ARDUINO_ESP8266_RELEASE -#define ARDUINO_CORE_RELEASE "STAGE" -#else -#define ARDUINO_CORE_RELEASE ARDUINO_ESP8266_RELEASE -#endif -#endif -#ifdef ESP32 -#ifndef ARDUINO_ESP32_RELEASE -#define ARDUINO_CORE_RELEASE "STAGE" -#else -#define ARDUINO_CORE_RELEASE ARDUINO_ESP32_RELEASE -#endif -#endif - #ifdef USE_PWM_DIMMER_REMOTE #ifdef USE_PWM_DIMMER #ifndef USE_DEVICE_GROUPS @@ -295,6 +280,32 @@ const char kWebColors[] PROGMEM = COLOR_BUTTON_TEXT "|" COLOR_BUTTON "|" COLOR_BUTTON_HOVER "|" COLOR_BUTTON_RESET "|" COLOR_BUTTON_RESET_HOVER "|" COLOR_BUTTON_SAVE "|" COLOR_BUTTON_SAVE_HOVER "|" COLOR_TIMER_TAB_TEXT "|" COLOR_TIMER_TAB_BACKGROUND "|" COLOR_TITLE_TEXT; +/*********************************************************************************************\ + * ESP8266 vs ESP32 related parameters +\*********************************************************************************************/ + +#ifdef ESP8266 + +#ifndef ARDUINO_ESP8266_RELEASE +#define ARDUINO_CORE_RELEASE "STAGE" +#else +#define ARDUINO_CORE_RELEASE ARDUINO_ESP8266_RELEASE +#endif // ARDUINO_ESP8266_RELEASE + +#endif // ESP8266 + +#ifdef ESP32 + +#ifndef ARDUINO_ESP32_RELEASE +#define ARDUINO_CORE_RELEASE "STAGE" +#else +#define ARDUINO_CORE_RELEASE ARDUINO_ESP32_RELEASE +#endif // ARDUINO_ESP32_RELEASE + +#undef USE_HM10 // Disable support for HM-10 as a BLE-bridge (+9k3 code) on ESP32 + +#endif // ESP32 + /*********************************************************************************************\ * Macros \*********************************************************************************************/ diff --git a/tasmota/xsns_62_MI_ESP32.ino b/tasmota/xsns_62_MI_ESP32.ino index 4a5cf8069..7c687402c 100644 --- a/tasmota/xsns_62_MI_ESP32.ino +++ b/tasmota/xsns_62_MI_ESP32.ino @@ -24,6 +24,8 @@ forked - from arendst/tasmota - https://github.com/arendst/Tasmota */ +#ifdef ESP32 // ESP32 only. Use define USE_HM10 for ESP8266 support + #ifdef USE_MI_ESP32 #define XSNS_62 62 @@ -217,7 +219,7 @@ class MI32SensorCallback : public NimBLEClientCallbacks { } else if(params->supervision_timeout > 100) { /** 10ms units */ return false; } - return true; + return true; } }; @@ -304,7 +306,7 @@ uint32_t MIBLEgetSensorSlot(uint8_t (&_serial)[6], uint16_t _type){ } } if(!_success) return 0xff; - + DEBUG_SENSOR_LOG(PSTR("%s: vector size %u"),D_CMND_MI32, MIBLEsensors.size()); for(uint32_t i=0; isetAdvertisedDeviceCallbacks(&MI32ScanCallbacks); pScan->setActiveScan(false); pScan->start(5, MI32scanEndedCB); // hard coded duration @@ -502,10 +504,10 @@ void MI32connectLYWSD03(){ NimBLERemoteCharacteristic* pChr = nullptr; static BLEUUID serviceUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6"); static BLEUUID charUUID("ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6"); - pSvc = MI32Client->getService(serviceUUID); + pSvc = MI32Client->getService(serviceUUID); if(pSvc) { pChr = pSvc->getCharacteristic(charUUID); - } + } if(pChr->canNotify()) { if(!pChr->registerForNotify(MI32notifyCB)) { MI32.mode.willConnect = 0; @@ -549,10 +551,10 @@ void MI32TimeTask(void *pvParameters){ NimBLERemoteCharacteristic* pChr = nullptr; static BLEUUID serviceUUID("EBE0CCB0-7A0A-4B0C-8A1A-6FF2997DA3A6"); static BLEUUID charUUID("EBE0CCB7-7A0A-4B0C-8A1A-6FF2997DA3A6"); - pSvc = MI32Client->getService(serviceUUID); + pSvc = MI32Client->getService(serviceUUID); if(pSvc) { pChr = pSvc->getCharacteristic(charUUID); - } + } if(pChr->canWrite()) { union { uint8_t buf[5]; @@ -617,7 +619,7 @@ void MI32BatteryTask(void *pvParameters){ case FLORA: MI32batteryFLORA(); break; - case LYWSD02: + case LYWSD02: MI32batteryLYWSD02(); break; case CGD1: @@ -647,7 +649,7 @@ void MI32batteryFLORA(){ static BLEUUID FLserviceUUID("00001204-0000-1000-8000-00805f9b34fb"); static BLEUUID FLcharUUID("00001a02-0000-1000-8000-00805f9b34fb"); - pSvc = MI32Client->getService(FLserviceUUID); + pSvc = MI32Client->getService(FLserviceUUID); if(pSvc) { /** make sure it's not null */ pChr = pSvc->getCharacteristic(FLcharUUID); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: got Flora char %s"),D_CMND_MI32, pChr->getUUID().toString().c_str()); @@ -677,7 +679,7 @@ void MI32batteryLYWSD02(){ static BLEUUID LY2serviceUUID("EBE0CCB0-7A0A-4B0C-8A1A-6FF2997DA3A6"); static BLEUUID LY2charUUID("EBE0CCC4-7A0A-4B0C-8A1A-6FF2997DA3A6"); - pSvc = MI32Client->getService(LY2serviceUUID); + pSvc = MI32Client->getService(LY2serviceUUID); if(pSvc) { pChr = pSvc->getCharacteristic(LY2charUUID); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: got LYWSD02 char %s"),D_CMND_MI32, pChr->getUUID().toString().c_str()); @@ -707,7 +709,7 @@ void MI32batteryCGD1(){ static BLEUUID CGD1serviceUUID("180F"); static BLEUUID CGD1charUUID("2A19"); - pSvc = MI32Client->getService(CGD1serviceUUID); + pSvc = MI32Client->getService(CGD1serviceUUID); if(pSvc) { pChr = pSvc->getCharacteristic(CGD1charUUID); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("%s: got CGD1 char %s"),D_CMND_MI32, pChr->getUUID().toString().c_str()); @@ -766,7 +768,7 @@ void MI32parseMiBeacon(char * _buf, uint32_t _slot){ case 0x07: MIBLEsensors[_slot].lux=_beacon.lux & 0x00ffffff; DEBUG_SENSOR_LOG(PSTR("Mode 7: U24: %u Lux"), _beacon.lux & 0x00ffffff); - break; + break; case 0x08: _tempFloat =(float)_beacon.moist; if(_tempFloat<100){ @@ -898,7 +900,7 @@ bool MI32readBat(char *_buf){ /** * @brief Main loop of the driver, "high level"-loop - * + * */ void MI32EverySecond(bool restart){ @@ -918,7 +920,7 @@ void MI32EverySecond(bool restart){ if (MI32.mode.willSetTime == 0){ MI32.mode.willSetTime = 1; MI32StartTask(MI32_TASK_TIME); - } + } } if (MI32.mode.willReadBatt) return; @@ -952,7 +954,7 @@ void MI32EverySecond(bool restart){ else{ MI32StartTask(MI32_TASK_CONN); } - + } if (MI32.state.sensor==MIBLEsensors.size()-1) { _nextSensorSlot= 0; @@ -1079,7 +1081,7 @@ void MI32Show(bool json) ResponseAppend_P(PSTR(",\"Fertility\":%d"), MIBLEsensors[i].fertility); } } - if (MIBLEsensors[i].type>FLORA){ + if (MIBLEsensors[i].type>FLORA){ if(!isnan(MIBLEsensors[i].hum) && !isnan(MIBLEsensors[i].temp)){ ResponseAppendTHD(MIBLEsensors[i].temp, MIBLEsensors[i].hum); } @@ -1090,7 +1092,7 @@ void MI32Show(bool json) dtostrfd((MIBLEsensors[i].volt)/100.0f, Settings.flag2.temperature_resolution, slave); // reuse slave, borrow temperature resolution ResponseAppend_P(PSTR(",\"" D_VOLTAGE "\":%s"), slave); } - } + } ResponseAppend_P(PSTR("}")); } #ifdef USE_WEBSERVER @@ -1111,7 +1113,7 @@ void MI32Show(bool json) WSContentSend_PD(HTTP_MI32, i+1,stemp,MIBLEsensors.size()); for (i; iavailable()) { // delay(0); if(iFLORA){ + if (MIBLEsensors[i].type>FLORA){ if(!isnan(MIBLEsensors[i].hum) && !isnan(MIBLEsensors[i].temp)){ ResponseAppendTHD(MIBLEsensors[i].temp, MIBLEsensors[i].hum); } } if(MIBLEsensors[i].bat!=0x00){ // this is the error code -> no battery ResponseAppend_P(PSTR(",\"Battery\":%u"), MIBLEsensors[i].bat); - } + } ResponseAppend_P(PSTR("}")); } #ifdef USE_WEBSERVER @@ -1210,7 +1212,7 @@ void HM10Show(bool json) WSContentSend_PD(HTTP_HM10, HM10.firmware, i+1,stemp,MIBLEsensors.size()); for (i; i