first commit
This commit is contained in:
98
ESP8266_DOMOTICZ_DEEP_SLEEP/Modules.cpp
Executable file
98
ESP8266_DOMOTICZ_DEEP_SLEEP/Modules.cpp
Executable file
@@ -0,0 +1,98 @@
|
||||
#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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Modules::readTemp()
|
||||
{
|
||||
//DS18B20.begin();
|
||||
DS18B20.requestTemperatures();
|
||||
temp = DS18B20.getTempCByIndex(0);
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(temp);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user