#include <WiFi.h>
#include "time.h"
const char* ssid = "Wokwi-GUEST";
const char* password = "";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 3600;
const int daylightOffset_sec = 3600;
String serialoutput = "";
int lastStartAuto = 0;
int counter = 0;
String printDigits(int digits) {
if (digits < 10) {
return '0' + String(digits);
} else {
return String(digits);
}
}
void printLocalTime()
{
struct tm timeinfo;
if(getLocalTime(&timeinfo)){
Serial.println(&timeinfo, " %H:%M:%S");
}
}
String getOutput(String channel) {
struct tm timeinfo;
if(getLocalTime(&timeinfo)){
String time = String(millis());
time = time.substring(time.length() - 3, time.length());
String serial = "";
serial += "*0000 ";
serial += channel;
serial += " ";
serial += printDigits(timeinfo.tm_hour);
serial += ":";
serial += printDigits(timeinfo.tm_min);
serial += ":";
serial += printDigits(timeinfo.tm_sec);
serial += ".";
serial += time;
serial += " 00\r";
//Serial.println(timeinfo.tm_sec);
return serial;
}
}
void IRAM_ATTR start_auto()
{
if ((millis() - lastStartAuto) > 1000) {
serialoutput += getOutput("C2 ");
//counter++;
lastStartAuto = millis();
}
}
void setup()
{
//Pins definieren
pinMode(15, INPUT_PULLUP);
pinMode(32, OUTPUT);
//Serielle Konsole oeffnen
Serial.begin(115200);
//Verbindung zum Wlan
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
//Mit dem Wlan verbunden, aktuelle Zeit holen
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
//test if time is working
struct tm timeinfo;
if(getLocalTime(&timeinfo)){
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
digitalWrite(32, HIGH);
Serial.println(getOutput("C9 "));
}
//Interrupts für die Lichtschranke und Handtaster setzen
attachInterrupt(15, start_auto, RISING);
}
void loop()
{
/*if (serialoutput.length()) {
Serial.print(serialoutput);
serialoutput = "";
}*/
Serial.println(counter);
delay(1000);
}
Fehlermeldung ist:
abort() was called at PC 0x40084e5b on core 1 Backtrace: 0x400837da:0x3ffbf13c |<-CORRUPTED
Nach etwas Testen weiß ich, dass das Problem auftritt, beim Aufrufen von getOutput im Interupt.
Ich hoffe ihr könnt mir helfen.
Danke schonmal