forked from rinie/weatherstationFSK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherstationFSK.ino
706 lines (639 loc) · 21.4 KB
/
weatherstationFSK.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
/// FSK weather station receiver
/// Receive packets echoes to serial.
/// Updates DCF77 time.
/// Supports Alecto WS3000, WS4000, Fine Offset WH1080 and similar 868MHz stations
/// National Geographic 265 requires adaptation of frequency to 915MHz band.
/// input handler and send functionality in code, but not implemented or used.
/// @see http://jeelabs.org/2010/12/11/rf12-acknowledgements/
// 2013-03-03<[email protected]> http://opensource.org/licenses/mit-license.php
// 2013-03-29 Rinie added IT+ and TI+WS1600 decoding
//#include <JeeLib.h>
#include "RF12WS.h"
#include <Time.h>
//Define the printed output
#define LOGRAW 1 //comment = disable, uncomment = enable logging received package group_id 212 (0xD4)
#define LOGPKT 1 //comment = disable, uncomment = enable logging unique package passing crc
#define LOGDCF 1 //comment = disable, uncomment = enable updating time and logging of DCF77 values
#define LOGDAT 1 //comment = disable, uncomment = enable logging of parsed sensor data
//WH1080 V2 protocol defines
#define MSG_WS4000 1
#define MSG_WS3000 2
#define LEN_WS4000 10
#define LEN_WS3000 9
#define LEN_MAX 10
#define CRC_LEN_MIN 10
#define ITPLUS // Rinie
#ifdef ITPLUS
#define MSG_UNKNOWN 0
#define MSG_ITPLUS 3
#define LEN_ITPLUS 5
//#define LEN_MAX 48
#define CRC_LEN_MIN 5
#define MSG_ITPLUS1600 4
#define ITPLUS1600
#undef ITPLUS1600 // fine offset and IT+ TX37/29
#ifdef ITPLUS1600
#define LEN_MAX 16
#endif
#endif
#define SERIAL_BAUD 57600
//#define LED_PIN 9 // activity LED, comment out to disable
#define COLLECT 0x20 // collect mode, i.e. pass incoming without sending acks
#define NODE_ID 22 //any node works wih modified driver. Use 31 for unmodified driver.
//#define NODE_ID (31 | COLLECT)
#define GROUP_ID 212
static void activityLed (byte on) {
#ifdef LED_PIN
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, !on);
#endif
}
//inputHandler parameters
static byte value/*, stack[RF12_MAXDATA], top*/;
//receive parameters
static byte quiet=0;
//send parameters
static char cmd;
static byte sendLen, dest;
static byte testbuf[RF12_MAXDATA]/*, testCounter*/;
static unsigned long ok_ts;
static byte packet_found = 0;
static byte ok_cnt = 0;
static byte pkt_cnt = 0;
static uint8_t packet[LEN_MAX];
static uint8_t msgformat = 0;
static uint8_t pktlen = LEN_MAX;
void configureWH1080 () {
rf12_control(0x80E7); // 80E7 868 Mhz;enable tx register; enable RX
// fifo buffer; xtal cap 12pf
rf12_control(0xA67C); // A67C 868.300 MHz
//rf12_control(0xE105); // E105 Wakeup timer 10ms
//rf12_control(0xC80E); // disable low dutycycle, but set at D=7 (3%)
rf12_control(0xC49F); // C49F AFC keep during receive VDI=high; enable AFC; enable
// frequency offset register; +15 -16
rf12_control(0xC26A); // C26A manual, fast mode, digital filter, DQD=2
#ifndef ITPLUS1600
rf12_control(0xC613); // C613 17.24 kbps // fine offset and IT+ TX37/29 http://fredboboss.free.fr/tx29/index.php?lang=en, http://forum.jeelabs.net/node/110, http://gcrnet.net/node/32
#else
//rf12_control(0xC623); // C613 17.24 kbps ws1600 try POR
rf12_control(0xC628); // C613 half speed at http://www.g-romahn.de/ws1600
#endif
rf12_control(0xC006); // 1.00MHz, 2.8V
rf12_control(0x94A0); // 94A0 VDI; FAST; 134khz; Gain -0db; DRSSI 103dbm
//rf12_control(0xCED4); // Synchron word = 0x2DD4
rf12_control(0xCA81); // CA81 FIFO intliength=8, sync on 0x2DD4.,
// reset non-sensitive, disable FIFO
rf12_control(0x820D); // 820D disable receiver
//need for those transmit related commands unclear!
rf12_control(0xCC67); // CC67 pll settings command
rf12_control(0xB800); // TX register write command not used
rf12_control(0x82DD); // 82DD enable receiver
rf12_control(0xCA83); // CA83 FIFO intliength=8, sync on 0x2DD4.,
// reset non-sensitive, enable FIFO
}
static void do_tests() {
Serial.println(F("Test time packet WS3000"));
uint8_t testbuf1[] = {0x6D, 0x7A, 0x49, 0x04, 0x21, 0x13, 0x83, 0x04, 0xD6};
byte crc_ok = testbuf1[8] == _crc8(testbuf1, 8);
Serial.print(crc_ok ? F("crc ok ") : F("crc nok "));
update_time((uint8_t*)testbuf1);
Serial.println(F("Test sensor packet WS3000"));
uint8_t testbuf2[] = {0x5D, 0x70, 0x2D, 0x41, 0x02, 0x05, 0x03, 0x0C, 0x4C};
crc_ok = testbuf2[8] == _crc8(testbuf2, 8);
Serial.print(crc_ok ? F("crc ok ") : F("crc nok "));
decodeSensorData(MSG_WS3000, testbuf2);
//Serial.println(F("Test time packet WS4000"));
//char testbuf[] = {0xB4, 0x00, 0x56, 0x03, 0x31, 0x13, 0xC3, 0x03, 0x45, 0x4C};
//update_time((uint8_t*)testbuf);
//Serial.println(F("Test sensor packet WS4000"));
//char testbuf3[] = {0xA4, 0xF0, 0x3C, 0x48, 0x00, 0x00, 0x03, 0xC6, 0x04, 0x53};
//decodeSensorData(MSG_WS4000, testbuf3);
////negative temperature
//char testbuf4[] = {0xA4, 0xF8, 0x3C, 0x48, 0x00, 0x00, 0x03, 0xC6, 0x04, 0x53};
//decodeSensorData(MSG_WS4000, testbuf4);
}
static void handleInput (char c) {
if ('0' <= c && c <= '9') {
value = 10 * value + c - '0';
} else if ('a' <= c && c <='z') {
Serial.print("> ");
Serial.print((int) value);
Serial.println(c);
switch (c) {
default:
Serial.print("\n - input handler not implemented");
break;
case 'h': // help
Serial.print("\n - help - input handler not implemented");
break;
}
value = 0;
} else if ('A' <= c && c <= 'Z') {
Serial.print("\n - input handler not implemented");
} else if (c > ' ')
Serial.print("\n - input handler not implemented");
}
void setup() {
cmd = 0;
Serial.begin(SERIAL_BAUD);
Serial.println();
#ifndef ITPLUS1600
Serial.println("[weatherstationFSK]");
#else
Serial.println("[weatherstationWS1600FSK]");
#endif
activityLed(1);
rf12_initialize(NODE_ID, RF12_868MHZ, GROUP_ID);
configureWH1080();
rf12_setFixedLength(LEN_MAX);
//test
//do_tests();
}
void loop() {
if (Serial.available())
handleInput(Serial.read());
if (rf12_recvDone()) {
//check crc
pkt_cnt++;
byte crc_ok = 0;
uint8_t mt = rf12_buf[1] >> 4;
switch (mt) {
case 0x5:
case 0x6: {
crc_ok = rf12_buf[9] == _crc8(&rf12_buf[1], 8);
if (crc_ok) ok_cnt++;
msgformat = MSG_WS3000;
pktlen = LEN_WS3000;
break;
}
case 0x9: // it+ fast
crc_ok = rf12_buf[5] == _crc8(&rf12_buf[1], 4);
if (crc_ok) ok_cnt++;
msgformat = MSG_ITPLUS;
pktlen = LEN_ITPLUS;
break;
case 0xA:
#ifdef ITPLUS1600
{
byte datasets = rf12_buf[2] & 0x07; // 2bytes, 4 nibbles
if (datasets <= 5) { // odd, blank lower 0 of last byte
pktlen = datasets * 2 + 2 + 1;
crc_ok = rf12_buf[pktlen] == _crc8(&rf12_buf[1], pktlen-1);
if (crc_ok) { ok_cnt++;
msgformat = MSG_ITPLUS1600;
}
}
break;
}
#endif
case 0xB: {
crc_ok = rf12_buf[10] == _crc8(&rf12_buf[1], 9);
if (crc_ok) ok_cnt++;
msgformat = MSG_WS4000;
pktlen = LEN_WS4000;
break;
}
default:
msgformat = MSG_UNKNOWN;
break; //crc_ok=0;
}
#ifdef LOGRAW
#ifdef ITPLUS
if ((!msgformat)|| (!crc_ok)) {
#endif
//Log all packages. Packages may be missed due to short intervals
Serial.print(crc_ok ? " ok " : "nok ");
#if 1
if (!crc_ok) {
for (byte i = 2; i < LEN_MAX; i++) { // test if crc with itself is 0
if (!_crc8(&rf12_buf[1], i)) {
Serial.print("crclen ");
Serial.print(i);
Serial.print(":");
}
}
}
#endif
for (byte i = 1; i < LEN_MAX+1; i++) {
Serial.print(' ');
Serial.print(rf12_buf[i] >> 4, HEX);
Serial.print(rf12_buf[i] & 0x0F, HEX);
}
Serial.println();
//Serial.println(millis());
#ifdef ITPLUS
}
#if 0 // capture only unknown
//else {
msgformat = MSG_UNKNOWN;
crc_ok = 0;
//}
#endif
#endif
#endif
//save the first crc_ok package of a burst
if ((!packet_found) && crc_ok){
//start one second interval to count upto six identical packets.
ok_ts=millis();
packet_found = 1; //true
memcpy(packet, (char *)&rf12_buf[1], LEN_MAX);
}
//Standard RF12 messages requireing an ACK
if (rf12_crc == 0) {
activityLed(1);
//if (RF12_WANTS_ACK)
// rf12_sendStart(RF12_ACK_REPLY, 0, 0);
if (RF12_WANTS_ACK && (NODE_ID & COLLECT) == 0) {
Serial.println(" -> ack");
rf12_sendStart(RF12_ACK_REPLY, 0, 0);
}
activityLed(0);
}
}
//Report if transmission is finished (38ms after first package detected)
if (packet_found && (((msgformat == MSG_ITPLUS) || (msgformat == MSG_ITPLUS1600)) || ((millis()-ok_ts > 50)))) {
#ifdef LOGDCF
//Set time if time packet received
uint8_t mt = packet[0] >> 4;
if (mt == 0xB || mt == 0x6) {
update_time(/*msgformat,*/ packet);
}
#endif
#ifdef LOGPKT
//Transmission of repeated packages is done. Report results.
#ifdef ITPLUS
if ((msgformat != MSG_ITPLUS) && (msgformat != MSG_ITPLUS1600)) {
#endif
timestamp();
Serial.print(" pkt_cnt: ");
Serial.print(pkt_cnt);
Serial.print(" ok_cnt: ");
Serial.print(ok_cnt);
Serial.print(" pkt: ");
for (byte i = 0; i < pktlen; i++) {
//Serial.print(' ');
Serial.print(packet[i] >> 4, HEX);
Serial.print(packet[i] & 0x0F, HEX);
//Serial.print((int) rf12_data[i]);
}
#if 1
Serial.println();
#endif
#ifdef ITPLUS
}
#endif
#endif
#ifdef LOGDAT
#ifdef ITPLUS
if (msgformat == MSG_ITPLUS) {
decodeSensorDataItPlus(packet);
}
else if (msgformat == MSG_ITPLUS1600) {
decodeSensorDataWs1600(packet);
}
else if (ok_cnt > 1)
#endif
if (mt == 0xA || mt == 0x5) {
timestamp();
decodeSensorData(msgformat, packet);
}
#endif
//reset administration
ok_cnt = pkt_cnt = 0;
packet_found = 0; //false
}
if (cmd && rf12_canSend()) {
activityLed(1);
Serial.print(" -> ");
Serial.print((int) sendLen);
Serial.println(" b");
byte header = cmd == 'a' ? RF12_HDR_ACK : 0;
if (dest)
header |= RF12_HDR_DST | dest;
rf12_sendStart(header, testbuf, sendLen);
cmd = 0;
activityLed(0);
}
}
/*
* Function taken from Luc Small (http://lucsmall.com), itself
* derived from the OneWire Arduino library. Modifications to
* the polynomial according to Fine Offset's CRC8 calulations.
*/
//uint8_t _crc8( const uint8_t *addr, uint8_t len)
uint8_t _crc8(volatile uint8_t *addr, uint8_t len)
{
uint8_t crc = 0;
// Indicated changes are from reference CRC-8 function in OneWire library
while (len--) {
uint8_t inbyte = *addr++;
uint8_t i;
for (i = 8; i; i--) {
uint8_t mix = (crc ^ inbyte) & 0x80; // changed from & 0x01
crc <<= 1; // changed from right shift
if (mix) crc ^= 0x31;// changed from 0x8C;
inbyte <<= 1; // changed from right shift
}
}
return crc;
}
void timestamp()
{
Serial.print(year());
Serial.print("-");
printDigits(month());
Serial.print("-");
printDigits(day());
Serial.print(" ");
printDigits(hour());
Serial.print(":");
printDigits(minute());
Serial.print(":");
printDigits(second());
Serial.print(" ");
}
void printDigits(int digits){
// utility function for digital clock display: leading 0
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
int BCD2bin(uint8_t BCD) {
return (10 * (BCD >> 4 & 0xF) + (BCD & 0xF));
}
void update_time(uint8_t* tbuf) {
setTime(BCD2bin(tbuf[2] & 0x3F),BCD2bin(tbuf[3]),BCD2bin(tbuf[4]),BCD2bin(tbuf[7]),BCD2bin(tbuf[6] & 0x1F),BCD2bin(tbuf[5]));
Serial.print("Time synchronized with DCF77: ");
timestamp();
Serial.println();
}
char* formatDouble( double val, byte precision, char* ascii, uint8_t ascii_len){
// formats val with number of decimal places determine by precision
// precision is a number from 0 to 6 indicating the desired decimial places
snprintf(ascii,ascii_len,"%d",int(val));
if( precision > 0) {
strcat(ascii,".");
unsigned long frac;
unsigned long mult = 1;
byte padding = precision -1;
while(precision--)
mult *=10;
if(val >= 0)
frac = (val - int(val)) * mult;
else
frac = (int(val)- val ) * mult;
unsigned long frac1 = frac;
while( frac1 /= 10 )
padding--;
while( padding--)
strcat(ascii,"0");
char str[7];
snprintf(str,sizeof(str),"%d",frac);
strcat(ascii,str);
}
}
void decodeSensorData(uint8_t fmt, uint8_t* sbuf) {
char *compass[] = {"N ", "NNE", "NE ", "ENE", "E ", "ESE", "SE ", "SSE", "S ", "SSW", "SW ", "WSW", "W ", "WNW", "NW ", "NNW"};
uint8_t windbearing = 0;
// station id
uint8_t stationid = (sbuf[0] << 4) | (sbuf[1] >>4);
// temperature
uint8_t sign = (sbuf[1] >> 3) & 1;
int16_t temp = ((sbuf[1] & 0x07) << 8) | sbuf[2];
if (sign)
temp = (~temp)+sign;
double temperature = temp * 0.1;
//humidity
uint8_t humidity = sbuf[3] & 0x7F;
//wind speed
double windspeed = sbuf[4] * 0.34;
//wind gust
double windgust = sbuf[5] * 0.34;
//rainfall
double rain = (((sbuf[6] & 0x0F) << 8) | sbuf[7]) * 0.3;
if (fmt == MSG_WS4000) {
//wind bearing
windbearing = sbuf[8] & 0x0F;
}
char tstr[6];
formatDouble(temperature, 1, tstr, sizeof(tstr));
char wsstr[6];
formatDouble(windspeed, 1, wsstr, sizeof(wsstr));
char wgstr[6];
formatDouble(windgust, 1, wgstr, sizeof(wgstr));
char rstr[7];
formatDouble(rain, 1, rstr, sizeof(rstr));
char str[110];
str[0] = 0;
if (fmt == MSG_WS4000) {
snprintf(str,sizeof(str),"ID: %2X, T=%5s`C, relH=%3d%%, Wvel=%5sm/s, Wmax=%5sm/s, Wdir=%3s, Rain=%6smm",
stationid,
tstr,
humidity,
wsstr,
wgstr,
compass[windbearing],
rstr);
}
if (fmt == MSG_WS3000) {
snprintf(str,sizeof(str),"ID: %2X, T=%5s`C, relH=%3d%%, Wvel=%5sm/s, Wmax=%5sm/s, Rain=%6smm",
stationid,
tstr,
humidity,
wsstr,
wgstr,
rstr);
}
Serial.println(str);
}
void PrintChar(byte S) {
Serial.write(S);
}
void PrintComma(void)
{
Serial.print(", ");
}
void PrintNum(uint16_t x, char c, byte digits) {
// Rinie add space for small digits
if(c) {
PrintChar(c);
}
for (uint16_t i=1, val=10; i < digits; i++, val *= 10) {
if (x < val) {
PrintChar(' ');
}
}
Serial.print(x,DEC);
}
void PrintNumHex(uint16_t x, char c, byte digits) {
// Rinie add space for small digits
if(c) {
PrintChar(c);
}
for (uint16_t i=1, val=16; i < digits; i++, val *= 16) {
if (x < val) {
PrintChar('0');
}
}
Serial.print(x,HEX);
}
void PrintByteHex(uint8_t x, char c) {
// Rinie add space for small digits
PrintNumHex(x, c, 2);
}
/*
* IT Plus
*
* http://fredboboss.free.fr/tx29/index.php?lang=en
* http://forum.jeelabs.net/node/110
* http://gcrnet.net/node/32
*/
void decodeSensorDataItPlus(uint8_t* sbuf) {
char *compass[] = {"N ", "NNE", "NE ", "ENE", "E ", "ESE", "SE ", "SSE", "S ", "SSW", "SW ", "WSW", "W ", "WNW", "NW ", "NNW"};
uint8_t windbearing = 0;
// station id
uint8_t stationid = ((sbuf[0] & 0x0F) << 4) | ((sbuf[1] & 0xC0) >>4);
uint8_t newBattery = (sbuf[1] & 0x20) >> 5;
int8_t temp;
int8_t tempDeci;
//humidity
uint8_t humidity = (sbuf[3]) & 0x7F;
uint8_t lowBat = (sbuf[3] & 0x80) >> 7;
temp = BCD2bin(sbuf[1] & 0x0F) * 10 + BCD2bin((sbuf[2] & 0xF0)>>4);
temp = temp - 40;
tempDeci = BCD2bin((sbuf[2] & 0x0F));
Serial.print("IT+ ID: ");
Serial.print(stationid, HEX);
Serial.print(" Temp: ");
Serial.print(temp);
PrintChar('.');
PrintNum(tempDeci, 0, 1);
if (humidity < 106) {
Serial.print(" Humidity:");
PrintNum(humidity, ' ', 2);
}
if (newBattery) {
Serial.print(" N");
}
else if (lowBat) {
Serial.print(" L");
}
Serial.print(" RawData:");
for (byte i = 0; i < LEN_ITPLUS; i++) {
PrintByteHex(sbuf[i], ' ');
}
Serial.println();
}
/*
http://www.g-romahn.de/ws1600/Datepakete_raw.txt
Data - organized in nibbles - are structured as follows (exammple with blanks added for clarity):
a 5a 5 0 628 1 033 2 000 3 e00 4 000 bd
data always start with "a"
from next 1.5 nibbles (here 5a) the 6 msb are identifier of transmitter,
bit 1 indicates acquisition/synchronizing phase (so 5a >> 58 thereafter)
bit 0 will be 1 in case of error (e.g. no wind sensor 5a >> 5b)
the msb of the next nibble will be 1 in case of a low battery (LowBattery flag)
the remaining three bits are the count of quartets (here 5) that will be transmitted.
up to 5 quartets of data follow
each quartet starts with type indicator (here 0,1,2,3,4)
0: temperature, 3 nibbles bcd coded tenth of °c plus 400 (here 628-400 = 22.8°C)
1: humidity, 3 nibbles bcd coded (here 33 %rH), meaning of 1st nibble still unclear
2: rain, 3 nibbles, counter of contact closures
3: wind, first nibble direction of wind vane (multiply by 22.5 to obtain degrees,
here 0xe*22.5 = 315 degrees)
next two nibbles wind speed in m per sec (i.e. no more than 255 m/s; 9th bit still not found)
4: gust, speed in m per sec (yes, TX23 sensor does measure gusts and data are transmitted
but not displayed by WS1600), number of significant nibbles still unclear
next two bytes (here bd) are crc.
During acquisition/synchronizing phase (abt. 5 hours) all 5 quartets are sent, see examplke above. Thereafter
data strings contain only a few ( 1 up ton 3) quartets, so data strings are not! always of
equal length.
After powering on, the complete set of data will be transmitted every 4.5 secs for 5 hours during acquisition phase.
Lateron only selected sets of data will be transmitted.
Stream of received data follows:
1st line: raw data in hex format as received from sensors
2nd line: meteorological data from outdoor sensors decoded, Same values
are displayed on basestation (last duet is "calculated crc" - always 00).
a1250444109120003808401b89 00
Temp 044 Humi 91 Rain 000 Wind 028 Dir 180 Gust 097 ( 4.4 °C, 91 %rH, no rain, wind 2.8 km/h from south, gust 9.7 km/h)
*/
void decodeSensorDataWs1600(uint8_t* sbuf) {
char *compass[] = {"N ", "NNE", "NE ", "ENE", "E ", "ESE", "SE ", "SSE", "S ", "SSW", "SW ", "WSW", "W ", "WNW", "NW ", "NNW"};
uint8_t windbearing = 0;
// station id
uint8_t stationid = ((sbuf[0] & 0x0F) << 2) | ((sbuf[1] & 0xC0) >>6);
uint8_t dataSets = sbuf[1] & 0x7;
int8_t temp;
int8_t tempDeci;
//humidity
uint8_t humidity = 0;
//wind speed
uint8_t windspeed = 0;
//wind gust
uint8_t windgust = 0;
//rainfall
uint16_t rain = 0;
Serial.print("IT+WS1600 ID: ");
Serial.print(stationid, HEX);
for (byte i = 0; i < dataSets; i++) {
byte j = 2 + i*2;
byte sensorType = (sbuf[j] & 0xF0) >> 4;
switch (sensorType) { // e.g. a 5a 5 0 628 1 033 2 000 3 e00 4 000 bd
case 0: // 0: temperature, 3 nibbles bcd coded tenth of °c plus 400 (here 628-400 = 22.8°C)
temp = BCD2bin(sbuf[j] & 0x0F) * 10 + BCD2bin((sbuf[j + 1] & 0xF0)>>4);
temp = temp - 40;
tempDeci = BCD2bin((sbuf[j + 1] & 0x0F));
Serial.print(" Temp: ");
Serial.print(temp);
PrintChar('.');
PrintNum(tempDeci, 0, 1);
break;
case 1: // 1: humidity, 3 nibbles bcd coded (here 33 %rH), meaning of 1st nibble still unclear
humidity = BCD2bin(sbuf[j + 1]);
Serial.print(" Humidity:");
PrintNum(humidity, ' ', 2);
break;
case 2: // 2: rain, 3 nibbles, counter of contact closures
rain = ((sbuf[j] & 0x0F) + (sbuf[j + 1]) * 100);
Serial.print(" Rain:");
PrintNum(rain, ' ', 3);
break;
case 3: //3: wind, first nibble direction of wind vane (multiply by 22.5 to obtain degrees,
// here 0xe*22.5 = 315 degrees)
// next two nibbles wind speed in m per sec (i.e. no more than 255 m/s; 9th bit still not found)
windbearing = (sbuf[j] & 0x0F);
windspeed = (sbuf[j + 1]);
Serial.print(" Windbearing:");
PrintNum(windbearing, ' ', 2);
Serial.print(" Windspeed:");
if (windspeed >= 0xFE) {
Serial.print("---");
}
else {
PrintNum(windspeed, ' ', 3);
}
break;
case 4: // 4: gust, speed in m per sec (yes, TX23 sensor does measure gusts and data are transmitted
// but not displayed by WS1600), number of significant nibbles still unclear
windgust = ((sbuf[j] & 0x0F) * 256 + (sbuf[j + 1]));
Serial.print(" Gust:");
if (windgust >= 0xFE) {
Serial.print("---");
}
else {
PrintNum(windgust, ' ', 3);
}
break;
default:
Serial.print(" Unknown: ");
PrintNumHex(sensorType, 0, 1);
PrintNumHex(((sbuf[j] & 0x0F) * 256 + (sbuf[j + 1])), ' ', 3);
break;
}
}
Serial.print(" RawData:");
for (byte i = 0; i < dataSets * 2 + 3; i++) {
PrintByteHex(sbuf[i], ' ');
}
Serial.println();
}