0

I am trying to make my ESP8266(nodemcu) as a Web server. When my code operates, and user connects esp's wifi and enters '192.168.4.1/set_peroid' by IE or chrome, this webpage appears:

enter image description here

This is setting menu page. Usually, user puts sampling rate and time peroid, and duration or counter. Then presses 'submit', these data are going to be saved on my esp's EEPROM.

This is the code: (apologize about its complexity)

void input_handleForm() {

  int sample_int=0;
  int s_peroid_int=0;
  int m_peroid_int=0;

  int h_timer_int=0;
  int m_timer_int=0;

  int count_int=0;
  unsigned short curr_tmp=0;
  unsigned short max_tmp=0;


  //setting sampling rate
  String sample_str = server.arg("sample"); //get string data to 'sample' blank
  sample_int = sample_str.toInt(); //and convert to int data 

  sample_int = (sample_int/4);
  EEPROM.write(SAMPLING_TIMES, sample_int); //devide by 4 and save it 

  //setting user peroid (second or minute)
  String s_peroid_str = server.arg("peroid_s"); //get string data to peroid(sec) blank
      if(s_peroid_str !=NULL){
          s_peroid_int = s_peroid_str.toInt(); //and save it

            if(s_peroid_int<1){
              s_peroid_int=1;
            }
          EEPROM.write(SECOND_INDEX,s_peroid_int); //and save to the eeprom
          EEPROM.write(MINUTE_INDEX,0);
         }
       else{
          s_peroid_int =0;
          EEPROM.write(SECOND_INDEX,0);
        }

  String m_peroid_str = server.arg("peroid_m"); //get string data to peroid(min) blank

      if(m_peroid_str != NULL){

        m_peroid_int = m_peroid_str.toInt(); //save it by int

          if(m_peroid_int <1){
            m_peroid_int=1;      
          }

        EEPROM.write(MINUTE_INDEX,m_peroid_int);//and save the integer to eeprom
        EEPROM.write(SECOND_INDEX,0);
      }
      else{
        m_peroid_int=0;
        EEPROM.write(MINUTE_INDEX,0);
       }

      //if user do not input anything ...
      if(m_peroid_int ==0 && s_peroid_int ==0){
        s_peroid_int = 1; 
        EEPROM.write(SECOND_INDEX,s_peroid_int);
      }

    //setting timer
    String h_timer_str = server.arg("hour"); //get string data to hour blank
      if(h_timer_str != NULL){
        h_timer_int = h_timer_str.toInt();

          if(h_timer_int <1){
            h_timer_int=0;
          }
      }
      else{//if get null
        h_timer_int=0;
      }

    String m_timer_str = server.arg("minit"); //get string data to minute blank
      if(m_timer_str !=NULL){
        m_timer_int = m_timer_str.toInt();

          if(m_timer_int<1){
            m_timer_int=1;
          }
      }
      else{//if get null
        m_timer_int =0;
      }

      //caculate the 'repeat count' by (time/peroid)

      unsigned long until = (h_timer_int * 60) + m_timer_int;
         //until is set standard by minute. if user's peroid is second, have to *60

        if(until>0 && m_peroid_int >0){ //if peroid is setted by minute

            unsigned short index = until/ m_peroid_int;
            index+=3;
            EEPROM.put( MAXIMUM_INDEX , (unsigned short) index );

        }

        else if(until>0 && s_peroid_int>0){ //if peroid is setted by second
              until = until * 60; //make until(minute) to second
              unsigned short index = until / s_peroid_int;
              index+=3;
              EEPROM.put( MAXIMUM_INDEX, (unsigned short) index );

        }


        else if(until ==0){ //if user do not set timer, then scan the counter input.

          String count_str = server.arg("counts");//get string data to 'count' blank

            if(count_str !=NULL){
               count_int = count_str.toInt();
               unsigned short count_short = (unsigned short) count_int;
               count_short+=3;
                EEPROM.put( MAXIMUM_INDEX, (unsigned short) (count_short) );
            }

            else{//if user do not set timer and do not input count then...
              unsigned short tmp_default = 5;
               EEPROM.put(MAXIMUM_INDEX, (unsigned short) tmp_default );
            }

        }


         EEPROM.commit();

         delay(100);

    String s = "setting done.";
    s += "<a href='/'> Go Back </a>";
    server.send(200, "text/html", s); //Send web page

}

Even though they look complex, they are usually working. But problem is, when input the data and press 'submit', sometimes, very sometimes the program breaks down, irregularly. And when it breaks down, it says:

ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

Although there is 'wdt reset', but system does not reset. ESP just stops and does nothing.

Please give me advice about what is the problem, and help for a solution.

  • you have io 0 LOW (the 1 in mode should be 3 for normal boot). on reset esp8266 starts in flashing mode – Juraj Sep 9 '19 at 12:58
  • wdt rest is watchdog reset. it happens when the code doesn't get out of the loop 10 or more seconds and yield() or delay() is not called to let the SDK handle the WiFi – Juraj Sep 9 '19 at 13:03
  • thank you for answering. – lee du Sep 9 '19 at 23:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.