11/* *
22 * @file Wemos - Advanced Example
33 * This example reads data from a sensor and sends it to the hackAIR platform
4- * using the Wemos integrated WiFi on a configurable frequency . This code
5- * assumes a DHT11 humidity sensor connected to pin 2 .
4+ * using the Wemos integrated WiFi . This code
5+ * assumes a DHT11 humidity sensor connected to pin D4 .
66 *
7- * @author Ilias Stavrakas
7+ * @author LoRAthens Air Quality team
88 * @author Thanasis Georgiou (Cleanup)
99 *
1010 * This example is part of the hackAIR Arduino Library and is available
1111 * in the Public Domain.
1212 */
1313
1414#include < Arduino.h>
15- #include < DHT.h>
15+ #include < DHT.h> // Adafruit's DHT sensor library https://github.com/adafruit/DHT-sensor-library
1616#include < DHT_U.h>
17- #include < DNSServer.h>
18- #include < ESP8266WebServer.h>
19- #include < ESP8266WiFi.h>
20- #include < FS.h>
21- #include < WiFiClientSecure.h>
22- #include < WiFiManager.h> // https://github.com/tzapu/WiFiManager
23- #include < hackair.h>
17+ #include < DNSServer.h> // Local DNS Server used for redirecting all requests to the configuration portal
18+ #include < ESP8266WebServer.h> // Local WebServer used to serve the configuration portal
19+ #include < ESP8266WiFi.h> // ESP8266 Core WiFi Library (you most likely already have this in your sketch)
20+ #include < FS.h> // this needs to be 2nd. Don't change it...
21+ #include < WiFiClientSecure.h> // Variant of WiFiClient with TLS support (from ESP82266 core wifi)
22+ #include < WiFiManager.h> // https://github.com/tzapu/WiFiManager
23+ #include < hackair.h> // https://github.com/hackair-project/hackAir-Arduino
2424
2525// Replace the string below with your Authorization Token from the hackAIR
2626// platform
27- #define AUTHORIZATION " AUTHORIZATION TOKEN HERE "
27+ #define AUTHORIZATION " AUTHORIZATION TOKEN"
2828
2929// Sensor initialization
3030hackAIR sensor (SENSOR_SDS011);
3131
32- // Setup the humidity sensor (pin 2 )
33- DHT dht (2 , DHT11);
32+ // Setup the humidity sensor (pin D4 )
33+ DHT dht (D4 , DHT11);
3434
3535// How often to measure (in minutes)
36- const unsigned long minutes_time_interval = 120 ;
36+ const unsigned long minutes_time_interval = 5 ;
3737
3838// Setup ADC to measure Vcc (battery voltage)
3939ADC_MODE (ADC_VCC);
@@ -61,7 +61,7 @@ void setup() {
6161
6262 // Initialize the WiFi connection
6363 WiFiManager wifiManager;
64- if (!wifiManager.autoConnect (" hackAIR-AP " )) {
64+ if (!wifiManager.autoConnect (" ESP-wemos " )) {
6565 Serial.println (" failed to connect, please push reset button and try again" );
6666 delay (3000 );
6767 ESP.reset ();
@@ -110,7 +110,7 @@ void loop() {
110110 float humidity = dht.readHumidity ();
111111 // Read temperature as Celsius (the default)
112112 float temperature = dht.readTemperature ();
113-
113+
114114 // Send the data to the hackAIR server
115115 String dataJson = " {\" reading\" :{\" PM2.5_AirPollutantValue\" :\" " ;
116116 dataJson += pm25;
@@ -129,7 +129,7 @@ void loop() {
129129 client.print (" Host: api.hackair.eu\r\n " );
130130 client.print (" Connection: close\r\n " );
131131 client.print (" Authorization: " );
132- client.println (Authorization );
132+ client.println (AUTHORIZATION );
133133 client.print (" Accept: application/vnd.hackair.v1+json\r\n " );
134134 client.print (" Cache-Control: no-cache\r\n " );
135135 client.print (" Content-Type: application/json\r\n " );
@@ -158,4 +158,4 @@ void loop() {
158158 }
159159 previous_millis = current_millis;
160160 sensor.turnOn ();
161- }
161+ }
0 commit comments