2024-10-0600 Besser Erkennung von BMP / BME280 und Topic entfernen.
This commit is contained in:
parent
c9620768e5
commit
440630f29f
|
@ -31,7 +31,7 @@ void init_MCP9808(){
|
|||
// 1 1 0 0x1E
|
||||
// 1 1 1 0x1F
|
||||
if (!tempsensor.begin(0x18)) {
|
||||
Serial.println("Couldn't find MCP9808! Check your connections and verify the address is correct.");
|
||||
Serial.println("MCP9808 not connected!");
|
||||
SystemStatus = SystemStatus | MCP9808noReady;
|
||||
F_MCP9808 = false;
|
||||
|
||||
|
|
|
@ -10,9 +10,12 @@
|
|||
#include "Adafruit_Sensor.h"
|
||||
#include "Adafruit_BME280.h"
|
||||
uint8_t BME280_adresse[2] = {0x76, 0x76};
|
||||
#ifndef SEALEVELPRESSURE_HPA
|
||||
#define SEALEVELPRESSURE_HPA (1013.25f)
|
||||
#endif
|
||||
//----------------------------------------------------------------
|
||||
|
||||
bool F_BME280 = true;
|
||||
|
||||
const float No_Val = 999.99;
|
||||
float Temp[2] = {No_Val, No_Val};
|
||||
|
@ -58,6 +61,8 @@ if (Anzahl_Sensoren_BME280 > 0) {
|
|||
Temperatur_BME = No_Val;
|
||||
Luftfeuchte_BME = No_Val;
|
||||
Luftdruck_BME = No_Val;
|
||||
Serial.println("BME280 not connected!");
|
||||
F_BME280 = false;
|
||||
}
|
||||
if (i == 0) { // erster BME
|
||||
Temp[0] = Temperatur_BME; // Hier kann die Zuordnung der Sensoren geändert werden
|
||||
|
@ -87,3 +92,16 @@ void M2M_BME280(String deviceId = "4711") {
|
|||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/pressure" );
|
||||
client.publish(topic, BME280Data.pressure, true);
|
||||
}
|
||||
void Clear_BME280(String deviceId = "4711"){
|
||||
char topic[100];
|
||||
char test[1] = "";
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_BME_280" );
|
||||
client.publish(topic,test, false);
|
||||
delay(10);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/humity_BME280" );
|
||||
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);
|
||||
}
|
|
@ -4,12 +4,14 @@
|
|||
#include <Adafruit_BMP280.h>
|
||||
|
||||
|
||||
#define SEALEVELPRESSURE_HPA (1013.25) // 1013.25
|
||||
#ifndef SEALEVELPRESSURE_HPA
|
||||
#define SEALEVELPRESSURE_HPA (1013.25f)
|
||||
#endif
|
||||
// Richen 219 m über NN
|
||||
// Eppingem 195 m über NN
|
||||
|
||||
Adafruit_BMP280 bmp; // I2C
|
||||
float K_BMP280 = -0.0;
|
||||
|
||||
|
||||
bool F_BMP280;
|
||||
|
||||
|
@ -23,15 +25,15 @@ struct {
|
|||
|
||||
|
||||
void Init_BMP280(){
|
||||
bool status = bmp.begin();
|
||||
bool status = bmp.begin(0x76);
|
||||
F_BMP280 = true;
|
||||
if (!status) {
|
||||
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
||||
Serial.println("BMP280 not connected!");
|
||||
F_BMP280 = false;
|
||||
SystemStatus = SystemStatus | BMP280noReady;
|
||||
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
|
||||
delay(5000);
|
||||
} 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 */
|
||||
|
@ -49,14 +51,14 @@ void read_BMP_280() {
|
|||
|
||||
Serial.print("Temperature (BMP280):\t");
|
||||
float t = bmp.readTemperature();
|
||||
t = t + K_BMP280;
|
||||
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 + 13;
|
||||
p = p + KorrekturLuftdruck;
|
||||
dtostrf(p,7,1,BMP280Data.pressure);
|
||||
Serial.print(BMP280Data.pressure);
|
||||
Serial.println(" hPa");
|
||||
|
@ -78,3 +80,16 @@ void M2M_BMP280(String deviceId = "4711") {
|
|||
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);
|
||||
}
|
|
@ -51,7 +51,8 @@ build_flags = ${env.build_flags}
|
|||
-DTLOWBATT=60
|
||||
-DTINTERVAL=10
|
||||
-DSpannungsteiler=5.4
|
||||
-DKorrekturLuftdruck=22.58
|
||||
-DKorrekturLuftdruck=23.58
|
||||
-DKorrekturTemperatur=0.0
|
||||
|
||||
[env:marcel] ; Produktivsystem:
|
||||
build_flags = ${env.build_flags}
|
||||
|
@ -69,6 +70,7 @@ build_flags = ${env.build_flags}
|
|||
-DTLOWBATT=60
|
||||
-DTINTERVAL=10
|
||||
-DKorrekturLuftdruck=0.0
|
||||
-DKorrekturTemperatur=0.0
|
||||
|
||||
[env:boris] ; Produktivsystem:
|
||||
build_flags = ${env.build_flags}
|
||||
|
@ -86,6 +88,7 @@ build_flags = ${env.build_flags}
|
|||
-DTLOWBATT=60
|
||||
-DTINTERVAL=5
|
||||
-DKorrekturLuftdruck=0.0
|
||||
-DKorrekturTemperatur=0.0
|
||||
|
||||
[env:hjk]
|
||||
build_flags = ${env.build_flags}
|
||||
|
@ -104,6 +107,7 @@ build_flags = ${env.build_flags}
|
|||
-DTINTERVAL=10
|
||||
-DSpannungsteiler=5.4
|
||||
-DKorrekturLuftdruck=23.58
|
||||
-DKorrekturTemperatur=0.0
|
||||
|
||||
[env:filamentbox]
|
||||
build_flags = ${env.build_flags}
|
||||
|
@ -121,4 +125,5 @@ build_flags = ${env.build_flags}
|
|||
-DTLOWBATT=60
|
||||
-DTINTERVAL=15
|
||||
-DKorrekturLuftdruck=0.0
|
||||
-DKorrekturTemperatur=0.0
|
||||
|
||||
|
|
26
src/main.cpp
26
src/main.cpp
|
@ -25,7 +25,8 @@ PubSubClient client(espClient);
|
|||
|
||||
#include<mess_htu21.h>
|
||||
|
||||
//#include <mess_BMP280.h>
|
||||
#include <mess_BMP280.h>
|
||||
|
||||
#include <mess_BME280.h>
|
||||
|
||||
#include <mess_Ub_old.h>
|
||||
|
@ -48,7 +49,7 @@ IPAddress dns;
|
|||
IPAddress secondaryDNS(8, 8, 8, 8);
|
||||
|
||||
|
||||
const char* mqtt_fprint = "a3:44:1d:aa:6e:e5:c7:55:02:20:98:ea:9b:df:1a:42:a2:f3:e3:0d";
|
||||
//const char* mqtt_fprint = "a3:44:1d:aa:6e:e5:c7:55:02:20:98:ea:9b:df:1a:42:a2:f3:e3:0d";
|
||||
const char* mqtt_user = "mqtt";
|
||||
const char* mqtt_pass = "fische";
|
||||
|
||||
|
@ -93,7 +94,7 @@ void setup() {
|
|||
delay(500);
|
||||
#if (MQTT == 0)
|
||||
init_HTU21();
|
||||
//Init_BMP280();
|
||||
Init_BMP280();
|
||||
Sensor_BME280();
|
||||
|
||||
init_MCP9808();
|
||||
|
@ -115,12 +116,16 @@ void setup() {
|
|||
if (F_ADS1115 == true){
|
||||
MessungADS();
|
||||
}
|
||||
/* if (F_BMP280 == true){
|
||||
if (F_BMP280 == true){
|
||||
read_BMP_280();
|
||||
}*/
|
||||
}
|
||||
if (F_MCP9808 == true){
|
||||
valTemp = getTemperature_MCP9808();
|
||||
}
|
||||
if (!F_BME280 == true){
|
||||
Serial.println("Topic BME280 löschen!");
|
||||
Clear_BME280(hostname.c_str());
|
||||
}
|
||||
setup_wifi(); // ca. 4,5 s
|
||||
deviceId = ESP.getChipId();
|
||||
sprintf(sID, "%010ld", deviceId);
|
||||
|
@ -131,6 +136,14 @@ void setup() {
|
|||
client.setServer(mqtt_server, mqtt_port);
|
||||
client.setCallback(callback);
|
||||
Serial.printf("Systemstatus : 0x%02x \n", SystemStatus);
|
||||
if (!F_BME280 == true){
|
||||
Serial.println("Topic BME280 löschen!");
|
||||
Clear_BME280(hostname.c_str());
|
||||
}
|
||||
if (!F_BMP280 == true){
|
||||
Serial.println("Topic BMP280 löschen!");
|
||||
Clear_BME280(hostname.c_str());
|
||||
}
|
||||
//----------
|
||||
|
||||
}
|
||||
|
@ -152,8 +165,9 @@ void loop() {
|
|||
}
|
||||
|
||||
if (F_HTU_21D) M2M_HTU21D(hostname.c_str());
|
||||
M2M_BME280(hostname.c_str());
|
||||
if (F_BME280) M2M_BME280(hostname.c_str());
|
||||
if (F_MCP9808) M2M_Temperatur_MCP9808(hostname.c_str());
|
||||
if (F_BMP280) M2M_BMP280(hostname.c_str());
|
||||
sprintf(msg,"%ld", Feldstaerke);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", hostname.c_str(), "/telemetry/RSSI" );
|
||||
client.publish(topic, msg, true);
|
||||
|
|
Loading…
Reference in New Issue
Block a user