2 Replies Latest reply on Jan 14, 2015 8:31 PM by oasuria

    AP Config Mode and STA

    oasuria

      Hi,

       

      I am trying to edit the config_http_content in order to achieve following:

       

      At initial startup of the the device, it will run in config mode to allow user to identify the user wifi connection to connect to. This will also be available to the user at any time by pressing a push button. The idea here is that, I would like to automate the connection to STA for the user interactively. I am using appliance app as a basis and making required changes to the library files.

       

      From user's perspective we would like to do the following:

      1) User can connect to the Config AP and browse to wiced.com (redirected to AP web server)

      2) Goto Wifi scan page

      3) Select the Wifi network to connect to and provide password and press "connect" button

      4) If connected to the wifi network, the user will be shown the IP address of the device, and the Config AP web server will be shutdown and STA web server started (And if possible the user's browser redirected to the STA interface for other settings that require internet connection)

      5) Otherwise, the user will be informed that the connection to the wifi network was not established (Try again)

       

       

      In Appliance app, first function that is called after wiced_init() is wiced_configure_device(). I have made a new function wiced_configure_device2(), which is a modified version of the original. Also made changes other required functions to achieve the above mentioned behavior.

       

      Now when I press connect, whether with correct password or incorrect one, at the first call XMLHttpRequest returns with readyState 4 and status 0, the ajax fails. When second time connect is clicked, it works. I have defined a new function for connect process which returns the IP address in case of successful connections and "Error" in case of unsuccessful connection, using following:

       

      wiced_tcp_stream_write( stream, "Error", strlen("Error"));

       

      Since I am using library function for STA connection

       

      wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

       

      it tries is three times before giving up, so can take some time if incorrect password is typed. With correct credentials it is much quicker (obviously). I have noticed that XMLHttpRequest returns status 0 and readyState 4 before the dynamic function has even completed. Thus, the data part is missing (using do_ajax provided). But when the same request is done the second time, it waits until the function completes and then return correct status 200 with data (Error or the IP address).

       

      What could be the cause of this? I have tried to debug this issue but can't figure it out.

       

      Has anyone implemented something similar? Some guidance will be appreciated.

       

      -------------------------------------------------------------------------

      Additional information to the original post:

      I was able to single out the problematic part of the above process.

       

      wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

       

      Calling the above function from the dynamic web function (named process_connect2()) makes the request unresponsive. Somehow connecting to an STA interface interferes with the HTTP web server running on CONFIG_AP interface. Is that normal?

       

      I also tried to create a new thread that will take care of STA interface connection setup and return text (via wiced_tcp_stream_t) signifying that thread has been created successfully. Another request is made to another dynamic web function (called process_join_result()) by the client web browser after a 10s delay to retrieve connection status (Error if STA connection was not successful or the new IP address if successful).

       

      But this fix also didn't pan out, as the process_join_result() did not work as it was supposed to and returned the content of the homepage (instead of Error or IP address). It didn't even run this function. The function runs fine if the request is made before the connect request. Also, the device becomes unresponsive and resets by itself, so I am assuming that my thread creation and deletion may not be correct.

       

      --

      Omair