9 years, 4 months ago.

Websocket loss of connection causes hang?

My program uses wifi and websockets, if internet connection is lost then the program freezes (or crashes with watchdog). Here is simplified code:

void main()
{
      while(true)
      {
              //OTHER STUFF

              if(ws.is_connected() == true)
              {
                     led2 = 1;
                     sprintf(wstemp, "%f*%f*%f*%f", temp, trip_level, hyst_amount, wscontrol);
                      ws.send(wstemp); 
        
                      if(ws.read(ws_recv))
                      {
                            string check = ws_recv;
                             {
                                      char *wdi;
                                      wdi = strtok(ws_recv,"*");
                                       trip_level = atof(wdi);
                                       while(wdi != NULL)
                                        {
                                               hyst_amount = atof(wdi);
                                                wdi = strtok (NULL, "*");
                                         }
                              }
                       }
                       led2 = 0;
              } 
       }
}

Using a oscilloscope I can see the program spends a lot of time in the websocket.is_connected loop.

Be the first to answer this question.