2023-05-19
SystemStatus geändert.
This commit is contained in:
parent
fea3fe2e3d
commit
62ec975329
|
@ -1,37 +1,31 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <LittleFS.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
#define AkkuLeer 0x80
|
#define AkkuLeer 0x80
|
||||||
|
#define ADS1115noReady 0x01
|
||||||
|
#define HTU21noReady 0x02
|
||||||
|
#define BMP280noReady 0x04
|
||||||
|
#define MCP9808noReady 0x08
|
||||||
|
|
||||||
void ErrorBegin(){
|
byte SystemStatus;
|
||||||
if (!LittleFS.begin()) {
|
|
||||||
Serial.println("LittleFS mount failed");
|
|
||||||
delay(5000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void datenSave(int wert){
|
|
||||||
File k = LittleFS.open("/error.dat", "w");
|
|
||||||
if(!k){
|
|
||||||
Serial.println("file open failed");
|
|
||||||
}
|
|
||||||
k.write(wert);
|
|
||||||
k.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
int readDaten()
|
|
||||||
|
void writeSystemStatus()
|
||||||
{
|
{
|
||||||
int Error;
|
EEPROM.begin(512);
|
||||||
File k = LittleFS.open("/error.dat", "r");
|
EEPROM.put(0,SystemStatus);
|
||||||
if(!k){
|
EEPROM.commit();
|
||||||
Serial.println("file open failed");
|
EEPROM.end();
|
||||||
Error = 255;
|
}
|
||||||
}else{
|
|
||||||
Error = k.read();
|
void readSystemStatus()
|
||||||
k.close();
|
{
|
||||||
}
|
EEPROM.begin(512);
|
||||||
return Error;
|
EEPROM.get(0,SystemStatus);
|
||||||
|
EEPROM.commit();
|
||||||
|
EEPROM.end();
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,9 +11,12 @@ 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
|
||||||
|
@ -29,7 +32,9 @@ 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.");
|
||||||
while (1);
|
SystemStatus = SystemStatus | MCP9808noReady;
|
||||||
|
F_MCP9808 = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
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:
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
* 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};
|
||||||
|
@ -28,8 +29,11 @@ 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
|
||||||
|
|
|
@ -28,6 +28,7 @@ void Init_BMP280(){
|
||||||
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); */
|
||||||
|
@ -56,7 +57,7 @@ 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 + 22;
|
//p = p + 22;
|
||||||
dtostrf(p,5,0,BMP280Data.pressure);
|
dtostrf(p,7,1,BMP280Data.pressure);
|
||||||
Serial.print(BMP280Data.pressure);
|
Serial.print(BMP280Data.pressure);
|
||||||
Serial.println(" hPa");
|
Serial.println(" hPa");
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
ADC_MODE(ADC_VCC);
|
ADC_MODE(ADC_);
|
||||||
|
|
||||||
const float MinimalSpannung = 2.85;
|
const float MinimalSpannung = 2.85;
|
||||||
float korectur = 9.2800899887514060742407199100112e-4;
|
float korectur = 9.2800899887514060742407199100112e-4;
|
||||||
|
@ -16,7 +16,7 @@ float getBattery()
|
||||||
int Vcc = ESP.getVcc();
|
int Vcc = ESP.getVcc();
|
||||||
float VCC = Vcc * korectur ;
|
float VCC = Vcc * korectur ;
|
||||||
Serial.printf("Rohdaten: %d, ", Vcc);
|
Serial.printf("Rohdaten: %d, ", Vcc);
|
||||||
dtostrf(VCC,7,2,floatString);
|
dtostrf(VCC,8,2,floatString);
|
||||||
Serial.printf("Vcc: %s V\n", floatString);
|
Serial.printf("Vcc: \t%s V\n", floatString);
|
||||||
return VCC;
|
return VCC;
|
||||||
}
|
}
|
|
@ -17,6 +17,7 @@ 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
F_HTU_21D = true;
|
F_HTU_21D = true;
|
||||||
|
|
52
src/main.cpp
52
src/main.cpp
|
@ -21,6 +21,8 @@ void pulse_pin(uint8_t pin);
|
||||||
WiFiClientSecure 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>
|
||||||
|
@ -31,7 +33,6 @@ PubSubClient client(espClient);
|
||||||
|
|
||||||
#include <mcp9808.h>
|
#include <mcp9808.h>
|
||||||
|
|
||||||
#include <error.h>
|
|
||||||
|
|
||||||
|
|
||||||
const char* ssid = STASSID;
|
const char* ssid = STASSID;
|
||||||
|
@ -65,7 +66,6 @@ char topic[100];
|
||||||
char topic_1[50];
|
char topic_1[50];
|
||||||
char topicWert[20];
|
char topicWert[20];
|
||||||
char msg[20];
|
char msg[20];
|
||||||
int SystemStatus;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,36 +80,32 @@ void setup() {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
delay(5000);
|
readSystemStatus();
|
||||||
//SystemStatus = readDaten();
|
Serial.printf("Systemstatus : 0x%02x \n", SystemStatus);
|
||||||
//korectur = readKorectur();
|
SystemStatus = 0x00;
|
||||||
//Serial.print("Korektur: "); Serial.println(korectur,6);
|
delay(500);
|
||||||
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
|
|
||||||
//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();
|
||||||
//initADS();
|
|
||||||
init_MCP9808();
|
init_MCP9808();
|
||||||
|
initADS();
|
||||||
#endif
|
#endif
|
||||||
AKKU = getBattery(); // ca. 170 ms
|
valTemp = getTemperature_MCP9808();
|
||||||
|
AKKU = getBattery(korectur); // ca. 170 ms
|
||||||
// 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();
|
}
|
||||||
Serial.println("Testpunkt 4");
|
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);
|
|
||||||
datenSave(0x00);
|
|
||||||
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);
|
||||||
|
@ -118,6 +114,7 @@ void setup() {
|
||||||
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);
|
||||||
//----------
|
//----------
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -127,13 +124,12 @@ 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_HTU21D();
|
||||||
read_BMP_280();
|
read_BMP_280();
|
||||||
//valTemp = getTemperature_MCP9808();
|
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);
|
||||||
|
@ -157,6 +153,9 @@ void loop() {
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
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%02x \n", SystemStatus);
|
||||||
|
writeSystemStatus();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Pause = interval -((endTime - startTime) * 1000); // Pause ca. 15 Minuten
|
Pause = interval -((endTime - startTime) * 1000); // Pause ca. 15 Minuten
|
||||||
|
@ -171,6 +170,7 @@ 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
|
||||||
|
|
||||||
|
@ -218,10 +218,6 @@ 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();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user