Skip to content

Commit d795c55

Browse files
committed
Use new average measurement API in examples, remove duplicate simple/advanced sketches
1 parent a11319c commit d795c55

File tree

5 files changed

+11
-215
lines changed

5 files changed

+11
-215
lines changed

examples/Ethernet-Simple/Ethernet-Simple.ino

Lines changed: 0 additions & 60 deletions
This file was deleted.

examples/Ethernet-Advanced/Ethernet-Advanced.ino renamed to examples/Ethernet/Ethernet.ino

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,9 @@ void loop() {
6262
// Collect data
6363
struct hackAirData data;
6464
sensor.clearData(data);
65-
sensor.refresh(data);
65+
sensor.readAverageData(data, 60);
6666

67-
// Average readings
68-
double pm25 = data.pm25;
69-
double pm10 = data.pm10;
70-
int error = 0;
71-
72-
// We will take 60 averages
73-
for (int i = 0; i < 60; i++) {
74-
// Read from the sensor
75-
sensor.refresh(data);
76-
77-
// If error is not zero something went wrong with this measurment
78-
// and we should not send it.
79-
if (data.error == 0) {
80-
// Calculate average between the new reading and the old average
81-
pm25 = (pm25 + data.pm25) / 2;
82-
pm10 = (pm10 + data.pm10) / 2;
83-
} else {
84-
error++;
85-
}
86-
87-
delay(1000); // Wait one second
88-
}
89-
90-
// Send with ethernet shield
91-
data.pm25 = pm25;
92-
data.pm10 = pm10;
93-
data.error = error;
67+
// Send data to the hackAIR platform
9468
hackAirNet.sendData(data);
9569

9670
// Turn off sensor while we wait the specified time

examples/Wemos-Advanced/Wemos-Advanced.ino renamed to examples/Wemos/Wemos.ino

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,40 +82,17 @@ void loop() {
8282

8383
// Measure data
8484
sensor.clearData(data);
85-
sensor.refresh(data);
86-
87-
// Average readings (60 measurments)
88-
double pm25 = data.pm25;
89-
double pm10 = data.pm10;
90-
int error = 0;
91-
for (int i = 0; i < 59; i++) {
92-
// Read from the sensor
93-
sensor.refresh(data);
94-
95-
// If error is not zero something went wrong with this measurment
96-
// and we should not send it.
97-
if (data.error == 0) {
98-
pm25 = (pm25 + data.pm25) / 2;
99-
pm10 = (pm10 + data.pm10) / 2;
100-
} else {
101-
error++;
102-
}
103-
delay(1000); // Wait one second
104-
}
105-
data.pm25 = pm25;
106-
data.pm10 = pm10;
107-
data.error = error;
85+
sensor.readAverageData(data, 60); // 60 averages
10886

109-
// Measure humidity and temperature
87+
// Compensate for humidity
11088
float humidity = dht.readHumidity();
111-
// Read temperature as Celsius (the default)
112-
float temperature = dht.readTemperature();
89+
sensor.humidityCompensation(data, humidity);
11390

11491
// Send the data to the hackAIR server
11592
String dataJson = "{\"reading\":{\"PM2.5_AirPollutantValue\":\"";
116-
dataJson += pm25;
93+
dataJson += data.pm25;
11794
dataJson += "\",\"PM10_AirPollutantValue\":\"";
118-
dataJson += pm10;
95+
dataJson += data.pm10;
11996
dataJson += "\"},\"battery\":\"";
12097
dataJson += vdd;
12198
dataJson += "\",\"tamper\":\"";

examples/WiFiShield-Simple/WiFiShield-Simple.ino

Lines changed: 0 additions & 69 deletions
This file was deleted.

examples/WiFiShield-Advanced/WiFiShield-Advanced.ino renamed to examples/WiFiShield/WiFiShield.ino

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file hackAIR WiFi Shield - Advanced Example
2+
* @file hackAIR WiFi Shield - Example
33
* This example reads data from a sensor and sends it to the hackAIR platform
44
* using the hackAIR WiFi Shield on a configurable frequency.
55
*
@@ -43,36 +43,10 @@ void loop() {
4343
// Wait for sensor to settle
4444
delay(1000 * 30);
4545

46-
// Refresh data
47-
sensor.refresh(data);
46+
// Make 60 measurements and return the mean values
47+
sensor.readAverageData(data, 60);
4848

49-
// Average readings
50-
double pm25 = data.pm25;
51-
double pm10 = data.pm10;
52-
int error = 0;
53-
54-
// We will take 60 averages
55-
for (int i = 0; i < 60; i++) {
56-
// Read from the sensor
57-
sensor.refresh(data);
58-
59-
// If error is not zero something went wrong with this measurment
60-
// and we should not send it.
61-
if (data.error == 0) {
62-
// Calculate average between the new reading and the old average
63-
pm25 = (pm25 + data.pm25) / 2;
64-
pm10 = (pm10 + data.pm10) / 2;
65-
} else {
66-
error++;
67-
}
68-
69-
delay(1000); // Wait one second
70-
}
71-
72-
// Send data to the hackAIR server
73-
data.pm25 = pm25;
74-
data.pm10 = pm10;
75-
data.error = error;
49+
// Send data to the hackAIR platform
7650
wifi_sendData(data);
7751

7852
// Turn off sensor while we wait the specified time

0 commit comments

Comments
 (0)