2021-06-20 12:57:47 +03:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
2021-06-22 15:51:58 +03:00
|
|
|
#include "ota.hpp"
|
2021-06-23 16:44:37 +03:00
|
|
|
#include "server.hpp"
|
2021-06-22 12:35:48 +03:00
|
|
|
|
|
|
|
// DHT Temperature & Humidity Sensor
|
|
|
|
// Unified Sensor Library Example
|
|
|
|
// Written by Tony DiCola for Adafruit Industries
|
|
|
|
// Released under an MIT license.
|
|
|
|
|
|
|
|
// REQUIRES the following Arduino libraries:
|
|
|
|
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
|
|
|
|
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
|
|
|
|
|
|
|
|
#include <Adafruit_Sensor.h>
|
|
|
|
#include <DHT.h>
|
|
|
|
#include <DHT_U.h>
|
|
|
|
|
|
|
|
|
2021-06-23 11:49:22 +03:00
|
|
|
// mini https://chewett.co.uk/blog/1066/pin-numbering-for-wemos-d1-mini-esp8266/
|
|
|
|
DHT dht_in(4, DHT11); // D2 on mini
|
|
|
|
DHT dht_out(5, DHT11); // D1 on mini
|
2021-06-22 12:35:48 +03:00
|
|
|
|
2021-06-23 11:49:22 +03:00
|
|
|
// Set delay between sensor readings based on sensor details.
|
|
|
|
uint32_t delayMS = 3000 ;
|
2021-06-22 12:35:48 +03:00
|
|
|
|
|
|
|
const char* ssid = "fan_XXX";
|
|
|
|
|
2021-06-23 16:44:37 +03:00
|
|
|
|
2021-06-22 12:35:48 +03:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
2021-06-22 15:51:58 +03:00
|
|
|
ota_setup(ssid);
|
2021-06-23 16:44:37 +03:00
|
|
|
server_setup();
|
2021-06-23 11:49:22 +03:00
|
|
|
Serial.println(WiFi.softAPIP());
|
|
|
|
|
2021-06-22 12:35:48 +03:00
|
|
|
|
|
|
|
// Initialize device.
|
2021-06-23 11:49:22 +03:00
|
|
|
dht_in.begin();
|
|
|
|
dht_out.begin();
|
|
|
|
Serial.println(F("DHT set up"));
|
2021-06-20 12:57:47 +03:00
|
|
|
}
|
|
|
|
|
2021-06-22 12:35:48 +03:00
|
|
|
void loop() {
|
|
|
|
ArduinoOTA.handle();
|
|
|
|
|
|
|
|
// Delay between measurements.
|
|
|
|
delay(delayMS);
|
2021-06-23 11:49:22 +03:00
|
|
|
|
2021-06-22 12:35:48 +03:00
|
|
|
// Get temperature event and print its value.
|
2021-06-23 11:49:22 +03:00
|
|
|
Serial.print(F("Temperature inside: "));
|
|
|
|
Serial.print(dht_in.readTemperature());
|
|
|
|
Serial.println(F("°C"));
|
|
|
|
Serial.print(F("Temperature outside: "));
|
|
|
|
Serial.print(dht_out.readTemperature());
|
|
|
|
Serial.println("°C");
|
|
|
|
}
|