-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.ino
153 lines (145 loc) · 3.96 KB
/
log.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
String _fileName;
bool log_heading(String heading)
{
//#ifdef _MICROBIT_V2_
SD.begin(_sd_cs);
//#endif
uint16_t count = getFileCount("DATA");
String fileName = "DATA/DATA_" + String(count + 1) + ".CSV";
_fileName = fileName;
File dataFile = SD.open(_fileName, FILE_WRITE);
if (dataFile) {
dataFile.println(heading);
dataFile.close();
// print to the serial port too:
//Serial.println(heading);
return true;
}
return false;
}
String data_string()
{
String finalDataString = "";
#ifdef DEVELOPER_DEBUG
finalDataString += String(millis()) + "," +
#endif
finalDataString += data.latitude + "," +
data.longitude + "," +
data.latitudedms + "," +
data.longitudedms + "," +
data.altitude + "," +
data.speed + "," +
data.hdop + "," +
data.day + "," +
data.month + "," +
data.year + "," +
data.hours + "," +
data.minutes + "," +
data.seconds + "," +
data.temperature + "," +
data.pressure + "," +
data.humidity + "," +
data.co2 + "," +
data.tvoc + "," +
data.pm10 + "," +
data.pm25 + "," +
data.pm100;
return finalDataString;
}
void log_data(String data)
{
//#ifdef _MICROBIT_V2_
SD.begin(_sd_cs);
//#endif
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open(_fileName, FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(data);
dataFile.close();
// print to the serial port too:
////Serial.println(data);
}
// if the file isn't open, pop up an error:
else {
//debugPrint("error opening " + _fileName);
}
}
int getFileCount(String dir)
{
File d = SD.open(dir);
int count_files = 0;
while (true)
{
File entry = d.openNextFile();
if (!entry)
{
// no more files. Let's return the number of files.
return count_files;
}
String file_name = entry.name(); //Get file name so that we can check
//if it's a duplicate
if ( file_name.indexOf('~') != 0 ) //Igrnore filenames with a ~. It's a mac thing.
{ //Just don't have file names that have a ~ in them
count_files++;
}
}
}
void getDetails()
{
// Wire.begin();
// xOD01 OD01;
// OD01.begin();
// OD01.clear();
if (!SD.begin(_sd_cs)) {
Wire.begin();
ui.sdFail();
return;
}
SD.begin(_sd_cs);
File myFile;
if (SD.exists("CONFIG/WIFISSID.txt")) {
myFile = SD.open("CONFIG/WIFISSID.txt", FILE_READ);
while (myFile.available()) {
cw01_vars.ssid += (char)myFile.read();
}
myFile.close();
Wire.begin();
//OD01.println(cw01_vars.ssid);
ui.sdPass();
}
SD.begin(_sd_cs);
if (SD.exists("CONFIG/WIFIPASS.txt")) {
myFile = SD.open("CONFIG/WIFIPASS.txt", FILE_READ);
while (myFile.available()) {
cw01_vars.pass += (char)myFile.read();
}
myFile.close();
Wire.begin();
//OD01.println(cw01_vars.pass);
ui.sdPass();
}
SD.begin(_sd_cs);
if (SD.exists("CONFIG/ATTID.txt")) {
myFile = SD.open("CONFIG/ATTID.txt", FILE_READ);
while (myFile.available()) {
cw01_vars.DEVICE_ID += (char)myFile.read();
}
myFile.close();
Wire.begin();
//OD01.println(cw01_vars.DEVICE_ID);
ui.sdPass();
}
SD.begin(_sd_cs);
if (SD.exists("CONFIG/ATTTOKEN.txt")) {
myFile = SD.open("CONFIG/ATTTOKEN.txt", FILE_READ);
while (myFile.available()) {
cw01_vars.TOKEN += (char)myFile.read();
}
myFile.close();
Wire.begin();
//OD01.println(cw01_vars.TOKEN);
ui.sdPass();
}
}