So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By axiom
#74359 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();
}
User avatar
By btidey
#74363 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;
   }
}
 
User avatar
By axiom
#74368 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;
   }
}