106 lines
2.9 KiB
C++
Executable File
106 lines
2.9 KiB
C++
Executable File
#include "Modules.h"
|
|
|
|
Modules::Modules()
|
|
{
|
|
|
|
}
|
|
|
|
void Modules::barometre() {
|
|
/* See Example: TypeA_WithDIPSwitches */
|
|
Wire.begin(SDA, SCL);
|
|
delay(200);
|
|
// init
|
|
bmp.init();
|
|
|
|
// Initialize the sensor (it is important to get calibration values stored on the device).
|
|
|
|
if (bmp.hasValidID())
|
|
Serial.println("BMP180 init success");
|
|
else
|
|
{
|
|
// Oops, something went wrong, this is usually a connection problem,
|
|
// see the comments at the top of this sketch for the proper connections.
|
|
|
|
Serial.println("BMP180 init fail");
|
|
return;
|
|
}
|
|
|
|
delay(500);
|
|
Serial.println("Barometre: ");
|
|
|
|
temp = bmp.getTemperature();
|
|
pressure = bmp.getPressure();
|
|
// Print out the measurement:
|
|
Serial.print("temperature: ");
|
|
Serial.print(temp,2);
|
|
Serial.print(" deg C, ");
|
|
Serial.print((9.0/5.0) * temp + 32.0,2);
|
|
Serial.println(" deg F");
|
|
// Print out the measurement:
|
|
Serial.print("absolute pressure: ");
|
|
Serial.print(pressure, 2);
|
|
Serial.print(" mb, ");
|
|
Serial.print(pressure * 0.0295333727, 2);
|
|
Serial.println(" inHg");
|
|
|
|
// // The pressure sensor returns abolute pressure, which varies with altitude.
|
|
// // To remove the effects of altitude, use the sealevel function and your current altitude.
|
|
// // This number is commonly used in weather reports.
|
|
// // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
|
|
// // Result: pression = sea-level compensated pressure in mb
|
|
//
|
|
pression = sealevel(pressure,ALTITUDE); // we're at n meters
|
|
Serial.print("relative (sea-level) pressure: ");
|
|
Serial.print(pression,2);
|
|
Serial.print(" mb, ");
|
|
pressionHg = pression*0.0295333727;
|
|
Serial.print(pressionHg,2);
|
|
Serial.println(" inHg");
|
|
|
|
// On the other hand, if you want to determine your altitude from the pressure reading,
|
|
// use the altitude function along with a baseline pressure (sea-level or other).
|
|
// Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
|
|
// Result: a = altitude in m.
|
|
|
|
alt = altitude(pressure,pression);
|
|
Serial.print("computed altitude: ");
|
|
Serial.print(alt, 0);
|
|
Serial.print(" meters, ");
|
|
Serial.print(alt * 3.28084,0);
|
|
Serial.println(" feet");
|
|
}
|
|
|
|
|
|
void Modules::sleep(int sleepTime)
|
|
{
|
|
Serial.print("Go to sleep ");
|
|
Serial.println(sleepTime);
|
|
delay(20);
|
|
|
|
ESP.deepSleep(sleepTime * 1000000L);
|
|
|
|
//sleepWifi();
|
|
delay(200);
|
|
}
|
|
|
|
void Modules::readLuminosite()
|
|
{
|
|
lum = analogRead(PIN_LUM);
|
|
}
|
|
|
|
double Modules::sealevel(double P, double A)
|
|
// Given a pressure P (mb) taken at a specific altitude (meters),
|
|
// return the equivalent pressure (mb) at sea level.
|
|
// This produces pressure readings that can be used for weather measurements.
|
|
{
|
|
return(P/pow(1-(A/44330.0),5.255));
|
|
}
|
|
|
|
|
|
double Modules::altitude(double P, double P0)
|
|
// Given a pressure measurement P (mb) and the pressure at a baseline P0 (mb),
|
|
// return altitude (meters) above baseline.
|
|
{
|
|
return(44330.0*(1-pow(P/P0,1/5.255)));
|
|
}
|