From 510d9b0cd09bc405ecf3857864f4016902ac9d53 Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Fri, 6 Jan 2017 18:52:22 -0600 Subject: [PATCH 01/13] move to new internal data format on acurite5n1 --- src/devices/acurite.c | 99 ++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 40 deletions(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index aaecd6321..2184663ff 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -491,54 +491,73 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { // The 5-n-1 weather sensor messages are 8 bytes. if (browlen == ACURITE_5N1_BITLEN / 8) { channel = acurite_getChannel(bb[0]); + sprintf(channel_str, "%c", channel); sensor_id = acurite_5n1_getSensorId(bb[0],bb[1]); repeat_no = acurite_5n1_getMessageCaught(bb[0]); message_type = bb[2] & 0x3f; - + if (message_type == 0x31) { - // Wind speed, wind direction, and rain fall - wind_speed = acurite_getWindSpeed(bb[3], bb[4]); - wind_speedmph = kmph2mph(wind_speed); - wind_dird = acurite_5n1_winddirections[bb[4] & 0x0f]; - wind_dirstr = acurite_5n1_winddirection_str[bb[4] & 0x0f]; - raincounter = acurite_getRainfallCounter(bb[5], bb[6]); - if (acurite_5n1t_raincounter > 0) { - // track rainfall difference after first run - // FIXME when converting to structured output, just output - // the reading, let consumer track state/wrap around, etc. - rainfall = ( raincounter - acurite_5n1t_raincounter ) * 0.01; - if (raincounter < acurite_5n1t_raincounter) { - printf("%s Acurite 5n1 sensor 0x%04X Ch %c, rain counter reset or wrapped around (old %d, new %d)\n", - time_str, sensor_id, channel, acurite_5n1t_raincounter, raincounter); - acurite_5n1t_raincounter = raincounter; - } - } else { - // capture starting counter - acurite_5n1t_raincounter = raincounter; - printf("%s Acurite 5n1 sensor 0x%04X Ch %c, Total rain fall since last reset: %0.2f\n", - time_str, sensor_id, channel, raincounter * 0.01); - } - - printf("%s Acurite 5n1 sensor 0x%04X Ch %c, Msg %02x, Wind %d kmph / %0.1f mph %0.1f° %s (%d), rain gauge %0.2f in.\n", - time_str, sensor_id, channel, message_type, - wind_speed, wind_speedmph, - wind_dird, wind_dirstr, bb[4] & 0x0f, rainfall); + // Wind speed, wind direction, and rain fall + wind_speed = acurite_getWindSpeed(bb[3], bb[4]); + wind_speedmph = kmph2mph(wind_speed); + wind_dird = acurite_5n1_winddirections[bb[4] & 0x0f]; + wind_dirstr = acurite_5n1_winddirection_str[bb[4] & 0x0f]; + raincounter = acurite_getRainfallCounter(bb[5], bb[6]); + if (acurite_5n1t_raincounter > 0) { + // track rainfall difference after first run + // FIXME when converting to structured output, just output + // the reading, let consumer track state/wrap around, etc. + rainfall = ( raincounter - acurite_5n1t_raincounter ) * 0.01; + if (raincounter < acurite_5n1t_raincounter) { + fprintf(stderr, "%s Acurite 5n1 sensor 0x%04X Ch %c, rain counter reset or wrapped around (old %d, new %d)\n", + time_str, sensor_id, channel, acurite_5n1t_raincounter, raincounter); + acurite_5n1t_raincounter = raincounter; + } + } else { + // capture starting counter + acurite_5n1t_raincounter = raincounter; + fprintf(stderr, "%s Acurite 5n1 sensor 0x%04X Ch %c, Total rain fall since last reset: %0.2f\n", + time_str, sensor_id, channel, raincounter * 0.01); + } + + data = data_make( + "time", "", DATA_STRING, time_str, + "model", "", DATA_STRING, "Acurite 5n1 sensor", + "sensor_id", NULL, DATA_FORMAT, "0x%02X", DATA_INT, sensor_id, + "channel", NULL, DATA_STRING, &channel_str, + "message_type", NULL, DATA_INT, message_type, + "wind_speed", NULL, DATA_FORMAT, "%d", DATA_INT, wind_speed, + "wind_dir_deg", NULL, DATA_FORMAT, "%.1f", DATA_DOUBLE, wind_dird, + "wind_dir", NULL, DATA_STRING, wind_dirstr, + "rainfall", NULL, DATA_FORMAT, "%.2f in", DATA_DOUBLE, rainfall, + NULL); + + data_acquired_handler(data); } else if (message_type == 0x38) { - // Wind speed, temperature and humidity - wind_speed = acurite_getWindSpeed(bb[3], bb[4]); - wind_speedmph = kmph2mph((float) wind_speed); - tempf = acurite_getTemp(bb[4], bb[5]); - tempc = fahrenheit2celsius(tempf); - humidity = acurite_getHumidity(bb[6]); - - printf("%s Acurite 5n1 sensor 0x%04X Ch %c, Msg %02x, Wind %d kmph / %0.1f mph, %3.1F C %3.1F F %d %% RH\n", - time_str, sensor_id, channel, message_type, - wind_speed, wind_speedmph, tempc, tempf, humidity); + // Wind speed, temperature and humidity + wind_speed = acurite_getWindSpeed(bb[3], bb[4]); + wind_speedmph = kmph2mph((float) wind_speed); + tempf = acurite_getTemp(bb[4], bb[5]); + tempc = fahrenheit2celsius(tempf); + humidity = acurite_getHumidity(bb[6]); + + data = data_make( + "time", "", DATA_STRING, time_str, + "model", "", DATA_STRING, "Acurite 5n1 sensor", + "sensor_id", NULL, DATA_FORMAT, "0x%02X", DATA_INT, sensor_id, + "channel", NULL, DATA_STRING, &channel_str, + "message_type", NULL, DATA_INT, message_type, + "wind_speed", NULL, DATA_FORMAT, "%d", DATA_INT, wind_speed, + "temperature", NULL, DATA_FORMAT, "%.1f C", DATA_DOUBLE, tempc, + "humidity", NULL, DATA_FORMAT, "%d", DATA_INT, humidity, + NULL); + data_acquired_handler(data); + } else { - printf("%s Acurite 5n1 sensor 0x%04X Ch %c, Status %02X, Unknown message type 0x%02x\n", - time_str, sensor_id, channel, bb[3], message_type); + fprintf(stderr, "%s Acurite 5n1 sensor 0x%04X Ch %c, Status %02X, Unknown message type 0x%02x\n", + time_str, sensor_id, channel, bb[3], message_type); } } From f613417032aa73ae764289ab634617b66ac984a3 Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Fri, 6 Jan 2017 18:57:50 -0600 Subject: [PATCH 02/13] remove old acurite5n1 decoder, now uses acurite_txr --- include/rtl_433_devices.h | 1 - src/devices/acurite.c | 68 --------------------------------------- 2 files changed, 69 deletions(-) diff --git a/include/rtl_433_devices.h b/include/rtl_433_devices.h index 8b87d689d..6a26b2a6f 100755 --- a/include/rtl_433_devices.h +++ b/include/rtl_433_devices.h @@ -12,7 +12,6 @@ DECL(elv_em1000) \ DECL(elv_ws2000) \ DECL(lacrossetx) \ - DECL(acurite5n1) \ DECL(acurite_rain_gauge) \ DECL(acurite_th) \ DECL(oregon_scientific) \ diff --git a/src/devices/acurite.c b/src/devices/acurite.c index 2184663ff..b6d1f685b 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -232,64 +232,6 @@ static int acurite_5n1_getBatteryLevel(uint8_t byte){ } -int acurite5n1_callback(bitbuffer_t *bitbuffer) { - // acurite 5n1 weather sensor decoding for rtl_433 - // Jens Jensen 2014 - bitrow_t *bb = bitbuffer->bb; - int i; - uint8_t *buf = NULL; - // run through rows til we find one with good checksum (brute force) - for (i=0; i < BITBUF_ROWS; i++) { - if (acurite_detect(bb[i])) { - buf = bb[i]; - break; // done - } - } - - if (buf) { - // decode packet here - if (debug_output) { - fprintf(stdout, "Detected Acurite 5n1 sensor, %d bits\n",bitbuffer->bits_per_row[1]); - for (i=0; i < 8; i++) - fprintf(stdout, "%02X ", buf[i]); - fprintf(stdout, "Checksum OK\n"); - } - - if ((buf[2] & 0x0F) == 1) { - // wind speed, wind direction, rainfall - - float rainfall = 0.00; - int raincounter = acurite_getRainfallCounter(buf[5], buf[6]); - if (acurite_5n1raincounter > 0) { - // track rainfall difference after first run - rainfall = ( raincounter - acurite_5n1raincounter ) * 0.01; - } else { - // capture starting counter - acurite_5n1raincounter = raincounter; - } - - fprintf(stdout, "wind speed: %d kph, ", - acurite_getWindSpeed(buf[3], buf[4])); - fprintf(stdout, "wind direction: %0.1f°, ", - acurite_getWindDirection(buf[4])); - fprintf(stdout, "rain gauge: %0.2f in.\n", rainfall); - - } else if ((buf[2] & 0x0F) == 8) { - // wind speed, temp, RH - fprintf(stdout, "wind speed: %d kph, ", - acurite_getWindSpeed(buf[3], buf[4])); - fprintf(stdout, "temp: %2.1f° F, ", - acurite_getTemp(buf[4], buf[5])); - fprintf(stdout, "humidity: %d%% RH\n", - acurite_getHumidity(buf[6])); - } - } else { - return 0; - } - - return 1; -} - static int acurite_rain_gauge_callback(bitbuffer_t *bitbuffer) { bitrow_t *bb = bitbuffer->bb; // This needs more validation to positively identify correct sensor type, but it basically works if message is really from acurite raingauge and it doesn't have any errors @@ -819,16 +761,6 @@ static int acurite_606_callback(bitbuffer_t *bitbuf) { return 0; } -r_device acurite5n1 = { - .name = "Acurite 5n1 Weather Station", - .modulation = OOK_PULSE_PWM_RAW, - .short_limit = 280, - .long_limit = 520, - .reset_limit = 800, - .json_callback = &acurite5n1_callback, - .disabled = 1, - .demod_arg = 0, -}; r_device acurite_rain_gauge = { .name = "Acurite 896 Rain Gauge", From cecba5d041d261cb9c07d65d3fb97c297bf0c1b9 Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 08:56:01 -0600 Subject: [PATCH 03/13] normalize temperature key --- src/devices/acurite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index b6d1f685b..a826bc04d 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -492,7 +492,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "channel", NULL, DATA_STRING, &channel_str, "message_type", NULL, DATA_INT, message_type, "wind_speed", NULL, DATA_FORMAT, "%d", DATA_INT, wind_speed, - "temperature", NULL, DATA_FORMAT, "%.1f C", DATA_DOUBLE, tempc, + "temperature_C", "temperature", DATA_FORMAT, "%.1f C", DATA_DOUBLE, tempc, "humidity", NULL, DATA_FORMAT, "%d", DATA_INT, humidity, NULL); data_acquired_handler(data); From 51955a6e798e178db7018d8bedab42ff93efbceb Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 10:00:16 -0600 Subject: [PATCH 04/13] acurite5n1 battery status --- src/devices/acurite.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index a826bc04d..1cffde8b1 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -437,7 +437,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { sensor_id = acurite_5n1_getSensorId(bb[0],bb[1]); repeat_no = acurite_5n1_getMessageCaught(bb[0]); message_type = bb[2] & 0x3f; - + battery_low = bb[3] & 0x40 >> 6; if (message_type == 0x31) { // Wind speed, wind direction, and rain fall @@ -468,6 +468,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "model", "", DATA_STRING, "Acurite 5n1 sensor", "sensor_id", NULL, DATA_FORMAT, "0x%02X", DATA_INT, sensor_id, "channel", NULL, DATA_STRING, &channel_str, + "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", "message_type", NULL, DATA_INT, message_type, "wind_speed", NULL, DATA_FORMAT, "%d", DATA_INT, wind_speed, "wind_dir_deg", NULL, DATA_FORMAT, "%.1f", DATA_DOUBLE, wind_dird, @@ -490,6 +491,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "model", "", DATA_STRING, "Acurite 5n1 sensor", "sensor_id", NULL, DATA_FORMAT, "0x%02X", DATA_INT, sensor_id, "channel", NULL, DATA_STRING, &channel_str, + "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", "message_type", NULL, DATA_INT, message_type, "wind_speed", NULL, DATA_FORMAT, "%d", DATA_INT, wind_speed, "temperature_C", "temperature", DATA_FORMAT, "%.1f C", DATA_DOUBLE, tempc, From 520aad325aab7d599724d4ca71d01469f77afeef Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 10:19:15 -0600 Subject: [PATCH 05/13] correct acurite5n1 wind speed formula --- src/devices/acurite.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index 1cffde8b1..631a65b63 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -153,15 +153,18 @@ static float acurite_getTemp (uint8_t highbyte, uint8_t lowbyte) { return temp; } -static int acurite_getWindSpeed (uint8_t highbyte, uint8_t lowbyte) { +static float acurite_getWindSpeed_kph (uint8_t highbyte, uint8_t lowbyte) { // range: 0 to 159 kph - // TODO: sensor does not seem to be in kph, e.g., - // a value of 49 here was registered as 41 kph on base unit - // value could be rpm, etc which may need (polynomial) scaling factor?? + // raw number is cup rotations per 4 seconds + // http://www.wxforum.net/index.php?topic=27244.0 (found from weewx driver) int highbits = ( highbyte & 0x1F) << 3; int lowbits = ( lowbyte & 0x70 ) >> 4; - int speed = highbits | lowbits; - return speed; + int rawspeed = highbits | lowbits; + float speed_kph = 0; + if (rawspeed > 0) { + speed_kph = rawspeed * 0.8278 + 1.0; + } + return speed_kph; } // For the 5n1 based on a linear/circular encoding. @@ -347,12 +350,12 @@ static float acurite_txr_getTemp (uint8_t highbyte, uint8_t lowbyte) { static int acurite_txr_callback(bitbuffer_t *bitbuf) { int browlen, valid = 0; uint8_t *bb; - float tempc, tempf, wind_dird, rainfall = 0.0, wind_speedmph; + float tempc, tempf, wind_dird, rainfall = 0.0, wind_speed, wind_speedmph; uint8_t humidity, sensor_status, repeat_no, message_type; char channel, *wind_dirstr = ""; char channel_str[2]; uint16_t sensor_id; - int wind_speed, raincounter, temp, battery_low; + int raincounter, temp, battery_low; uint8_t strike_count, strike_distance; data_t *data; @@ -441,7 +444,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { if (message_type == 0x31) { // Wind speed, wind direction, and rain fall - wind_speed = acurite_getWindSpeed(bb[3], bb[4]); + wind_speed = acurite_getWindSpeed_kph(bb[3], bb[4]); wind_speedmph = kmph2mph(wind_speed); wind_dird = acurite_5n1_winddirections[bb[4] & 0x0f]; wind_dirstr = acurite_5n1_winddirection_str[bb[4] & 0x0f]; @@ -468,9 +471,9 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "model", "", DATA_STRING, "Acurite 5n1 sensor", "sensor_id", NULL, DATA_FORMAT, "0x%02X", DATA_INT, sensor_id, "channel", NULL, DATA_STRING, &channel_str, - "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", + "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", "message_type", NULL, DATA_INT, message_type, - "wind_speed", NULL, DATA_FORMAT, "%d", DATA_INT, wind_speed, + "wind_speed", NULL, DATA_FORMAT, "%.1f km/h", DATA_DOUBLE, wind_speed, "wind_dir_deg", NULL, DATA_FORMAT, "%.1f", DATA_DOUBLE, wind_dird, "wind_dir", NULL, DATA_STRING, wind_dirstr, "rainfall", NULL, DATA_FORMAT, "%.2f in", DATA_DOUBLE, rainfall, @@ -480,8 +483,8 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { } else if (message_type == 0x38) { // Wind speed, temperature and humidity - wind_speed = acurite_getWindSpeed(bb[3], bb[4]); - wind_speedmph = kmph2mph((float) wind_speed); + wind_speed = acurite_getWindSpeed_kph(bb[3], bb[4]); + wind_speedmph = kmph2mph(wind_speed); tempf = acurite_getTemp(bb[4], bb[5]); tempc = fahrenheit2celsius(tempf); humidity = acurite_getHumidity(bb[6]); @@ -491,9 +494,9 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "model", "", DATA_STRING, "Acurite 5n1 sensor", "sensor_id", NULL, DATA_FORMAT, "0x%02X", DATA_INT, sensor_id, "channel", NULL, DATA_STRING, &channel_str, - "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", + "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", "message_type", NULL, DATA_INT, message_type, - "wind_speed", NULL, DATA_FORMAT, "%d", DATA_INT, wind_speed, + "wind_speed", NULL, DATA_FORMAT, "%.1f km/h", DATA_DOUBLE, wind_speed, "temperature_C", "temperature", DATA_FORMAT, "%.1f C", DATA_DOUBLE, tempc, "humidity", NULL, DATA_FORMAT, "%d", DATA_INT, humidity, NULL); From 476f2c878d783f47f2aba1a6e35455c82912212f Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 14:12:32 -0600 Subject: [PATCH 06/13] add raw msg debug output for acurite5n1 --- src/devices/acurite.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index 631a65b63..03028bdf4 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -435,6 +435,10 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { // The 5-n-1 weather sensor messages are 8 bytes. if (browlen == ACURITE_5N1_BITLEN / 8) { + if (debug_output) { + fprintf(stderr, "Acurite 5n1 raw msg: %02X %02X %02X %02X %02X %02X %02X %02X\n", + bb[0], bb[1], bb[2], bb[3], bb[4], bb[5], bb[6], bb[7]); + } channel = acurite_getChannel(bb[0]); sprintf(channel_str, "%c", channel); sensor_id = acurite_5n1_getSensorId(bb[0],bb[1]); From 458398208bf02d62d7e5e2e3cf0531301f2a3a8d Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 14:14:04 -0600 Subject: [PATCH 07/13] acurite5n1: fix battery status --- src/devices/acurite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index 03028bdf4..fb75c23e7 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -444,7 +444,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { sensor_id = acurite_5n1_getSensorId(bb[0],bb[1]); repeat_no = acurite_5n1_getMessageCaught(bb[0]); message_type = bb[2] & 0x3f; - battery_low = bb[3] & 0x40 >> 6; + battery_low = (bb[2] & 0x40) >> 6; if (message_type == 0x31) { // Wind speed, wind direction, and rain fall From 51c6307e7522d4b6cbb966462d6773196266ef0f Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 17:21:47 -0600 Subject: [PATCH 08/13] don't mess up device ordering --- include/rtl_433_devices.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/rtl_433_devices.h b/include/rtl_433_devices.h index 6a26b2a6f..cf18a9203 100755 --- a/include/rtl_433_devices.h +++ b/include/rtl_433_devices.h @@ -12,6 +12,7 @@ DECL(elv_em1000) \ DECL(elv_ws2000) \ DECL(lacrossetx) \ + DECL(template) \ DECL(acurite_rain_gauge) \ DECL(acurite_th) \ DECL(oregon_scientific) \ From 89da09b7e49e2985fb74a051fd208c3cb2911119 Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 17:44:12 -0600 Subject: [PATCH 09/13] remove old, incorrect wind direction mapping --- src/devices/acurite.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index fb75c23e7..058e93d79 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -61,14 +61,6 @@ static char time_str[LOCAL_TIME_BUFLEN]; // E, 7, NNE, 22.5 // F, C, S, 180.0 - - -// original 5-n-1 wind direction values -// from Jens/Helge -const float acurite_winddirections[] = - { 337.5, 315.0, 292.5, 270.0, 247.5, 225.0, 202.5, 180, - 157.5, 135.0, 112.5, 90.0, 67.5, 45.0, 22.5, 0.0 }; - // From draythomp/Desert-home-rtl_433 // matches acu-link internet bridge values // The mapping isn't circular, it jumps around. @@ -103,7 +95,7 @@ const float acurite_5n1_winddirections[] = 67.5, // 8 - ENE 135.0, // 9 - SE 90.0, // a - E - 112.5, // b - 112.5 + 112.5, // b - ESE 45.0, // c - NE 157.5, // d - SSE 22.5, // e - NNE @@ -167,13 +159,6 @@ static float acurite_getWindSpeed_kph (uint8_t highbyte, uint8_t lowbyte) { return speed_kph; } -// For the 5n1 based on a linear/circular encoding. -static float acurite_getWindDirection (uint8_t byte) { - // 16 compass points, ccw from (NNW) to 15 (N) - int direction = byte & 0x0F; - return acurite_winddirections[direction]; -} - static int acurite_getHumidity (uint8_t byte) { // range: 1 to 99 %RH int humidity = byte & 0x7F; From 47d00dd8b26cbac3a825caa084ea984b4de98faf Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 17:53:17 -0600 Subject: [PATCH 10/13] output raw rain counter values, use define for msg type --- src/devices/acurite.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index 058e93d79..bde2d2fa0 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -26,6 +26,10 @@ #define ACURITE_5N1_BITLEN 64 #define ACURITE_6045_BITLEN 72 +// ** Acurite known message types +#define ACURITE_MSGTYPE_WINDSPEED_WINDDIR_RAINFALL 0x31 +#define ACURITE_MSGTYPE_WINDSPEED_TEMP_HUMIDITY 0x38 + static char time_str[LOCAL_TIME_BUFLEN]; @@ -431,7 +435,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { message_type = bb[2] & 0x3f; battery_low = (bb[2] & 0x40) >> 6; - if (message_type == 0x31) { + if (message_type == ACURITE_MSGTYPE_WINDSPEED_WINDDIR_RAINFALL) { // Wind speed, wind direction, and rain fall wind_speed = acurite_getWindSpeed_kph(bb[3], bb[4]); wind_speedmph = kmph2mph(wind_speed); @@ -465,12 +469,13 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "wind_speed", NULL, DATA_FORMAT, "%.1f km/h", DATA_DOUBLE, wind_speed, "wind_dir_deg", NULL, DATA_FORMAT, "%.1f", DATA_DOUBLE, wind_dird, "wind_dir", NULL, DATA_STRING, wind_dirstr, - "rainfall", NULL, DATA_FORMAT, "%.2f in", DATA_DOUBLE, rainfall, + "rainfall_accumulation", NULL, DATA_FORMAT, "%.2f in", DATA_DOUBLE, rainfall, + "raincounter_raw", NULL, DATA_INT, raincounter, NULL); data_acquired_handler(data); - } else if (message_type == 0x38) { + } else if (message_type == ACURITE_MSGTYPE_WINDSPEED_TEMP_HUMIDITY) { // Wind speed, temperature and humidity wind_speed = acurite_getWindSpeed_kph(bb[3], bb[4]); wind_speedmph = kmph2mph(wind_speed); From 35c84721562d18c8423e4422f87abb45629b9af6 Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 18:56:14 -0600 Subject: [PATCH 11/13] move all units to native customary/US --- src/devices/acurite.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index bde2d2fa0..9a36f5bf6 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -145,8 +145,8 @@ static float acurite_getTemp (uint8_t highbyte, uint8_t lowbyte) { int highbits = (highbyte & 0x0F) << 7 ; int lowbits = lowbyte & 0x7F; int rawtemp = highbits | lowbits; - float temp = (rawtemp - 400) / 10.0; - return temp; + float temp_F = (rawtemp - 400) / 10.0; + return temp_F; } static float acurite_getWindSpeed_kph (uint8_t highbyte, uint8_t lowbyte) { @@ -466,7 +466,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "channel", NULL, DATA_STRING, &channel_str, "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", "message_type", NULL, DATA_INT, message_type, - "wind_speed", NULL, DATA_FORMAT, "%.1f km/h", DATA_DOUBLE, wind_speed, + "wind_speed", NULL, DATA_FORMAT, "%.1f mph", DATA_DOUBLE, wind_speedmph, "wind_dir_deg", NULL, DATA_FORMAT, "%.1f", DATA_DOUBLE, wind_dird, "wind_dir", NULL, DATA_STRING, wind_dirstr, "rainfall_accumulation", NULL, DATA_FORMAT, "%.2f in", DATA_DOUBLE, rainfall, @@ -490,8 +490,8 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "channel", NULL, DATA_STRING, &channel_str, "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", "message_type", NULL, DATA_INT, message_type, - "wind_speed", NULL, DATA_FORMAT, "%.1f km/h", DATA_DOUBLE, wind_speed, - "temperature_C", "temperature", DATA_FORMAT, "%.1f C", DATA_DOUBLE, tempc, + "wind_speed", NULL, DATA_FORMAT, "%.1f mph", DATA_DOUBLE, wind_speedmph, + "temperature_F", "temperature", DATA_FORMAT, "%.1f F", DATA_DOUBLE, tempf, "humidity", NULL, DATA_FORMAT, "%d", DATA_INT, humidity, NULL); data_acquired_handler(data); From 877cf4fc29ded4d25c71517cba5a40ca489d6d97 Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Sat, 7 Jan 2017 19:24:18 -0600 Subject: [PATCH 12/13] remove another unused function --- src/devices/acurite.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index 9a36f5bf6..44f4ccd7d 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -125,19 +125,6 @@ static int acurite_checksum(uint8_t row[BITBUF_COLS], int cols) { return 0; } -static int acurite_detect(uint8_t *pRow) { - int i; - if ( pRow[0] != 0x00 ) { - // invert bits due to wierd issue - for (i = 0; i < 8; i++) - pRow[i] = ~pRow[i] & 0xFF; - pRow[0] |= pRow[8]; // fix first byte that has mashed leading bit - - if (acurite_checksum(pRow, 7)) - return 1; // valid checksum - } - return 0; -} // Temperature encoding for 5-n-1 sensor and possibly others static float acurite_getTemp (uint8_t highbyte, uint8_t lowbyte) { From 33aabf6cd5c409e7e37dc54f749b0b39404f75ee Mon Sep 17 00:00:00 2001 From: Jens Jensen Date: Tue, 10 Jan 2017 12:08:30 -0600 Subject: [PATCH 13/13] acurite 5n1: output message sequence number --- src/devices/acurite.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/devices/acurite.c b/src/devices/acurite.c index 44f4ccd7d..26058b1ad 100755 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -327,7 +327,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { int browlen, valid = 0; uint8_t *bb; float tempc, tempf, wind_dird, rainfall = 0.0, wind_speed, wind_speedmph; - uint8_t humidity, sensor_status, repeat_no, message_type; + uint8_t humidity, sensor_status, sequence_num, message_type; char channel, *wind_dirstr = ""; char channel_str[2]; uint16_t sensor_id; @@ -418,7 +418,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { channel = acurite_getChannel(bb[0]); sprintf(channel_str, "%c", channel); sensor_id = acurite_5n1_getSensorId(bb[0],bb[1]); - repeat_no = acurite_5n1_getMessageCaught(bb[0]); + sequence_num = acurite_5n1_getMessageCaught(bb[0]); message_type = bb[2] & 0x3f; battery_low = (bb[2] & 0x40) >> 6; @@ -451,6 +451,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "model", "", DATA_STRING, "Acurite 5n1 sensor", "sensor_id", NULL, DATA_FORMAT, "0x%02X", DATA_INT, sensor_id, "channel", NULL, DATA_STRING, &channel_str, + "sequence_num", NULL, DATA_INT, sequence_num, "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", "message_type", NULL, DATA_INT, message_type, "wind_speed", NULL, DATA_FORMAT, "%.1f mph", DATA_DOUBLE, wind_speedmph, @@ -475,6 +476,7 @@ static int acurite_txr_callback(bitbuffer_t *bitbuf) { "model", "", DATA_STRING, "Acurite 5n1 sensor", "sensor_id", NULL, DATA_FORMAT, "0x%02X", DATA_INT, sensor_id, "channel", NULL, DATA_STRING, &channel_str, + "sequence_num", NULL, DATA_INT, sequence_num, "battery", NULL, DATA_STRING, battery_low ? "OK" : "LOW", "message_type", NULL, DATA_INT, message_type, "wind_speed", NULL, DATA_FORMAT, "%.1f mph", DATA_DOUBLE, wind_speedmph,