Rebase fixes

This commit is contained in:
Theo Arends 2021-01-18 11:33:13 +01:00
parent ff6c328ba9
commit 1c6b0d8a4d
2 changed files with 30 additions and 36 deletions

View File

@ -283,16 +283,13 @@ void ESP32Init() {
if (TasmotaGlobal.global_state.wifi_down) { return; } if (TasmotaGlobal.global_state.wifi_down) { return; }
TasmotaGlobal.wifi_stay_asleep = true;
if (WiFi.getSleep() == false) { if (WiFi.getSleep() == false) {
if (0 == Settings.flag3.sleep_normal) { AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: Put WiFi modem in sleep mode"),"BLE");
AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: About to restart to put WiFi modem in sleep mode"),"BLE"); WiFi.setSleep(true); // Sleep
Settings.flag3.sleep_normal = 1; // SetOption60 - Enable normal sleep instead of dynamic sleep
TasmotaGlobal.restart_flag = 2;
}
return;
} }
AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: Initializing Blueetooth..."),"BLE"); AddLog_P(LOG_LEVEL_DEBUG,PSTR("%s: Initializing Bluetooth..."),"BLE");
if (!ESP32BLE.mode.init) { if (!ESP32BLE.mode.init) {
NimBLEDevice::init(""); NimBLEDevice::init("");
@ -1020,4 +1017,4 @@ bool Xsns52(byte function)
#endif // USE_IBEACON #endif // USE_IBEACON
#endif #endif // USE_BLE_ESP32

View File

@ -590,17 +590,17 @@ int MI32_decryptPacket(char *_buf, uint16_t _bufSize, uint32_t _type){
MI32_ReverseMAC(packet->MAC); MI32_ReverseMAC(packet->MAC);
uint8_t _bindkey[16] = {0x0}; uint8_t _bindkey[16] = {0x0};
bool foundNoKey = true; bool foundNoKey = true;
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: search key for MAC: %02x %02x %02x %02x %02x %02x"), packet->MAC[0], packet->MAC[1], packet->MAC[2], packet->MAC[3], packet->MAC[4], packet->MAC[5]); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Search key for MAC: %02x %02x %02x %02x %02x %02x"), packet->MAC[0], packet->MAC[1], packet->MAC[2], packet->MAC[3], packet->MAC[4], packet->MAC[5]);
for(uint32_t i=0; i<MIBLEbindKeys.size(); i++){ for(uint32_t i=0; i<MIBLEbindKeys.size(); i++){
if(memcmp(packet->MAC,MIBLEbindKeys[i].MAC,sizeof(packet->MAC))==0){ if(memcmp(packet->MAC,MIBLEbindKeys[i].MAC,sizeof(packet->MAC))==0){
memcpy(_bindkey,MIBLEbindKeys[i].key,sizeof(_bindkey)); memcpy(_bindkey,MIBLEbindKeys[i].key,sizeof(_bindkey));
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: decryption Key found")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Decryption Key found"));
foundNoKey = false; foundNoKey = false;
break; break;
} }
} }
if(foundNoKey){ if(foundNoKey){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: no Key found !!")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: No Key found !!"));
return -2; return -2;
} }
@ -620,7 +620,7 @@ int MI32_decryptPacket(char *_buf, uint16_t _bufSize, uint32_t _type){
ret = br_ccm_check_tag(&ctx, &tag); ret = br_ccm_check_tag(&ctx, &tag);
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: Err:%i, Decrypted : %02x %02x %02x %02x %02x "), ret, packet->payload[1],packet->payload[2],packet->payload[3],packet->payload[4],packet->payload[5]); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Err:%i, Decrypted : %02x %02x %02x %02x %02x "), ret, packet->payload[1],packet->payload[2],packet->payload[3],packet->payload[4],packet->payload[5]);
return ret-1; return ret-1;
} }
#endif // USE_MI_DECRYPTION #endif // USE_MI_DECRYPTION
@ -661,7 +661,7 @@ uint32_t MIBLEgetSensorSlot(uint8_t (&_MAC)[6], uint16_t _type, uint8_t counter)
bool _success = false; bool _success = false;
for (uint32_t i=0;i<MI32_TYPES;i++){ // i < sizeof(kMI32DeviceID) gives compiler warning for (uint32_t i=0;i<MI32_TYPES;i++){ // i < sizeof(kMI32DeviceID) gives compiler warning
if(_type == kMI32DeviceID[i]){ if(_type == kMI32DeviceID[i]){
DEBUG_SENSOR_LOG(PSTR("MI32: ID is type %u"), i); DEBUG_SENSOR_LOG(PSTR("M32: ID is type %u"), i);
_type = i+1; _type = i+1;
_success = true; _success = true;
} }
@ -780,26 +780,23 @@ void MI32PreInit(void) {
MI32.option.showRSSI = 1; MI32.option.showRSSI = 1;
MI32.option.ignoreBogusBattery = 1; // from advertisements MI32.option.ignoreBogusBattery = 1; // from advertisements
MI32.option.holdBackFirstAutodiscovery = 1; MI32.option.holdBackFirstAutodiscovery = 1;
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: pre-init")); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: pre-init"));
} }
void MI32Init(void) { void MI32Init(void) {
if (MI32.mode.init) { return; } if (MI32.mode.init) { return; }
if (TasmotaGlobal.global_state.wifi_down) { return; } if (TasmotaGlobal.global_state.wifi_down) { return; }
TasmotaGlobal.wifi_stay_asleep = true;
if (WiFi.getSleep() == false) { if (WiFi.getSleep() == false) {
// AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: WiFi modem not in sleep mode, BLE cannot start yet")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Put WiFi modem in sleep mode"));
if (0 == Settings.flag3.sleep_normal) { WiFi.setSleep(true); // Sleep
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: About to restart to put WiFi modem in sleep mode"));
Settings.flag3.sleep_normal = 1; // SetOption60 - Enable normal sleep instead of dynamic sleep
TasmotaGlobal.restart_flag = 2;
}
return;
} }
if (!MI32.mode.init) { if (!MI32.mode.init) {
NimBLEDevice::init(""); NimBLEDevice::init("");
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: init BLE device")); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Init BLE device"));
MI32.mode.canScan = 1; MI32.mode.canScan = 1;
MI32.mode.init = 1; MI32.mode.init = 1;
MI32.period = Settings.tele_period; MI32.period = Settings.tele_period;
@ -1287,7 +1284,7 @@ void MI32parseMiBeacon(char * _buf, uint32_t _slot, uint16_t _bufSize){
break; break;
} }
if(decryptRet!=0){ if(decryptRet!=0){
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: decryption failed with error: %d"),decryptRet); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Decryption failed with error: %d"),decryptRet);
return; return;
} }
#endif //USE_MI_DECRYPTION #endif //USE_MI_DECRYPTION
@ -1460,7 +1457,7 @@ void MI32parseCGD1Packet(char * _buf, uint32_t length, uint8_t addr[6], int RSSI
} }
break; break;
default: default:
DEBUG_SENSOR_LOG(PSTR("MI32: unexpected CGD1-packet")); DEBUG_SENSOR_LOG(PSTR("M32: Unexpected CGD1-packet"));
} }
if(MIBLEsensors[_slot].eventType.raw == 0) return; if(MIBLEsensors[_slot].eventType.raw == 0) return;
MIBLEsensors[_slot].shallSendMQTT = 1; MIBLEsensors[_slot].shallSendMQTT = 1;
@ -1492,7 +1489,7 @@ void MI32ParseResponse(char *buf, uint16_t bufsize, uint8_t addr[6], int RSSI) {
* @param UUID * @param UUID
*/ */
void MI32ParseGenericBeacon(uint8_t* payload, size_t payloadLength, uint16_t* CID, uint16_t*SVC, uint16_t* UUID){ void MI32ParseGenericBeacon(uint8_t* payload, size_t payloadLength, uint16_t* CID, uint16_t*SVC, uint16_t* UUID){
AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("MI32: Beacon:____________")); AddLog_P(LOG_LEVEL_DEBUG_MORE,PSTR("M32: Beacon:____________"));
for (uint32_t i = 0; i<payloadLength;){ for (uint32_t i = 0; i<payloadLength;){
uint32_t ADtype = payload[i+1]; uint32_t ADtype = payload[i+1];
uint32_t offset = payload[i]; uint32_t offset = payload[i];
@ -1550,13 +1547,13 @@ void MI32HandleGenericBeacon(uint8_t* payload, size_t payloadLength, int RSSI, u
} }
// else handle scan // else handle scan
if(MIBLEscanResult.size()>19) { if(MIBLEscanResult.size()>19) {
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: Scan buffer full")); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Scan buffer full"));
MI32.state.beaconScanCounter = 1; MI32.state.beaconScanCounter = 1;
return; return;
} }
for(auto _scanResult : MIBLEscanResult){ for(auto _scanResult : MIBLEscanResult){
if(memcmp(addr,_scanResult.MAC,6)==0){ if(memcmp(addr,_scanResult.MAC,6)==0){
// AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: known device")); // AddLog_P(LOG_LEVEL_INFO,PSTR("M32: known device"));
return; return;
} }
} }
@ -1586,12 +1583,12 @@ void MI32addBeacon(uint8_t index, char* data){
_new.time = 0; _new.time = 0;
if(memcmp(_empty,_new.MAC,6) == 0){ if(memcmp(_empty,_new.MAC,6) == 0){
_new.active = false; _new.active = false;
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: beacon%u deactivated"), index); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Beacon%u deactivated"), index);
} }
else{ else{
_new.active = true; _new.active = true;
MI32.mode.activeBeacon = 1; MI32.mode.activeBeacon = 1;
AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: beacon added with MAC: %s"), _MAC); AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Beacon added with MAC: %s"), _MAC);
} }
} }
@ -1846,7 +1843,7 @@ void CmndMi32Time(void) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (MIBLEsensors.size() > XdrvMailbox.payload) { if (MIBLEsensors.size() > XdrvMailbox.payload) {
if ((LYWSD02 == MIBLEsensors[XdrvMailbox.payload].type) || (MHOC303 == MIBLEsensors[XdrvMailbox.payload].type)) { if ((LYWSD02 == MIBLEsensors[XdrvMailbox.payload].type) || (MHOC303 == MIBLEsensors[XdrvMailbox.payload].type)) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("MI32: will set Time")); AddLog_P(LOG_LEVEL_DEBUG, PSTR("M32: Will set Time"));
MI32.state.sensor = XdrvMailbox.payload; MI32.state.sensor = XdrvMailbox.payload;
MI32.mode.canScan = 0; MI32.mode.canScan = 0;
MI32.mode.canConnect = 0; MI32.mode.canConnect = 0;
@ -1876,7 +1873,7 @@ void CmndMi32Unit(void) {
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
if (MIBLEsensors.size() > XdrvMailbox.payload) { if (MIBLEsensors.size() > XdrvMailbox.payload) {
if ((LYWSD02 == MIBLEsensors[XdrvMailbox.payload].type) || (MHOC303 == MIBLEsensors[XdrvMailbox.payload].type)) { if ((LYWSD02 == MIBLEsensors[XdrvMailbox.payload].type) || (MHOC303 == MIBLEsensors[XdrvMailbox.payload].type)) {
AddLog_P(LOG_LEVEL_DEBUG,PSTR("MI32: will set Unit")); AddLog_P(LOG_LEVEL_DEBUG,PSTR("M32: Will set Unit"));
MI32.state.sensor = XdrvMailbox.payload; MI32.state.sensor = XdrvMailbox.payload;
MI32.mode.canScan = 0; MI32.mode.canScan = 0;
MI32.mode.canConnect = 0; MI32.mode.canConnect = 0;
@ -1926,11 +1923,11 @@ void CmndMi32Block(void){
switch (XdrvMailbox.index) { switch (XdrvMailbox.index) {
case 0: case 0:
MIBLEBlockList.clear(); MIBLEBlockList.clear();
// AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: size of ilist: %u"), MIBLEBlockList.size()); // AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Size of ilist: %u"), MIBLEBlockList.size());
ResponseCmndIdxChar(PSTR("block list cleared")); ResponseCmndIdxChar(PSTR("Block list cleared"));
break; break;
case 1: case 1:
ResponseCmndIdxChar(PSTR("show block list")); ResponseCmndIdxChar(PSTR("Show block list"));
break; break;
} }
} }
@ -1956,7 +1953,7 @@ void CmndMi32Block(void){
ResponseCmndIdxChar(XdrvMailbox.data); ResponseCmndIdxChar(XdrvMailbox.data);
MI32removeMIBLEsensor(_MACasBytes.buf); MI32removeMIBLEsensor(_MACasBytes.buf);
} }
// AddLog_P(LOG_LEVEL_INFO,PSTR("MI32: size of ilist: %u"), MIBLEBlockList.size()); // AddLog_P(LOG_LEVEL_INFO,PSTR("M32: Size of ilist: %u"), MIBLEBlockList.size());
break; break;
} }
} }
@ -2323,4 +2320,4 @@ bool Xsns62(uint8_t function)
} }
#endif // USE_MI_ESP32 #endif // USE_MI_ESP32
#endif // ESP32 #endif // ESP32
#endif #endif // USE_BLE_ESP32