2023-05-19
SystemStatus geändert.
This commit is contained in:
parent
fea3fe2e3d
commit
62ec975329
|
@ -1,37 +1,31 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
#include <LittleFS.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
#define AkkuLeer 0x80
|
||||
#define ADS1115noReady 0x01
|
||||
#define HTU21noReady 0x02
|
||||
#define BMP280noReady 0x04
|
||||
#define MCP9808noReady 0x08
|
||||
|
||||
void ErrorBegin(){
|
||||
if (!LittleFS.begin()) {
|
||||
Serial.println("LittleFS mount failed");
|
||||
delay(5000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
byte SystemStatus;
|
||||
|
||||
|
||||
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;
|
||||
File k = LittleFS.open("/error.dat", "r");
|
||||
if(!k){
|
||||
Serial.println("file open failed");
|
||||
Error = 255;
|
||||
}else{
|
||||
Error = k.read();
|
||||
k.close();
|
||||
EEPROM.begin(512);
|
||||
EEPROM.put(0,SystemStatus);
|
||||
EEPROM.commit();
|
||||
EEPROM.end();
|
||||
}
|
||||
return Error;
|
||||
|
||||
void readSystemStatus()
|
||||
{
|
||||
EEPROM.begin(512);
|
||||
EEPROM.get(0,SystemStatus);
|
||||
EEPROM.commit();
|
||||
EEPROM.end();
|
||||
|
||||
}
|
|
@ -11,9 +11,12 @@ float valTemp;
|
|||
// Create MCP9808 temperature sensor object
|
||||
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
|
||||
|
||||
bool F_MCP9808;
|
||||
|
||||
char Temperature[15] = {0};
|
||||
|
||||
void init_MCP9808(){
|
||||
F_MCP9808 = true;
|
||||
// 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
|
||||
// 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
|
||||
if (!tempsensor.begin(0x18)) {
|
||||
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!");
|
||||
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(I2C_ADDRESS);
|
||||
bool F_ADS1115;
|
||||
|
||||
struct {
|
||||
char Akku[15] = {0};
|
||||
|
@ -28,8 +29,11 @@ struct {
|
|||
|
||||
void initADS() {
|
||||
Wire.begin();
|
||||
F_ADS1115 = true;
|
||||
if(!adc.init()){
|
||||
Serial.println("ADS1115 not connected!");
|
||||
SystemStatus = (SystemStatus | ADS1115noReady);
|
||||
F_ADS1115 = false;
|
||||
}
|
||||
|
||||
/* Set the voltage range of the ADC to adjust the gain
|
||||
|
|
|
@ -28,6 +28,7 @@ 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); */
|
||||
|
@ -56,7 +57,7 @@ void read_BMP_280() {
|
|||
Serial.print("Pressure:\t\t");
|
||||
float p = bmp.readPressure() / 100.0F;
|
||||
//p = p + 22;
|
||||
dtostrf(p,5,0,BMP280Data.pressure);
|
||||
dtostrf(p,7,1,BMP280Data.pressure);
|
||||
Serial.print(BMP280Data.pressure);
|
||||
Serial.println(" hPa");
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
ADC_MODE(ADC_VCC);
|
||||
ADC_MODE(ADC_);
|
||||
|
||||
const float MinimalSpannung = 2.85;
|
||||
float korectur = 9.2800899887514060742407199100112e-4;
|
||||
|
@ -16,7 +16,7 @@ float getBattery()
|
|||
int Vcc = ESP.getVcc();
|
||||
float VCC = Vcc * korectur ;
|
||||
Serial.printf("Rohdaten: %d, ", Vcc);
|
||||
dtostrf(VCC,7,2,floatString);
|
||||
Serial.printf("Vcc: %s V\n", floatString);
|
||||
dtostrf(VCC,8,2,floatString);
|
||||
Serial.printf("Vcc: \t%s V\n", floatString);
|
||||
return VCC;
|
||||
}
|
|
@ -17,6 +17,7 @@ void init_HTU21(){
|
|||
F_HTU_21D = false;
|
||||
if (!htu.begin()) {
|
||||
Serial.println("Couldn't find sensor HUT21D!");
|
||||
SystemStatus = SystemStatus | HTU21noReady;
|
||||
|
||||
}
|
||||
F_HTU_21D = true;
|
||||
|
|
52
src/main.cpp
52
src/main.cpp
|
@ -21,6 +21,8 @@ void pulse_pin(uint8_t pin);
|
|||
WiFiClientSecure espClient;
|
||||
PubSubClient client(espClient);
|
||||
|
||||
#include <error.h>
|
||||
|
||||
#include<mess_htu21.h>
|
||||
|
||||
#include <mess_BMP280.h>
|
||||
|
@ -31,7 +33,6 @@ PubSubClient client(espClient);
|
|||
|
||||
#include <mcp9808.h>
|
||||
|
||||
#include <error.h>
|
||||
|
||||
|
||||
const char* ssid = STASSID;
|
||||
|
@ -65,7 +66,6 @@ char topic[100];
|
|||
char topic_1[50];
|
||||
char topicWert[20];
|
||||
char msg[20];
|
||||
int SystemStatus;
|
||||
|
||||
|
||||
|
||||
|
@ -80,36 +80,32 @@ void setup() {
|
|||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
delay(5000);
|
||||
//SystemStatus = readDaten();
|
||||
//korectur = readKorectur();
|
||||
//Serial.print("Korektur: "); Serial.println(korectur,6);
|
||||
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);
|
||||
readSystemStatus();
|
||||
Serial.printf("Systemstatus : 0x%02x \n", SystemStatus);
|
||||
SystemStatus = 0x00;
|
||||
delay(500);
|
||||
#if (MQTT == 0)
|
||||
init_HTU21();
|
||||
Init_BMP280();
|
||||
//initADS();
|
||||
init_MCP9808();
|
||||
initADS();
|
||||
#endif
|
||||
AKKU = getBattery(); // ca. 170 ms
|
||||
valTemp = getTemperature_MCP9808();
|
||||
AKKU = getBattery(korectur); // ca. 170 ms
|
||||
// ca. 280 ms
|
||||
if (F_HTU_21D == true){
|
||||
read_HTU21D();
|
||||
}
|
||||
if (F_ADS1115 == true){
|
||||
MessungADS();
|
||||
}
|
||||
if (F_BMP280 == true){
|
||||
read_BMP_280();
|
||||
//MessungADS();
|
||||
Serial.println("Testpunkt 4");
|
||||
}
|
||||
if (F_MCP9808 == true){
|
||||
valTemp = getTemperature_MCP9808();
|
||||
}
|
||||
setup_wifi(); // ca. 4,5 s
|
||||
// ca. 12ms
|
||||
// ---------------------------------
|
||||
// Status ändern !!! 0
|
||||
//datenSave(0);
|
||||
// ---------------------------------
|
||||
//digitalWrite(BUILTIN_LED, HIGH);
|
||||
datenSave(0x00);
|
||||
deviceId = ESP.getChipId();
|
||||
sprintf(sID, "%010ld", deviceId);
|
||||
Serial.print("ID: \t\t"); Serial.println(deviceId);
|
||||
|
@ -118,6 +114,7 @@ void setup() {
|
|||
espClient.setFingerprint(mqtt_fprint);
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
client.setCallback(callback);
|
||||
Serial.printf("Systemstatus : 0x%02x \n", SystemStatus);
|
||||
//----------
|
||||
|
||||
}
|
||||
|
@ -127,13 +124,12 @@ void loop() {
|
|||
if (!client.connected()) {
|
||||
reconnect();
|
||||
}
|
||||
//client.loop();
|
||||
int currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= 10000) {
|
||||
previousMillis = currentMillis;
|
||||
read_HTU21D();
|
||||
/* read_HTU21D();
|
||||
read_BMP_280();
|
||||
//valTemp = getTemperature_MCP9808();
|
||||
valTemp = getTemperature_MCP9808(); */
|
||||
dtostrf(AKKU,8,2,ADSData.Akku);
|
||||
sprintf(topic, "%s%s%s", "hjk/devices/", hostname.c_str(), "/telemetry/battery" );
|
||||
client.publish(topic, ADSData.Akku, true);
|
||||
|
@ -157,6 +153,9 @@ void loop() {
|
|||
// ---------------------------------
|
||||
Pause = intervalLowBatt -((endTime - startTime) * 1000); // Pause ca. 60 Minuten
|
||||
Serial.println("AKKU entladen!");
|
||||
SystemStatus = (SystemStatus | AkkuLeer);
|
||||
Serial.printf("Systemstatus : 0x%02x \n", SystemStatus);
|
||||
writeSystemStatus();
|
||||
}
|
||||
else{
|
||||
Pause = interval -((endTime - startTime) * 1000); // Pause ca. 15 Minuten
|
||||
|
@ -171,6 +170,7 @@ void loop() {
|
|||
#if (DEBUG == 1)
|
||||
ESP.deepSleep(10e6);
|
||||
#else
|
||||
writeSystemStatus();
|
||||
ESP.deepSleep(Pause);
|
||||
#endif
|
||||
|
||||
|
@ -218,10 +218,6 @@ void setup_wifi() {
|
|||
Serial.print(".");
|
||||
ErrCount ++;
|
||||
if (ErrCount >= MaxErrCount){
|
||||
// ---------------------------------
|
||||
// Status ändern !!! -1
|
||||
datenSave(-1);
|
||||
// ---------------------------------
|
||||
endTime = millis();
|
||||
unsigned long Pause = stoerung -((endTime - startTime) * 1000); // Pause
|
||||
Serial.println();
|
||||
|
|
Loading…
Reference in New Issue
Block a user