esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
16.07k stars 13.33k forks source link

software watchdog timer - some memory problem #9036

Closed seregr closed 11 months ago

seregr commented 11 months ago

Hi lads,

I made a little sprinkler system with esp8266 /Nodemcu 0.9/. It has an I2C 20X4 Lcd, a RTC modul, a Relay, a Button and a Water Flow Sensor, and wifi connection to LAN. I currently use the latest arduino IDE. After inserting the eeprom code it started resetting repeatedly. I tried inserting some delay between the eeprom access commands, and at first glance it seemed to solve the problem. Then I turned it off for a week, and upon restarting the problem started again. Now it seems to originate from the low wifi signal. If I leave the eeprom code out of the program, it works well. Any insight on what the problem could be?

The serial monitor output:

Connecting to Wi-Fi...
SSID: MkT ,PASS: ************
.....Disconnected from Wi-Fi.
....Connecting to Wi-Fi...
SSID: MkT ,PASS: ************

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (9):
epc1=0x40105f90 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000003 depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffed10 end: 3fffffb0 offset: 0150
3fffee60:  401061c1 0024930d 3ffeefd0 00000000  
3fffee70:  3ffee410 3ffeefd0 31343761 ffffff00  
3fffee80:  00000000 002230b3 4020e8b0 000001f4  
3fffee90:  3ffeefd0 00001c20 000001f4 000001f4  
3fffeea0:  00001c20 000001f4 00001c20 4020e932  
3fffeeb0:  00000000 00001c20 1a1cac08 0020851e  
3fffeec0:  40247523 3ffeedd2 00000001 3ffeec8c  
3fffeed0:  3ffeec98 00001c20 000001f4 4020f680  
3fffeee0:  3ffeec98 3ffeedd2 3ffeee2c 402012b9  
3fffeef0:  3fffef10 3ffeea28 e1cac083 60000600  
3fffef00:  3ffeea28 3ffee410 3ffeea1c 40209490  
3fffef10:  4020125c 3ffefa90 402110ec 402110e4  
3fffef20:  00000002 00222ec7 3ffee410 60000600  
3fffef30:  006dd75a 3ffee410 3ffeea3c 40244a8d  
3fffef40:  40244ad2 3fffdab0 00000000 3fffdcb0  
3fffef50:  3ffee420 3fffdab0 00000000 4020e70a  
3fffef60:  40000f49 40000f49 3fffdab0 40000f49  
3fffef70:  40000e19 00053977 bff00000 0000bfff  
3fffef80:  00000005 aa55aa55 000000ed 401058e5  
3fffef90:  401058eb bff00000 0000bfff ff2c8980  
3fffefa0:  4010000d bff00000 00053977 401000ab  
3fffefb0:  40234dd8 3fffef4c 40234d91 3ffffed8  
3fffefc0:  3fffffd0 00000000 00000000 feefeffe  
3fffefd0:  feefeffe feefeffe feefeffe feefeffe  
3fffefe0:  feefeffe feefeffe feefeffe feefeffe  
3fffeff0:  feefeffe feefeffe feefeffe feefeffe  
3ffff000:  feefeffe feefeffe feefeffe feefeffe  
3ffff010:  feefeffe feefeffe feefeffe feefeffe  
3ffff020:  feefeffe feefeffe feefeffe feefeffe 

My code:

#include <Wire.h> // Library for I2C communication
#include <SPI.h>  // not used here, but needed to prevent a RTClib compile error
#include "RTClib.h"
#include <LiquidCrystal_I2C.h> // Library for LCD
#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <AsyncMqtt_Generic.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <EEPROM.h>
#include <ESP8266WiFi.h>            
#include <ESP8266WebServer.h>

#define WIFI_SSID          "MkT"
#define WIFI_PASSWORD      "............"

//GMT Time Zone with sign
#define GMT_TIME_ZONE      +2
#define NTP_SERVER         "0.us.pool.ntp.org"

//#define MQTT_HOST        
#define MQTT_HOST           IPAddress(192, 168, 1, 5)        // Broker address
#define MQTT_PORT           1883

// MQTT Topics
#define MQTT_PUB_SET         "kislocsolo/set"
#define MQTT_PUB_ACTUALSET   "kislocsolo/actual"

String ssid;// = "MkT";
String pass;// = "...............";

bool mqttclient_connection_state;
bool mqttclient_session_present;

int  lcd_light_moment;
bool lcd_light;
int  lcd_light_default_time = 2;  //perc
bool settings_changed;

byte actual_settings[12]; //akuális beállítások 9 byte - start1óra,start1perc,futásidő1,heti1,start2óra,start2perc,futásidő2,heti2,azonnalkibe
                          //10 flow nagy 11 flow kicsi 12 béna appinventor miatt - 10 vagy 11 0 érték esetén 
byte old_settings[12];

int act_flow;

int midnight = 1440;               //percekben
int actual_time;                   //szintén percekben 
int old_time;
int next_switchtime;             //percekben, az éjfél átlépését kezekni kell
int minutes_of_last_switch = 0;
bool sprinkle = 0;

unsigned int count; //átfolyásmérő számláló
unsigned int count0; //vészjelzéshez -- kikapcsolt állapotban is van átfolyás
unsigned int flowLitres;
//int flowLitres0;
unsigned int laekLitres;
bool flowmeter_overload = 0;
bool leakage_overload = 0;

unsigned long laektime;
unsigned long laektime0;

const int buttonPin   = D5;
const int sprinklePin = D6;
const int flowPin     = D7;

/*
                                              0 1         2        3        4 5         6         7            8          9 10
aktuális beállítás (válasz) adatszerkezet: start1(2)_runtime1(1)_week1(1)_start2(2)_runtime2(1)_week2(1)_működésjelző(1)_flow(2) : 11 byte
*/

AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;

WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer; 

LiquidCrystal_I2C lcd(0x27, 20, 4);

DS1307 rtc;     // Setup an instance of DS1307 naming it RTC

char daysOfTheWeek[7][12]={"Su","Mo","Tu","We","Th","Fr","Sa"};

WiFiUDP ntpUDP;

// Define NTP Client to get timeWiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, NTP_SERVER, GMT_TIME_ZONE * 3600 , 60000);

ESP8266WebServer server(80);

volatile bool press = 0;
volatile bool button_pressed = 0;

void setup () {

   Serial.begin(57600); // Set serial port speed

   EEPROM.begin(512);  //Initialize EEPROM

   delay(10);

   int ssid_length = EEPROM.read(10);

    for (int i=0;i<ssid_length;i++){
     ssid += char(EEPROM.read(11+i));
     delay(50);
    }

    int pass_length = EEPROM.read(40);

    for (int i=0;i<pass_length;i++){
     pass += char(EEPROM.read(41+i));
     delay(50);
    }

    Serial.print ("SSID: ");
    Serial.print (ssid);
    Serial.print (" ,PASS: ");
    Serial.println (pass);

   Wire.begin(); // Start the I2C
   rtc.begin();  // Init RTC
   /* rtc.adjust(DateTime(__DATE__, __TIME__));  // Time and date is expanded to date and time on your computer at compiletime
   // Serial.print('Time and date set');*/

   //  lcd_update_time = millis();

   //ESP8266WebServer server(80);
    actual_settings[0]  = EEPROM.read(0); //start1óra
    actual_settings[1]  = EEPROM.read(1); //start1perc
    actual_settings[2]  = EEPROM.read(2); //futásidő1
    actual_settings[3]  = EEPROM.read(3); //heti1
    actual_settings[4]  = EEPROM.read(4); //start2óra
    actual_settings[5]  = EEPROM.read(5); //start2perc
    actual_settings[6]  = EEPROM.read(6); //futásidő2
    actual_settings[7]  = EEPROM.read(7); //heti2
    actual_settings[8]  = 0;              //azonnalkibe / működésjelző - ill. gyors bekapcsolási idő
    actual_settings[9]  = 1;              //flow nagy
    actual_settings[10] = 1;              //flow kicsi
    actual_settings[11] = 7;              //appinventor béna tömbkezelése miatt - ha actual_settings[9]  = 0 akkor 2 actual_settings[9]  = 0 pedig 1. - 00000010
                                          //  - ha actual_settings[10]  = 0 akkor 4 actual_settings[9]  = 0 pedig 1.                                  - 00000100

   lcd.init(); 
   lcd.backlight();

   pinMode(buttonPin, INPUT);
   pinMode(sprinklePin, OUTPUT);
   pinMode(flowPin, INPUT); 

   DateTime now = rtc.now();
   lcd_light_moment =  now.hour()*60+now.minute();
   lcd_light = 1;

   attachInterrupt(digitalPinToInterrupt(buttonPin), gombvaltozas, CHANGE);
   attachInterrupt(flowPin, Flow, RISING); 

   delay(5);

   if (digitalRead(buttonPin)){    // indítás nyomva tartott gombbal

      wifi_initialize();           // wifi hálózat beállítás - ezt követően újra kell indítani    
   }

   wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
   wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);

   mqttClient.onConnect(onMqttConnect); 
   mqttClient.onDisconnect(onMqttDisconnect);
   mqttClient.onSubscribe(onMqttSubscribe);
   mqttClient.onUnsubscribe(onMqttUnsubscribe);
   mqttClient.onMessage(onMqttMessage);
   mqttClient.onPublish(onMqttPublish);
   mqttClient.setServer(MQTT_HOST, MQTT_PORT);
   // If your broker requires authentication (username and password), set them below
   //mqttClient.setCredentials("REPlACE_WITH_YOUR_USER", "REPLACE_WITH_YOUR_PASSWORD");
   connectToWifi();
   syncTime();

   mqttClient.subscribe(MQTT_PUB_SET, 2);

}

void loop() {
  DateTime now = rtc.now();   
  actual_time = now.hour()*60+now.minute();

  if (old_time != actual_time) {                 //ha az idő változott - lcd frissítés
    old_time = actual_time;
    settings_changed = 1;
    if (lcd_light && (lcd_light_moment + lcd_light_default_time) < actual_time){
      lcd.noBacklight();
      lcd_light = 0;
    }
    if (actual_time == midnight) laekLitres = 0; //szivárgásmérő éjfélkor nullázódik
  }

  if (settings_changed){                         //ha actual_settings változott - mqtt üzenet, lcd írás

    byte nulltransfer = 121; 
    char texttosend[13] = {'\0'};

    if (sprinkle){
      if (actual_time < next_switchtime){
         actual_settings[8] = next_switchtime - actual_time; 
      }
      else{
        actual_settings[8] = midnight - actual_time + next_switchtime; //next_switchtime éjfél átlépése után  
      }

    }
    else {
     actual_settings[8] = 0;   
    }

    for (int i = 0; i < 12; i++) {
      if (actual_settings[i] == 0){
         texttosend[i] = nulltransfer;
       }
       else {
         texttosend[i] = actual_settings[i];
       }    
    }

     mqttClient.publish(MQTT_PUB_ACTUALSET, 1, true, texttosend);

    writeToLcd();

    actual_settings[8] = 0;  
    }

  if (actual_time == next_switchtime) switchtime();

  if (press){
    delay(5);                   // prell miatt
     if (press){
       buttonLocal();
     } 
     else{
       button_pressed = 0; 
     }
  } 

  if (count != count0){
    count0 = count;
    if (sprinkle){
     flowSensor();
    }
    else{
     flowLeakage();
    }
  }

  serial_datawriting();  

 //forced_start a next_switchtime-t módosítja, nem szükséges külön ellenőrzés - éjfélkor viszont újra ellenőrzés kell

}

void connectToWifi() {
  Serial.println("Connecting to Wi-Fi...");
 // WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  Serial.print ("SSID: ");
  Serial.print (ssid);
  Serial.print (" ,PASS: ");
  Serial.println (pass);

  WiFi.begin(ssid, pass);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }
}

void onWifiConnect(const WiFiEventStationModeGotIP& event) {
  Serial.println("Connected to Wi-Fi.");
  connectToMqtt();
}

void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
  Serial.println("Disconnected from Wi-Fi.");
  mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
  delay(50);
  wifiReconnectTimer.once(2, connectToWifi);
}

void connectToMqtt() {
  Serial.println("Connecting to MQTT...");
  mqttClient.connect();
}

void onMqttConnect(bool sessionPresent) {
  Serial.println("Connected to MQTT.");
  Serial.print("Session present: ");
  Serial.println(sessionPresent);
  mqttclient_connection_state = 1;
  mqttclient_session_present = sessionPresent;  
}

void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
  Serial.println("Disconnected from MQTT.");
  mqttclient_connection_state = 0;
  mqttclient_session_present  = 0;

  if (WiFi.isConnected()) {
    mqttReconnectTimer.once(2, connectToMqtt);
  }
}

void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
  Serial.println("Subscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
  Serial.print("  qos: ");
  Serial.println(qos);
}

void onMqttUnsubscribe(uint16_t packetId) {
  Serial.println("Unsubscribe acknowledged.");
  Serial.print("  packetId: ");
  Serial.println(packetId);
}

void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) { 
  Serial.println("Publish received.");
  Serial.print("  topic: ");
  Serial.println(topic);
  Serial.print("  qos: ");
  Serial.println(properties.qos);
  Serial.print("  dup: ");
  Serial.println(properties.dup);
  Serial.print("  retain: ");
  Serial.println(properties.retain);
  Serial.print("  len: ");
  Serial.println(len);
  Serial.print("  index: ");
  Serial.println(index);
  Serial.print("  total: ");
  Serial.println(total);

    DateTime now     = rtc.now();
    int forced_start = payload[8];    //0: nincs üzenet, 1-100: azonnal bekapcs.-futásidő percekben, 101: forced_stop, 102: csak lekérdezés
    int actual_time  = now.hour()*60+now.minute();
    int midnight     = 1440;

    lcd_light = 1;
    lcd_light_moment = actual_time;    
    lcd.backlight(); 

  if (forced_start){ 
   if (forced_start ==103){    //reset
      laekLitres = 0;
   }
   else{
   if (forced_start ==102){    //csak lekérdezés

       //   settings_changed = 1;
   }
   else {
    if (forced_start ==101){   //azonnali leallitas - leáll, de a köv. indítás nem változik    
     switch_off();
    }
    else {                           //azonnali inditas - bekapcs, kov. valtas: akt. ido + gyorsindítás ideje  (max. 100 perc)
     forced_start = min(forced_start,100);
     next_switchtime = actual_time + forced_start;
     if (next_switchtime > midnight) next_switchtime = next_switchtime - midnight; // ha holnapra esne

     switch_on();
    }
   }
  }
    /*
                                                 0 1         2        3        4 5         6         7            8          9 10
    aktuális beállítás (válasz) adatszerkezet: start1(2)_runtime1(1)_week1(1)_start2(2)_runtime2(1)_week2(1)_működésjelző(1)_flow(2) : 11 byte
    */

    actual_settings[8] = 0; //beállítást követően lenullázza

  }
  else {  //ha a forced start 0
      for (byte i = 0; i < 9; i++) {
     if ( payload[i]==121){     // appinventor list ill. mqtt nem jól kezeli a 0-t így 121-el megkerüljük
       actual_settings[i] = 0;
     }
     else {
       actual_settings[i] = payload[i];
     }

   }
        actual_settings[8] = 0;
  /*                             0         1          2      3     4              5         6     7        8
   bejövő adatszerkezet:   start1 óra,start1 perc,runtime1,heti1,start2 óra,start2 perc,runtime2,heti2,azonnalkibe : 9 byte
  */
   /* for (int i = 0; i = 7; i++) { - ezzel valami baj van
         EEPROM.write (i, actual_settings[i]);
    } */

         EEPROM.write(0,actual_settings[0]);//start1óra
         EEPROM.write(1,actual_settings[1]);//start1perc
         EEPROM.write(2,actual_settings[2]);//futásidő1
         EEPROM.write(3,actual_settings[3]);//heti1
         EEPROM.write(4,actual_settings[4]); //start2óra
         EEPROM.write(5,actual_settings[5]);//start2perc
         EEPROM.write(6,actual_settings[6]); //futásidő2
         EEPROM.write(7,actual_settings[7]);//heti2

         EEPROM.commit();
  }
  settings_changed = 1; //a beállítás végén a loop ciklus felé
} 

void onMqttPublish(uint16_t packetId) {
  Serial.print("Publish acknowledged.");
  Serial.print("  packetId: ");
  Serial.print(packetId);
  Serial.println((char*)actual_settings);
}

void syncTime(void) { 
  timeClient.begin();
  timeClient.update(); 
  long actualTime = timeClient.getEpochTime();
  Serial.print("Internet Epoch Time: ");
  Serial.println(actualTime);
  rtc.adjust(DateTime(actualTime));
  timeClient.end();
}

void writeToLcd() { 

 /*                                                    01234567890123456789
    lcd 4x20    ido        mqtt csatorna mukodes-ido   np hh:mm     MS KWWW         
                napi 1.                   heti beall   1. hh:mm mm  0000000
                napi 2.                   heti beall   2. hh:mm mm  0000000
                flowmeter,               ip;           1234    xxx.xxx.x.xx
 */

        settings_changed = 0;  
        DateTime now = rtc.now();   
        lcd.clear();  
        lcd.setCursor(0,0);
        lcd.print(daysOfTheWeek[now.dayOfWeek()]);
        lcd.print(" ");
        lcd.print(now.hour());
        lcd.print(':');
        lcd.print(now.minute());   

       if (mqttclient_connection_state){
          lcd.setCursor(13,0);
          lcd.print("M");
       }
       else
       {
          lcd.setCursor(13,0);
          lcd.print(" ");     
       }

        if (mqttclient_session_present){
          lcd.setCursor(14,0);
          lcd.print("S");
        }
       else
       {
          lcd.setCursor(14,0 );
          lcd.print(" ");    
       }

        lcd.setCursor(0,1);
        lcd.print("1.");  
        lcd.print(actual_settings[0]); //start1óra
        lcd.print(":"); 
        lcd.print(actual_settings[1]); //start1perc
        lcd.print(" "); 
        lcd.print(actual_settings[2]); //futásidő1
        lcd.setCursor(13,1);
        for (int i = 0; i < 7; i++) {
          lcd.print(bitRead(actual_settings[3],i));  //heti1    
        }

        lcd.setCursor(0,2);
        lcd.print("2.");  
        lcd.print(actual_settings[4]); //start2óra
        lcd.print(":"); 
        lcd.print(actual_settings[5]); //start2perc
        lcd.print(" "); 
        lcd.print(actual_settings[6]); //futásidő2
        lcd.setCursor(13,2);        
        for (int i = 0; i < 7; i++) {
          lcd.print(bitRead(actual_settings[7],i));  //heti2    
        }

        lcd.setCursor(8,3);
        lcd.print(WiFi.localIP()); 

        if (sprinkle) {
          lcd.setCursor(15,0);
        // uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
        //lcd.createChar(4, duck);
        //lcd.printByte(4);
          lcd.print("+:" );       
          lcd.print(actual_settings[8]);
          lcd.setCursor(0,3);    
          lcd.print(flowLitres);

        } 
        else{
            flowLitres = 0;
            lcd.setCursor(0,3);    
            lcd.print(laekLitres);
        }    
}

void switchtime() {            //switchtime()  mindent az éjfél óta eltelt percekben mér - időt /actual_time/ a hívás előtt aktualizálni kell!!!
 /*
                                               0 1         2        3        4 5         6         7            8         
 aktuális beállítás (bejövő) adatszerkezet: start1(2)_runtime1(1)_week1(1)_start2(2)_runtime2(1)_week2(1)_azonnalkibe(1): 9 byte
 */
 //azonnali indítás,leállítás ellenőrzése az onMqttMessage()-ben megtörténik

       // heti ellenorzes, ha ma nincs locsolas  időpontok 0, ha van beállítja a kapcsolási időpontokat

       DateTime now = rtc.now(); 
       int start1 = 0;
       int stop1  = 0;           //kikapcsolva - ha a heti 0, így is marad

       if (bitRead(actual_settings[3],now.dayOfWeek() )) {   //ha aznapra a heti1 = 1  beállítja a kapcsolási időpontokat
         start1 = actual_settings[0]*60+actual_settings[1];
         stop1  = start1 + actual_settings[2];   
        }

       int start2 = 0;
       int stop2  = 0;           // 2. időpont

       if (bitRead(actual_settings[7],now.dayOfWeek()) ) {  
         start2 = actual_settings[4]*60+actual_settings[5]; 
         stop2  = start2 + actual_settings[6];      
       }

       //elvégzi az aktuális kapcsolást - ha nincs kikapcsol /ilyen gombos vagy távvezérléses bekapcsolás után lehet/
       //ha a be és kikapcsolási időpontok egybeesnek inkább kikapcsol

       bool switch_ok = 0;

       if ((start1 - actual_time) == 0) {    //start1 : ha pont következik >> kapcsolás             
           if (start1 != stop1){  
             switch_ok = 1;        
             switch_on();           
           }
       } 

       if (start2 - actual_time == 0) { 
           if (start2 != stop2){   
             switch_ok = 1;       
             switch_on();
           }
       } 

       if (stop1 - actual_time == 0) {
            switch_ok = 1;
            switch_off();         
       }

       if (stop2 - actual_time == 0) {
            switch_ok = 1;
            switch_off();         
       }

       if (switch_ok == 0) {     
            switch_off();         
       }

       //köv. kapcsolás kiválasztása - legkisebb még hátralevő 

       next_switchtime = midnight; //ha nem volna hátra semmi éjféli ellenőrzés

       if (start1 > actual_time && start1 != stop1)   next_switchtime = start1;
       if (start2 > actual_time && start2 != stop2)   next_switchtime = min(start2,next_switchtime);
       if (stop1  > actual_time && start1 != stop1)   next_switchtime = min(stop1,next_switchtime);
       if (stop2  > actual_time && start2 != stop2)   next_switchtime = min(stop2,next_switchtime);

       if (next_switchtime > midnight) next_switchtime = next_switchtime - midnight; // ha holnapra esne az egyik kikapcsolás
}

void flowSensor(){   
  if (count/660 >=1){
    noInterrupts();
    count = 0;
    interrupts();
    flowLitres++;
    lcd.setCursor(0,3);    
    lcd.print(flowLitres);

    int high_part = flowLitres >> 8;
    //  actual_settings[9]  high_byte 
    //  actual_settings[10] low_byte
    if (high_part > 254){
      actual_settings[9] = 256;
      flowmeter_overload = 1;
    }
    else {
      actual_settings[9]  = byte(high_part);
    }
      actual_settings[10] = byte(flowLitres - (high_part << 8));

      if (actual_settings[9] == 0){
        actual_settings[9] = 1;       
        bitSet(actual_settings[11],2);
      }
      else{
        bitClear(actual_settings[11],2);
      }

       if (actual_settings[10] == 0){
        actual_settings[10] = 1;       
        bitSet(actual_settings[11],1);
      }
      else{
        bitClear(actual_settings[11],1);
      }

    settings_changed = 1;
  }
}

void flowLeakage(){  //szivárgás - fél másodpercenként villog, ill. laekLitres-t - kiírja; laekLitres éjfélkor nullázódik
  laektime = millis();
  if (laektime > (laektime0 + 500)){  
    laektime0 = laektime;
     if (lcd_light){
       lcd_light = 0;
       lcd.noBacklight();
     }
     else {
       lcd_light_moment = actual_time;
       lcd.backlight(); 
       lcd_light = 1;
     }

  }
  if (count/660 >=1){
    noInterrupts();
    count = 0;
    interrupts();
    laekLitres++;
    lcd.setCursor(0,3);    
    lcd.print(laekLitres);

    int high_part = flowLitres >> 8;
    //  actual_settings[9]  high_byte 
    //  actual_settings[10] low_byte
    if (high_part > 255){
      actual_settings[9] = 256;
      flowmeter_overload = 1;
    }
    else {
      actual_settings[9]  = byte(high_part);
    }
      actual_settings[10] = byte(flowLitres - (high_part << 8));

      if (actual_settings[9] == 0){
        actual_settings[9] = 1;       
        bitSet(actual_settings[11],2);
      }
      else{
        bitClear(actual_settings[11],2);
      }

       if (actual_settings[10] == 0){
        actual_settings[10] = 1;       
        bitSet(actual_settings[11],1);
      }
      else{
        bitClear(actual_settings[11],1);
      }

   settings_changed = 1;
  }
}

void switch_on(){
 //kacsa_on
 sprinkle = 1;
 digitalWrite(sprinklePin, HIGH);
}

void switch_off(){
 //kacsa_off 
 sprinkle = 0;
 digitalWrite(sprinklePin, LOW);
}

void buttonLocal(){ 

  // gombnyomás esetén loop a gomb elengedéséig - LCD bekapcsol, majd a locsolás kapcsol be vagy ki - 1s folyamatos nyomás után az aktuális locsolási idő állítódik

  unsigned long button_press_moment;           //  gomb nyomvatartási idő
  unsigned long step_time_base;              //  nyomvatartás léptetési időköz ellenőrzése
  int step_time  = 200;                      //  nyomvatartás léptetési időköz
  int default_sprinkle_time = 20;            //  alapértelmezett locsolási idő  
  int max_sprinkle_time = 100;               //  max locsolási idő  
  int sprinkle_time = 0;                     //  valós locsolási idő  

     if(!lcd_light){                                                                                //1.gombnyomás csak LCD világítást kapcsol 
            lcd_light_moment = actual_time;
            lcd.backlight(); 
            lcd_light  = 1;
            button_pressed = 1;
          }
     if (lcd_light && !button_pressed){
        button_press_moment  = millis();                             // nyomvatartási idő nullázása   
         while (press){    
            lcd_light_moment = actual_time;                             // LCD világos marad
            if ( millis() - button_press_moment >= 1000 ){              // 1s nyomvatartás után kézi időbeállítás       
               if ( millis() - step_time_base >= step_time ){ 
                   lcd.setCursor(15,0);
                   lcd.print("S:   ");                                                //törlés
                 sprinkle_time++; 
                   lcd.setCursor(17,0);
                   lcd.print(sprinkle_time);                                       // percenként növekvő bekapcs idő      
                 Serial.print(sprinkle_time);

                  step_time_base = millis(); 
                  if (sprinkle_time > max_sprinkle_time) sprinkle_time = max_sprinkle_time; // amíg a max bekapcs időt eléri   

               }
              }        
         } 
         if (sprinkle_time){                                                                          // bekapcs a beállított időre               
                next_switchtime = actual_time + sprinkle_time;
                if (next_switchtime > midnight) next_switchtime = next_switchtime - midnight;   // ha holnapra esne
                switch_on(); 
                settings_changed = 1;             
              } 
              else {
                 if (sprinkle){
                   switch_off(); 
                   switchtime(); 
                   settings_changed = 1;                                                                           //kikapcs
                 }
                else {
                   next_switchtime = actual_time + default_sprinkle_time;                                 // bekapcs default időre
                   if (next_switchtime > midnight) next_switchtime = next_switchtime - midnight; // ha holnapra esne
                   switch_on();
                   settings_changed = 1; 
                }
              }
     }

}

ICACHE_RAM_ATTR void gombvaltozas(){
   if (digitalRead(buttonPin)) {
    press = 1;
      }
    else{
    press = 0;
  }

}

ICACHE_RAM_ATTR void Flow(){
   count++; 
}

void serial_datawriting(){ 
  if ((millis()%1000>998)){    //lassítás
    DateTime now = rtc.now(); 
    Serial.print("press:"); 
    Serial.print(press);
    Serial.print(" sprinkle: ");
    Serial.print(sprinkle);
    Serial.print(" acttime:");
    Serial.print(actual_time);
    Serial.print(" hour:");
    Serial.print(now.hour());
    Serial.print(" min:");
    Serial.print(now.minute());
    Serial.print(" nxt_sw:");
    Serial.print(next_switchtime);
    Serial.print(" cpunt:");
    Serial.print(count);
    Serial.print(" ");
    Serial.print(flowLitres);
    Serial.println("l "); 
  }
}

void wifi_initialize(){

 //Setting the AP Mode with SSID, Password, and Max Connection Limit
  if(WiFi.softAP("kislocsolo","",1,false)==true){

    Serial.print("Access Point is Creadted ");
    Serial.print("Access Point IP: ");
    Serial.println(WiFi.softAPIP());
  }
  else
  {
    Serial.println("Unable to Create Access Point");
  }

  lcd.setCursor(8,3);
  lcd.print(WiFi.softAPIP());

  server.on("/", processPostData);

  server.begin();

  while (true)  server.handleClient();    //Handling of incoming requests

}

void processPostData(){

   Serial.print("POST Arguments: " ); Serial.println(server.args());
   Serial.print("SSID: "); Serial.println(server.argName(0));
   Serial.print("PASS: "); Serial.println(server.arg(0));

    String ssid = server.argName(0);

    EEPROM.write(10,byte(ssid.length()));
    byte buffer_ssid[ssid.length()+1];
    ssid.getBytes(buffer_ssid,ssid.length()+1);

    for(int i=0;i<ssid.length();i++){
      EEPROM.write(11+i,buffer_ssid[i]);
       delay(10);
    }

    String pass = server.arg(0);

    EEPROM.write(40,byte(pass.length()));
    byte buffer_pass[pass.length()+1];
    pass.getBytes(buffer_pass,pass.length()+1);

    for(int i=0;i<pass.length();i++){
      EEPROM.write(41+i,buffer_pass[i]);
       delay(10);
    }

    EEPROM.commit();

    int ssid_length = EEPROM.read(10);
     String ssid_read;
    for (int i=0;i<ssid_length;i++){
     ssid_read += char(EEPROM.read(11+i));
     delay(10);
    }

    int pass_length = EEPROM.read(40);
     String pass_read;
    for (int i=0;i<pass_length;i++){
     pass_read += char(EEPROM.read(41+i));
     delay(10);
    }

    Serial.print ("SSID: ");
    Serial.print (ssid_read);
    Serial.print (" ,PASS: ");
    Serial.println (pass_read);

    lcd.clear();  
    lcd.setCursor(0,1);
    lcd.print("SSID: ");
    lcd.print(ssid_read);
    lcd.setCursor(0,2);
    lcd.print("PASS: ");
    lcd.print(pass_read);

    server.send(200, "text/plain", "ok");
} 
d-a-v commented 11 months ago

You were presented an issue template that you deleted. You are not helping us helping you. I therefore close your issue. Please open a new issue and do fill in the issue template. And in your case, as you have an exception, please decode it before posting because we can't do it for you: https://arduino-esp8266.readthedocs.io/en/latest/faq/a02-my-esp-crashes.html#exception