Wetterstation_Boris/include/mess_BMP280.h

95 lines
3.0 KiB
C

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#ifndef SEALEVELPRESSURE_HPA
#define SEALEVELPRESSURE_HPA (1013.25f)
#endif
// Richen 219 m über NN
// Eppingem 195 m über NN
Adafruit_BMP280 bmp; // I2C
bool F_BMP280;
struct {
char temperature[15] = {0};
char pressure[15] = {0};
char approx_altitud[15] = {0};
char humity[15] = {0};
} BMP280Data;
void Init_BMP280(){
bool status = bmp.begin(0x76);
F_BMP280 = true;
if (!status) {
Serial.println("BMP280 not connected!");
F_BMP280 = false;
SystemStatus = SystemStatus | BMP280noReady;
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
delay(5000);
} else{
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
//bmp_temp->printSensorDetails();
Serial.println("BMP280 gefunden");
}
}
void read_BMP_280() {
Serial.print("Temperature (BMP280):\t");
float t = bmp.readTemperature();
t = t + KorrekturTemperatur;
dtostrf(t,7,1,BMP280Data.temperature);
Serial.print(BMP280Data.temperature);
Serial.println(" °C");
Serial.print("Pressure:\t\t");
float p = bmp.readPressure() / 100.0F;
p = p + KorrekturLuftdruck;
dtostrf(p,7,1,BMP280Data.pressure);
Serial.print(BMP280Data.pressure);
Serial.println(" hPa");
Serial.print("Approx. Altitude:\t");
float a = bmp.readAltitude(SEALEVELPRESSURE_HPA);
dtostrf(a,7,1,BMP280Data.approx_altitud);
Serial.print(BMP280Data.approx_altitud);
Serial.println(" m über NN");
Serial.println();
}
void M2M_BMP280(String deviceId = "4711") {
char topic[100];
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_BMP_280" );
client.publish(topic, BMP280Data.temperature, true);
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/pressure" );
client.publish(topic, BMP280Data.pressure, true);
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/approx_altitude" );
client.publish(topic, BMP280Data.approx_altitud);
}
void Clear_BMP280(String deviceId = "4711"){
char topic[100];
char test[1] = "";
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_BMP_280" );
client.publish(topic,test, false);
delay(10);
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/approx_altitude" );
client.publish(topic,test, false);
delay(10);
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/pressure" );
client.publish(topic,test, false);
delay(10);
}