From d8293a7502ad3fc148e5e1ef44a3ffaa8ba056fe Mon Sep 17 00:00:00 2001 From: "Christian W. Zuckschwerdt" Date: Thu, 3 Mar 2022 14:10:57 +0100 Subject: [PATCH] Add support for Altronics X7064 sensor (closes #2000) --- README.md | 1 + conf/rtl_433.example.conf | 1 + include/rtl_433_devices.h | 1 + src/CMakeLists.txt | 1 + src/devices/altronics_x7064.c | 131 ++++++++++++++++++++++++++++++++++ vs15/rtl_433.vcxproj | 1 + vs15/rtl_433.vcxproj.filters | 3 + 7 files changed, 139 insertions(+) create mode 100644 src/devices/altronics_x7064.c diff --git a/README.md b/README.md index d2fdcd2c06..4cfba6d227 100644 --- a/README.md +++ b/README.md @@ -297,6 +297,7 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md). [212] Renault 0435R TPMS [213] Fine Offset Electronics WS80 weather station [214] EMOS E6016 weatherstation with DCF77 + [215] Altronics X7064 temperature and humidity sensor * Disabled by default, use -R n or -G diff --git a/conf/rtl_433.example.conf b/conf/rtl_433.example.conf index b3cee49b11..772cbcbb91 100644 --- a/conf/rtl_433.example.conf +++ b/conf/rtl_433.example.conf @@ -436,6 +436,7 @@ stop_after_successful_events false protocol 212 # Renault 0435R TPMS protocol 213 # Fine Offset Electronics WS80 weather station protocol 214 # EMOS E6016 weatherstation with DCF77 + protocol 215 # Altronics X7064 temperature and humidity sensor ## Flex devices (command line option "-X") diff --git a/include/rtl_433_devices.h b/include/rtl_433_devices.h index e03c6300bf..9cb0ed1b8d 100644 --- a/include/rtl_433_devices.h +++ b/include/rtl_433_devices.h @@ -222,6 +222,7 @@ DECL(tpms_renault_0435r) \ DECL(fineoffset_ws80) \ DECL(emos_e6016) \ + DECL(altronics_7064) \ /* Add new decoders here. */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c99ea172b..b050dd5972 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,6 +46,7 @@ add_library(r_433 STATIC devices/acurite_01185m.c devices/akhan_100F14.c devices/alecto.c + devices/altronics_x7064.c devices/ambient_weather.c devices/ambientweather_tx8300.c devices/ambientweather_wh31e.c diff --git a/src/devices/altronics_x7064.c b/src/devices/altronics_x7064.c new file mode 100644 index 0000000000..160982441d --- /dev/null +++ b/src/devices/altronics_x7064.c @@ -0,0 +1,131 @@ +/** @file + Altronics X7064 temperature and humidity sensor. + + Copyright (C) 2022 Christian W. Zuckschwerdt + based on protocol decoding by Thomas White + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. +*/ + +#include "decoder.h" + +/** +Altronics X7064 temperature and humidity sensor. + +S.a. issue #2000 + +- Likely a rebranded device, sold by Altronics +- Data length is 32 bytes with a preamble of 10 bytes + +Data Layout: + + // That fits nicely: aaa16e95 a3 8a ae 2d is channel 1, id 6e95, temp 38e (=910, 1 F, -17.2 C), hum 2d (=45). + + AA AC II IB AT TA AT HH AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA SS + +- C: (4 bit) channel +- I: (12 bit) ID, maybe longer +- B: (4 bit) battery indication, might be ID still +- T: (12 bit) temperature in F, offset 900, scale 10 +- H: (8 bit) humidity +- A: (4 bit) fixed values of 0xA +- S: (8 bit) checksum + +Raw data: + + FF FF AA AA AA AA AA CA CA 54 + AA A1 6E 95 A6 BA A5 3B AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA AA D0 + AA 00 0 + +Format string: + + 12h CH:4h ID:12h BAT:4h TEMP:4x4h4h4x4x4h HUM:8d 184h CHKSUM:8h 8x + +Decoded example: + + aaa CH:1 ID:6e9 BAT:5 TEMP:6b5 HUM:059 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa CHKSUM:d0 000 + +*/ + +static int altronics_7064_decode(r_device *decoder, bitbuffer_t *bitbuffer) +{ + // full preamble is ffffaaaaaaaaaacaca54 + uint8_t const preamble_pattern[] = {0xaa, 0xaa, 0xca, 0xca, 0x54}; + + int ret = 0; + for (unsigned row = 0; row < bitbuffer->num_rows; ++row) { + unsigned pos = bitbuffer_search(bitbuffer, row, 0, preamble_pattern, sizeof(preamble_pattern) * 8); + + if (pos >= bitbuffer->bits_per_row[row]) { + decoder_log(decoder, 2, __func__, "Preamble not found"); + ret = DECODE_ABORT_EARLY; + continue; + } + decoder_logf(decoder, 2, __func__, "Found row: %d", row); + + pos += sizeof(preamble_pattern) * 8; + // we expect 32 bytes + if (pos + 32 * 8 >= bitbuffer->bits_per_row[row]) { + decoder_log(decoder, 2, __func__, "Length check fail"); + ret = DECODE_ABORT_LENGTH; + continue; + } + uint8_t b[32] = {0}; + bitbuffer_extract_bytes(bitbuffer, row, pos, b, sizeof(b) * 8); + + // verify checksum + if ((add_bytes(b, 31) & 0xff) != b[31]) { + decoder_log(decoder, 2, __func__, "Checksum fail"); + ret = DECODE_FAIL_MIC; + continue; + } + + int channel = (b[1] & 0xf); + int id = (b[2] << 4) | (b[3] >> 4); + int battery_low = (b[3] & 0x04); + int temp_raw = ((b[4] & 0x0f) << 8) | (b[5] & 0xf0) | (b[6] & 0x0f); // weird format + float temp_f = (temp_raw - 900) * 0.1f; + int humidity = b[7]; + + /* clang-format off */ + data_t *data = data_make( + "model", "", DATA_STRING, "Altronics-X7064", + "id", "", DATA_FORMAT, "%03x", DATA_INT, id, + "channel", "Channel", DATA_INT, channel, + "battery_ok", "Battery_OK", DATA_INT, !battery_low, + "temperature_F", "Temperature_F", DATA_FORMAT, "%.1f", DATA_DOUBLE, temp_f, + "humidity", "Humidity", DATA_FORMAT, "%u", DATA_INT, humidity, + "mic", "Integrity", DATA_STRING, "CHECKSUM", + NULL); + /* clang-format on */ + + decoder_output_data(decoder, data); + return 1; + } + return ret; +} + +static char *output_fields[] = { + "model", + "id", + "channel", + "battery_ok", + "temperature_F", + "humidity", + "mic", + NULL, +}; + +r_device altronics_7064 = { + .name = "Altronics X7064 temperature and humidity sensor", + .modulation = FSK_PULSE_PCM, + .short_width = 90, + .long_width = 90, + .gap_limit = 900, + .reset_limit = 9000, + .decode_fn = &altronics_7064_decode, + .fields = output_fields, +}; diff --git a/vs15/rtl_433.vcxproj b/vs15/rtl_433.vcxproj index 42de865732..d32451eab3 100644 --- a/vs15/rtl_433.vcxproj +++ b/vs15/rtl_433.vcxproj @@ -181,6 +181,7 @@ COPY ..\..\libusb\MS64\dll\libusb*.dll $(TargetDir) + diff --git a/vs15/rtl_433.vcxproj.filters b/vs15/rtl_433.vcxproj.filters index c3239cc5f9..8cdcec2f66 100644 --- a/vs15/rtl_433.vcxproj.filters +++ b/vs15/rtl_433.vcxproj.filters @@ -280,6 +280,9 @@ Source Files\devices + + Source Files\devices + Source Files\devices