-
Notifications
You must be signed in to change notification settings - Fork 3
/
monitor.cc
745 lines (665 loc) · 18.8 KB
/
monitor.cc
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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
// compile with:
// g++ monitor.cc -o monitor -L/usr/local/lib -lwiringPi
#include <cmath>
#include <cstring>
#include <dirent.h>
#include <fcntl.h>
#include <fstream>
#include <getopt.h>
#include <iomanip>
#include <iostream>
#include <linux/i2c-dev.h>
#include <sstream>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/ioctl.h>
#include <time.h>
#include <unistd.h>
#include <vector>
#include <wiringPi.h>
#define MAXTIMINGS 85
// w1 ID - 10 is considered the max usable count
char dev[20][16];
// w1 path
char path[] = "/sys/bus/w1/devices";
// found w1 devices
int w1count = 0;
// write individual sensor output for mrtg
bool mrtgoutput = false;
// global sensor count
int globalcount = 1;
// file output
bool fileoutput = false;
// help message
static void show_usage ( std::string name )
{
std::cerr << "Usage: " << name << " [-f, --file] <outputfile> [Option(s)]" << std::endl;
std::cerr << "\t-f, --file\t\tThe output file to write to." << std::endl;
std::cerr << "\t\t\t\tIf no file is selected, messages are sent to stdout." << std::endl;
std::cerr << "Options:" << std::endl;
std::cerr << "\t-h, --help\t\tShow this help message" << std::endl;
std::cerr << "\t-d, --dht11\t\tUse a DHT11 t/h sensor" << std::endl;
std::cerr << "\t-w, --w1\t\tUse w1 t sensor(s)" << std::endl;
std::cerr << "\t-s, --sht11\t\tUse a SHT11 t/h sensor" << std::endl;
std::cerr << "\t-b, --bme280\t\tUse a BME-280 t/h/p sensor" << std::endl;
std::cerr << "If no sensors are selected, all variants are probed!" << std::endl;
}
// writes to mrtg files
void mrtg_write ( std::string inputstring )
{
std::string filename;
std::stringstream ss;
ss << globalcount;
std::string str = ss.str ( );
filename = "/var/www/scripts/sensoroutput/" + str + ".txt";
std::ofstream outfile ( filename.c_str ( ) );
outfile << inputstring << std::endl;
outfile.close ( );
globalcount++;
}
// returns the current time in a formatted string
std::string gettime ( )
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
char timebuffer [90];
strftime ( timebuffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo );
return ( timebuffer );
}
// read a bme280
std::string read_bme ( )
{
// return string
std::string retstr = "";
// i2c bus
const char *bus = "/dev/i2c-1";
// raw calibration data
char data[24] = { 0 };
// temperature calibration coeff.
int T[3] = { 0 };
// pressure calibration coeff.
int P[9] = { 0 };
// humidity calibration coeff.
int H[6] = { 0 };
// the device
int device = 0;
// the register
char reg[1] = { 0 };
if ( ( device = open ( bus, O_RDWR ) ) < 0 )
{
std::cout << " BME-280 : Could not open I2C-Bus!" << std::endl;
globalcount++;
return ( "X" );
}
// get I2C device
ioctl ( device, I2C_SLAVE, 0x77 );
// get status
reg[0] = 0xF3;
write ( device, reg, 1 );
if ( read ( device, data, 1 ) != 1 )
{
std::cout << " BME-280 : Unable to read device status!" << std::endl;
globalcount++;
return ( "X" );
}
char * start = &data[0];
int total = 0;
while ( * start )
{
total *= 2;
if (*start++ == '1') total += 1;
}
// std::cout << total << std::endl;
// read 24 bytes of calibration data from address(0x88)
reg[0] = 0x88;
write ( device, reg, 1 );
if ( read ( device, data, 24 ) != 24 )
{
std::cout << " BME-280 : Unable to read temperature and pressure calibration data!" << std::endl;
globalcount++;
return ( "X" );
}
// temp coefficents
T[0] = data[1] * 256 + data[0];
T[1] = data[3] * 256 + data[2];
if ( T[1] > 32767 )
{
T[1] -= 65536;
}
T[2] = data[5] * 256 + data[4];
if ( T[2] > 32767 )
{
T[2] -= 65536;
}
// pressure coefficents
P[0] = data[7] * 256 + data[6];
for ( int i = 0; i < 8; i++ )
{
P[i + 1] = data[2 * i + 9] * 256 + data[2 * i + 8];
if ( P[i + 1] > 32767 )
{
P[i + 1] -= 65536;
}
}
// humidity coefficents, part 1
reg[0] = 0xA1;
write ( device, reg, 1 );
if ( read ( device, data, 1 ) != 1 )
{
std::cout << " BME-280 : Unable to read humidity calibration data, part 1!" << std::endl;
globalcount++;
return ( "X" );
}
H[0] = data[0];
// part 2
reg[0] = 0xE1;
write ( device, reg, 1);
if ( read ( device, data, 7 ) != 7 )
{
std::cout << " BME-280 : Unable to read humidity calibration data, part 2!" << std::endl;
globalcount++;
return ( "X" );
}
H[1] = data[1] * 256 + data[0];
if ( H[1] > 32767 )
{
H[1] -= 65536;
}
H[2] = data[2] & 0xFF;
H[3] = ( data[3] * 16 + ( data[4] * 0xF ) );
if ( H[3] > 32767 )
{
H[3] -= 65536;
}
H[4] = ( data[4] / 16 ) + ( data[5] * 16 );
if ( H[4] > 32767 )
{
H[4] -= 65536;
}
H[5] = data[6];
if ( H[5] > 32767 )
{
H[5] -= 65536;
}
char config[2] = {0};
// select control humidity register 0xF2
// humidity oversampliung rate = 1 ( 0x01 )
config[0] = 0xF2;
config[1] = 0x01;
write ( device, config, 2 );
// select control measurement register 0xF4
// normal mode, temp and pressure oversampling rate = 1 ( 0x27 )
config[0] = 0xF4;
config[1] = 0x27;
write ( device, config, 2 );
// select config register 0xF5
// stand-by time = 1000 ms = 0xA0
config[0] = 0xF5;
config[1] = 0xA0;
write ( device, config, 2 );
sleep ( 1 );
// read 8 bytes of data from register 0xF7
// pressure msb1, pressure msb, pressure lsb, temperature msb1, temperature msb, temperature lsb, humidity lsb, humidity msb
reg[0] = 0xF7;
write ( device, reg, 1 );
if ( read ( device, data, 8 ) != 8 )
{
std::cout << " BME-280 : Unable to read measurement data!" << std::endl;
globalcount++;
return ( "X" );
}
// onvert pressure, temperature and humidity data to 19-bits
long pres_read = ( ( long ) ( data[0] * 65536 + ( ( long ) ( data[1] * 256 ) + ( long ) ( data[2] & 0xF0 ) ) ) ) / 16;
long temp_read = ( ( long ) ( data[3] * 65536 + ( ( long ) ( data[4] * 256 ) + ( long ) ( data[5] & 0xF0 ) ) ) ) / 16;
long humi_read = ( long ) ( data[6] * 256 + data[7] );
// temperature offset calculations
double temp1 = ( ( ( double ) temp_read ) / 16384.0 - ( ( double ) T[0] ) / 1024.0 ) * ( ( double ) T[1]);
double temp2 = ( ( ( ( double ) temp_read ) / 131072.0 - ( ( double ) T[0] ) / 8192.0 ) * ( ( ( double ) temp_read ) / 131072.0 - ( ( double ) T[0] ) / 8192.0 ) ) * ( ( double ) T[2] );
double temp3 = temp1 + temp2;
double temperature = temp3 / 5120.0;
// pressure offset calculations
double pres1 = ( temp3 / 2.0 ) - 64000.0;
double pres2 = pres1 * pres1 * ( ( double ) P[5] ) / 32768.0;
pres2 = pres2 + pres1 * ( ( double ) P[4] ) * 2.0;
pres2 = ( pres2 / 4.0 ) + ( ( ( double ) P[3] ) * 65536.0 );
pres1 = ( ( ( double ) P[2] ) * pres1 * pres1 / 524288.0 + ( ( double ) P[1] ) * pres1 ) / 524288.0;
pres1 = ( 1.0 + pres1 / 32768.0 ) * ( ( double ) P[0] );
double pres3 = 1048576.0 - ( double ) pres_read;
// don't divide by 0
double pressure = 0.0;
if ( pres1 != 0.0 )
{
pres3 = ( pres3 - ( pres2 / 4096.0 ) ) * 6250.0 / pres1;
pres1 = ( ( double ) P[8] ) * pres3 * pres3 / 2147483648.0;
pres2 = pres3 * ( ( double ) P[7] ) / 32768.0;
pressure = ( pres3 + ( pres1 + pres2 + ( ( double ) P[6] ) ) / 16.0 ) / 100.0;
}
// humidity offset calculations
double humi1 = temp3 - 76800.0;
humi1 = ( humi_read - ( H[3] * 64.0 + H[4] / 16384.0 * humi1 ) ) * (H[1] / 65536.0 * ( 1.0 + H[5] / 67108864.0 * humi1 * ( 1.0 + H[2] / 67108864.0 * humi1 ) ) );
double humidity = humi1 * ( 1.0 - H[0] * humi1 / 524288.0 );
if ( humidity > 100.0 )
{
humidity = 100.0;
}
else if ( humidity < 0.0 )
{
humidity = 0.0;
}
// calculate pressure at sea level from barometric formula
// double alt = 100.0;
// double pressure_nn = pressure * pow ( 1 - ( -0.0065 * alt ) / ( temperature + 273.16 ), 5.255 );
// std::cout << "BME-280: Pressure: " << pressure << " hPa, pressure at sea level: " << pressure_nn << " hPa, humidity: " << humidity << " %, temperature: " << temperature << " degrees" << std::endl;
char tempstr[320];
snprintf ( tempstr, sizeof ( tempstr ), "%4.2f", pressure );
retstr = retstr + tempstr + " ";
snprintf ( tempstr, sizeof ( tempstr ), "%4.2f", humidity );
retstr = retstr + tempstr + " ";
snprintf ( tempstr, sizeof ( tempstr ), "%4.2f", temperature );
retstr = retstr + tempstr;
return ( retstr );
}
// read a dht11
std::string read_dht11 ( int DHTPIN )
{
int dht11_dat[5] = { 0 };
uint8_t laststate = HIGH;
uint8_t counter = 0;
uint8_t j = 0;
// pull pin down for at least 18 milliseconds
pinMode ( DHTPIN, OUTPUT );
digitalWrite ( DHTPIN, LOW );
delay ( 20 );
// then pull it up for 40 microseconds
digitalWrite ( DHTPIN, HIGH );
delayMicroseconds ( 40 );
// prepare to read the pin
pinMode ( DHTPIN, INPUT );
// detect change and read data
for ( int i = 0; i < MAXTIMINGS; i++ )
{
counter = 0;
while ( digitalRead ( DHTPIN ) == laststate )
{
counter++;
delayMicroseconds ( 1 );
if ( counter == 255 )
{
break;
}
}
laststate = digitalRead ( DHTPIN );
if ( counter == 255 )
{
break;
}
// ignore first 3 transitions
if ( ( i >= 4 ) && ( i % 2 == 0 ) )
{
// shove each bit into the storage bytes
dht11_dat[j / 8] <<= 1;
if ( counter > 16 )
{
dht11_dat[j / 8] |= 1;
}
j++;
}
}
char retstr[32];
// check that we read 40 bits ( 8bit x 5 ) and verify checksum in the last byte
if ( ( j >= 40 ) && ( dht11_dat[4] == ( ( dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3] ) & 0xFF ) ) )
{
snprintf ( retstr, sizeof ( retstr ), "%d.%02d %d.%02d", dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3] );
mrtg_write( retstr );
return ( retstr );
}
else
{
std::cout << " DHT11(" << DHTPIN << "): Read error! Output is " << dht11_dat[0] << " " << dht11_dat[1]<< " " << dht11_dat[2]<< " " << dht11_dat[3] << " !" << std::endl;
globalcount++;
return ( "X" );
}
}
// reads 1-Wire sensors
std::string read_w1 ( )
{
double thetemp[20] = { 0.0 };
std::string retstr = "";
for ( int i = 0; i < w1count; i++ )
{
// path to device
char devPath[128];
// data from device
char buf[256];
// temperature in degrees C * 1000 reported by device
char tmpData[6];
ssize_t numRead;
sprintf ( devPath, "%s/%s/w1_slave", path, dev[i] );
int fd = open ( devPath, O_RDONLY );
if ( fd == -1 )
{
// read error
globalcount++;
std::cout << " w1(" << i << ") : Read error!" << std::endl;
return ( "X" );
}
while ( ( numRead = read ( fd, buf, 256 ) ) > 0 )
{
strncpy ( tmpData, strstr ( buf, "t=" ) + 2, 6 );
thetemp[i] = strtof ( tmpData, NULL );
}
close ( fd );
char tempstr[320];
snprintf ( tempstr, sizeof ( tempstr ), "%4.2f", thetemp[i] / 1000.0 );
mrtg_write( tempstr );
retstr = retstr + tempstr + " ";
}
return ( retstr );
}
// reads i2c sht11 or si7021 sensors
std::string read_sht11 ( )
{
std::string retstr = "";
// create the I2C bus
int file;
const char *bus = "/dev/i2c-1";
if ( ( file = open ( bus, O_RDWR ) ) < 0 )
{
std::cout << " SHT11 : Read error! Could not open I2C-Bus!" << std::endl;
globalcount++;
return ( "X" );
}
// get i2c device, sht11 and si7021 i2c addresses are 0x40(64)
ioctl ( file, I2C_SLAVE, 0x40 );
// the command to send
char config[1];
// the data to read
char data[2] = {0};
// send humidity measurement command 0xF5
config[0] = 0xF5;
write ( file, config, 1 );
sleep ( 1 );
// read 2 bytes of humidity data: humidity msb, humidity lsb
if ( read ( file, data, 2 ) != 2 )
{
std::cout << " SHT11 : Error in reading SHT11 humidity!" << std::endl;
globalcount++;
return ( "X" );
}
else
{
// data conversion
float humidity = ( ( ( data[0] * 256 + data[1] ) * 125.0 ) / 65536.0 ) - 6;
char tempstr[320];
snprintf ( tempstr, sizeof ( tempstr ), "%4.2f", humidity );
retstr = retstr + tempstr + " ";
}
// send temperature measurement command 0xF3
config[0] = 0xF3;
write ( file, config, 1 );
sleep ( 1 );
// read 2 bytes of temperature data: temperature msb, temperature lsb
if ( read ( file, data, 2 ) != 2 )
{
std::cout << " SHT11 : Error in reading SHT11 temperature!" << std::endl;
globalcount++;
return ( "X" );
}
else
{
// data conversion
float temperature = ( ( ( data[0] * 256 + data[1] ) * 175.72 ) / 65536.0 ) - 46.85;
char tempstr[320];
snprintf ( tempstr, sizeof ( tempstr ), "%4.2f", temperature );
retstr = retstr + tempstr + " ";
}
mrtg_write( retstr );
return ( retstr );
}
// the main program
int main ( int argc, char** argv )
{
bool dht11on = false;
bool w1on = false;
bool sht11on = false;
bool bmeon = false;
std::string filename = "";
if ( argc > 1 )
{
for ( int i = 1; i < argc; i++ )
{
std::stringstream astream;
astream << argv[i];
if ( astream.str ( ) == "-h" || astream.str ( ) == "--help" )
{
show_usage ( argv[0] );
exit ( 0 );
}
else if ( astream.str ( ) == "-d" || astream.str ( ) == "--dht11" )
{
dht11on = true;
std::cout << "DHT11 is ON!" << std::endl;
}
else if ( astream.str ( ) == "-w" || astream.str ( ) == "--w1" )
{
w1on = true;
std::cout << "w1 is ON!" << std::endl;
}
else if ( astream.str ( ) == "-s" || astream.str ( ) == "--sht11" )
{
sht11on = true;
std::cout << "SHT11 is ON!" << std::endl;
}
else if ( astream.str ( ) == "-b" || astream.str ( ) == "--bme280" )
{
bmeon = true;
std::cout << "BME280 is ON!" << std::endl;
}
else if ( astream.str ( ) == "-f" || astream.str ( ) == "--file" )
{
if ( ( i + 1 ) < argc )
{
astream.str ( std::string ( ) );
astream << argv[i + 1];
fileoutput = true;
filename = astream.str ( );
std::cout << "Writing to file " << filename << "..." << std::endl;
}
else
{
std::cerr << "Flag \"-f | --file\" invoked, but no file name specified!" << std::endl;
std::cerr << std::endl;
show_usage ( argv[0] );
exit ( -1 );
}
i++;
}
else
{
std::cerr << "Unknown option \"" << astream.str ( ) << "\"" << std::endl;
show_usage ( argv[0] );
exit ( -1 );
}
}
// catch no sensors selected
if ( !dht11on && !w1on && !sht11on && !bmeon)
{
std::cout << "No sensors selected, probing all!" << std::endl;
dht11on = true;
w1on = true;
sht11on = true;
bmeon = true;
}
std::cout << "Hit control + c to quit!" << std::endl;
std::cout << std::endl;
}
else
{
std::cout << "No arguments given, writing to stdout!" << std::endl;
std::cout << "No sensors specified, assuming all types..." << std::endl;
std::cout << "Run " << argv[0] << " --help to show help!" << std::endl;
std::cout << std::endl;
dht11on = true;
w1on = true;
sht11on = true;
bmeon = true;
fileoutput = false;
}
std::ofstream myfile;
if ( fileoutput == true )
{
myfile.open ( filename.c_str ( ), std::ios_base::app );
if ( !myfile.is_open ( ) )
{
std::cout << "Error in opening output file!" << std::endl;
exit ( 1 );
}
}
// check if wiringPi loaded - needed for dht11
if ( wiringPiSetup ( ) == -1 && dht11on == true )
{
std::cout << "wiringPi not loaded! This is needed for DHT11 sensors!" << std::endl;
exit ( 1 );
}
/*
// gpio pin - 'gpio readall' prints a table of pins
// set dht11 count
int ndht11 = 0;
int dhtadd[30] = { 0 };
std::cout << "Probing DHT11s..." << std::endl;
sleep ( 10 );
for ( int i=0; i<30; i++ )
{
std::string tempstr = "";
tempstr = read_dht11 ( i );
if ( tempstr != "X" )
{
std::cout << "Found DHT11 no. " << ndht11 << " at GPIO pin " << i << "!" << std::endl;
dhtadd[ ndht11 ] = i;
ndht11++;
} else {
std::cout << "Didn't find sth at " << i << std::endl;
}
sleep ( 10 );
}
*/
int dhtadd[30] = { 0 };
int ndht11 = 1;
dhtadd[0] = 7;
dhtadd[1] = 1;
dhtadd[2] = 2;
dhtadd[3] = 3;
// get the w1 devices
if ( w1on == true )
{
DIR *dir;
struct dirent *dirent;
std::vector<std::string> devices;
dir = opendir ( path );
if ( dir != NULL )
{
while ( ( dirent = readdir ( dir ) ) )
// devices begin with 10-
if ( dirent->d_type == DT_LNK && strstr( dirent->d_name, "10-" ) != NULL )
{
strcpy ( dev[w1count], dirent->d_name );
std::cout << "Found w1 device " << w1count << ": " << dev[w1count] << std::endl;
w1count++;
if ( w1count > 20 )
{
std::cout << "Warning! Found more than 20 1-Wire sensors!" << std::endl;
exit ( 1 );
}
}
( void ) closedir ( dir );
}
else
{
std::cout << "Couldn't open the device directory!" << std::endl;
exit ( 1 );
}
}
// delay in s
int delayrate = 2;
while ( 1 )
{
std::string thetime = gettime ( );
std::string mydht11 = "";
std::string myw1 = "";
std::string mysht11 = "";
std::string mybme = "";
if ( dht11on == true )
{
for ( int i = 0; i < ndht11; i++ )
{
mydht11 += read_dht11 ( dhtadd[i] ) + " ";
}
}
if ( w1on == true )
{
myw1 = read_w1 ( );
}
if ( sht11on == true )
{
mysht11 = read_sht11 ( );
}
if ( bmeon == true )
{
mybme = read_bme ( );
}
std::size_t found_dht11 = mydht11.find ( "X" );
std::size_t found_w1 = myw1.find ( "X" );
std::size_t found_sht11 = mysht11.find ( "X" );
std::size_t found_bme = mybme.find ( "X" );
if ( found_dht11 != std::string::npos )
{
if ( delayrate < 5 )
{
delayrate++;
}
std::cout << " Failed to read a DHT11 device, retrying in " << delayrate << " s..." << std::endl;
}
else if ( found_w1 != std::string::npos )
{
if ( delayrate < 5 )
{
delayrate++;
}
std::cout << " Failed to read a w1 device, retrying in " << delayrate << " s..." << std::endl;
}
else if ( found_sht11 != std::string::npos )
{
if ( delayrate < 5 )
{
delayrate++;
}
std::cout << " Failed to read a SHT11 device, retrying in " << delayrate << " s..." << std::endl;
}
else if ( found_bme != std::string::npos )
{
if ( delayrate < 5 )
{
delayrate++;
}
std::cout << " Failed to read a BME device, retrying in " << delayrate << " s..." << std::endl;
}
else
{
std::cout << thetime << " " << mydht11 << myw1 << mysht11 << mybme << std::endl;
if ( fileoutput == true )
{
myfile << thetime << " " << mydht11 << myw1 << mysht11 << mybme << "\n";
myfile.flush ( );
}
delayrate = 1;
}
sleep ( delayrate );
// reset
globalcount = 1;
}
return ( 0 );
}