From 925481ffd080a667c46e62faabbc3bd372edc3cc Mon Sep 17 00:00:00 2001 From: m7i-org <64315540+m7i-org@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:07:53 -0400 Subject: [PATCH] Sub-GHz: Nexus-TH weather station protocol improvements on detection (#256) * feat(subghz): Nexus-TH improvements on detection Added detection improvements for Nexus-TH as in https://github.com/merbanan/rtl_433/blob/00bd97c63a58083d2a79ccb7089786ff9d0fda2e/src/devices/nexus.c#L63-L78 : - If hum==0% there's no humidity sensor, so don't overwrite to 20% - If the Rubicson check matches, then it's probably not a Nexus-TH - Check temp range beween -50C and 100C * Update changelog --------- Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com> --- CHANGELOG.md | 1 + lib/subghz/protocols/nexus_th.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a85a803de..960e17a5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ - Enforce int module (like in OFW) usage due to lack of required hardware on external boards (PathIsolate (+rf switch for multiple paths)) and incorrect usage and/or understanding the purpose of frequency analyzer app by users, it should be used only to get frequency of the remote placed around 1-10cm around flipper's left corner - Fix possible GSM mobile towers signal interference by limiting upper frequency to 920mhz max - Fix duplicated frequency lists and use user config for nearest frequency selector too + - Nexus-TH weather station protocol improvements on detection (#256 by @m7i-org) - Infrared: - Additions to MNTM specific LED, Digital Sign, Monitor universal remotes from IRDB (#240 by @jaylikesbunda) - UL: Replace LEDs universal remote with new one by Unleashed team, includes color options (by @amec0e & @xMasterX) diff --git a/lib/subghz/protocols/nexus_th.c b/lib/subghz/protocols/nexus_th.c index 0ed331967..6a0585af7 100644 --- a/lib/subghz/protocols/nexus_th.c +++ b/lib/subghz/protocols/nexus_th.c @@ -101,11 +101,30 @@ void ws_protocol_decoder_nexus_th_reset(void* context) { static bool ws_protocol_nexus_th_check(WSProtocolDecoderNexus_TH* instance) { uint8_t type = (instance->decoder.decode_data >> 8) & 0x0F; - if((type == NEXUS_TH_CONST_DATA) && ((instance->decoder.decode_data >> 4) != 0xffffffff)) { - return true; - } else { - return false; - } + if(type != NEXUS_TH_CONST_DATA) return false; + if((instance->decoder.decode_data >> 4) == 0xffffffff) return false; + + if(!((instance->decoder.decode_data >> 23) & 1) && + ((instance->decoder.decode_data >> 12) & 0x07FF) > 1000) + return false; // temp>100C + if(((instance->decoder.decode_data >> 23) & 1) && + (~(instance->decoder.decode_data >> 12) & 0x07FF) > 500) + return false; // temp<-50C + if((instance->decoder.decode_data & 0xFF) > 100) return false; // hum>100 + + // The nexus protocol will trigger on rubicson data, so calculate the rubicson crc and make sure + // it doesn't match. By guesstimate it should generate a correct crc 1/255% of the times. + // So less then 0.5% which should be acceptable. + uint8_t msg_rubicson_crc[] = { + instance->decoder.decode_data >> 28, + instance->decoder.decode_data >> 20, + instance->decoder.decode_data >> 12, + 0xf0, + (instance->decoder.decode_data & 0xf0) | (instance->decoder.decode_data & 0x0f)}; + + if(subghz_protocol_blocks_crc8(msg_rubicson_crc, 5, 0x31, 0x6c) == 0) + return false; // rubicson match, probably not a Nexus + return true; } @@ -214,6 +233,8 @@ static void ws_protocol_nexus_th_remote_controller(WSBlockGeneric* instance) { instance->humidity = instance->data & 0xFF; if(instance->humidity > 95) instance->humidity = 95; + else if(instance->humidity == 0) + instance->humidity = WS_NO_HUMIDITY; else if(instance->humidity < 20) instance->humidity = 20; }