-
Notifications
You must be signed in to change notification settings - Fork 0
/
air_quality_monitor.ino
126 lines (110 loc) · 3.87 KB
/
air_quality_monitor.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
/******************************************************************************
* air_quality_monitor.ino
*
* An http server for Arduino Ethernet Shield 2 that provides high precision
* temperature, humidity atmospheric pressure and eCO2 based on the Sparkfun
* SEN-14348 CCS811 and BME280 combo sensor.
*
* Created by Ioannis Tornazakis ( [email protected] ) on 2021-03-28
*
* * Hardware:
* - Arduino Uno R3
* - Arduino Ethernet Shield 2
* - Sparkfun SEN-14348
*
* https://learn.sparkfun.com/tutorials/ccs811bme280-qwiic-environmental-combo-breakout-hookup-guide?_ga=2.127395085.1624253088.1616957378-581135722.1616957378
*
* Pinout:
* +---------+---------+
* |SEN-14348| Arduino |
* +---------+---------+
* | VCC | 3.3V |
* | GND | GND |
* | SCL | A5 |
* | SDA | A4 |
* +---------+---------+
*
******************************************************************************/
#include <Ethernet.h>
#include <SPI.h>
#ifdef DEBUG
#include <Arduino.h>
#include <SoftwareSerial.h>
#endif
#include "sparkfun_bme280.h"
#include "sparkfun_ccs811.h"
#include "sensor_server.h"
/******************************************************************************
* GLOBALS *
******************************************************************************/
/* TODO: Fill in the gaps */
byte mac[] = {0x__, 0x__, 0x__, 0x__, 0x__, 0x__};
IPAddress ip(192, 168, ___, ___);
IPAddress gateway(192, 168, ___, ___);
IPAddress subnet(255, 255, ___, ___);
IPAddress myDns(192, 168, ___, ___);
/* TODO: Calibrate temperature and humidity readings because sensors are located
in viccinity and are affected by one another */
float bme_calibration_temp = 0.0;
float bme_calibration_hum = 0.0;
/******************************************************************************
* SET UP *
******************************************************************************/
void setup() {
#ifdef DEBUG
init_serial();
#endif
init_i2c();
init_ethernet();
init_server();
init_sparkfun_bme280();
init_sparkfun_ccs811();
#ifdef DEBUG
init_system();
#endif
}
/******************************************************************************
* LOOP *
******************************************************************************/
void loop() {
EthernetClient client = server.available();
if (client) {
#ifdef DEBUG
print_info_on_connect(client);
#endif
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
#ifdef DEBUG
Serial.write(c);
#endif
if (c == '\n' && current_line_is_blank) {
html_header(client, "Air Quality Monitor", "60");
html_sensor(client, print_sparkfun_bme280);
html_sensor(client, print_sparkfun_ccs811);
client.println("<h1 style=\"color:blue; font-size:24px;\">");
client.println("> ");
client.println("<a href=\"https://iaqscience.lbl.gov/voc-intro\">Indoor Air Quality</a>");
client.println("<br />");
client.println("> ");
client.println("<a href=\"https://www.kane.co.uk/knowledge-centre/what-are-safe-levels-of-co-and-co2-in-rooms\">Kane</a>");
client.println("</h1>");
html_footer(client);
delay(SENSOR_INTERVAL); /* Do not overheat the board!!! */
break;
}
if (c == '\n') {
current_line_is_blank = true;
} else if(c != '\r') {
current_line_is_blank = false;
}
} /* end if (client.available()) */
} /* end if (client.connected()) */
delay(1);
client.stop();
#ifdef DEBUG
print_info_on_disconnect();
#endif
} /* End if (client) */
}