8 Replies Latest reply on Jan 15, 2015 12:03 PM by AnSa_1225656

    Problem stopping/starting webserver

    cogoc_1937206

      Hello,

       

      I'm having trouble starting / stopping a webserver on my AP-mode interface once a client has connected.  I can stop/start it at will as long as no clients have connected to it, but once a client has connected (even if it first leaves the AP-mode network), if I stop and later start the webserver I get an error.  The error seems to come from:

       

      err_t netconn_bind(struct netconn *conn, ip_addr_t *addr, u16_t port)

       

      in api_lib.c, though I didn't try to trace it any further.  I'm hoping that there's just some TCP/IP connection information that I need to clear in addition to stopping the webserver and AP-mode interface, but I guess I need some guidance.

       

      I'm using FreeRTOS/LwIP and WICED-SDK 2.4.1.

       

      Thanks in advance!

        • 1. Re: Problem stopping/starting webserver

          Hi Colby, I still don't see that your question has been answered. Is this issue still outstanding for you?

           

          userc_2031

          metac_349616

          • 2. Re: Problem stopping/starting webserver
            cogoc_1937206

            Hey Rob,

             

            Yes, this issue is still outstanding for me.  I've moved on to other things for now, so it's not holding me up, but it would be nice to get it resolved soon.

             

            Thanks!

            • 3. Re: Problem stopping/starting webserver
              GregG_16

              I Will try to duplicate this.  Does it happen with netx threadx also?

              Any other info on how to best duplicate would be helpful.

              • 4. Re: Re: Problem stopping/starting webserver
                cogoc_1937206

                Hi gangi, thanks for looking into this!  I suppose I should start by elaborating a bit on exactly what I'm trying to do -- I'm trying to run config_mode in AP mode, then upon joining:

                • startup the webserver again on the STA interface
                • restart the AP-mode interface and run a second copy of the webserver on that interface

                 

                I've done a bit more testing and found some discrepancies between the ThreadX/NetX-Duo and FreeRTOS/LwIP options:

                 

                ThreadX/NetX-Duo

                • I can stop/start the AP-mode interface and its webserver in isolation (I've added CLI commands for doing this) no problem.  (Works even when a client is connected to the webserver.)
                • Same goes for the STA-mode interface once my eval board has been commissioned to a network.
                • My automatic stop/start of the AP-mode interface across joining in STA-mode during commissioning works, but starting up the webserver for AP-mode fails (WICED_ERROR).
                  • Once commissioned to a network, my code first joins this network in STA-mode on startup, then attempts to form its AP-mode network (following the apsta snippet).  With ThreadX/NetX-Duo, I still get WICED_ERROR when attempting to startup the AP-mode interface webserver after a reboot.  (I.e. I wouldn't expect any previously connected clients to be causing an issue...(?))

                 

                FreeRTOS/LwIP

                • Stop/start of the AP-mode interface and its webserver in isolation works if no client has connected to the webserver (okay if client is connected to the network).  The webserver fails to start (WICED_ERROR) however, once a client has been connected to the webserver.
                • Same goes for the STA-mode interface once my eval board has been commissioned to a network.
                • Automatic stop/start of the AP-mode interface across joining in STA-mode during commissioning works, but starting up the webserver for AP-mode fails (WICED_ERROR).
                  • Unlike ThreadX/NetX-Duo, once commissioned to a network, both webservers do start successfully after a reboot (where my logic automatically starts up the STA-interface and its webserver, then the AP-interface and its webserver).

                I'll try adding some code snippets showing what I'm doing exactly to start/stop the interfaces in another comment.

                Cheers!

                • 5. Re: Re: Problem stopping/starting webserver
                  cogoc_1937206

                  Here are the functions I've written for starting and stopping the network interfaces along with their webservers.  These get called from some automated logic, but I also have CLI handlers that allow me to call them manually for testing.

                   

                  void nwkMgr_startApMode()
                  {
                      wiced_result_t result;
                  
                      if (!wiced_network_is_up(WICED_AP_INTERFACE))
                      {
                          wiced_network_up(WICED_AP_INTERFACE, WICED_USE_INTERNAL_DHCP_SERVER, &device_init_ip_settings);
                          // Start the DNS redirect server
                          result = wiced_dns_redirector_start(&dns_redirector, WICED_AP_INTERFACE);
                          WPRINT_APP_INFO(("AP-mode DNS-redirector start: %s (%d)\r\n",
                                           result == WICED_SUCCESS ? "SUCCESS" : "FAIL",
                                           (int)result));
                          // Start the HTTP server
                          memset(&webserver_apMode, 0, sizeof(webserver_apMode));
                          result = wiced_http_server_start(&webserver_apMode, HTTP_PORT, neurio_web_pages, WICED_AP_INTERFACE);
                          WPRINT_APP_INFO(("AP-mode HTTP server start: %s (%d)\r\n",
                                           result == WICED_SUCCESS ? "SUCCESS" : "FAIL",
                                           (int)result));
                      }
                  }
                  
                  void nwkMgr_stopApMode()
                  {
                      wiced_rtos_deregister_timed_event(&ap_mode_stop_check_event);
                  
                      if (wiced_network_is_up(WICED_AP_INTERFACE))
                      {
                          /* Cleanup HTTP server */
                          wiced_http_server_stop(&webserver_apMode);
                          /* Cleanup DNS server */
                          wiced_dns_redirector_stop(&dns_redirector);
                          /* Turn off AP */
                          wiced_network_down(WICED_AP_INTERFACE);
                      }
                  }
                  
                  
                  static wiced_result_t joinAndStartWebserver(void* arg)
                  {
                      wiced_result_t result;
                      result = wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL);
                      if ( result == WICED_SUCCESS )
                      {
                          WPRINT_APP_INFO(("STA-mode%sjoin succeeded!\r\n", arg == NULL ? " " : " first "));
                          // Start the HTTP server
                          memset(&webserver_staMode, 0, sizeof(webserver_staMode));
                          result = wiced_http_server_start(&webserver_staMode, HTTP_PORT, neurio_web_pages, WICED_STA_INTERFACE);
                          WPRINT_APP_INFO(("STA-mode HTTP server start: %s (%d)\r\n",
                                           result == WICED_SUCCESS ? "SUCCESS" : "FAIL",
                                           (int)result));
                          // stop the periodic join attempts
                          wiced_rtos_deregister_timed_event(&join_attempt_event);
                      } else {
                          WPRINT_APP_INFO(("STA-mode%sjoin failed...\r\n", arg == NULL ? " " : " first "));
                      }
                  
                      return result;
                  }
                  
                  
                  
                  
                  void nwkMgr_startStaMode()
                  {
                      joinAndStartWebserver(NULL);
                  }
                  
                  
                  
                  
                  void nwkMgr_stopStaMode()
                  {
                      // (shouldn't be necessary, but just to be thorough...)
                      wiced_rtos_deregister_timed_event(&join_attempt_event);
                  
                      if (wiced_network_is_up(WICED_STA_INTERFACE))
                      {
                          /* Cleanup HTTP server */
                          wiced_http_server_stop(&webserver_staMode);
                          /* Turn off AP */
                          wiced_network_down(WICED_STA_INTERFACE);
                      }
                  }
                  
                  
                  
                  
                  
                  
                  • 6. Re: Problem stopping/starting webserver
                    cogoc_1937206

                    Hi gangi,

                     

                    It's not clear to me what I may have been doing wrong before, but this problem seems to have mostly resolved itself for me.  I do still have an issue running a separate webserver on each of the STA and AP interfaces under ThreadX/NetX-Duo.  It looks like the wiced_tcp_listen() function for NetX-Duo makes an assumption about all ports using the STA interface(?) and fails out on its call to nx_tcp_server_socket_relisten().

                     

                    More concisely:  Running a webserver on each of the STA and AP interfaces is working under FreeRTOS/LwIP and ThreadX/NetX.  It does not work, however, for ThreadX/NetX-Duo unless the webservers are configured to listen on different ports.

                     

                    Cheers!

                    • 7. Re: Problem stopping/starting webserver
                      GregG_16

                      Hello,

                      Maybe it is best to create a new discussion with the new issue.  This will help avoid confusion.

                      • 8. Re: Re: Problem stopping/starting webserver
                        AnSa_1225656

                        I am having the same issue with Webserver needing a different port for each interface.  Is there a work-around to allow the same port 80 to be used for both?

                         

                        "More concisely:  Running a webserver on each of the STA and AP interfaces is working under FreeRTOS/LwIP and ThreadX/NetX.  It does not work, however, for ThreadX/NetX-Duo unless the webservers are configured to listen on different ports."