80 lines
2.5 KiB
C
80 lines
2.5 KiB
C
#include <SPI.h>
|
|
#include <Wire.h>
|
|
#include <Adafruit_Sensor.h>
|
|
#include <Adafruit_BMP280.h>
|
|
|
|
|
|
#define SEALEVELPRESSURE_HPA (1013.25) // 1013.25
|
|
// Richen 219 m über NN
|
|
// Eppingem 195 m über NN
|
|
|
|
Adafruit_BMP280 bmp; // I2C
|
|
float K_BMP280 = -0.0;
|
|
|
|
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();
|
|
F_BMP280 = true;
|
|
if (!status) {
|
|
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
|
F_BMP280 = false;
|
|
SystemStatus = SystemStatus | BMP280noReady;
|
|
} else{
|
|
/* Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
|
|
delay(5000); */
|
|
/* 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 + K_BMP280;
|
|
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 + 13;
|
|
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);
|
|
} |