Merge pull request #10589 from iot-sle/development

only in case of valid key do action. Issue#10585
This commit is contained in:
Theo Arends 2021-01-17 14:20:18 +01:00 committed by GitHub
commit fc23329133
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 71 additions and 64 deletions

View File

@ -274,8 +274,15 @@ bool Wiegand::WiegandConversion ()
{ {
bool bRet = false; bool bRet = false;
unsigned long nowTick = millis(); unsigned long nowTick = millis();
if ((nowTick - lastFoundTime) > WIEGAND_BIT_TIMEOUT) //last bit found is WIEGAND_BIT_TIMEOUT ms ago //add a maximum wait time for new bits
{ unsigned long diffTicks = nowTick - lastFoundTime;
if ((diffTicks > WIEGAND_BIT_TIMEOUT) && (diffTicks >= 5000 )) { //max. 5 secs between 2 bits comming in
bitCount=0;
rfidBuffer=0;
lastFoundTime=nowTick;
return bRet;
}
if (diffTicks > WIEGAND_BIT_TIMEOUT) { //last bit found is WIEGAND_BIT_TIMEOUT ms ago
#if (DEV_WIEGAND_TEST_MODE)>0 #if (DEV_WIEGAND_TEST_MODE)>0
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: raw tag: %llu "), rfidBuffer); AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: raw tag: %llu "), rfidBuffer);
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bit count: %u "), bitCount); AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bit count: %u "), bitCount);
@ -363,19 +370,19 @@ void Wiegand::ScanForTag() {
#endif #endif
if (bitCount > 0) { if (bitCount > 0) {
uint64_t oldTag = rfid; uint64_t oldTag = rfid;
bool newKey = WiegandConversion(); bool validKey = WiegandConversion();
#if (DEV_WIEGAND_TEST_MODE)>0 #if (DEV_WIEGAND_TEST_MODE)>0
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: previous tag: %llu"), oldTag); AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: previous tag: %llu"), oldTag);
#endif #endif
if(newKey && (oldTag != rfid)) { // only in case of valid key do action. Issue#10585
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: new= %llu"), rfid); if(validKey) {
} if (oldTag != rfid) { AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: new= %llu"), rfid); }
else else { AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: prev= %llu"), rfid); }
{ AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: prev= %llu"), rfid);}
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bits= %u"), tagSize); AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bits= %u"), tagSize);
ResponseTime_P(PSTR(",\"Wiegand\":{\"UID\":\"%0llu\"}}"), rfid); ResponseTime_P(PSTR(",\"Wiegand\":{\"UID\":\"%0llu\"}}"), rfid);
MqttPublishTeleSensor(); MqttPublishTeleSensor();
} }
}
} }
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER