forked from sakuraio/SakuraIOArduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HDC1000.ino
66 lines (54 loc) · 1.39 KB
/
HDC1000.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
#include <HDC1000.h>
#include <SakuraIO.h>
SakuraIO_I2C sakuraio;
HDC1000 hdc1000;
uint32_t cnt = 0;
void setup() {
hdc1000.begin();
Serial.begin(9600);
Serial.print("Waiting to come online");
for(;;){
if( (sakuraio.getConnectionStatus() & 0x80) == 0x80 ) break;
Serial.print(".");
delay(1000);
}
Serial.println("");
}
void loop() {
cnt++;
Serial.println(cnt);
float temp = hdc1000.getTemperature();
if (temp == HDC1000_ERROR_CODE) {
hdc1000.begin(); // retry once
temp = hdc1000.getTemperature();
}
Serial.print("Temperature: ");
Serial.println(temp);
float humi = hdc1000.getHumidity();
if (humi== HDC1000_ERROR_CODE) {
hdc1000.begin(); // retry once
humi = hdc1000.getHumidity();
}
Serial.print("Humidity: ");
Serial.println(humi);
if(sakuraio.enqueueTx(0,temp) != CMD_ERROR_NONE){
Serial.println("[ERR] enqueue error");
}
if(sakuraio.enqueueTx(1,humi) != CMD_ERROR_NONE){
Serial.println("[ERR] enqueue error");
}
if(sakuraio.enqueueTx(2,cnt) != CMD_ERROR_NONE){
Serial.println("[ERR] enqueue error");
}
sakuraio.send();
delay(5000);
uint8_t available;
uint8_t queued;
if(sakuraio.getTxQueueLength(&available, &queued) != CMD_ERROR_NONE){
Serial.println("[ERR] get tx queue length error");
}
Serial.print("Available :");
Serial.print(available);
Serial.print(" Queued :");
Serial.println(queued);
}