122 lines
3.0 KiB
C++
122 lines
3.0 KiB
C++
#include "Modules.h"
|
|
|
|
// int status = WL_IDLE_STATUS; // the Wifi radio's status
|
|
//WiFiClient client;
|
|
// Dallas
|
|
|
|
OneWire oneWire(ONE_WIRE_BUS);
|
|
DallasTemperature DS18B20(&oneWire);
|
|
|
|
// Initialize DHT sensor for normal 16mhz Arduino
|
|
DHT dht(DHTPIN, DHTTYPE);
|
|
|
|
Modules::Modules()
|
|
{
|
|
Serial.println("--------------------------------------");
|
|
Serial.println("Init Module");
|
|
pinMode(RELAY_PIN, OUTPUT);
|
|
digitalWrite(RELAY_PIN, LOW);
|
|
pinMode(RELAY_PIN_02, OUTPUT);
|
|
digitalWrite(RELAY_PIN_02, LOW);
|
|
pinMode(RELAY_PIN_03, OUTPUT);
|
|
digitalWrite(RELAY_PIN_03, LOW);
|
|
pinMode(RELAY_PIN_03, OUTPUT);
|
|
digitalWrite(RELAY_PIN_03, LOW);
|
|
}
|
|
|
|
bool Modules::readTemp()
|
|
{
|
|
//DS18B20.begin();
|
|
Serial.println("--------------------------------------");
|
|
DS18B20.requestTemperatures();
|
|
temp = DS18B20.getTempCByIndex(0);
|
|
Serial.print("Température Dallas =");
|
|
|
|
Serial.println(temp);
|
|
if (temp > 0 && temp < 70) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
void Modules::barometre() {
|
|
/* See Example: TypeA_WithDIPSwitches */
|
|
|
|
delay(500);
|
|
Serial.print("Barometre: ");
|
|
Serial.println(bmp.begin());
|
|
// BMP
|
|
|
|
if (bmp.begin()) {
|
|
delay(1000);
|
|
temp = bmp.readTemperature();
|
|
pressure = bmp.readPressure() / 100.0;
|
|
pression = pressure / 101.325;
|
|
pression = pression * 0.760 * 100;
|
|
// http://en.wikipedia.org/wiki/Atmospheric_pressure#Mean_sea_level_pressure
|
|
// Serial.print("Presiure la nivelul marii (calculata) = ");
|
|
presiune = bmp.readSealevelPressure(ALTITUDE) / 101.325;
|
|
presiune = presiune * 0.760;
|
|
Serial.print("Temperature="); Serial.println(temp);
|
|
Serial.print("pressure="); Serial.println(pressure);
|
|
Serial.print("pression="); Serial.println(pression);
|
|
}
|
|
else {
|
|
Serial.print("Pas de barometre détecté");
|
|
|
|
}
|
|
}
|
|
|
|
void Modules::sleep(int sleepTime)
|
|
{
|
|
Serial.print("Go to sleep ");
|
|
Serial.println(sleepTime);
|
|
delay(20);
|
|
|
|
ESP.deepSleep(sleepTime * 1000000L); // Infini
|
|
|
|
//sleepWifi();
|
|
delay(200);
|
|
}
|
|
|
|
void Modules::readDht()
|
|
{
|
|
// Reading temperature or humidity takes about 250 milliseconds!
|
|
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
|
|
humidity = dht.readHumidity();
|
|
|
|
// Read temperature as Celsius
|
|
temp = dht.readTemperature();
|
|
// Read temperature as Fahrenheit
|
|
float f = dht.readTemperature(true);
|
|
|
|
// Check if any reads failed and exit early (to try again).
|
|
if (isnan(humidity) || isnan(temp) || isnan(f)) {
|
|
// Serial.println("Failed to read from DHT sensor!");
|
|
return;
|
|
} else {
|
|
// Compute heat index
|
|
// Must send in temp in Fahrenheit!
|
|
float hi = dht.computeHeatIndex(f, humidity);
|
|
|
|
Serial.print("Humidity: ");
|
|
Serial.print(humidity);
|
|
Serial.print(" %\t");
|
|
Serial.print("Temperature: ");
|
|
Serial.print(temp);
|
|
Serial.print(" *C ");
|
|
Serial.print(f);
|
|
Serial.print(" *F\t");
|
|
Serial.print("Heat index: ");
|
|
Serial.print(hi);
|
|
Serial.println(" *F");
|
|
}
|
|
}
|
|
|
|
void Modules::relay(int pin, int value)
|
|
{
|
|
delay(100);
|
|
digitalWrite(pin, value);
|
|
delay(100);
|
|
} |