-->
Page 1 of 1

How to Wait before connect to Wifi, without triggering WDT

PostPosted: Sun Mar 04, 2018 1:09 pm
by axiom
Hi Community!

I'm new to native development in ESP8266, I'm using ESP-Open-SDK and ESP-Open-RTOS.

My problem: I need to wait about 1 min before connect to Wi-Fi and start producing sensor data, this is because I have some HW that needs to initialize.

What is the suggested way to achieve this initial delay without triggering the WDT and go into an infinite reboot loop?

I would like to put the delay in to user_init(void) before any call to start Wi-Fi.

Pseudocode:

void user_init(void) {
uart_set_baud(0, 115200);

wait_for_hw() //wait X ms or maybe wait for a GPIO);

wifi__init(); <- will init other tasks on connection ready

gpio_init();
}

Re: How to Wait before connect to Wifi, without triggering W

PostPosted: Sun Mar 04, 2018 5:36 pm
by btidey
Break the delay up into small units of delay each less than 1 second. The delay call yields to the background task.

My preferred method in a Arduino loop environment is to have a state variable that keeps track of the state of initialisation. Although it looks excessive, in many cases one wants to expand on the number of states the system can be in. Something like

Code: Select all//delay in msec
#define DELAY_STARTUP 60000
int timeInterval = 25;
unsigned long elapsedTime;
int state = 0;

void loop() {
   delay(timeInterval);
   elapsedTime++;
   if(state = 0 && elapsedTime * timeInterval > DELAY_STARTUP) {
      state = 1;
      //do delayed initialisation stuff here
                // and set state = 2 if successful
   }
   if(state > 1 ) {
      //do run time stuff after initalisation;
   }
}
 

Re: How to Wait before connect to Wifi, without triggering W

PostPosted: Mon Mar 05, 2018 8:47 am
by axiom
Thanks!,

I'm trying to do the same but with the Native RTOS SDK, but I'm unable to find a way to avoid Wifi connection before my wait code, at boot no matter what ESP8266 connect to Wi-Fi, then wait

btidey wrote:Break the delay up into small units of delay each less than 1 second. The delay call yields to the background task.

My preferred method in a Arduino loop environment is to have a state variable that keeps track of the state of initialisation. Although it looks excessive, in many cases one wants to expand on the number of states the system can be in. Something like

Code: Select all//delay in msec
#define DELAY_STARTUP 60000
int timeInterval = 25;
unsigned long elapsedTime;
int state = 0;

void loop() {
   delay(timeInterval);
   elapsedTime++;
   if(state = 0 && elapsedTime * timeInterval > DELAY_STARTUP) {
      state = 1;
      //do delayed initialisation stuff here
                // and set state = 2 if successful
   }
   if(state > 1 ) {
      //do run time stuff after initalisation;
   }
}
 

Re: How to Wait before connect to Wifi, without triggering W

PostPosted: Mon Mar 05, 2018 11:47 am
by btidey
wifi_station_set_auto_connect

sets whether it automatically tries to autoconnect or not at power up.

By default this has been programmed to autoconect so it needs to be turned off at least once.