Compare commits
No commits in common. "main" and "master" have entirely different histories.
1
.vscode/extensions.json
vendored
1
.vscode/extensions.json
vendored
|
@ -2,7 +2,6 @@
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
// for the documentation about the extensions.json format
|
// for the documentation about the extensions.json format
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"ijustdev.gitea-vscode",
|
|
||||||
"platformio.platformio-ide"
|
"platformio.platformio-ide"
|
||||||
],
|
],
|
||||||
"unwantedRecommendations": [
|
"unwantedRecommendations": [
|
||||||
|
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
"gitea.instanceURL": "https://hjkgitunix.dedyn.io/hans-jurgen/Wetterstation_Boris.git",
|
"gitea.instanceURL": "https://hjkgitunix.dedyn.io/",
|
||||||
"gitea.owner": "hans-jürgen"
|
"gitea.owner": "hans-jurgen",
|
||||||
|
"gitea.repo": "Wetterstation",
|
||||||
|
"gitea.token": " vscodegitea"
|
||||||
}
|
}
|
1
data/Korektur.txt
Normal file
1
data/Korektur.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
1.02910
|
|
@ -1 +0,0 @@
|
||||||
0
|
|
1
data/status.txt
Normal file
1
data/status.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
5
|
|
@ -1,31 +0,0 @@
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#include <EEPROM.h>
|
|
||||||
|
|
||||||
#define AkkuLeer 0x80
|
|
||||||
#define ADS1115noReady 0x01
|
|
||||||
#define HTU21noReady 0x02
|
|
||||||
#define BMP280noReady 0x04
|
|
||||||
#define MCP9808noReady 0x08
|
|
||||||
|
|
||||||
byte SystemStatus;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void writeSystemStatus()
|
|
||||||
{
|
|
||||||
EEPROM.begin(512);
|
|
||||||
EEPROM.put(0,SystemStatus);
|
|
||||||
EEPROM.commit();
|
|
||||||
EEPROM.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void readSystemStatus()
|
|
||||||
{
|
|
||||||
EEPROM.begin(512);
|
|
||||||
EEPROM.get(0,SystemStatus);
|
|
||||||
EEPROM.commit();
|
|
||||||
EEPROM.end();
|
|
||||||
|
|
||||||
}
|
|
|
@ -11,12 +11,9 @@ float valTemp;
|
||||||
// Create MCP9808 temperature sensor object
|
// Create MCP9808 temperature sensor object
|
||||||
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
|
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
|
||||||
|
|
||||||
bool F_MCP9808;
|
|
||||||
|
|
||||||
char Temperature[15] = {0};
|
char Temperature[15] = {0};
|
||||||
|
|
||||||
void init_MCP9808(){
|
void init_MCP9808(){
|
||||||
F_MCP9808 = true;
|
|
||||||
// Make sure the sensor is found, you can also pass in a different i2c
|
// Make sure the sensor is found, you can also pass in a different i2c
|
||||||
// address with tempsensor.begin(0x19) for example, also can be left in blank for default address use
|
// address with tempsensor.begin(0x19) for example, also can be left in blank for default address use
|
||||||
// Also there is a table with all addres possible for this sensor, you can connect multiple sensors
|
// Also there is a table with all addres possible for this sensor, you can connect multiple sensors
|
||||||
|
@ -32,12 +29,10 @@ void init_MCP9808(){
|
||||||
// 1 1 1 0x1F
|
// 1 1 1 0x1F
|
||||||
if (!tempsensor.begin(0x18)) {
|
if (!tempsensor.begin(0x18)) {
|
||||||
Serial.println("Couldn't find MCP9808! Check your connections and verify the address is correct.");
|
Serial.println("Couldn't find MCP9808! Check your connections and verify the address is correct.");
|
||||||
SystemStatus = SystemStatus | MCP9808noReady;
|
datenSave(-20);
|
||||||
F_MCP9808 = false;
|
while (1);
|
||||||
|
|
||||||
} else {
|
|
||||||
Serial.println("Found MCP9808!");
|
|
||||||
}
|
}
|
||||||
|
Serial.println("Found MCP9808!");
|
||||||
tempsensor.setResolution(3); // sets the resolution mode of reading, the modes are defined in the table bellow:
|
tempsensor.setResolution(3); // sets the resolution mode of reading, the modes are defined in the table bellow:
|
||||||
// Mode Resolution SampleTime
|
// Mode Resolution SampleTime
|
||||||
// 0 0.5°C 30 ms
|
// 0 0.5°C 30 ms
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
|
* ADS1115_WE adc = ADS1115_WE(&Wire, I2C_ADDRESS); -> all together
|
||||||
*/
|
*/
|
||||||
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
|
ADS1115_WE adc = ADS1115_WE(I2C_ADDRESS);
|
||||||
bool F_ADS1115;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
char Akku[15] = {0};
|
char Akku[15] = {0};
|
||||||
|
@ -29,11 +28,8 @@ struct {
|
||||||
|
|
||||||
void initADS() {
|
void initADS() {
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
F_ADS1115 = true;
|
|
||||||
if(!adc.init()){
|
if(!adc.init()){
|
||||||
Serial.println("ADS1115 not connected!");
|
Serial.println("ADS1115 not connected!");
|
||||||
SystemStatus = (SystemStatus | ADS1115noReady);
|
|
||||||
F_ADS1115 = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the voltage range of the ADC to adjust the gain
|
/* Set the voltage range of the ADC to adjust the gain
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
#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);
|
|
||||||
}
|
|
|
@ -4,12 +4,12 @@
|
||||||
#include <Adafruit_BMP280.h>
|
#include <Adafruit_BMP280.h>
|
||||||
|
|
||||||
|
|
||||||
#define SEALEVELPRESSURE_HPA (1013.25) // 1013.25
|
#define SEALEVELPRESSURE_HPA (1002.7) // 1013.25
|
||||||
// Richen 219 m über NN
|
// Richen 219 m über NN
|
||||||
// Eppingem 195 m über NN
|
// Eppingem 195 m über NN
|
||||||
|
|
||||||
Adafruit_BMP280 bmp; // I2C
|
Adafruit_BMP280 bmp; // I2C
|
||||||
float K_BMP280 = -0.0;
|
float K_BMP280 = -1.30;
|
||||||
|
|
||||||
bool F_BMP280;
|
bool F_BMP280;
|
||||||
|
|
||||||
|
@ -23,15 +23,14 @@ struct {
|
||||||
|
|
||||||
|
|
||||||
void Init_BMP280(){
|
void Init_BMP280(){
|
||||||
bool status = bmp.begin();
|
bool status = bmp.begin(0x76);
|
||||||
F_BMP280 = true;
|
F_BMP280 = true;
|
||||||
if (!status) {
|
if (!status) {
|
||||||
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
||||||
F_BMP280 = false;
|
F_BMP280 = false;
|
||||||
SystemStatus = SystemStatus | BMP280noReady;
|
|
||||||
} else{
|
} else{
|
||||||
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
|
/* Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
|
||||||
delay(5000);
|
delay(5000); */
|
||||||
/* Default settings from datasheet. */
|
/* Default settings from datasheet. */
|
||||||
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
|
||||||
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
|
||||||
|
@ -56,8 +55,8 @@ void read_BMP_280() {
|
||||||
|
|
||||||
Serial.print("Pressure:\t\t");
|
Serial.print("Pressure:\t\t");
|
||||||
float p = bmp.readPressure() / 100.0F;
|
float p = bmp.readPressure() / 100.0F;
|
||||||
p = p + KorrekturLuftdruck;
|
//p = p + 22;
|
||||||
dtostrf(p,7,1,BMP280Data.pressure);
|
dtostrf(p,5,0,BMP280Data.pressure);
|
||||||
Serial.print(BMP280Data.pressure);
|
Serial.print(BMP280Data.pressure);
|
||||||
Serial.println(" hPa");
|
Serial.println(" hPa");
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
ADC_MODE(ADC_VCC);
|
||||||
|
|
||||||
const float MinimalSpannung = 2.85;
|
const float MinimalSpannung = 2.85;
|
||||||
float korectur = 0.001015;
|
float korectur = 9.2800899887514060742407199100112e-4;
|
||||||
char floatString[15] = {0};
|
char floatString[15] = {0};
|
||||||
float AKKU;
|
float AKKU;
|
||||||
|
|
||||||
|
@ -12,11 +13,10 @@ float getBattery()
|
||||||
Serial.print("Batterie:\t\t 3.05 V\n");
|
Serial.print("Batterie:\t\t 3.05 V\n");
|
||||||
return 3.05;
|
return 3.05;
|
||||||
#endif
|
#endif
|
||||||
int Vcc = analogRead(A0);
|
int Vcc = ESP.getVcc();
|
||||||
Vcc = Vcc * ((100+220+220)/100);
|
|
||||||
float VCC = Vcc * korectur ;
|
float VCC = Vcc * korectur ;
|
||||||
Serial.printf("Rohdaten: %d, ", Vcc);
|
Serial.printf("Rohdaten: %d, ", Vcc);
|
||||||
dtostrf(VCC,8,2,floatString);
|
dtostrf(VCC,7,2,floatString);
|
||||||
Serial.printf("Vcc: \t%s V\n", floatString);
|
Serial.printf("Vcc: %s V\n", floatString);
|
||||||
return VCC;
|
return VCC;
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
const float MinimalSpannung = 2.85;
|
const float MinimalSpannung = 2.85;
|
||||||
float koa = 0.984326019;
|
float korectur = 1.02910;
|
||||||
char floatString[15] = {0};
|
char floatString[15] = {0};
|
||||||
float AKKU;
|
float AKKU;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
||||||
|
|
||||||
bool F_HTU_21D;
|
bool F_HTU_21D;
|
||||||
float K_HTU= -0.00;
|
float K_HTU= -1.30;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
char temperature[15] = {0};
|
char temperature[15] = {0};
|
||||||
|
@ -17,13 +17,10 @@ void init_HTU21(){
|
||||||
F_HTU_21D = false;
|
F_HTU_21D = false;
|
||||||
if (!htu.begin()) {
|
if (!htu.begin()) {
|
||||||
Serial.println("Couldn't find sensor HUT21D!");
|
Serial.println("Couldn't find sensor HUT21D!");
|
||||||
SystemStatus = SystemStatus | HTU21noReady;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
F_HTU_21D = true;
|
F_HTU_21D = true;
|
||||||
Serial.println("HUT21D gefunden");
|
Serial.println("HUT21D gefunden");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_HTU21D() {
|
void read_HTU21D() {
|
||||||
|
|
|
@ -12,24 +12,22 @@
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = d1
|
board = d1
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board_build.filesystem = littlefs
|
monitor_port = /dev/ttyUSB0
|
||||||
monitor_port = COM5
|
|
||||||
monitor_speed = 74800
|
monitor_speed = 74800
|
||||||
monitor_filters = time
|
monitor_filters = time
|
||||||
upload_port = COM5
|
board_build.filesystem = littlefs
|
||||||
lib_deps =
|
lib_deps =
|
||||||
knolleary/PubSubClient @ 2.8
|
knolleary/PubSubClient @ 2.8
|
||||||
adafruit/Adafruit HTU21DF Library @ 1.0.5
|
adafruit/Adafruit HTU21DF Library @ 1.0.5
|
||||||
|
adafruit/Adafruit BMP280 Library @ 2.6.6
|
||||||
wollewald/ADS1115_WE @ 1.4.3
|
wollewald/ADS1115_WE @ 1.4.3
|
||||||
adafruit/Adafruit MCP9808 Library @ 2.0.0
|
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 =
|
build_flags =
|
||||||
-DTEMPTEST33=1
|
-DTEMPTEST33=1
|
||||||
-DNOBATT=0
|
-DNOBATT=0
|
||||||
-DMaxErrCount=20
|
-DMaxErrCount=30
|
||||||
|
-DMQTT=0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,20 +35,19 @@ build_flags =
|
||||||
build_flags = ${env.build_flags}
|
build_flags = ${env.build_flags}
|
||||||
-DDEBUG=0
|
-DDEBUG=0
|
||||||
-DNOADS=0
|
-DNOADS=0
|
||||||
-DNAME=\"WETTERSTATION\"
|
-DNAME=\"WETTERSTATIONEPPINGEN\"
|
||||||
-DSTASSID=\"MagentaWLAN-RGDO\"
|
-DSTASSID=\"St.-Peters-Gasse\"
|
||||||
-DSTAPSK=\"93329248424922704583\"
|
-DSTAPSK=\"1952994784599318\"
|
||||||
-DGATEWAY=\"192.168.127.1\"
|
-DGATEWAY=\"192.168.127.1\"
|
||||||
-DDNS=\"192.168.127.1\"
|
-DDNS=\"192.168.127.1\"
|
||||||
-DKMYIP=\"192.168.127.40\"
|
-DKMYIP=\"192.168.127.48\"
|
||||||
-Dmqtt_server=\"hjkmqtt.dedyn.io\"
|
-Dmqtt_server=\"hjkmqtt.dedyn.io\"
|
||||||
-Dmqtt_port=61883
|
-Dmqtt_port=8883
|
||||||
-DTERROR=5
|
-DTERROR=5
|
||||||
-DTLOWBATT=60
|
-DTLOWBATT=60
|
||||||
-DTINTERVAL=1
|
-DTINTERVAL=1
|
||||||
-DKorrekturLuftdruck=0.0
|
|
||||||
|
|
||||||
[env:marcel] ; Produktivsystem:
|
[env:release] ; Produktivsystem:
|
||||||
build_flags = ${env.build_flags}
|
build_flags = ${env.build_flags}
|
||||||
-DDEBUG=0
|
-DDEBUG=0
|
||||||
-DEMAIL=\"koerner.c.m@gmail.com\"
|
-DEMAIL=\"koerner.c.m@gmail.com\"
|
||||||
|
@ -65,56 +62,4 @@ build_flags = ${env.build_flags}
|
||||||
-DTERROR=20
|
-DTERROR=20
|
||||||
-DTLOWBATT=60
|
-DTLOWBATT=60
|
||||||
-DTINTERVAL=10
|
-DTINTERVAL=10
|
||||||
-DKorrekturLuftdruck=0.0
|
|
||||||
|
|
||||||
[env:boris] ; Produktivsystem:
|
|
||||||
build_flags = ${env.build_flags}
|
|
||||||
-DDEBUG=0
|
|
||||||
-DEMAIL=\"koerner.c.m@gmail.com\"
|
|
||||||
-DNAME=\"WETTERSTATIONBORIS\"
|
|
||||||
-DSTASSID=\"FRITZ!Box7362SL\"
|
|
||||||
-DSTAPSK=\"BorisundEva2007\"
|
|
||||||
-DGATEWAY=\"192.168.2.1\"
|
|
||||||
-DDNS=\"192.168.2.1\"
|
|
||||||
-DKMYIP=\"192.168.2.41\"
|
|
||||||
-Dmqtt_server=\"hjkmqtt.dedyn.io\"
|
|
||||||
-Dmqtt_port=8883
|
|
||||||
-DTERROR=20
|
|
||||||
-DTLOWBATT=60
|
|
||||||
-DTINTERVAL=5
|
|
||||||
-DKorrekturLuftdruck=0.0
|
|
||||||
|
|
||||||
[env:hjk]
|
|
||||||
build_flags = ${env.build_flags}
|
|
||||||
-DDEBUG=0
|
|
||||||
-DNOADS=0
|
|
||||||
-DNAME=\"WETTERSTATION\"
|
|
||||||
-DSTASSID=\"MagentaWLAN-RGDO\"
|
|
||||||
-DSTAPSK=\"93329248424922704583\"
|
|
||||||
-DGATEWAY=\"192.168.127.1\"
|
|
||||||
-DDNS=\"192.168.127.1\"
|
|
||||||
-DKMYIP=\"192.168.127.41\"
|
|
||||||
-Dmqtt_server=\"hjkmqtt.dedyn.io\"
|
|
||||||
-Dmqtt_port=61883
|
|
||||||
-DTERROR=5
|
|
||||||
-DTLOWBATT=60
|
|
||||||
-DTINTERVAL=10
|
|
||||||
-DKorrekturLuftdruck=23.6
|
|
||||||
|
|
||||||
[env:filamentbox]
|
|
||||||
build_flags = ${env.build_flags}
|
|
||||||
-DDEBUG=0
|
|
||||||
-DNOADS=0
|
|
||||||
-DNAME=\"filamenbox\"
|
|
||||||
-DSTASSID=\"MagentaWLAN-RGDO\"
|
|
||||||
-DSTAPSK=\"93329248424922704583\"
|
|
||||||
-DGATEWAY=\"192.168.127.1\"
|
|
||||||
-DDNS=\"192.168.127.1\"
|
|
||||||
-DKMYIP=\"192.168.127.42\"
|
|
||||||
-Dmqtt_server=\"hjkmqtt.dedyn.io\"
|
|
||||||
-Dmqtt_port=61883
|
|
||||||
-DTERROR=5
|
|
||||||
-DTLOWBATT=60
|
|
||||||
-DTINTERVAL=15
|
|
||||||
-DKorrekturLuftdruck=0.0
|
|
||||||
|
|
||||||
|
|
195
src/main.cpp
195
src/main.cpp
|
@ -1,11 +1,12 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
#include <FS.h> //this needs to be first, or it all crashes and burns...
|
||||||
|
#include <LittleFS.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
|
|
||||||
// #define BUILTIN_LED D2
|
#define BUILTIN_LED D15
|
||||||
#define TRIGGER_PIN D7
|
#define TRIGGER_PIN D7
|
||||||
#define START_STOP_PIN D6
|
#define START_STOP_PIN D6
|
||||||
|
|
||||||
|
@ -13,20 +14,20 @@
|
||||||
|
|
||||||
void reconnect();
|
void reconnect();
|
||||||
void setup_wifi();
|
void setup_wifi();
|
||||||
|
void datenSave(int wert);
|
||||||
|
int readDaten();
|
||||||
|
int saveKorektur(float wert);
|
||||||
|
float readKorectur();
|
||||||
void verifyFingerprint();
|
void verifyFingerprint();
|
||||||
void callback(char* topic1, byte* payload, unsigned int length);
|
void callback(char* topic1, byte* payload, unsigned int length);
|
||||||
void pulse_pin(uint8_t pin);
|
void pulse_pin(uint8_t pin);
|
||||||
|
|
||||||
WiFiClient espClient;
|
WiFiClientSecure espClient;
|
||||||
PubSubClient client(espClient);
|
PubSubClient client(espClient);
|
||||||
|
|
||||||
#include <error.h>
|
|
||||||
|
|
||||||
#include<mess_htu21.h>
|
#include<mess_htu21.h>
|
||||||
|
|
||||||
//#include <mess_BMP280.h>
|
#include <mess_BMP280.h>
|
||||||
#include <mess_BME280.h>
|
|
||||||
|
|
||||||
#include <mess_Ub.h>
|
#include <mess_Ub.h>
|
||||||
|
|
||||||
|
@ -35,7 +36,6 @@ PubSubClient client(espClient);
|
||||||
#include <mcp9808.h>
|
#include <mcp9808.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char* ssid = STASSID;
|
const char* ssid = STASSID;
|
||||||
const char* password = STAPSK;
|
const char* password = STAPSK;
|
||||||
String hostname = NAME;
|
String hostname = NAME;
|
||||||
|
@ -67,69 +67,79 @@ char topic[100];
|
||||||
char topic_1[50];
|
char topic_1[50];
|
||||||
char topicWert[20];
|
char topicWert[20];
|
||||||
char msg[20];
|
char msg[20];
|
||||||
long int Feldstaerke;
|
int SystemStatus;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
startTime = millis();
|
pinMode(TRIGGER_PIN, OUTPUT);
|
||||||
/* pinMode(BUILTIN_LED, OUTPUT);
|
pinMode(START_STOP_PIN, OUTPUT);
|
||||||
digitalWrite(BUILTIN_LED, LOW);
|
digitalWrite(TRIGGER_PIN, HIGH);
|
||||||
delay(5000);
|
digitalWrite(START_STOP_PIN, LOW);
|
||||||
digitalWrite(BUILTIN_LED, HIGH); */
|
pulse_pin(TRIGGER_PIN); // ==> 1
|
||||||
Serial.begin(74880);
|
Serial.begin(74880);
|
||||||
while ( !Serial ) delay(100); // wait for native usb
|
while ( !Serial ) delay(100); // wait for native usb
|
||||||
|
Serial.println(F("BMP280 Sensor event test"));
|
||||||
|
Serial.println("HTU21D-F test");
|
||||||
|
startTime = millis();
|
||||||
WiFi.mode( WIFI_OFF );
|
WiFi.mode( WIFI_OFF );
|
||||||
WiFi.forceSleepBegin();
|
WiFi.forceSleepBegin();
|
||||||
|
pulse_pin(TRIGGER_PIN); // ==> 1
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
//Serial.println("Testpunkt 1");
|
||||||
|
/* if (!LittleFS.begin()) {
|
||||||
|
Serial.println("LittleFS mount failed");
|
||||||
|
delay(5000);
|
||||||
|
return;
|
||||||
|
} */
|
||||||
|
//Serial.println("Testpunkt 2");
|
||||||
|
/* Dir dir = LittleFS.openDir("/data");
|
||||||
|
while (dir.next()) {
|
||||||
|
Serial.print(dir.fileName());
|
||||||
|
if(dir.fileSize()) {
|
||||||
|
File f = dir.openFile("r");
|
||||||
|
Serial.println(f.size());
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
//Serial.println("Testpunkt 3");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
readSystemStatus();
|
//SystemStatus = readDaten();
|
||||||
Serial.printf("Systemstatus : 0x%02x \n", SystemStatus);
|
//korectur = readKorectur();
|
||||||
SystemStatus = 0x00;
|
//Serial.print("Korektur: "); Serial.println(korectur,6);
|
||||||
writeSystemStatus();
|
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
|
||||||
delay(500);
|
//digitalWrite(BUILTIN_LED, LOW);
|
||||||
|
//digitalWrite(BUILTIN_LED, HIGH);
|
||||||
|
//Serial.print("STATUS (Systemmeldung): "); Serial.println(SystemStatus);
|
||||||
#if (MQTT == 0)
|
#if (MQTT == 0)
|
||||||
init_HTU21();
|
init_HTU21();
|
||||||
//Init_BMP280();
|
Init_BMP280();
|
||||||
Sensor_BME280();
|
//initADS();
|
||||||
|
//init_MCP9808();
|
||||||
init_MCP9808();
|
|
||||||
initADS();
|
|
||||||
#endif
|
#endif
|
||||||
if (!F_ADS1115 == true){
|
|
||||||
AKKU = getBattery(); // ca. 170 ms
|
AKKU = getBattery(); // ca. 170 ms
|
||||||
Serial.println("ALTE UB MESSUNG:");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
MessungADS();
|
|
||||||
AKKU = readChannel(ADS1115_COMP_0_GND);
|
|
||||||
}
|
|
||||||
// ca. 280 ms
|
// ca. 280 ms
|
||||||
if (F_HTU_21D == true){
|
if (F_HTU_21D == true){
|
||||||
read_HTU21D();
|
read_HTU21D();
|
||||||
}
|
}
|
||||||
if (F_ADS1115 == true){
|
|
||||||
MessungADS();
|
|
||||||
}
|
|
||||||
/* if (F_BMP280 == true){
|
|
||||||
read_BMP_280();
|
read_BMP_280();
|
||||||
}*/
|
//MessungADS();
|
||||||
if (F_MCP9808 == true){
|
|
||||||
valTemp = getTemperature_MCP9808();
|
|
||||||
}
|
|
||||||
setup_wifi(); // ca. 4,5 s
|
setup_wifi(); // ca. 4,5 s
|
||||||
|
// ca. 12ms
|
||||||
|
// ---------------------------------
|
||||||
|
// Status ändern !!! 0
|
||||||
|
//datenSave(0);
|
||||||
|
// ---------------------------------
|
||||||
|
//digitalWrite(BUILTIN_LED, HIGH);
|
||||||
deviceId = ESP.getChipId();
|
deviceId = ESP.getChipId();
|
||||||
sprintf(sID, "%010ld", deviceId);
|
sprintf(sID, "%010ld", deviceId);
|
||||||
Serial.print("ID: \t\t"); Serial.println(deviceId);
|
Serial.print("ID: \t\t"); Serial.println(deviceId);
|
||||||
|
|
||||||
// ca. 5 s
|
// ca. 5 s
|
||||||
//espClient.setFingerprint(mqtt_fprint);
|
espClient.setFingerprint(mqtt_fprint);
|
||||||
client.setServer(mqtt_server, mqtt_port);
|
client.setServer(mqtt_server, mqtt_port);
|
||||||
client.setCallback(callback);
|
client.setCallback(callback);
|
||||||
Serial.printf("Systemstatus : 0x%02x \n", SystemStatus);
|
|
||||||
//----------
|
//----------
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -139,40 +149,38 @@ void loop() {
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
reconnect();
|
reconnect();
|
||||||
}
|
}
|
||||||
|
//client.loop();
|
||||||
int currentMillis = millis();
|
int currentMillis = millis();
|
||||||
if (currentMillis - previousMillis >= 10000) {
|
if (currentMillis - previousMillis >= 10000) {
|
||||||
previousMillis = currentMillis;
|
previousMillis = currentMillis;
|
||||||
|
read_HTU21D();
|
||||||
|
read_BMP_280();
|
||||||
|
//valTemp = getTemperature_MCP9808();
|
||||||
dtostrf(AKKU,8,2,ADSData.Akku);
|
dtostrf(AKKU,8,2,ADSData.Akku);
|
||||||
sprintf(topic, "%s%s%s", "hjk/devices/", hostname.c_str(), "/telemetry/battery" );
|
sprintf(topic, "%s%s%s", "hjk/devices/", hostname.c_str(), "/telemetry/battery" );
|
||||||
client.publish(topic, ADSData.Akku, true);
|
client.publish(topic, ADSData.Akku, true);
|
||||||
if (F_ADS1115 == true){
|
#if(MQTT == 0)
|
||||||
sprintf(topic, "%s%s%s", "hjk/devices/", hostname.c_str(), "/telemetry/Solar" );
|
M2M_HTU21D(hostname.c_str());
|
||||||
client.publish(topic, ADSData.Solar, true);
|
M2M_BMP280(hostname.c_str());
|
||||||
}
|
M2M_Temperatur_MCP9808(hostname.c_str());
|
||||||
|
#endif
|
||||||
if (F_HTU_21D) M2M_HTU21D(hostname.c_str());
|
long int Feldstaerke = WiFi.RSSI();
|
||||||
M2M_BME280(hostname.c_str());
|
|
||||||
if (F_MCP9808) M2M_Temperatur_MCP9808(hostname.c_str());
|
|
||||||
sprintf(msg,"%ld", Feldstaerke);
|
sprintf(msg,"%ld", Feldstaerke);
|
||||||
sprintf(topic, "%s%s%s", "hjk/devices/", hostname.c_str(), "/telemetry/RSSI" );
|
sprintf(topic, "%s%s%s", "hjk/devices/", hostname.c_str(), "/telemetry/RSSI" );
|
||||||
client.publish(topic, msg, true);
|
client.publish(topic, msg, true);
|
||||||
sprintf(msg,"0x%02x", SystemStatus);
|
|
||||||
sprintf(topic, "%s%s%s", "hjk/devices/", hostname.c_str(), "/telemetry/SystemStatus" );
|
|
||||||
client.publish(topic, msg, true);
|
|
||||||
client.loop();
|
client.loop();
|
||||||
delay(500);
|
delay(500);
|
||||||
//digitalWrite(BUILTIN_LED, HIGH);
|
digitalWrite(BUILTIN_LED, HIGH);
|
||||||
/* ESP.deepSleep(5e6);
|
/* ESP.deepSleep(5e6);
|
||||||
delay(100); */
|
delay(100); */
|
||||||
endTime = millis();
|
endTime = millis();
|
||||||
if (AKKU < MinimalSpannung){
|
if (AKKU < MinimalSpannung){
|
||||||
|
// ---------------------------------
|
||||||
|
// Status ändern !!! -5
|
||||||
|
datenSave(-5);
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
Pause = intervalLowBatt -((endTime - startTime) * 1000); // Pause ca. 60 Minuten
|
Pause = intervalLowBatt -((endTime - startTime) * 1000); // Pause ca. 60 Minuten
|
||||||
Serial.println("AKKU entladen!");
|
Serial.println("AKKU entladen!");
|
||||||
SystemStatus = (SystemStatus | AkkuLeer);
|
|
||||||
Serial.printf("Systemstatus : 0x%04x \n", SystemStatus);
|
|
||||||
writeSystemStatus();
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Pause = interval -((endTime - startTime) * 1000); // Pause ca. 15 Minuten
|
Pause = interval -((endTime - startTime) * 1000); // Pause ca. 15 Minuten
|
||||||
|
@ -187,7 +195,6 @@ void loop() {
|
||||||
#if (DEBUG == 1)
|
#if (DEBUG == 1)
|
||||||
ESP.deepSleep(10e6);
|
ESP.deepSleep(10e6);
|
||||||
#else
|
#else
|
||||||
writeSystemStatus();
|
|
||||||
ESP.deepSleep(Pause);
|
ESP.deepSleep(Pause);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -210,7 +217,7 @@ void setup_wifi() {
|
||||||
delay( 1 );
|
delay( 1 );
|
||||||
WiFi.persistent( false );
|
WiFi.persistent( false );
|
||||||
WiFi.mode( WIFI_STA );
|
WiFi.mode( WIFI_STA );
|
||||||
WiFi.setHostname(hostname.c_str()); //define hostname
|
//WiFi.setHostname(hostname.c_str()); //define hostname
|
||||||
WiFi.hostname(hostname.c_str());
|
WiFi.hostname(hostname.c_str());
|
||||||
WiFi.mode( WIFI_STA );
|
WiFi.mode( WIFI_STA );
|
||||||
if (!ip.fromString(MyIP)) { // try to parse into the IPAddress
|
if (!ip.fromString(MyIP)) { // try to parse into the IPAddress
|
||||||
|
@ -235,6 +242,10 @@ void setup_wifi() {
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
ErrCount ++;
|
ErrCount ++;
|
||||||
if (ErrCount >= MaxErrCount){
|
if (ErrCount >= MaxErrCount){
|
||||||
|
// ---------------------------------
|
||||||
|
// Status ändern !!! -1
|
||||||
|
datenSave(-1);
|
||||||
|
// ---------------------------------
|
||||||
endTime = millis();
|
endTime = millis();
|
||||||
unsigned long Pause = stoerung -((endTime - startTime) * 1000); // Pause
|
unsigned long Pause = stoerung -((endTime - startTime) * 1000); // Pause
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
@ -246,8 +257,7 @@ void setup_wifi() {
|
||||||
}
|
}
|
||||||
Serial.println(" WiFi connected");
|
Serial.println(" WiFi connected");
|
||||||
Serial.print("IP address: \t");
|
Serial.print("IP address: \t");
|
||||||
Feldstaerke = WiFi.RSSI();
|
Serial.print(WiFi.localIP()); Serial.print("\tRESSI: "); Serial.println(WiFi.RSSI());
|
||||||
Serial.print(WiFi.localIP()); Serial.print("\tRESSI: "); Serial.println(Feldstaerke);
|
|
||||||
/* delay(2000);
|
/* delay(2000);
|
||||||
ESP.deepSleep(2e6, WAKE_RF_DEFAULT);
|
ESP.deepSleep(2e6, WAKE_RF_DEFAULT);
|
||||||
delay(100); */
|
delay(100); */
|
||||||
|
@ -268,22 +278,28 @@ void callback(char* topic1, byte* payload, unsigned int length)
|
||||||
Serial.println();
|
Serial.println();
|
||||||
korectur = atof(msg);
|
korectur = atof(msg);
|
||||||
Serial.print("Korektur:\t");Serial.println(korectur, 8);
|
Serial.print("Korektur:\t");Serial.println(korectur, 8);
|
||||||
|
int er = saveKorektur(korectur);
|
||||||
|
if (er != 0){
|
||||||
|
Serial.println("Daten konnten nicht gespeichert werden.");
|
||||||
|
}
|
||||||
|
float test = readKorectur();
|
||||||
|
Serial.print("Korektur:\t");Serial.println(test, 8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reconnect() {
|
void reconnect() {
|
||||||
// Loop until we're reconnected
|
// Loop until we're reconnected
|
||||||
sprintf(clientName, "%s%s", "ESP8266Wetter", sID);
|
sprintf(clientName, "%s%s", "ESP8266Client", sID);
|
||||||
while (!client.connected()) {
|
while (!client.connected()) {
|
||||||
Serial.print("Attempting MQTT connection...");
|
Serial.print("Attempting MQTT connection...");
|
||||||
//verifyFingerprint();
|
verifyFingerprint();
|
||||||
// Attempt to connect
|
// Attempt to connect
|
||||||
if (client.connect(clientName)) {
|
if (client.connect(clientName)) {
|
||||||
Serial.println("connected");
|
Serial.println("connected");
|
||||||
// Once connected, publish an announcement...
|
// Once connected, publish an announcement...
|
||||||
// client.publish("outTopic", "hello world");
|
client.publish("outTopic", "hello world");
|
||||||
// ... and resubscribe
|
// ... and resubscribe
|
||||||
// client.subscribe("inTopic");
|
client.subscribe("inTopic");
|
||||||
} else {
|
} else {
|
||||||
Serial.print("failed, rc=");
|
Serial.print("failed, rc=");
|
||||||
Serial.print(client.state());
|
Serial.print(client.state());
|
||||||
|
@ -295,9 +311,56 @@ void reconnect() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void datenSave(int wert){
|
||||||
|
File k = LittleFS.open("/status.txt", "w");
|
||||||
|
if(!k){
|
||||||
|
Serial.println("file open failed");
|
||||||
|
}
|
||||||
|
k.println(wert);
|
||||||
|
k.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
int readDaten()
|
||||||
|
{
|
||||||
|
int Error;
|
||||||
|
File k = LittleFS.open("/status.txt", "r");
|
||||||
|
if(!k){
|
||||||
|
Serial.println("file open failed");
|
||||||
|
Error = -10;
|
||||||
|
}else{
|
||||||
|
String data = k.readString();
|
||||||
|
Error = data.toInt();
|
||||||
|
k.close();
|
||||||
|
}
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int saveKorektur(float wert){
|
||||||
|
int Error = 0;
|
||||||
|
File k = LittleFS.open("/Korektur.txt", "w");
|
||||||
|
if(!k){
|
||||||
|
Serial.println("file open failed");
|
||||||
|
Error = -1;
|
||||||
|
}else{
|
||||||
|
k.println(String(wert,8));
|
||||||
|
k.close();
|
||||||
|
}
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
float readKorectur(){
|
||||||
|
float Korektur;
|
||||||
|
File k = LittleFS.open("/Korektur.txt", "r");
|
||||||
|
if(!k){
|
||||||
|
Serial.println("file open failed");
|
||||||
|
Korektur = 1.00;
|
||||||
|
}else{
|
||||||
|
String data = k.readString();
|
||||||
|
Korektur = data.toFloat();
|
||||||
|
k.close();
|
||||||
|
}
|
||||||
|
return Korektur;
|
||||||
|
}
|
||||||
|
|
||||||
void verifyFingerprint() {
|
void verifyFingerprint() {
|
||||||
unsigned long Pause = 0;
|
unsigned long Pause = 0;
|
||||||
|
|
4
workspace.code-workspace
Normal file
4
workspace.code-workspace
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"folders": [],
|
||||||
|
"settings": {}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user