This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3100 - enable/disable HTTP server when toggling between AP/STA

Other Parts Discussed in Thread: CC3100

Hi,

What should be the simplelink API flow/sequence to enable/disable the HTTP-server when toggling between AP/STA?

My application boots to AP, waits for PROFILE configuration via HTTP-server and is triggered to change to STA.
If it fails to connect to AP (timeout) - it toggles between AP and STA, retrying the PROFILE, but giving a chance for the user to reconfigure.
I need to disable the HTTP-server in STA.

My code runs well, as long as I don't disable the HTTP-server. If I disable it - I can't get it running again when in AP.

Description of my application:
 - Power-up:
   - Initialize CC3100 HW (nHIB, nRESET, 3-25-250 ms, according to spec)
   - sl_Start() (wait for callback)
   - sl_WlanPolicySet(AUTO)
   - Configure HTTP-server <- ENABLE, here it should be disabled!!!
   - Check for existing PROFILE (to jump directly to STA)
 - AP:
   - sl_WlanSetMode(ROLE_AP)
   - sl_WlanSet(SSID/SECURITY_TYPE/PASSWORD
   - sl_Stop() and sl_Start() (wait for callback)
   - Wait for acquiring IP
   - Radio in AP, waiting for PROFILE configuration and trigger to toggle to STA
 - STA:
   - sl_WlanSetMode(ROLE_STA)
   - sl_Stop() and sl_Start() (wait for callback)
   - Wait for connection and acquiring IP (till timeout and back to AP flow)
   - Radio in STA

I've tried almost every possibility of enable/disable of the HTTP-server in the AP and STA flow, can disable the HTTP-server, but can't get it running again.

I'm using:
 + SDK 1.1.0
 + ServicePack 1.0.0.10.0
 + SPI interface
 + No-OS (main loop with state-machine)

Thanks

  • Hi Rami,

    The 'sl_NetAppStop' or 'sl_NetAppStar' API starts/stops the service in the current configured mode. Also this configuration is persistence.
    In AP mode stop the HTTP service and in STA mode start the HTTP and you needn't have to configure this every time.

    Regards,
    Ankur
  • Hi,

    If I understand correctly, the CC3100 has 2 HTTP settings: AP-HTTP setting and STA-HTTP setting.

    In AP mode I enable it, using this code:

    {
        static bool firstTimeAP = true;
        if (firstTimeAP == true)  {
            firstTimeAP = false;
    
            /* Enable HTTP server */
            {
                _i32 rv;
                byte optionValue;
    
                Debug_UART_Send("CC_B(): Starting HTTP server\n");
    
                optionValue = 0;
                rv = sl_NetAppSet(SL_NET_APP_HTTP_SERVER_ID, NETAPP_SET_GET_HTTP_OPT_AUTH_CHECK, 1, &optionValue);
                if (rv != 0) {
                    Debug_UART_Send("CC_B(): Failed to set _AUTH_CHECK %d (%d)\n", optionValue, rv);
                    state = STATE_INIT;
                    break;
                }
    
                optionValue = 80;
                rv = sl_NetAppSet(SL_NET_APP_HTTP_SERVER_ID, NETAPP_SET_GET_HTTP_OPT_PORT_NUMBER, 1, &optionValue);
                if (rv != 0) {
                    Debug_UART_Send("CC_B(): Failed to set _PORT_NUMBER %d (%d)\n", optionValue, rv);
                    state = STATE_INIT;
                    break;
                }
    
                rv = sl_NetAppStart(SL_NET_APP_HTTP_SERVER_ID);
                if (rv != 0) {
                    Debug_UART_Send("CC_B(): Failed to start HTTP server (%d)\n", rv);
                    state = STATE_INIT;
                    break;
                }
            }
        }
    }

    In STA mode I disable it, using this code:

    {
        static bool firstTimeSTA = true;
        if (firstTimeSTA == true)  {
            firstTimeSTA = false;
    
            /* Disable HTTP server */
            {
                _i16 rv;
                Debug_UART_Send("CC_B(): Stoping HTTP server\n");
                rv = sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
                if (rv != 0) {
                    Debug_UART_Send("CC_B(): Failed to stop HTTP server (%d)\n", rv);
                    state = STATE_INIT;
                    break;
                }
            }
        }
    }
    

    I tried inserting both blocks:

    1. Between sl_WlanSetMode(ROLE_xxx) and sl_Stop(0) / sl_Start((...)
    2. After waiting for connection / IP-acquiring (end of flow)

    In both scenarios - HTTP-server is disabled when returning to AP.

  • Rami,

    Yes - Your understanding is correct.
    Can you please confirm this below sequence in your application?
    - Set role to AP
    - Restart SimpleLink
    - Enable HTTP Server (Enables it for AP role till it's reconfigured by the application in AP role)
    - Set role to STA
    - Restart SimpleLink
    - Disable HTTP Server (Disables it for STA role till it's reconfigured by the application in STA role)

    -/Praneet
  • I tried this sequence - configuring HTTP after the sl_Stop() / sl_Start() combination, ENABLE for AP, DISABLE for STA.

    I found 'inconsistencies' - sometimes the configuration works, sometimes it doesn't work (meaning in AP I cannot GET 192.168.1.1, 'connection refused').

    I tried 'restarting the simplelink' both with the sl_Stop() / sl_Start() combination and with the full HW reset (nHIB 250ms, etc.).

    I tried compiling with no optimization, but I'm quite sure my code is stable.

  • I've finally found the answer!
    Looking at my code snippet above, when updating the port number

    optionValue = 80;
    rv = sl_NetAppSet(SL_NET_APP_HTTP_SERVER_ID, NETAPP_SET_GET_HTTP_OPT_PORT_NUMBER, 1, &optionValue);

    optionValue is a byte , instead of an unsigned short - that's it!

    I'm encouraging myself with the thought that passing size '1' should have returned an error :-)