diff --git a/tasmota/xsns_92_MI_HM10.ino b/tasmota/xsns_92_MI_HM10.ino index 045392d73..a384d446a 100644 --- a/tasmota/xsns_92_MI_HM10.ino +++ b/tasmota/xsns_92_MI_HM10.ino @@ -34,20 +34,20 @@ #define HM_PIN_TX 4 // D2 #include +#include TasmotaSerial *HM10Serial; #define HM10_MAX_TASK_NUMBER 12 uint8_t HM10_TASK_LIST[HM10_MAX_TASK_NUMBER+1][2]; // first value: kind of task - second value: delay in x * 100ms -// uint8_t HM10.current_task_delay = 0; // number of 100ms-cycles -// uint8_t HM10.last_command; + #define HM10_MAX_RX_BUF 512 -char HM10_RX_STRING[HM10_MAX_RX_BUF] = {0}; // make a buffer bigger than the usual 10-byte-message +char HM10_RX_STRING[HM10_MAX_RX_BUF] = {0}; struct { - uint8_t current_task_delay; + uint8_t current_task_delay; // number of 100ms-cycles uint8_t last_command; uint16_t firmware; struct { @@ -64,6 +64,32 @@ struct { } LYWSD03; #pragma pack(0) +struct mi_sensor_t{ + uint8_t type; //flora = 1; MI-HT_V1=2; LYWSD02=3; LYWSD03=4 + uint8_t serial[6]; + uint8_t showedUp; + union { + struct { + float temp; + float moisture; + float fertility; + uint16_t lux; + } Flora; + struct { + float temp; + float hum; + uint8_t bat; + } MJ_HT_V1; + struct { + float temp; + float hum; + uint8_t bat; + } LYWSD0x; // LYWSD02 and LYWSD03 + }; +}; + +std::vector MIBLEsensors; + /*********************************************************************************************\ * constants \*********************************************************************************************/ @@ -140,7 +166,56 @@ void HM10_Reset(void) { HM10_Launchtask(TASK_HM10_ROLE1,0,1); // set r HM10_Launchtask(TASK_HM10_DISCONN,11,250); // disconnect } - +/** + * @brief Return the slot number of a known sensor or return create new sensor slot + * + * @param _serial BLE address of the sensor + * @param _type Type number of the sensor + * @return uint32_t Known or new slot in the sensors-vector + */ +uint32_t MIBLEgetSensorSlot(uint8_t (&_serial)[6], uint8_t _type){ + DEBUG_SENSOR_LOG(PSTR("MIBLE: vector size %u"), MIBLEsensors.size()); + for(uint32_t i=0; i0) { - char temperature[33]; - float _temp = (float)LYWSD03.temp/100.0F; - dtostrfd(_temp, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(LYWSD03.hum, Settings.flag2.humidity_resolution, humidity); - if (json) { + if (MIBLEsensors.size()==0) return; + + char temperature[33]; + dtostrfd(MIBLEsensors.at(0).LYWSD0x.temp, Settings.flag2.temperature_resolution, temperature); + char humidity[33]; + dtostrfd(MIBLEsensors.at(0).LYWSD0x.hum, Settings.flag2.humidity_resolution, humidity); + ResponseAppend_P(JSON_SNS_TEMPHUM, F("LYWSD03"), temperature, humidity); -#ifdef USE_DOMOTICZ - if (0 == tele_period) { - DomoticzTempHumSensor(temperature, humidity); - } -#endif // USE_DOMOTICZ -#ifdef USE_KNX - if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, _temp); - KnxSensor(KNX_HUMIDITY, LYWSD03.hum); - } -#endif // USE_KNX #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_HM10, HM10.firmware); + if (MIBLEsensors.size()==0) return; + + char temperature[33]; + dtostrfd(MIBLEsensors.at(0).LYWSD0x.temp, Settings.flag2.temperature_resolution, temperature); + char humidity[33]; + dtostrfd(MIBLEsensors.at(0).LYWSD0x.hum, Settings.flag2.humidity_resolution, humidity); + WSContentSend_PD(HTTP_SNS_TEMP, F("LYWSD03"), temperature, TempUnit()); WSContentSend_PD(HTTP_SNS_HUM, F("LYWSD03"), humidity); #endif // USE_WEBSERVER } - } } /*********************************************************************************************\