-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.cpp
More file actions
56 lines (53 loc) · 1.67 KB
/
temp.cpp
File metadata and controls
56 lines (53 loc) · 1.67 KB
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
auto lastRead = millis();
int sampling_time = 0;
void loop() {
/* Serial.printf("\npress anykey when ready to send temp and humidity to Gdoc");
String site;
do {
site = Serial.readString();
} while (site == ""); */
static const char * pm2dot5;
const auto n = Pmsx003::Reserved;
pms.write(Pmsx003::cmdWakeup);
pms.waitForData(Pmsx003::wakeupTime);
Pmsx003::pmsData data[n];
Pmsx003::PmsStatus status = pms.read(data, n);
switch (status) {
case Pmsx003::OK:
{
Serial.println("_________________");
auto newRead = millis();
sampling_time = newRead - lastRead;
lastRead = newRead;
pm2dot5 = Pmsx003::getMetrics(4);
}
case Pmsx003::noData:
Serial.println("_________________");
Serial.println("No Data received! Please Check the wiring!");
break;
default:
Serial.println("_________________");
Serial.println(Pmsx003::errorMsg[status]);
};
if (sampling_time != 0) {
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
String buf;
buf += F("Temperature=");
buf += String(temperature, 3);
buf += F("&Humidity=");
buf += String(humidity, 3);
buf += F("&PM2.5=");
buf += pm2dot5;
buf += F("&Sampling%20time=");
buf += String(sampling_time, 3);
BearSSL::WiFiClientSecure *bear = new BearSSL::WiFiClientSecure();
// Integrate the cert store with this connection
bear->setCertStore(&certStore);
POST_data(bear, "script.google.com", 443, "/macros/s/AKfycbxUjBnKnfZZgr2jZw2yLCmDdXdZl6BAxd3pF-jQfVrHiWbYD-M/exec", buf);
delete bear;
}
Serial.println("end of loop, putting to sleep pms7003, waiting 30s");
pms.write(Pmsx003::cmdSleep);
delay(30000);
}