Skip to content

Commit

Permalink
Fix EMOS-6016 checksum, add DCF77
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed Mar 1, 2022
1 parent 7ef6daf commit 0a2272b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md).
[211] Regency Ceiling Fan Remote (-f 303.75M to 303.96M)
[212] Renault 0435R TPMS
[213] Fine Offset Electronics WS80 weather station
[214] EMOS 6016 DCF77, Temp, Hum, Windspeed, Winddir sensor
[214] EMOS E6016 weatherstation with DCF77
* Disabled by default, use -R n or -G
Expand Down
2 changes: 1 addition & 1 deletion conf/rtl_433.example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ stop_after_successful_events false
protocol 211 # Regency Ceiling Fan Remote (-f 303.75M to 303.96M)
protocol 212 # Renault 0435R TPMS
protocol 213 # Fine Offset Electronics WS80 weather station
protocol 214 # EMOS 6016 DCF77, Temp, Hum, Windspeed, Winddir sensor
protocol 214 # EMOS E6016 weatherstation with DCF77

## Flex devices (command line option "-X")

Expand Down
2 changes: 1 addition & 1 deletion include/rtl_433_devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
DECL(regency_fan) \
DECL(tpms_renault_0435r) \
DECL(fineoffset_ws80) \
DECL(emos6016) \
DECL(emos_e6016) \

/* Add new decoders here. */

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ add_library(r_433 STATIC
devices/elro_db286a.c
devices/elv.c
devices/emontx.c
devices/emos6016.c
devices/emos_e6016.c
devices/enocean_erp1.c
devices/ert_idm.c
devices/ert_scm.c
Expand Down
96 changes: 58 additions & 38 deletions src/devices/emos6016.c → src/devices/emos_e6016.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
EMOS 6016 Sensors contains DCF77, Temp, Hum, Windspeed, Winddir.
EMOS E6016 weatherstation with DCF77.
Copyright (C) 2022 Dirk Utke-Woehlke <[email protected]>
Expand All @@ -11,27 +11,32 @@

#include "decoder.h"

static uint8_t add_inverted(uint8_t *b, int len)
{
int sum = 0;
for (int i = 0; i < len; i++) {
sum += b[i] ^ 0xff;
}
sum = (sum & 0xff) ^ 0xff;
return sum;
}

/**
EMOS 6016 Sensors contains DCF77, Temp, Hum, Windspeed, Winddir.
DCF77 not supported at the currently.
EMOS E6016 weatherstation with DCF77.
- Manufacturer: EMOS
- Transmit Interval: every ~61 s
- Frequency: 433.92 MHz
- Modulation: OOK PWM
- Modulation: OOK PWM, INVERTED
Data Layout:
PP PP PP II BK KK KK KK CT TT HH SS D? XX RR
RAW DATA:
- P: (24 bit) preamble
- I: (8 bit) ID
- B: (2 bit) battery indication
- K: (32 bit) datetime, fields are 6d-4d-5d 5d:6d:6d
- C: (2 bit) channel
- T: (12 bit) temperature, signed, scale 10
- H: (8 bit) humidity
- S: (8 bit) wind speed
- D: (4 bit) wind direction
- ?: (4 bit) unknown
- X: (8 bit) checksum
- R: (8 bit) repeat counter
Raw data:
[00] {120} 55 5a 7c 00 6a a5 60 e7 3f 36 da ff 5d 38 ff
[01] {120} 55 5a 7c 00 6a a5 60 e7 3f 36 da ff 5d 38 fe
Expand All @@ -40,63 +45,77 @@ RAW DATA:
[04] {120} 55 5a 7c 00 6a a5 60 e7 3f 36 da ff 5d 38 fb
[05] {120} 55 5a 7c 00 6a a5 60 e7 3f 36 da ff 5d 38 fa
BitBench String the raw data must be inverted
Format string:
MODEL?:8h8h8h ID?:8d BAT?4d SEC:30d CH:2d TEMP:12d HUM?8d WSPEED:8d WINDIR:4d ?4h CHK:8h REPEAT:8h
MODEL?:8h8h8h ID?:8d BAT?2b DT:6d-4d-5dT5d:6d:6d CH:2d TEMP:12d HUM?8d WSPEED:8d WINDIR:4d ?4h CHK:8h REPEAT:8h
Decoded record
Decoded example:
MODEL?:aaa583 ID?:255 BAT?09 SEC:0359300195 CH:0 TEMP:0201 HUM?037 WSPEED:000 WINDIR:10 ?2 CHK:c7 REPEAT:00
MODEL?:aaa583 ID?:255 BAT?10 DT:21-05-21T07:49:35 CH:0 TEMP:0201 HUM?037 WSPEED:000 WINDIR:10 ?2 CHK:c7 REPEAT:00
*/

static int emos6016_decode(r_device *decoder, bitbuffer_t *bitbuffer)
static int emos_e6016_decode(r_device *decoder, bitbuffer_t *bitbuffer)
{
int r = bitbuffer_find_repeated_row(bitbuffer, 3, 120 - 8); // ignores the repeat byte

if (r < 0) {
int row = bitbuffer_find_repeated_prefix(bitbuffer, 3, 120 - 8); // ignores the repeat byte
if (row < 0) {
decoder_log(decoder, 2, __func__, "Repeated row fail");
return DECODE_ABORT_EARLY;
}
decoder_logf(decoder, 2, __func__, "Found row: %d", r);
decoder_logf(decoder, 2, __func__, "Found row: %d", row);

uint8_t *b = bitbuffer->bb[r];
uint8_t *b = bitbuffer->bb[row];
// we expect 120 bits
if (bitbuffer->bits_per_row[r] != 120) {
if (bitbuffer->bits_per_row[row] != 120) {
decoder_log(decoder, 2, __func__, "Length check fail");
return DECODE_ABORT_LENGTH;
}

// model check 55 5a 7c
if (b[0] != 0x55 || b[1] != 0x5a || b[2] != 0x7c) {
decoder_log(decoder, 2, __func__, "Model check fail");
return DECODE_ABORT_EARLY;
}

bitbuffer_invert(bitbuffer);

// check checksum
if (add_inverted(b, 13) != b[13]) {
if ((add_bytes(b, 13) & 0xff) != b[13]) {
decoder_log(decoder, 2, __func__, "Checksum fail");
return DECODE_FAIL_MIC;
}

int id = b[3];
int battery = ((b[4] & 0xf0) >> 4);
int battery = (b[4] >> 6);
unsigned dcf77 = ((b[4] & 0x3f) << 26) | (b[5] << 18) | (b[6] << 10) | (b[7] << 2) | (b[8] >> 6);
int dcf77_sec = ((dcf77 >> 0) & 0x3f);
int dcf77_min = ((dcf77 >> 6) & 0x3f);
int dcf77_hour = ((dcf77 >> 12) & 0x1f);
int dcf77_day = ((dcf77 >> 17) & 0x1f);
int dcf77_mth = ((dcf77 >> 22) & 0x0f);
int dcf77_year = ((dcf77 >> 26) & 0x3f);
int channel = ((b[8] >> 4) & 0x3) + 1;
int temp_raw = ((b[8] & 0x0f) << 8) | b[9];
float temp_c = temp_raw >= 2048 ? (temp_raw - 4096) * 0.1 : temp_raw * 0.1;
int temp_raw = (int16_t)(((b[8] & 0x0f) << 12) | (b[9] << 4)); // use sign extend
float temp_c = (temp_raw >> 4) * 0.1f;
int humidity = b[10];
float speed_ms = b[11];
int dir_raw = (((b[12] & 0xf0) >> 4));
float dir_deg = dir_raw * 22.5f;

char dcf77_str[20]; // "2064-16-32T32:64:64"
sprintf(dcf77_str, "%4d-%02d-%02dT%02d:%02d:%02d", dcf77_year + 2000, dcf77_mth, dcf77_day, dcf77_hour, dcf77_min, dcf77_sec);

/* clang-format off */
data_t *data = data_make(
"model", "", DATA_STRING, "EMOS-6016",
"model", "", DATA_STRING, "EMOS-E6016",
"id", "House Code", DATA_INT, id,
"channel", "Channel", DATA_INT, channel,
"battery_ok", "Battery_OK", DATA_INT, !!battery,
"temperature_C", "Temperature_C", DATA_FORMAT, "%.1f", DATA_DOUBLE, temp_c,
"humidity", "Humidity", DATA_FORMAT, "%u", DATA_INT, humidity,
"wind_avg_m_s" , "WindSpeed m_s", DATA_FORMAT, "%.1f", DATA_DOUBLE, speed_ms,
"wind_dir_deg" , "Wind direction", DATA_FORMAT, "%.1f", DATA_DOUBLE, dir_deg,
"wind_avg_m_s", "WindSpeed m_s", DATA_FORMAT, "%.1f", DATA_DOUBLE, speed_ms,
"wind_dir_deg", "Wind direction", DATA_FORMAT, "%.1f", DATA_DOUBLE, dir_deg,
"radio_clock", "Radio Clock", DATA_STRING, dcf77_str,
"mic", "Integrity", DATA_STRING, "CHECKSUM",
NULL);
/* clang-format on */
Expand All @@ -114,18 +133,19 @@ static char *output_fields[] = {
"humidity",
"wind_avg_m_s",
"wind_dir_deg",
"radio_clock",
"mic",
NULL,
};
// n=EMOS6016,m=OOK_PWM,s=280,l=796,r=804,g=0,t=0,y=1836,rows>=3,bits=120
r_device emos6016 = {
.name = "EMOS 6016 DCF77, Temp, Hum, Windspeed, Winddir sensor",
// n=EMOS-E6016,m=OOK_PWM,s=280,l=796,r=804,g=0,t=0,y=1836,rows>=3,bits=120
r_device emos_e6016 = {
.name = "EMOS E6016 weatherstation with DCF77",
.modulation = OOK_PULSE_PWM,
.short_width = 280,
.long_width = 796,
.gap_limit = 3000,
.reset_limit = 804,
.sync_width = 1836,
.decode_fn = &emos6016_decode,
.decode_fn = &emos_e6016_decode,
.fields = output_fields,
};
2 changes: 1 addition & 1 deletion vs15/rtl_433.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ COPY ..\..\libusb\MS64\dll\libusb*.dll $(TargetDir)</Command>
<ClCompile Include="..\src\devices\elro_db286a.c" />
<ClCompile Include="..\src\devices\elv.c" />
<ClCompile Include="..\src\devices\emontx.c" />
<ClCompile Include="..\src\devices\emos6016.c" />
<ClCompile Include="..\src\devices\emos_e6016.c" />
<ClCompile Include="..\src\devices\enocean_erp1.c" />
<ClCompile Include="..\src\devices\ert_idm.c" />
<ClCompile Include="..\src\devices\ert_scm.c" />
Expand Down
2 changes: 1 addition & 1 deletion vs15/rtl_433.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
<ClCompile Include="..\src\devices\emontx.c">
<Filter>Source Files\devices</Filter>
</ClCompile>
<ClCompile Include="..\src\devices\emos6016.c">
<ClCompile Include="..\src\devices\emos_e6016.c">
<Filter>Source Files\devices</Filter>
</ClCompile>
<ClCompile Include="..\src\devices\enocean_erp1.c">
Expand Down

0 comments on commit 0a2272b

Please sign in to comment.