Compare commits
10
Commits
e11ae068bf
...
59044b3439
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59044b3439 | ||
|
|
91c89838e4 | ||
|
|
57fee5e257 | ||
|
|
ee2921f260 | ||
|
|
aa8828765b | ||
|
|
88cdb36a19 | ||
|
|
568c0778e3 | ||
|
|
1e85f6f43a | ||
|
|
87eee66b75 | ||
|
|
ac86764dcc |
+36
@@ -3,3 +3,39 @@
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
|
||||
# Ignore sensitive credentials
|
||||
secrets.ini
|
||||
|
||||
# --- SICHERHEIT & GEHEIMNISSE ---
|
||||
.env
|
||||
.env.*
|
||||
*.pem
|
||||
*.key
|
||||
secrets.*
|
||||
config/secrets.*
|
||||
forgejo-push
|
||||
gitea-push
|
||||
|
||||
# --- PYTHON ---
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
venv/
|
||||
.venv/
|
||||
|
||||
# --- DOCKER ---
|
||||
*.log
|
||||
docker-compose.override.yml
|
||||
data/
|
||||
db_data/
|
||||
|
||||
# --- ANDROID ---
|
||||
.gradle/
|
||||
build/
|
||||
local.properties
|
||||
*.apk
|
||||
*.keystore
|
||||
|
||||
# --- IDEs & OS ---
|
||||
.idea/
|
||||
.DS_Store
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
|
||||
bool F_ADS1115;
|
||||
float AKKU;
|
||||
|
||||
struct {
|
||||
char Akku[15] = {0};
|
||||
@@ -32,7 +33,6 @@ void initADS() {
|
||||
F_ADS1115 = true;
|
||||
if(!adc.init()){
|
||||
Serial.println("ADS1115 not connected!");
|
||||
SystemStatus = (SystemStatus | ADS1115noReady);
|
||||
F_ADS1115 = false;
|
||||
}
|
||||
|
||||
|
||||
+19
-36
@@ -13,8 +13,8 @@ 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};
|
||||
@@ -24,52 +24,35 @@ struct {
|
||||
char pressure[15] = {0};
|
||||
char approx_altitud[15] = {0};
|
||||
char humity[15] = {0};
|
||||
float Temperatur;
|
||||
float Luftfeuchte;
|
||||
float Luftdruck;
|
||||
} BME280Data;
|
||||
|
||||
void Sensor_BME280() {
|
||||
if (Anzahl_Sensoren_BME280 > 0) {
|
||||
float Temperatur_BME;
|
||||
float Luftfeuchte_BME;
|
||||
float Luftdruck_BME;
|
||||
BME280Data.Temperatur = No_Val;
|
||||
BME280Data.Luftdruck = No_Val;
|
||||
BME280Data.Luftfeuchte = No_Val;
|
||||
|
||||
boolean check;
|
||||
|
||||
Adafruit_BME280 my_bme;
|
||||
|
||||
for (byte i = 0; i < Anzahl_Sensoren_BME280; i++) {
|
||||
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();
|
||||
Luftdruck_BME = (Luftdruck_BME/100) + KorrekturLuftdruck;
|
||||
//Luftdruck_BME = 220;
|
||||
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);
|
||||
Serial.println(" hPa");
|
||||
}
|
||||
else {
|
||||
Temperatur_BME = No_Val;
|
||||
Luftfeuchte_BME = No_Val;
|
||||
Luftdruck_BME = No_Val;
|
||||
Serial.println(" KEIN BME 280 Gefunden !!!!");
|
||||
BME280Data.Temperatur = my_bme.readTemperature();
|
||||
BME280Data.Luftfeuchte = my_bme.readHumidity();
|
||||
BME280Data.Luftdruck = my_bme.readPressure();
|
||||
BME280Data.Luftdruck = (BME280Data.Luftdruck/100) + KorrekturLuftdruck;
|
||||
Serial.printf("Temperature (BME280): %0.2f C°\n", BME280Data.Temperatur);
|
||||
Serial.printf("Luftfeuchtigkeit (BME280): %0.2f %%\n", BME280Data.Luftfeuchte);
|
||||
Serial.printf("Luftdruck (BME280): %0.2f hPa\n", BME280Data.Luftdruck);
|
||||
} else {
|
||||
Serial.println(" KEIN BME 280 Gefunden !!!!");
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-18
@@ -18,6 +18,9 @@ struct {
|
||||
char pressure[15] = {0};
|
||||
char approx_altitud[15] = {0};
|
||||
char humity[15] = {0};
|
||||
float t = 0;
|
||||
float p = 0;
|
||||
float a = 0;
|
||||
} BMP280Data;
|
||||
|
||||
|
||||
@@ -28,7 +31,6 @@ void Init_BMP280(){
|
||||
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); */
|
||||
@@ -48,33 +50,24 @@ void read_BMP_280() {
|
||||
|
||||
|
||||
Serial.print("Temperature (BMP280):\t");
|
||||
float t = bmp.readTemperature();
|
||||
t = t + K_BMP280;
|
||||
dtostrf(t,7,1,BMP280Data.temperature);
|
||||
BMP280Data.t = bmp.readTemperature();
|
||||
BMP280Data.t = BMP280Data.t + K_BMP280;
|
||||
dtostrf(BMP280Data.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);
|
||||
BMP280Data.p = bmp.readPressure() / 100.0F;
|
||||
BMP280Data.p = BMP280Data.p + KorrekturLuftdruck;
|
||||
dtostrf(BMP280Data.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);
|
||||
BMP280Data.a = bmp.readAltitude(SEALEVELPRESSURE_HPA);
|
||||
dtostrf(BMP280Data.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);
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
float MinimalSpannung = MinimalSpannungAkku;
|
||||
|
||||
float korectur = 0.8870;
|
||||
float korectur = 0.9670;
|
||||
char floatString[15] = {0};
|
||||
float AKKU;
|
||||
|
||||
@@ -13,7 +13,7 @@ float getBattery(float kor = 1.000)
|
||||
return 3.05;
|
||||
#endif
|
||||
float valA0 = analogRead(A0);
|
||||
valA0 = valA0 * 5.9; // (R1 + r1 + r2) / r2
|
||||
valA0 = valA0 * 3.7; // (R1 + r1 + r2) / r2
|
||||
// r1 und r2 Spannungsteiler
|
||||
// r1 = 270k, r2 = 100k
|
||||
// Spannungsbereich = 5.2 Volt
|
||||
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
extra_configs = secrets.ini
|
||||
|
||||
[env]
|
||||
platform = espressif8266
|
||||
board = d1
|
||||
framework = arduino
|
||||
board_build.filesystem = littlefs
|
||||
monitor_port = /dev/ttyUSB0
|
||||
monitor_speed = 74800
|
||||
monitor_filters = time
|
||||
upload_port = /dev/ttyUSB0
|
||||
lib_deps =
|
||||
knolleary/PubSubClient @ 2.8
|
||||
adafruit/Adafruit HTU21DF Library @ 1.0.5
|
||||
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 BMP280 Library @ 3.0.0
|
||||
adafruit/Adafruit Unified Sensor @ 1.1.14
|
||||
bblanchon/ArduinoJson @ 7.4.3
|
||||
|
||||
build_flags =
|
||||
-DTEMPTEST33=1
|
||||
-DNOBATT=0
|
||||
-DMaxErrCount=40
|
||||
|
||||
|
||||
|
||||
[env:debug] ; Entwicklungssystem
|
||||
build_flags = ${env.build_flags}
|
||||
${secrets_debug.build_flags}
|
||||
-DDEBUG=0
|
||||
-DBME=0
|
||||
-DBMP=1
|
||||
-DMCP=0
|
||||
-DADS=0
|
||||
-DNAME=\"WETTERSTATION-RICHEN\"
|
||||
-DTERROR=5
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=5
|
||||
-DKorrekturLuftdruck=21.0
|
||||
-DKorrekturTemperaturHTU21D=-3.22
|
||||
-DMinimalSpannungAkku=2.95
|
||||
|
||||
[env:hjk] ; Entwicklungssystem
|
||||
build_flags = ${env.build_flags}
|
||||
${secrets_hjk.build_flags}
|
||||
-DDEBUG=0
|
||||
-DBME=1
|
||||
-DBMP=0
|
||||
-DMCP=1
|
||||
-DADS=1
|
||||
-DNAME=\"WETTERSTATION-SULZFELD\"
|
||||
-DTERROR=5
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=5
|
||||
-DKorrekturLuftdruck=22.58
|
||||
-DKorrekturTemperaturHTU21D=-2.3
|
||||
-DMinimalSpannungAkku=2.90
|
||||
|
||||
|
||||
[env:marcel] ; Entwicklungssystem
|
||||
build_flags = ${env.build_flags}
|
||||
${secrets_marcel.build_flags}
|
||||
-DDEBUG=0
|
||||
-DNOADS=0
|
||||
-DBME=0
|
||||
-DBMP=1
|
||||
-DMCP=0
|
||||
-DADS=0
|
||||
-DNAME=\"WETTERSTATION-RICHEN\"
|
||||
-DTERROR=5
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=10
|
||||
-DKorrekturLuftdruck=22.58
|
||||
-DKorrekturTemperaturHTU21D=-2.3
|
||||
-DMinimalSpannungAkku=2.90
|
||||
|
||||
[env:boris] ; Entwicklungssystem
|
||||
build_flags = ${env.build_flags}
|
||||
${secrets_boris.build_flags}
|
||||
-DDEBUG=0
|
||||
-DNOADS=0
|
||||
-DBME=0
|
||||
-DBMP=1
|
||||
-DMCP=0
|
||||
-DADS=0
|
||||
-DNAME=\"WETTERSTATION-WIESLOCH\"
|
||||
-DTERROR=5
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=10
|
||||
-DKorrekturLuftdruck=22.58
|
||||
-DKorrekturTemperaturHTU21D=-2.3
|
||||
-DMinimalSpannungAkku=2.90
|
||||
|
||||
[env:marcel_test] ; Entwicklungssystem
|
||||
build_flags = ${env.build_flags}
|
||||
${secrets_marcel_test.build_flags}
|
||||
-DDEBUG=0
|
||||
-DNOADS=0
|
||||
-DBME=0
|
||||
-DBMP=1
|
||||
-DMCP=0
|
||||
-DADS=0
|
||||
-DNAME=\"WETTERSTATION-RICHEN\"
|
||||
-DTERROR=5
|
||||
-DTLOWBATT=60
|
||||
-DTINTERVAL=10
|
||||
-DKorrekturLuftdruck=22.58
|
||||
-DKorrekturTemperaturHTU21D=-2.3
|
||||
-DMinimalSpannungAkku=2.90
|
||||
@@ -0,0 +1,65 @@
|
||||
[secrets_debug]
|
||||
build_flags =
|
||||
-DSTASSID=\"<your_ssid>\"
|
||||
-DSTAPSK=\"<your_password>\"
|
||||
-DGATEWAY=\"192.168.1.1\"
|
||||
-DDNS=\"192.168.1.1\"
|
||||
-DMYIP=\"192.168.1.100\"
|
||||
-Dmqtt_server=\"<mqtt_server_ip_or_domain>\"
|
||||
-Dmqtt_port=1883
|
||||
-Dmqtt_user=\"<mqtt_user>\"
|
||||
-Dmqtt_pass=\"<mqtt_password>\"
|
||||
|
||||
[secrets_hjk]
|
||||
build_flags =
|
||||
-DSTASSID=\"<your_ssid>\"
|
||||
-DSTAPSK=\"<your_password>\"
|
||||
-DGATEWAY=\"192.168.1.1\"
|
||||
-DDNS=\"192.168.1.1\"
|
||||
-DMYIP=\"192.168.1.100\"
|
||||
-Dmqtt_server=\"<mqtt_server_ip_or_domain>\"
|
||||
-Dmqtt_port=1883
|
||||
-Dmqtt_user=\"<mqtt_user>\"
|
||||
-Dmqtt_pass=\"<mqtt_password>\"
|
||||
|
||||
[secrets_marcel]
|
||||
build_flags =
|
||||
-DSTASSID=\"<your_ssid>\"
|
||||
-DSTAPSK=\"<your_password>\"
|
||||
-DGATEWAY=\"192.168.1.1\"
|
||||
-DDNS=\"192.168.1.1\"
|
||||
-DSECONDARDNS=\"8.8.8.8\"
|
||||
-DMYIP=\"192.168.1.100\"
|
||||
-DSUBNET=\"255.255.255.0\"
|
||||
-Dmqtt_server=\"<mqtt_server_ip_or_domain>\"
|
||||
-Dmqtt_port=1883
|
||||
-Dmqtt_user=\"<mqtt_user>\"
|
||||
-Dmqtt_pass=\"<mqtt_password>\"
|
||||
|
||||
[secrets_boris]
|
||||
build_flags =
|
||||
-DSTASSID=\"<your_ssid>\"
|
||||
-DSTAPSK=\"<your_password>\"
|
||||
-DGATEWAY=\"192.168.1.1\"
|
||||
-DDNS=\"192.168.1.1\"
|
||||
-DMYIP=\"192.168.1.100\"
|
||||
-DSUBNET=\"255.255.255.0\"
|
||||
-DSECONDARDNS=\"8.8.8.8\"
|
||||
-Dmqtt_server=\"<mqtt_server_ip_or_domain>\"
|
||||
-Dmqtt_port=1883
|
||||
-Dmqtt_user=\"<mqtt_user>\"
|
||||
-Dmqtt_pass=\"<mqtt_password>\"
|
||||
|
||||
[secrets_marcel_test]
|
||||
build_flags =
|
||||
-DSTASSID=\"<your_ssid>\"
|
||||
-DSTAPSK=\"<your_password>\"
|
||||
-DGATEWAY=\"192.168.1.1\"
|
||||
-DDNS=\"192.168.1.1\"
|
||||
-DSECONDARDNS=\"8.8.8.8\"
|
||||
-DMYIP=\"192.168.1.100\"
|
||||
-DSUBNET=\"255.255.255.0\"
|
||||
-Dmqtt_server=\"<mqtt_server_ip_or_domain>\"
|
||||
-Dmqtt_port=1883
|
||||
-Dmqtt_user=\"<mqtt_user>\"
|
||||
-Dmqtt_pass=\"<mqtt_password>\"
|
||||
+97
-18
@@ -6,12 +6,21 @@
|
||||
#include <Ticker.h>
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#if (BMP == 1)
|
||||
#include <mess_BMP280.h>
|
||||
#endif
|
||||
#if (BME == 1)
|
||||
#include <mess_BME280.h>
|
||||
#endif
|
||||
#include <mess_htu21.h>
|
||||
#if (MCP == 1)
|
||||
#include <mcp9808.h>
|
||||
#endif
|
||||
#if (ADS ==1)
|
||||
#include "messADS1115.h"
|
||||
#else
|
||||
#include <mess_Ub_old.h>
|
||||
|
||||
#endif
|
||||
unsigned long startTime;
|
||||
unsigned long endTime;
|
||||
|
||||
@@ -30,6 +39,7 @@ const char* topic = "hjk/"NAME"/env"; // CHANGE SensorID here!
|
||||
|
||||
//const unsigned long interval = TINTERVAL * 60000000LU; // Minuten * Mikrosekunden für Sleep Mode
|
||||
const unsigned long interval = TINTERVAL * 63800000LU; // Minuten * Mikrosekunden für Sleep Mode
|
||||
const unsigned long AkkuLeer = 60 * 63800000LU; // Akku entladen, dann Pause von 60 Minuten
|
||||
|
||||
/*
|
||||
* NTP Server Configuration for TimeStamps
|
||||
@@ -38,7 +48,12 @@ const char* ntp_server = "pool.ntp.org";
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
#if (BME == 1)
|
||||
Adafruit_BME280 bme;
|
||||
#endif
|
||||
#if (BMP == 1)
|
||||
Adafruit_BMP280 bme;
|
||||
#endif
|
||||
|
||||
|
||||
String clientID = "ESP8266-";
|
||||
@@ -48,6 +63,14 @@ String clientID = "ESP8266-";
|
||||
const size_t capacity = 256;
|
||||
JsonDocument data;
|
||||
|
||||
const char *MyIP = MYIP;
|
||||
IPAddress ip;
|
||||
IPAddress gateway;
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
IPAddress dns;
|
||||
IPAddress secondaryDNS(8, 8, 8, 8);
|
||||
|
||||
|
||||
float temp, humid = 0.0;
|
||||
char output[capacity] = {0};
|
||||
/*
|
||||
@@ -73,8 +96,8 @@ void reconnect() {
|
||||
while (!client.connected()) {
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
// Attempt to connect
|
||||
clientID += String(random(0xFFFF),HEX);
|
||||
Serial.printf("\tCientID = %s\n",clientID.c_str());
|
||||
String clientID = "ESP8266-" + String(random(0xFFFF),HEX);
|
||||
Serial.printf("\tCientID = %s ",clientID.c_str());
|
||||
if (client.connect(clientID.c_str(), mqtt_user, mqtt_pass)) { //mquu_user ???
|
||||
Serial.println("connected");
|
||||
} else {
|
||||
@@ -91,19 +114,40 @@ void reconnect() {
|
||||
void setup() {
|
||||
int ErrCount = 0;
|
||||
startTime = millis();
|
||||
AKKU = getBattery();
|
||||
WiFi.mode( WIFI_OFF );
|
||||
#if (ADS == 1)
|
||||
initADS();
|
||||
#endif
|
||||
WiFi.mode( WIFI_OFF );
|
||||
WiFi.forceSleepBegin();
|
||||
delay(100);
|
||||
WiFi.forceSleepWake();
|
||||
delay( 1 );
|
||||
WiFi.persistent( false );
|
||||
WiFi.mode( WIFI_STA );
|
||||
AKKU = getBattery(korectur);
|
||||
Serial.begin(74800);
|
||||
Serial.println("\n\n\n");
|
||||
#if (ADS == 1)
|
||||
AKKU = readChannel(ADS1115_COMP_0_GND);
|
||||
#endif
|
||||
#if (ADS == 0)
|
||||
AKKU = getBattery(korectur);
|
||||
#endif
|
||||
//Wire.begin(13, 16); // Needed if using Olimex POE Boards
|
||||
bme.begin();
|
||||
Serial.println("BME280 setup complete");
|
||||
if (!ip.fromString(MyIP)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable IP");
|
||||
}
|
||||
if (!dns.fromString(DNS)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable DNS");
|
||||
}
|
||||
if (!gateway.fromString(GATEWAY)) { // try to parse into the IPAddress
|
||||
Serial.println("UnParsable GATEWAY");
|
||||
}
|
||||
//WiFi.config( ip, dns, gateway, subnet );
|
||||
if (!WiFi.config(ip, gateway, subnet, dns, secondaryDNS))
|
||||
{
|
||||
Serial.println("STA Failed to configure");
|
||||
}
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
configTime(0, 0, ntp_server);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
@@ -119,15 +163,27 @@ void setup() {
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("WiFi Connected");
|
||||
Serial.println("IP Address: ");
|
||||
|
||||
Serial.print("WiFi Connected. ");
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.printf(" Signal: %i dBm\n",WiFi.RSSI());
|
||||
delay(1000);
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
#if (BMP == 1)
|
||||
//Sensor_BME280();
|
||||
Init_BMP280();
|
||||
read_BMP_280();
|
||||
#endif
|
||||
#if (BME == 1)
|
||||
Sensor_BME280();
|
||||
#endif
|
||||
init_HTU21();
|
||||
read_HTU21D();
|
||||
#if (MCP == 1)
|
||||
init_MCP9808();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -137,17 +193,34 @@ void loop() {
|
||||
}
|
||||
client.loop();
|
||||
|
||||
|
||||
//Sensor_BME280();
|
||||
|
||||
// Creating JSON Format
|
||||
data["temp"].set(Temp[0]);
|
||||
data["tempHTU"].set(htu.readTemperature());
|
||||
#if (BMP == 1)
|
||||
data["temp"].set(BMP280Data.t);
|
||||
data["druck"].set(BMP280Data.p);
|
||||
#endif
|
||||
#if (BME == 1)
|
||||
data["temp"].set(BME280Data.Temperatur);
|
||||
data["druck"].set(BME280Data.Luftdruck);
|
||||
#endif
|
||||
data["tempHTU"].set(htu.readTemperature() + KorrekturTemperaturHTU21D);
|
||||
#if (MCP == 1)
|
||||
data["temp9808"].set(getTemperature_MCP9808());
|
||||
data["humid"].set(Feuchte[0]);
|
||||
data["druck"].set(L_Druck[0]);
|
||||
#else
|
||||
data["temp9808"].set(htu.readTemperature() + KorrekturTemperaturHTU21D);
|
||||
#endif
|
||||
data["humid"].set(htu.readHumidity());
|
||||
#if (ADS == 0)
|
||||
data["akku"].set(AKKU);
|
||||
#endif
|
||||
#if (ADS == 1)
|
||||
data["akku"].set(readChannel(ADS1115_COMP_0_GND));
|
||||
data["solar"].set(readChannel(ADS1115_COMP_1_GND)*2);
|
||||
#endif
|
||||
data["RSSI"].set(WiFi.RSSI());
|
||||
data["time"].set(getLocalTimeNTP());
|
||||
|
||||
// Output Format
|
||||
serializeJson(data, output);
|
||||
|
||||
@@ -155,9 +228,15 @@ void loop() {
|
||||
client.publish(topic, output);
|
||||
delay(1000); // Publish data every 2 seconds to the Broker
|
||||
endTime = millis();
|
||||
if (AKKU < MinimalSpannungAkku){
|
||||
Pause = (AkkuLeer -((endTime - startTime) * 1000)); // Pause ca. 60 Minuten
|
||||
} else {
|
||||
Pause = (interval -((endTime - startTime) * 1000)); // Pause ca.
|
||||
Serial.printf("Ich gehe für ca. %i Minuten schlafen.", TINTERVAL);
|
||||
}
|
||||
//Pause = (interval -((endTime - startTime) * 1000) + (19 *1000 *1000)); // Pause ca.
|
||||
Pause = (interval -((endTime - startTime) * 1000)); // Pause ca.
|
||||
//Pause = (interval -((endTime - startTime) * 1000)); // Pause ca.
|
||||
//Serial.printf("%ld - %ld = %ld Diff.= %ld\n", endTime, startTime, (endTime - startTime), (interval - ((endTime - startTime)*1000)));
|
||||
Serial.printf("Ich gehe für ca. %i Minuten schlafen.", TINTERVAL);
|
||||
|
||||
ESP.deepSleep(Pause, WAKE_RF_DISABLED); // Pause
|
||||
}
|
||||
Reference in New Issue
Block a user