Wetterstation_Boris/include/mess_BMP280.h

95 lines
3.0 KiB
C
Raw Permalink Normal View History

2023-05-18 12:10:48 +02:00
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#ifndef SEALEVELPRESSURE_HPA
#define SEALEVELPRESSURE_HPA (1013.25f)
#endif
2023-05-18 12:10:48 +02:00
// Richen 219 m über NN
// Eppingem 195 m über NN
Adafruit_BMP280 bmp; // I2C
2023-05-18 12:10:48 +02:00
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);
2023-05-18 12:10:48 +02:00
F_BMP280 = true;
if (!status) {
Serial.println("BMP280 not connected!");
2023-05-18 12:10:48 +02:00
F_BMP280 = false;
2023-05-19 14:15:31 +02:00
SystemStatus = SystemStatus | BMP280noReady;
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
delay(5000);
2023-05-18 12:10:48 +02:00
} 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 + KorrekturTemperaturBMP;
2023-05-18 12:10:48 +02:00
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;
2023-05-19 14:15:31 +02:00
dtostrf(p,7,1,BMP280Data.pressure);
2023-05-18 12:10:48 +02:00
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);
2024-10-10 14:39:49 +02:00
delay(100);
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/approx_altitude" );
client.publish(topic,test, false);
2024-10-10 14:39:49 +02:00
delay(100);
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/pressure" );
client.publish(topic,test, false);
2024-10-10 14:39:49 +02:00
delay(100);
2023-05-18 12:10:48 +02:00
}