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.

Getting Started with HTTP Server on CC3200 Launchpad

Other Parts Discussed in Thread: CC3200, UNIFLASH, CC3100, ENERGIA, CC3200SDK

I'm just getting started using the CC3200 launchpad. I've completed project-0 and uploaded the httpserver example successfully. But I'm a little stuck understanding just how the ARM code interacts with the HTTP server. Is there a document that explains this? An API that I can go through?

Here's some specifics with regard to example/httpserver:

main.c:453 has a function called SimpleLinkHttpServerCallback(). It handles GET and POST requests and is pretty easy to step through. When you click the on/off on the web page, the client generates a POST, and this function handles it. Got it.

However, part of this function also handles a GET. The code is pretty easy to read and understand, but I'd like to step through it and I don't know how to get it to fire. If I load the page, the webserver handles these GETs directly without ever calling SimpleLinkHttpServerCallback(). If I try to guess a URL that connects to this function, I get a 404 from the webserver, again without calling SimpleLinkHttpServerCallback().

I've poked around in UniFlash, but I don't see how to specify which GET calls should be handed off to SimpleLinkHttpServerCallback(). Perhaps you specify this in the C code?

Someone please explain or point me at a document that does so I can finish my evaluation of this product.

Thanks!

Gre7g

  • I'm a little closer to answering this riddle! I found SWRU368 (CC3100\CC3200 SimpleLink™ Wi-Fi® Network Processor Subsystem) and it helped a bit.

    I realized that I can trigger the SimpleLinkHttpServerCallback() function to get called if I do a GET from URL: http://mysimplelink.net/led_demo.html?__SL_G_ULD

    I can single step through the code and see that it is working -- it generates the correct string. I can turn the breakpoint off and fetch the URL again (since the fetch will time out after 2 seconds).

    The problem is that the webserver still returns the HTML and not the dynamically computed string. So what's the trick to get that?

  • Okay, I think I'm getting closer still, but I'm still lost! Someone, please help.

    In the built-in demos, the client isn't doing a GET with a __SL_G_Uxx anywhere in it, but I can see GET from URLs such as http://mysimplelink.net/param_demos.html?_=1409151345861 where demos.html is the static file and so param_demos.html is clearly a dynamic page. This GET returns something along the lines of:

    <html>
    <body>
    <p id="Device_Temperature">Unknown Token</p>
    <p id="Device_Accelerometer">Unknown Token</p>
    <p id="Device_LED_Status">LED1_OFF,LED2_OFF</p>
    </body>
    </html>

    This appears to be a page that has been filled in by multiple calls to SimpleLinkHttpServerCallback(). That "LED1_OFF,LED2_OFF", for instance comes straight out of the code in example/htmlserver/main.c.

    But where do I find this template? How do I make one? How do I put my __SL_G_Uxx into it? Where is this documented?

    Please, someone, point me in the proper direction!

  • Hi Luterman,

    Whenever you open a web page in the browser, the built-in http client tries to find a html file for a url you entered. Html file needs to be flashed into the memory using UniFlasher application so the http client can process your html/template file and send it back to the browser.

    Below you have a screenshot from UniFlasher. Please note /www/ directory keeps all the public html/css/js files which will be served by the CC3200.


    Any html/template file can contain tokens. It's not documented but only following tokens patterns can be used:

    __SL_G_XXXXX for GET requests.

    If you load following page into /www/mypage.html directory:

    <html><body>__SL_G_MY_KEY</body></html>

    and than you will open the browser using address: [ip]/mypage.html, you will get SimpleLinkHttpServerCallback invocation. CC3200 will be asking you what data should be placed in exchange of __SL_G_MY_KEY token.

    You can handle the request with following code:

    ( Your browser will display <html><body>OK</body></html> )

    void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent, SlHttpServerResponse_t *pHttpResponse)
    {
      Report("SimpleLinkHttpServerCallback\r\n");
      
      switch (pHttpEvent->Event)
    	{
    		case SL_NETAPP_HTTPGETTOKENVALUE:
    		{
                      UINT8 * ptr = pHttpResponse->ResponseData.token_value.data;
                      ptr[0] = 'O';
                      ptr[1] = 'K';
                      pHttpResponse->ResponseData.token_value.len = 2;
                    }
                    break;
            }
    }




    So this are GET tokens which can be used to load the data from CC3200. There is other group of tokens which allows you to push the data from browser to CC3200 chip. It can be done using http POST requests. You can send a POST request to CC3200 with form-url-encoded parameters. The name of parameter must match following pattern:

    __SL_P_XXXX 

    There are several limitations of the current Simple Link Http Server:

    1. Only one POST parameter is handled by the server in a single request ( you can always box several into one ).

    2. You can't control body and status code of respond to POST request.

    3. You can't control status code of respond to GET request.

    4. You can't pass query parameters to C code for GET requests.

  • Awesome. Thanks for the detailed post.

    It would be great if this was more clear in the documentation.

    I'm on vacation today, but I will try it out when I get back to the office!

    Thanks,

    Gre7g

  • I agree, awesome post! I was just starting out on the HTTP GET part of my code and found this post excellent help, especially the sample code and description of the limitations.

    Glenn.

  • Back in the office today and finally had a chance to test. Works great. Thanks again for the help and I hope this becomes more evident in the documentation soon.

    Gre7g

  • I found a really nice doc from TI which describes build-in http server.

    http://www.ti.com/lit/ug/swru368/swru368.pdf ( Chapter: Http Server ).

  • This post was very helpful to me as well. Thanks.

    I do have another question.  I need to return data for a table that could have as many as 7000 rows.  The current limit for the response is 64 bytes. Is there a way to get the http server to keep making calls to SimpleLinkHttpServerCallback() on the same token until my data is exhausted or is the some better way to handle this situation?

    Steve Gibson

  • hi guys,

    Actually this topic is interesting for me because I have a project with cc3200.The project is to control the colour produced by 3 RGB leds through a wifi channel.From the examples of the SDK I have found two useful things (HTTP server.PWM) examples.I am intending to write the colour in the browser  and see the result on the lamps or to have number of push buttons in the browser and every one represent a colour so when I click the switch on the browser i will see the results directly as in the (off-on led) example.My problem is understanding the code of the http server I looked through it and in the network processor document but still i didn't get sufficient information because I am an automation engineer and I don't have good background with these type of programming.Please anybody can help me with some good notes in order to proceed.

  • Steve - this is where I am at also. I would like to use the built in HTTP server to pull large amounts of real time data ( currently in JSON format) up from an embedded device for display on a browser. Unless I am missing something the built is server is severely limited by the 64 byte GET limit and lack of JSON support. Have you got anywhere with your implementation?

    Thanks,

    Dan

  • Dan - I am afraid not. I tried embedding a new token inside of my response data to see if I could get some recursion going on but that did not work.  To me it seems like there should be some sort of basic scripting language you can put inside the html so that you can get it to loop until a certain condition is met.  Maybe something like this exists but I am not aware.  I am not a web programmer so I have very limited knowledge of how these things are supposed to work. If I come up with something I will be sure to post it.

  • How can I refresh the GET tokens automatically (eg. every second), without having to refresh the complete website.

    Henning

  • Dan,

    I was looking at the websock_camera example and it I think it close to this application. It loads an image (more than 64 bytes), to a browser.

    This example uses "sl_WebSocketSend()" to do this. Although there is documentation about using Sockets, I haven't found documentation in the SDK about Websockets specifically.

    It looks like there are all kinds of functions in NetApps folder for the SDK. Just going to have to browse through the includes to find them, and maybe find the one perfect for the application.


    Thanks,

    Markus

  • Markus,

    Thanks for the tip - I am using a 3100 but I would assume everything in that NetApps folder should port directly to the 3100. I wonder why these are not documented or packaged with the 3100 SDK? The built in server would be much simpler if anyone has a clever way around the 64 byte limit.

    Dan

  • One way around the limit could be to save your data into 64KB-chunked files (max file size for the SimpleLink FS) on the CC3X00's file-system with a "/www/data/" or whatever prefix. A "/www/data/index.txt" could contain an integer telling you how many chunks there are in that path. Then you request "http://your-cc/data/1.txt" and 2.txt and so forth until you get them all, then concat and parse them on the client side. They'll be served up automatically from the "/www/" prefix by the NetApp thing. It's hack-ish, but could be done easily enough even with Javascript for XHR requests from an HTML page. That could be used to dynamically refresh a table on an HTML page without having to refresh the whole thing.

    As for JSON access, the best library I've come across for *parsing* JSON on the CC3200 and other embedded environments is http://zserge.com/jsmn.html
    For encoding JSON, I think it might just be easiest to do a bunch of sprintf's to some buffer and keep the structure simple. You'll probably want the buffer that writes to the chunked files to be smaller than 64KB since that's a big amount to allocate from only 256KB of RAM.

  • Hi
    I have a problem to put large numbers and strings in the token, the truth is not that I am wrong I tried everything and I see the failure ...

    I also wanted to ask if you can get decimal numbers eg 45.4


    SimpleLinkHttpServerCallback and use within

    if (memcmp (pHttpServerEvent-> EventData.httpTokenName.data,
    GET_token_TEMP, strlen ((char *) GET_token_TEMP)) == 0)
    {
    fCurrentTemp char;
    BMP085 (& fCurrentTemp);
    cTemp char = (char) fCurrentTemp;
    short sTempLen = itoa (cTemp, (char *) tokenValue);
    tokenValue [sTempLen ++] = '*';
    tokenValue [sTempLen] = 'C';
    pHttpServerResponse->ResponseData.token_value.len += sTempLen + 1;
    }

    This case appears without decimals temperature but rather the problem I have in wanting to send the token Pressure worth 101234 This value is good but not the whole page I created token replacement is "204" ...

    I hope you can help me because I'm desperate and have to be silly. Also congratulation this post helps a lot to understand the creation of the token
    thanks.
  • Hi,

    Can u please tell me where i can find this http server example which u went through and contains SimpleLinkHttpServerCallback() function,and what platform you are using for this example Energia or code composer studio?

    Thanks in advance.

  • Hi Ravula,

    Please see httpserver example in SDK (CC3200SDK_1.2.0\cc3200-sdk\example\httpserver\) for CCS or IAR. SDK you can download here www.ti.com/.../CC3200SDK and best kit for start development with CC3200 is www.ti.com/.../cc3200-LAUNCHXL

    Jan