Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds checksum and battery_ok for WEC-2103. #2662

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions src/devices/wec2103.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,70 @@
/**
WEC-2103 temperature/humidity sensor.

Circuit board model numbers: TX07Y-THC V1, TX07K-THC V4

Similar to prologue, kedsum, esperanza_ews, s3318p
Only available information for this device: https://fcc.report/FCC-ID/WEC-2103

Data:

Byte: 0 1 2 3 4 5
Nibble: 1 2 3 4 5 6 7 8 9 10 11
Type: IIIIIIII XXXXFFFF TTTTTTTT TTTTHHHH HHHHCCCC ????
Type: IIIIIIII XXXXFFFF TTTTTTTT TTTTHHHH HHHHCCCC SS

- I: random device ID, changes on powercycle
- X: Checksum?
- F: Flags
- X: Checksum: mangled CRC-4, poly 3, init 0.
- F: Flags: tx-button pressed|batt-low|?|?
- T: Temperature
- H: Humidity
- Flags: tx-button pressed|?|?|?
- S: Stop bit(s): 0b10

Example datagram:

f2 90 6b5 96 1 8
|ID|Checksum?+Flags|Temperature|Humidity|Channel|unknown
f2 90 6b5 96 1 8
|ID|Checksum+Flags|Temperature|Humidity|Channel|Stop bits

- Temperature in Fahrenheit*100+900->hex
- Example: 82.4F->824->1724->0x6bc
*/

static int wec2103_decode(r_device *decoder, bitbuffer_t *bitbuffer)
{
if (bitbuffer->num_rows != 6 || bitbuffer->bits_per_row[2] != 42)
if (bitbuffer->num_rows != 6 || bitbuffer->bits_per_row[2] != 42) {
return DECODE_ABORT_LENGTH;

uint8_t b[6];
bitbuffer_extract_bytes(bitbuffer, 3, 0, b, 42);

int temp_raw = (b[2] << 4) | ((b[3] & 0xf0) >> 4);
int device_id = b[0];
int channel = b[4] & 0x0f;
int flags = b[1] & 0xf;
float temp_f = (temp_raw - 900) * 0.1f;
int humidity = ((b[3] & 0x0f) * 10) + ((b[4] & 0xf0) >> 4);
int button = (b[1] & 0x08) >> 3;
}

uint8_t b[5];
bitbuffer_extract_bytes(bitbuffer, 3, 0, b, 40);

int crc_received = b[1] >> 4;
b[1] = (b[1] & 0x0F) | ((b[4] & 0x0f) << 4);
int crc_calculated = crc4(b, sizeof(b) - 1, 3, 0) ^ (b[4] >> 4);
if (crc_calculated != crc_received) {
decoder_logf(decoder, 0, __func__, "CRC check failed (0x%X != 0x%X)", crc_calculated, crc_received);
return DECODE_FAIL_MIC;
}

int temp_raw = (b[2] << 4) | ((b[3] & 0xf0) >> 4);
int device_id = b[0];
int channel = b[4] & 0x0f;
int flags = b[1] & 0xf;
float temp_f = (temp_raw - 900) * 0.1f;
int humidity = ((b[3] & 0x0f) * 10) + ((b[4] & 0xf0) >> 4);
int button = (b[1] & 0x08) >> 3;
int battery_low = (b[1] & 0x04) >> 3;

/* clang-format off */
data_t *data = data_make(
"model", "", DATA_STRING, "WEC-2103",
"id", "ID", DATA_INT, device_id,
"channel", "Channel", DATA_INT, channel,
//"battery_ok", "Battery", DATA_INT, !battery_low,
"flags", "Flags", DATA_INT, flags,
"battery_ok", "Battery", DATA_INT, !battery_low,
"button", "Button", DATA_INT, button,
"temperature_F", "Temperature", DATA_FORMAT, "%.02f F", DATA_DOUBLE, temp_f,
"humidity", "Humidity", DATA_FORMAT, "%u %%", DATA_INT, humidity,
"button", "Button", DATA_INT, button,
//"mic", "Integrity", DATA_STRING, "CRC",
"flags", "Flags", DATA_INT, flags,
"mic", "Integrity", DATA_STRING, "CRC",
NULL);
/* clang-format on */

Expand All @@ -77,9 +89,12 @@ static char const *const output_fields[] = {
"model",
"id",
"channel",
"flags",
"battery_ok",
"button",
"temperature_F",
"humidity",
"flags",
"mic",
NULL,
};

Expand All @@ -91,6 +106,5 @@ r_device const wec2103 = {
.gap_limit = 4400,
.reset_limit = 9400,
.decode_fn = &wec2103_decode,
.disabled = 1, // no checksum
.fields = output_fields,
};
Loading