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 HTTP Server in Station Mode

Other Parts Discussed in Thread: CC3100, CC3200

Hi,

Here is what I want to do

1. Connect the CC3100 to my home wifi router

2. Access the data on the CC3100 to could server : https://dsp-clhprasanna.cloud.dreamfactory.com:443/rest/malnad/MonitoringInfo


The story so far

1. I tried the demo HTTP server applications in AP mode, where I can see the status if I have connected to Simplelink AP

2. I tried exosite, not able to get the data through.

Kindly guide me how can I use this on cloud server.

Thanks

Malnad

  • Hi Malnad,

    I recommend you check out the get_weather example provided with CC3200 and CC3100 SDKs. They show how you perform a Get request, which is what you will need to do to access a REST web service.

    I notice the service you are wanting to access delivers JSON data, you will then need to parse this data, so you can extract the bits you want. For JSON parsing, it would be helpful to use a library to assist, I have found the jsmn library works well with embedded systems, though there are many others available that may suit your needs.

    Glenn.

  • Dear Glenn,

                            Thanks for the information. I went through the get_weather, it helped. However how do I send the data like Voltage, Current to remote server. JSON parser helps to decode the data which is received from the server, but I actually want to put the data to the server from the device in JSON format.

    I'm not sure whether I'm making sense or doing something wrong. Is there any way of the sending the data to REST server easier way ?

    I'm using Dreamfactory+ MongoDb to store and process the data. I thought JSON might be easier way to send the diverse data to server, but not sure how to implement it on CC3100 +MSP430 platform.


    Thanks,

    Malnad

  • Hi Malnad,

    To send JSON data to the server you will need to perform a HTTP POST and not a HTTP GET, the POST is for sending data, the GET is for retrieving data.

    You can use the same example code, but when you create your header details, you will need to create a POST header. To see what it needs to look like, check out Martin's forum post here - http://e2e.ti.com/support/wireless_connectivity/f/968/p/359523/1262310.aspx#1262310

    All of this information is less related to the CC3100 and more related to HTTP Standards, so I recommend you spend some time reading up on the HTTP protocol and REST.

    Glenn.

  • It may be helpful to convert the JSON to CSV using json-csv.com

  • Edward Stewart said:
    It may be helpful to convert the JSON to CSV using json-csv.com

    I believe we have a spammer in the forum..hehe.

    Glenn.

  • Not at all - it could be an alternative for you instead of using the parser - but maybe I'm wrong.

  • Glenn,

                 I followed the forum post, I kind of got the idea on POST.  I'm not sure how to construct the POST header for the below.

    Below is the website details.

    https://dsp-clhprasanna.cloud.dreamfactory.com:443/rest/malnad/MonitoringInfo


    Example JSON Format for new record:
    {
        "record": [
            {
                "name": "name-here",
                "code": "code-here",
                "value": 200
            }
        ]
    }

    Can you please suggest how my buffer should look like ?, I know I'm asking you too much ..!
    Here is what I tried to do
    #define POST_BUFFER "POST rest/malnad/MonitoringInfo HTTP/1.1\r\n"
    #define POST_BUFFER2 "Host:  https://dsp-clhprasanna.cloud.dreamfactory.com\r\n\r\n"
    #define POST_BUFFER3 "userID:malnad&password:8123\r\n\r\n"
    #define POST_BUFFER4 " name: Malnad"
    #define POST_BUFFER5  " code: sagar"
    #define POST_BUFFER6  " value: 200"
    constructed the buffer and did the sl_send()
    what I'm doing wrong ?
    Malnad
  • Check out the first post in the other thread you posted in - http://e2e.ti.com/support/wireless_connectivity/f/968/t/359523.aspx

    Glenn.

  • Yeah, I followed that but that was not JSON. I was wondering what I'm missing. The content-type also I have added. some where the way I'm constructing the JSON query is wrong. since this is JSON data I'm POSTing, I'm not sure where do I insert that data in the string.

  • Hi Malnad,

    The actual data follows immediately after the Content-Length header (which I notice you have not included).

    This is from Martin's previous forum post I pointed you to:-

    POST /wiki/Spezial:Search HTTP/1.1
    Host: de.wikipedia.org
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 24
    search=Katzen&go=Artikel  <-----your json data would go here

    The questions you are asking have little to do with the CC3200, but are all standard protocol and C programming questions and as such I recommend you do some Internet searches to help you learn these essential skills. Knowledge in these key area is required for the task you have set your self.

    Another method to learn about the HTTP Protocol is to install a packet sniffer, for example Microsoft Network Monitor or Wireshark. Then while you are capturing packets sent by your computer, you can perform what you are attempting to do with a Web Browser and then view the network capture data. Once you find the relevant packet, you will be able to see exactly what it looks like.

    Glenn.

  • Dear Glenn, After your suggestions I learnt about Http methods. I have also installed the network sniffer to get a hand on protocol.

    Before I do anything on my server, I wanted to test it on sparfun data server, which is data.sparkfun.com

    below is my data stream 


    https://data.sparkfun.com/streams/MGGw9XdDNMs0QxRZ9EWG

    insert url:  https://data.sparkfun.com/input/MGGw9XdDNMs0QxRZ9EWG?private_key=nzz4MvnxlVhxXzbgRdo4&humidity=2.18&temp=11.57

    If you click on the above link, data will be inserted to my stream

    I tested the POST capability with Google postman. Below is the format I send from postman

    POST /input/9JJVzl4gQGhnzq1NNMdv?private_key=xzzaVWjR8MH1rMyBB8g7&Temp=6.57&humidity=28.61 HTTP/1.1
    Host: data.sparkfun.com
    Cache-Control: no-cache
    Content-Type: application/x-www-form-urlencoded

    I'm able to insert the data to the stream.

    Now, If I do the same thing on Eclipse + CC3100, no data is inserted. Also no response from sparkfun also. Even If I send the wrong format, it does not send the error. I was atleast expecting error from the server. I have feeling that something is wrong in my sl_send() and sl_recv().

    I have used #define WEATHER_SERVER  "data.sparkfun.com". I feel I'm very close and not able to figure out where I'm missing.  below is different strings I constructed to test. All I receive are few *********, that too there is a huge delay between sl_send() and sl_recv(), compared to google postman response.

    Test 3

    #define PREFIX_BUFFER "POST /input/MGGw9XdDNMs0QxRZ9EWG?private_key=nzz4MvnxlVhxXzbgRdo4&humidity=2.18&temp=11.57 HTTP/1.1\r\n"
    #define POST_BUFFER2 "Host: data.sparkfun.com\r\n"
    #define POST_BUFFER3 "Content-Type:application/x-www-form-urlencoded \r\n"
    #define POST_BUFFER4 "Content-Length: 25 \r\n"
    #define POST_BUFFER5 "humidity=2.18&temp=11.57"

     

    Test 2

    #define PREFIX_BUFFER "POST /input/MGGw9XdDNMs0QxRZ9EWG?private_key=nzz4MvnxlVhxXzbgRdo4&humidity=2.18&temp=11.57 HTTP/1.1\r\n"
    #define POST_BUFFER2 "Host: data.sparkfun.com\r\n"


    Test 1

    #define PREFIX_BUFFER "POST https://data.sparkfun.com/input/MGGw9Xd ... temp=11.57"

    Thanks

    Malnad

  • Hi Malnad, 

    were you able to make progress?

    I'm working on the same idea for CC3200 .. posting to data.sparkfun.com.

    First time working with HTTP POST for me!

    Dave

  • Malnad, I had some time to work on this today.

    I discovered some posts related to an open source project board that makes me hungry for a fruit pastry..

    The related posts disclosed a few tricks to posting on data.sparkfun.com

    Note my BOLD content below and mind the CRLF order.

    Good Luck!

    #define PREFIX_BUFFER "POST /input/yourpublickey.txt HTTP/1.1\r\n"

    #define POST_BUFFER1 "Phant-Private-Key: yourprivatekey\r\nHost: data.sparkfun.com\r\n"

    #define POST_BUFFER2 "Connection: close\r\nContent-Type: application/x-www-form-urlencoded\r\n"

    #define POST_BUFFER3 "Content-Length: 42\r\n\r\n"

    #define POST_BUFFER4 "detection_event=apocolypse&time_of_day=now\r\n\r\n"

    I learned that I needed an empty line before the body which appears to be HTTP specific and add ".txt" to the header which was a bit of a surprise.

    You should be able to take my example, load that into the buffer in the "get_weather" example (be sure to change the URL global to data.sparkfun.com as well)  and see if you have some better success.

    If anyone cares to comment on the ".txt" requirement (is it specific to Sparkfun), 'm still learning the subtleties of HTTP.

    Good Luck to all,

    DB 

  • Hi David,

                     Thanks a ton, this really works. Sparkfun has little subtleties that I was making some mistakes in it.

    I'm really really really thankful to you, you made my day.

    Cheers,

    Malnad

  • Hi David,


    Do you know if data.sparkfun.com supports posting with chunked data encoding? I can see that their server responds with a chunked data post, but I don't know if I can post with it.

    Thanks,

    Markus

  • Markus,

    Sorry, I don't know the answer.

    Dave

  • Looks like it does. Got it finally to work (after having given up for a day...) Just replaced Content-Length with Transfer-Encoding: chunked, and then modified the body to match the proper format.

  • Hi malnad sagar,am facing the same problems as u got.I ll be really thank full if u e mail me your code(only main.c-code) .  email ID-"pradeep.channagiri@gmail.com"

  • I worked on your given example.But i get an error as-"The server returned an invalid or incomplete response".

    and i have a big confusion in finding the content length.

    How to decide the content length? pls help.

    thank you,

    pradeep.channagiri

  • Hi Pradeep,

                           can you describe your problem and your POST query.

    Malnad