2023-05-18
Einiges geändert in main
This commit is contained in:
parent
00b1afa8ac
commit
fea3fe2e3d
37
include/error.h
Normal file
37
include/error.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
#define AkkuLeer 0x80
|
||||||
|
|
||||||
|
void ErrorBegin(){
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
int Error;
|
||||||
|
File k = LittleFS.open("/error.dat", "r");
|
||||||
|
if(!k){
|
||||||
|
Serial.println("file open failed");
|
||||||
|
Error = 255;
|
||||||
|
}else{
|
||||||
|
Error = k.read();
|
||||||
|
k.close();
|
||||||
|
}
|
||||||
|
return Error;
|
||||||
|
}
|
|
@ -29,7 +29,6 @@ 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.");
|
||||||
datenSave(-20);
|
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
Serial.println("Found MCP9808!");
|
Serial.println("Found MCP9808!");
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <Adafruit_BMP280.h>
|
#include <Adafruit_BMP280.h>
|
||||||
|
|
||||||
|
|
||||||
#define SEALEVELPRESSURE_HPA (1002.7) // 1013.25
|
#define SEALEVELPRESSURE_HPA (1013.25) // 1013.25
|
||||||
// Richen 219 m über NN
|
// Richen 219 m über NN
|
||||||
// Eppingem 195 m über NN
|
// Eppingem 195 m über NN
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ build_flags = ${env.build_flags}
|
||||||
-DNOADS=0
|
-DNOADS=0
|
||||||
-DNAME=\"WETTERSTATIONBORIS\"
|
-DNAME=\"WETTERSTATIONBORIS\"
|
||||||
-DSTASSID=\"St.-Peters-Gasse\"
|
-DSTASSID=\"St.-Peters-Gasse\"
|
||||||
-DSTAPSK=\"1952994784599319\"
|
-DSTAPSK=\"1952994784599317\"
|
||||||
-DGATEWAY=\"192.168.127.1\"
|
-DGATEWAY=\"192.168.127.1\"
|
||||||
-DDNS=\"192.168.127.1\"
|
-DDNS=\"192.168.127.1\"
|
||||||
-DKMYIP=\"192.168.127.49\"
|
-DKMYIP=\"192.168.127.49\"
|
||||||
|
|
99
src/main.cpp
99
src/main.cpp
|
@ -1,6 +1,5 @@
|
||||||
#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>
|
||||||
|
@ -14,10 +13,7 @@
|
||||||
|
|
||||||
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);
|
||||||
|
@ -35,6 +31,8 @@ PubSubClient client(espClient);
|
||||||
|
|
||||||
#include <mcp9808.h>
|
#include <mcp9808.h>
|
||||||
|
|
||||||
|
#include <error.h>
|
||||||
|
|
||||||
|
|
||||||
const char* ssid = STASSID;
|
const char* ssid = STASSID;
|
||||||
const char* password = STAPSK;
|
const char* password = STAPSK;
|
||||||
|
@ -72,39 +70,17 @@ int SystemStatus;
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(TRIGGER_PIN, OUTPUT);
|
startTime = millis();
|
||||||
pinMode(START_STOP_PIN, OUTPUT);
|
|
||||||
digitalWrite(TRIGGER_PIN, HIGH);
|
|
||||||
digitalWrite(START_STOP_PIN, LOW);
|
|
||||||
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();
|
||||||
|
delay(5000);
|
||||||
//SystemStatus = readDaten();
|
//SystemStatus = readDaten();
|
||||||
//korectur = readKorectur();
|
//korectur = readKorectur();
|
||||||
//Serial.print("Korektur: "); Serial.println(korectur,6);
|
//Serial.print("Korektur: "); Serial.println(korectur,6);
|
||||||
|
@ -116,7 +92,7 @@ void setup() {
|
||||||
init_HTU21();
|
init_HTU21();
|
||||||
Init_BMP280();
|
Init_BMP280();
|
||||||
//initADS();
|
//initADS();
|
||||||
//init_MCP9808();
|
init_MCP9808();
|
||||||
#endif
|
#endif
|
||||||
AKKU = getBattery(); // ca. 170 ms
|
AKKU = getBattery(); // ca. 170 ms
|
||||||
// ca. 280 ms
|
// ca. 280 ms
|
||||||
|
@ -125,6 +101,7 @@ void setup() {
|
||||||
}
|
}
|
||||||
read_BMP_280();
|
read_BMP_280();
|
||||||
//MessungADS();
|
//MessungADS();
|
||||||
|
Serial.println("Testpunkt 4");
|
||||||
setup_wifi(); // ca. 4,5 s
|
setup_wifi(); // ca. 4,5 s
|
||||||
// ca. 12ms
|
// ca. 12ms
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
|
@ -132,6 +109,7 @@ void setup() {
|
||||||
//datenSave(0);
|
//datenSave(0);
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
//digitalWrite(BUILTIN_LED, HIGH);
|
//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);
|
||||||
|
@ -175,9 +153,7 @@ void loop() {
|
||||||
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!");
|
||||||
|
@ -217,7 +193,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
|
||||||
|
@ -278,12 +254,6 @@ 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,56 +281,9 @@ 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;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user