-
Notifications
You must be signed in to change notification settings - Fork 76
/
SDUpdate.ino
142 lines (134 loc) · 2.68 KB
/
SDUpdate.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
void txSD() {
Serial.println("*** txSD ***");
// if the file opened okay, write to it:
if (myFile.open("post.csv", FILE_WRITE)) {
#if debuggEnabled
Serial.println(F("Writing..."));
#endif
float dec = 0;
for (int i=0; i<8; i++)
{
if (i<4) dec = 10;
else if (i<7) dec = 1000;
else if (i<8) dec = 100;
else dec = 1;
//myFile.print(i);
//myFile.print(" ");
myFile.print(SENSORvalue[i]/dec);
myFile.print(",");
}
myFile.print(sckRTCtime());
myFile.println();
// close the file:
myFile.close();
#if debuggEnabled
Serial.println(F("Closing..."));
#endif
}
}
char* SENSOR[10]={
"Temperature",
"Humidity",
"Light",
"Battery",
"Solar Panel",
"Carbon Monxide",
"Nitrogen Dioxide",
"Noise",
"Wifi Spots",
"UTC"
};
char* UNITS[10]={
#if F_CPU == 8000000
#if DataRaw
" C RAW",
" % RAW",
#else
" C",
" %",
#endif
#else
" C",
" %",
#endif
#if F_CPU == 8000000
" lx",
#else
" %",
#endif
" %",
" V",
" kOhm",
" kOhm",
#if DataRaw
" mV",
#else
" dB",
#endif
"",
""
};
void updateSensorsSD() {
#if F_CPU == 8000000
sckGetVcc();
sckGetSHT21();
SENSORvalue[0] = lastTemperature; // C
SENSORvalue[1] = lastHumidity; // %
#else
if (sckDHT22(IO3))
{
SENSORvalue[0] = lastTemperature; // C
SENSORvalue[1] = lastHumidity; // %
}
#endif
sckGetMICS();
SENSORvalue[2] = sckGetLight(); // %
SENSORvalue[3] = sckGetBattery(); //%
SENSORvalue[4] = sckGetPanel(); // %
SENSORvalue[5] = sckGetCO(); //Ohm
SENSORvalue[6] = sckGetNO2(); //Ohm
SENSORvalue[7] = sckGetNoise(); //dB
}
void txDebugSD() {
Serial.println("*** txDebugSD ***");
float dec = 0;
for(int i=0; i<8; i++)
{
if (i<4) dec = 10;
else if (i<7) dec = 1000;
else if (i<8) dec = 100;
else dec = 1;
Serial.print(SENSOR[i]);
Serial.print(": ");
Serial.print((SENSORvalue[i])/dec);
Serial.println(UNITS[i]);
}
Serial.print(SENSOR[9]);
Serial.print(": ");
Serial.println(sckRTCtime());
Serial.println(F("*******************"));
}
void txHeader() {
Serial.println("*** txHeader ***");
// if the file opened okay, write to it:
if (myFile.open("post.csv", FILE_WRITE)) {
#if debuggEnabled
Serial.println(F("Writing..."));
#endif
for (int i=0; i<8; i++)
{
myFile.print(SENSOR[i]);
myFile.print(" (");
myFile.print(UNITS[i]);
myFile.print(") ");
myFile.print(", ");
}
myFile.print(SENSOR[9]);
myFile.println();
// close the file:
myFile.close();
#if debuggEnabled
Serial.println(F("Closing..."));
#endif
}
}