|
| 1 | +/** @file |
| 2 | + Decoder for TFA Dostmann 14.1504.V2 (30.3254.01) |
| 3 | + Radio-controlled grill and meat thermometer |
| 4 | +
|
| 5 | + Copyright (C) 2022-2023 Joël Bourquard <[email protected]> |
| 6 | +
|
| 7 | + This program is free software; you can redistribute it and/or modify |
| 8 | + it under the terms of the GNU General Public License as published by |
| 9 | + the Free Software Foundation; either version 2 of the License, or |
| 10 | + (at your option) any later version. |
| 11 | +*/ |
| 12 | + |
| 13 | +/** |
| 14 | +Decoder for TFA Dostmann 14.1504.V2 (30.3254.01) |
| 15 | +
|
| 16 | +CAUTION: Do not confuse with TFA Dostmann 14.1504 (30.3201) which had a completely different protocol => [71] Maverick ET-732/733 BBQ Sensor |
| 17 | +
|
| 18 | +Payload format: |
| 19 | +- Preamble {36} 0x7aaaaaa5c (for robustness we only use the tail: {24}0xaaaa5c) |
| 20 | +- Flags {4} OR between: 0x2=battery ok, 0x5=resync button |
| 21 | +- Temperature {12} Raw temperature value. Temperature in ºC = (value/4)-532. Example: 0x8a0 = 20 ºC |
| 22 | +- Separator {8} 0xff (differs if resync) |
| 23 | +- Digest {16} 16-bit LFSR digest + final XOR |
| 24 | +
|
| 25 | +To get raw data: |
| 26 | +``` |
| 27 | +rtl_433 -R 0 -X 'n=TFA-141504v2,m=FSK_PCM,s=360,l=360,r=4096,preamble={24}aaaa5c' |
| 28 | +``` |
| 29 | +
|
| 30 | +Example payloads (excluding preamble): |
| 31 | +- Resync = 7052f9cee3 (encoding differs from temperature readings => not handled) |
| 32 | +- No probe = 2700ffb791 (just like a temperature reading => in this case we report the appropriate probe status and no temperature reading) |
| 33 | +- ... |
| 34 | +- 20 ºC = 28a0ffce69 |
| 35 | +- 21 ºC = 28a4ffa0f5 |
| 36 | +- ... |
| 37 | +- 24 ºC = 28b0ff6438 |
| 38 | +- ... |
| 39 | +- 44 ºC = 2900ff8c9d |
| 40 | +- ... |
| 41 | +*/ |
| 42 | + |
| 43 | +#include "decoder.h" |
| 44 | + |
| 45 | +#define NUM_BITS_PREAMBLE 24 |
| 46 | +#define NUM_BYTES_DATA 5 |
| 47 | +#define OFFSET_MIC (NUM_BYTES_DATA - 2) |
| 48 | +#define NUM_BITS_DATA (NUM_BYTES_DATA * 8) |
| 49 | +#define NUM_BITS_TOTAL (NUM_BITS_PREAMBLE + NUM_BITS_DATA) |
| 50 | +#define NUM_BITS_MAX (NUM_BITS_TOTAL + 12) |
| 51 | + |
| 52 | +static int tfa_14_1504_v2_callback(r_device *decoder, bitbuffer_t *bitbuffer) |
| 53 | +{ |
| 54 | + uint8_t const preamble[] = { |
| 55 | + 0xaa, |
| 56 | + 0xaa, |
| 57 | + 0x5c, |
| 58 | + }; |
| 59 | + |
| 60 | + if (bitbuffer->num_rows != 1) { |
| 61 | + return DECODE_ABORT_EARLY; |
| 62 | + } |
| 63 | + unsigned const row = 0; |
| 64 | + |
| 65 | + // Optional optimization: Early exit if row too short |
| 66 | + if (bitbuffer->bits_per_row[row] < NUM_BITS_TOTAL) { |
| 67 | + return DECODE_ABORT_EARLY; // considered "early" because preamble not checked |
| 68 | + } |
| 69 | + |
| 70 | + // Sync on preamble |
| 71 | + unsigned start_pos = bitbuffer_search(bitbuffer, row, 0, preamble, NUM_BITS_PREAMBLE); |
| 72 | + |
| 73 | + if (start_pos == bitbuffer->bits_per_row[row]) { |
| 74 | + return DECODE_ABORT_EARLY; // no preamble detected |
| 75 | + } |
| 76 | + |
| 77 | + const unsigned available_bits = bitbuffer->bits_per_row[row] - start_pos; |
| 78 | + |
| 79 | + // check min length |
| 80 | + if (available_bits < NUM_BITS_TOTAL || |
| 81 | + available_bits > NUM_BITS_MAX) { |
| 82 | + return DECODE_ABORT_LENGTH; |
| 83 | + } |
| 84 | + |
| 85 | + uint8_t data[NUM_BYTES_DATA]; |
| 86 | + bitbuffer_extract_bytes(bitbuffer, row, start_pos + NUM_BITS_PREAMBLE, data, NUM_BITS_DATA); |
| 87 | + |
| 88 | + uint8_t flags = data[0] >> 4; |
| 89 | + // ignore resync button |
| 90 | + if ((flags & 0x5) == 0x5) { |
| 91 | + return DECODE_FAIL_SANITY; |
| 92 | + } |
| 93 | + unsigned battery_ok = (flags & 0x2) != 0; |
| 94 | + |
| 95 | + if (data[2] != 0xff) { |
| 96 | + return DECODE_FAIL_SANITY; |
| 97 | + } |
| 98 | + |
| 99 | + uint16_t calc_mic = lfsr_digest16(data, OFFSET_MIC, 0x8810, 0x0d42) ^ 0x16eb; |
| 100 | + uint16_t data_mic = (data[OFFSET_MIC] << 8) + data[OFFSET_MIC+1]; |
| 101 | + if (calc_mic != data_mic) { |
| 102 | + return DECODE_FAIL_MIC; |
| 103 | + } |
| 104 | + |
| 105 | + // we discard the last 2 bits as those are always zero |
| 106 | + uint16_t raw_temp_c = ((data[0] & 0xf) << 6) + (data[1] >> 2); |
| 107 | + unsigned is_probe_connected = (raw_temp_c != 0x1c0); |
| 108 | + double temp_c = ((int)raw_temp_c) - 532; |
| 109 | + |
| 110 | + /* clang-format off */ |
| 111 | + data_t *output = data_make( |
| 112 | + "model", "", DATA_STRING, "TFA-141504v2", |
| 113 | + "battery_ok", "Battery", DATA_INT, battery_ok, |
| 114 | + "probe_fail", "Probe failure", DATA_INT, !is_probe_connected, |
| 115 | + "temperature_C", "Temperature", DATA_COND, is_probe_connected, DATA_FORMAT, "%.0f C", DATA_DOUBLE, temp_c, |
| 116 | + "mic", "Integrity", DATA_STRING, "CRC", |
| 117 | + NULL); |
| 118 | + /* clang-format on */ |
| 119 | + |
| 120 | + decoder_output_data(decoder, output); |
| 121 | + return 1; |
| 122 | +} |
| 123 | + |
| 124 | +static char *output_fields[] = { |
| 125 | + "model", |
| 126 | + "battery_ok", |
| 127 | + "probe_fail", |
| 128 | + "temperature_C", |
| 129 | + "mic", |
| 130 | + NULL, |
| 131 | +}; |
| 132 | + |
| 133 | +r_device tfa_14_1504_v2 = { |
| 134 | + .name = "TFA Dostmann 14.1504.V2 Radio-controlled grill and meat thermometer", |
| 135 | + .modulation = FSK_PULSE_PCM, |
| 136 | + .short_width = 360, |
| 137 | + .long_width = 360, |
| 138 | + .reset_limit = 4096, |
| 139 | + .decode_fn = &tfa_14_1504_v2_callback, |
| 140 | + .fields = output_fields, |
| 141 | +}; |
0 commit comments