2024-07-03-01
This commit is contained in:
parent
d6e10959bc
commit
203c388ae2
1
.vscode/extensions.json
vendored
1
.vscode/extensions.json
vendored
|
@ -2,6 +2,7 @@
|
|||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"ijustdev.gitea-vscode",
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
|
|
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"gitea.instanceURL": "https://hjkgitunix.dedyn.io/hans-jurgen/Wetterstation_Boris.git",
|
||||
"gitea.owner": "hans-jürgen"
|
||||
}
|
87
include/mess_BME280.h
Normal file
87
include/mess_BME280.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
#include "Wire.h"
|
||||
|
||||
#define Anzahl_Sensoren_BME280 1 // Mögliche Werte: '0','1','2'
|
||||
#define Korrektur_Luftdruck 0.0 // Korrekturwert um Abweichungen zu offiziellen Wetterstationen auszugleichen
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Konfiguration BME280 - Temperatur und Luftfeuchte
|
||||
//----------------------------------------------------------------
|
||||
#include "Adafruit_Sensor.h"
|
||||
#include "Adafruit_BME280.h"
|
||||
uint8_t BME280_adresse[2] = {0x76, 0x77};
|
||||
#define SEALEVELPRESSURE_HPA (1013.25f)
|
||||
//----------------------------------------------------------------
|
||||
|
||||
|
||||
const float No_Val = 999.99;
|
||||
float Temp[2] = {No_Val, No_Val};
|
||||
float Feuchte[2] = {No_Val, No_Val};
|
||||
float L_Druck[2] = {No_Val, No_Val};
|
||||
|
||||
struct {
|
||||
char temperature[15] = {0};
|
||||
char pressure[15] = {0};
|
||||
char approx_altitud[15] = {0};
|
||||
char humity[15] = {0};
|
||||
} BME280Data;
|
||||
|
||||
void Sensor_BME280() {
|
||||
if (Anzahl_Sensoren_BME280 > 0) {
|
||||
float Temperatur_BME;
|
||||
float Luftfeuchte_BME;
|
||||
float Luftdruck_BME;
|
||||
boolean check;
|
||||
|
||||
Adafruit_BME280 my_bme;
|
||||
|
||||
for (byte i = 0; i < Anzahl_Sensoren_BME280; i++) {
|
||||
check = my_bme.begin(BME280_adresse[i]); // I2C Adresse
|
||||
delay (100); // time to get system ready
|
||||
if (check) { // if bme ok
|
||||
Temperatur_BME = my_bme.readTemperature();
|
||||
Luftfeuchte_BME = my_bme.readHumidity();
|
||||
Luftdruck_BME = my_bme.readPressure();
|
||||
Serial.print("Temperature (BME280):\t\t");
|
||||
Serial.print(Temperatur_BME);
|
||||
Serial.println(" °C");
|
||||
Serial.print("Luftfeuchtigkeit (BME280):\t");
|
||||
Serial.print(Luftfeuchte_BME);
|
||||
Serial.println(" %");
|
||||
Serial.print("Luftdruck (BME280):\t\t");
|
||||
Serial.print(Luftdruck_BME/100);
|
||||
Serial.println(" hPa");
|
||||
}
|
||||
else {
|
||||
Temperatur_BME = No_Val;
|
||||
Luftfeuchte_BME = No_Val;
|
||||
Luftdruck_BME = No_Val;
|
||||
}
|
||||
if (i == 0) { // erster BME
|
||||
Temp[0] = Temperatur_BME; // Hier kann die Zuordnung der Sensoren geändert werden
|
||||
Feuchte[0] = Luftfeuchte_BME; // Hier kann die Zuordnung der Sensoren geändert werden
|
||||
L_Druck[0] = Luftdruck_BME/100;
|
||||
}
|
||||
if (i == 1) { // zweiter BME
|
||||
Temp[1] = Temperatur_BME; // Hier kann die Zuordnung der Sensoren geändert werden
|
||||
Feuchte[1] = Luftfeuchte_BME; // Hier kann die Zuordnung der Sensoren geändert werden
|
||||
L_Druck[1] = Luftdruck_BME/100;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void M2M_BME280(String deviceId = "4711") {
|
||||
char topic[100];
|
||||
dtostrf(Temp[0],7,1,BME280Data.temperature);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/temperature_BME_280" );
|
||||
client.publish(topic, BME280Data.temperature, true);
|
||||
|
||||
dtostrf(Feuchte[0],7,1,BME280Data.humity);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/humity_BME280" );
|
||||
client.publish(topic, BME280Data.humity, true);
|
||||
|
||||
dtostrf(L_Druck[0],7,1,BME280Data.pressure);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", deviceId.c_str(), "/telemetry/pressure" );
|
||||
client.publish(topic, BME280Data.pressure, true);
|
||||
}
|
|
@ -30,8 +30,8 @@ void Init_BMP280(){
|
|||
F_BMP280 = false;
|
||||
SystemStatus = SystemStatus | BMP280noReady;
|
||||
} else{
|
||||
/* Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
|
||||
delay(5000); */
|
||||
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 */
|
||||
|
@ -56,7 +56,7 @@ void read_BMP_280() {
|
|||
|
||||
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");
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
|
||||
const float MinimalSpannung = 2.85;
|
||||
float korectur = 0.0009350;
|
||||
float korectur = 0.001015;
|
||||
char floatString[15] = {0};
|
||||
float AKKU;
|
||||
|
||||
|
@ -13,7 +13,7 @@ float getBattery()
|
|||
return 3.05;
|
||||
#endif
|
||||
int Vcc = analogRead(A0);
|
||||
Vcc = Vcc * ((100+220+680)/100);
|
||||
Vcc = Vcc * ((100+220+220)/100);
|
||||
float VCC = Vcc * korectur ;
|
||||
Serial.printf("Rohdaten: %d, ", Vcc);
|
||||
dtostrf(VCC,8,2,floatString);
|
||||
|
|
|
@ -13,16 +13,18 @@ platform = espressif8266
|
|||
board = d1
|
||||
framework = arduino
|
||||
board_build.filesystem = littlefs
|
||||
monitor_port = COM6
|
||||
monitor_port = COM5
|
||||
monitor_speed = 74800
|
||||
monitor_filters = time
|
||||
upload_port = COM6
|
||||
upload_port = COM5
|
||||
lib_deps =
|
||||
knolleary/PubSubClient @ 2.8
|
||||
adafruit/Adafruit HTU21DF Library @ 1.0.5
|
||||
adafruit/Adafruit BMP280 Library @ 2.6.6
|
||||
wollewald/ADS1115_WE @ 1.4.3
|
||||
adafruit/Adafruit MCP9808 Library @ 2.0.0
|
||||
adafruit/Adafruit BusIO @ 1.16.1
|
||||
adafruit/Adafruit BME280 Library @ 2.2.4
|
||||
adafruit/Adafruit Unified Sensor @ 1.1.14
|
||||
|
||||
build_flags =
|
||||
-DTEMPTEST33=1
|
||||
|
@ -46,6 +48,7 @@ build_flags = ${env.build_flags}
|
|||
-DTERROR=5
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=1
|
||||
-DKorrekturLuftdruck=0.0
|
||||
|
||||
[env:marcel] ; Produktivsystem:
|
||||
build_flags = ${env.build_flags}
|
||||
|
@ -62,6 +65,7 @@ build_flags = ${env.build_flags}
|
|||
-DTERROR=20
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=10
|
||||
-DKorrekturLuftdruck=0.0
|
||||
|
||||
[env:boris] ; Produktivsystem:
|
||||
build_flags = ${env.build_flags}
|
||||
|
@ -78,6 +82,7 @@ build_flags = ${env.build_flags}
|
|||
-DTERROR=20
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=5
|
||||
-DKorrekturLuftdruck=0.0
|
||||
|
||||
[env:hjk]
|
||||
build_flags = ${env.build_flags}
|
||||
|
@ -93,7 +98,8 @@ build_flags = ${env.build_flags}
|
|||
-Dmqtt_port=61883
|
||||
-DTERROR=5
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=5
|
||||
-DTINTERVAL=10
|
||||
-DKorrekturLuftdruck=23.6
|
||||
|
||||
[env:filamentbox]
|
||||
build_flags = ${env.build_flags}
|
||||
|
@ -110,4 +116,5 @@ build_flags = ${env.build_flags}
|
|||
-DTERROR=5
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=15
|
||||
-DKorrekturLuftdruck=0.0
|
||||
|
||||
|
|
28
src/main.cpp
28
src/main.cpp
|
@ -5,7 +5,7 @@
|
|||
#include <PubSubClient.h>
|
||||
#include <Ticker.h>
|
||||
|
||||
#define BUILTIN_LED D15
|
||||
// #define BUILTIN_LED D2
|
||||
#define TRIGGER_PIN D7
|
||||
#define START_STOP_PIN D6
|
||||
|
||||
|
@ -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.h>
|
||||
|
||||
|
@ -72,6 +73,10 @@ long int Feldstaerke;
|
|||
|
||||
void setup() {
|
||||
startTime = millis();
|
||||
/* pinMode(BUILTIN_LED, OUTPUT);
|
||||
digitalWrite(BUILTIN_LED, LOW);
|
||||
delay(5000);
|
||||
digitalWrite(BUILTIN_LED, HIGH); */
|
||||
Serial.begin(74880);
|
||||
while ( !Serial ) delay(100); // wait for native usb
|
||||
WiFi.mode( WIFI_OFF );
|
||||
|
@ -84,10 +89,13 @@ void setup() {
|
|||
readSystemStatus();
|
||||
Serial.printf("Systemstatus : 0x%02x \n", SystemStatus);
|
||||
SystemStatus = 0x00;
|
||||
writeSystemStatus();
|
||||
delay(500);
|
||||
#if (MQTT == 0)
|
||||
init_HTU21();
|
||||
Init_BMP280();
|
||||
//Init_BMP280();
|
||||
Sensor_BME280();
|
||||
|
||||
init_MCP9808();
|
||||
initADS();
|
||||
#endif
|
||||
|
@ -106,9 +114,9 @@ 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();
|
||||
}
|
||||
|
@ -143,7 +151,7 @@ void loop() {
|
|||
}
|
||||
|
||||
if (F_HTU_21D) M2M_HTU21D(hostname.c_str());
|
||||
if (F_BMP280) M2M_BMP280(hostname.c_str());
|
||||
M2M_BME280(hostname.c_str());
|
||||
if (F_MCP9808) M2M_Temperatur_MCP9808(hostname.c_str());
|
||||
sprintf(msg,"%ld", Feldstaerke);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", hostname.c_str(), "/telemetry/RSSI" );
|
||||
|
@ -153,7 +161,7 @@ void loop() {
|
|||
client.publish(topic, msg, true);
|
||||
client.loop();
|
||||
delay(500);
|
||||
digitalWrite(BUILTIN_LED, HIGH);
|
||||
//digitalWrite(BUILTIN_LED, HIGH);
|
||||
/* ESP.deepSleep(5e6);
|
||||
delay(100); */
|
||||
endTime = millis();
|
||||
|
@ -265,7 +273,7 @@ void callback(char* topic1, byte* payload, unsigned int length)
|
|||
|
||||
void reconnect() {
|
||||
// Loop until we're reconnected
|
||||
sprintf(clientName, "%s%s", "ESP8266Client", sID);
|
||||
sprintf(clientName, "%s%s", "ESP8266Wetter", sID);
|
||||
while (!client.connected()) {
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
//verifyFingerprint();
|
||||
|
@ -273,9 +281,9 @@ void reconnect() {
|
|||
if (client.connect(clientName)) {
|
||||
Serial.println("connected");
|
||||
// Once connected, publish an announcement...
|
||||
client.publish("outTopic", "hello world");
|
||||
// client.publish("outTopic", "hello world");
|
||||
// ... and resubscribe
|
||||
client.subscribe("inTopic");
|
||||
// client.subscribe("inTopic");
|
||||
} else {
|
||||
Serial.print("failed, rc=");
|
||||
Serial.print(client.state());
|
||||
|
|
Loading…
Reference in New Issue
Block a user