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.

CCS/CC3220S-LAUNCHXL: http and https client sample codes utilizing the latest simplelink SDK 1.60.00.04 http client library

Part Number: CC3220S-LAUNCHXL
Other Parts Discussed in Thread: CC3220S, TMP006, UNIFLASH, CC3220SF

Tool/software: Code Composer Studio

Hi,

Could you please provide a http and https client sample codes and or step-by-step details of importing a CC3220 http client sample code utilizing the latest simplelink SDK 1.60.00.04 http client library to get it to run with my Code Composer Studio 7.4.0 and CC3220S launchpad?

I have followed several threads regarding this http client demo code and even read responses to the latest v1.6.0 sdk but there are no clear complete explanations how to go about using the new lib to create a http client and then create from that a https client.

regards,

Antolin

  • Hi Antolin,

    Try this example. Be aware that this is NOT an official example and there will be an official example released in the next quarterly SDK release. This will also include updates to the http client library, so you will want to update based on the official release when it is available.

    Best Regards,

    Ben M

    httpget.c

  • Hi Benjamin,

    Thanks for the caveats and another question is : can I use the "portable + wifi" example steps to create the TI-RTOS for the http client file you are sharing?

    -Antolin-

  • Hi Antolin,

    Actually, try using this platform.c file as the basis for the Wi-Fi handlers and the main thread. Then you should be able to base it off of just the portable example as long as you add the necessary libraries in.

    Best Regards,

    Ben M 

    platform.c

  • Hi Ben,

    Thanks for the pointer, and which libraries do we need to add?

    regards,
    Antolin
  • Anolin,

    It relies on slnetsock_release, slnetifwifi, httpclient, and simplelink libraries. The TI-DRIVERs build should already be there. As is, you will want the display driver, but this can be adjusted to use whichever printing mechanism you prefer.

    Best Regards,
    Ben M
  • hi Ben,

    I included the paths as best I can but I got the following errors at the end, might just be something simple I'm missing, thanks  in advance


    **** Build of configuration Debug for project portable_CC3220S_LAUNCHXL_tirtos_ccs ****

    "C:\\ti\\ccsv7\\utils\\bin\\gmake" -k -j 4 all -O

    'Building file: "../httpget.c"'
    'Invoking: ARM Compiler'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me --include_path="/source/ti/net/httpclient" --include_path="/source/ti/drivers/net/wifi" --include_path="/source/ti/drivers/net/wifi/slnetif" --include_path="C:/Users/Antolin/workspace_v7/portable_CC3220S_LAUNCHXL_tirtos_ccs" --include_path="C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source/ti/posix/ccs" --include_path="C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/include" --define=CC32XX --define=ONBOARD_TMP006 -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --preproc_with_compile --preproc_dependency="httpget.d_raw" --cmd_file="C:/Users/Antolin/workspace_v7/tirtos_builds_CC3220S_LAUNCHXL_release_ccs/Debug/configPkg/compiler.opt" "../httpget.c"
    'Finished building: "../httpget.c"'

    'Building file: "../CC3220S_LAUNCHXL.c"'
    'Invoking: ARM Compiler'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me --include_path="/source/ti/net/httpclient" --include_path="/source/ti/drivers/net/wifi" --include_path="/source/ti/drivers/net/wifi/slnetif" --include_path="C:/Users/Antolin/workspace_v7/portable_CC3220S_LAUNCHXL_tirtos_ccs" --include_path="C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source/ti/posix/ccs" --include_path="C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/include" --define=CC32XX --define=ONBOARD_TMP006 -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --preproc_with_compile --preproc_dependency="CC3220S_LAUNCHXL.d_raw" --cmd_file="C:/Users/Antolin/workspace_v7/tirtos_builds_CC3220S_LAUNCHXL_release_ccs/Debug/configPkg/compiler.opt" "../CC3220S_LAUNCHXL.c"
    'Finished building: "../CC3220S_LAUNCHXL.c"'

    'Building file: "../platform.c"'
    'Invoking: ARM Compiler'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me --include_path="/source/ti/net/httpclient" --include_path="/source/ti/drivers/net/wifi" --include_path="/source/ti/drivers/net/wifi/slnetif" --include_path="C:/Users/Antolin/workspace_v7/portable_CC3220S_LAUNCHXL_tirtos_ccs" --include_path="C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source/ti/posix/ccs" --include_path="C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/include" --define=CC32XX --define=ONBOARD_TMP006 -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --preproc_with_compile --preproc_dependency="platform.d_raw" --cmd_file="C:/Users/Antolin/workspace_v7/tirtos_builds_CC3220S_LAUNCHXL_release_ccs/Debug/configPkg/compiler.opt" "../platform.c"
    'Finished building: "../platform.c"'

    'Building target: "portable_CC3220S_LAUNCHXL_tirtos_ccs.out"'
    'Invoking: ARM Linker'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me --define=CC32XX --define=ONBOARD_TMP006 -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on -z -m"portable_CC3220S_LAUNCHXL_tirtos_ccs.map" -i"C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source/ti/drivers/net/wifi/ccs/rtos" -i"C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/lib" -i"C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source" -i"C:/ti/simplelink_cc32xx_sdk_1_60_00_04/kernel/tirtos/packages" -i"C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/include" --reread_libs --diag_wrap=off --display_error_number --warn_sections --xml_link_info="portable_CC3220S_LAUNCHXL_tirtos_ccs_linkInfo.xml" --rom_model -o "portable_CC3220S_LAUNCHXL_tirtos_ccs.out" "./CC3220S_LAUNCHXL.obj" "./httpget.obj" "./platform.obj" "../CC3220S_LAUNCHXL_TIRTOS.cmd" -l"C:/Users/Antolin/workspace_v7/tirtos_builds_CC3220S_LAUNCHXL_release_ccs/Debug/configPkg/linker.cmd" -l"ti/display/lib/display.aem4" -l"ti/drivers/lib/drivers_cc32xx.aem4" -l"third_party/fatfs/lib/fatfs.aem4" -l"ti/dpl/lib/dpl_cc32xx.aem4" -l"ti/devices/cc32xx/driverlib/ccs/Release/driverlib.a" -llibc.a -l"ti/drivers/net/wifi/ccs/rtos/simplelink.a"
    <Linking>

    undefined first referenced
    symbol in file
    --------- ----------------
    main C:\ti\ccsv7\tools\compiler\ti-cgt-arm_16.9.7.LTS\lib\rtsv7M4_T_le_eabi.lib<args_main.obj>

    error #10234-D: unresolved symbols remain
    error #10010: errors encountered during linking; "portable_CC3220S_LAUNCHXL_tirtos_ccs.out" not built

    >> Compilation failure
    makefile:154: recipe for target 'portable_CC3220S_LAUNCHXL_tirtos_ccs.out' failed
    gmake[1]: *** [portable_CC3220S_LAUNCHXL_tirtos_ccs.out] Error 1
    makefile:147: recipe for target 'all' failed
    gmake: *** [all] Error 2

    **** Build Finished ****

  • Hi Ben,

    I fixed the above errors by editing and adding back the main_tirtos.c file and referencing the mainThread() that is an extern called from platform.c ( commenting out irrelevant threads: console and temperature)

    but after that fix, I'm getting the following errors at the bottom part, please see last part

    //=================================================================


    **** Clean-only build of configuration Debug for project portable_CC3220S_LAUNCHXL_tirtos_ccs ****

    "C:\\ti\\ccsv7\\utils\\bin\\gmake" -k -j 4 clean -O

    DEL /F "portable_CC3220S_LAUNCHXL_tirtos_ccs.bin" "portable_CC3220S_LAUNCHXL_tirtos_ccs.out"
    DEL /F "CC3220S_LAUNCHXL.obj" "httpget.obj" "platform.obj"
    DEL /F "CC3220S_LAUNCHXL.d" "httpget.d" "platform.d"
    Could Not Find C:\Users\Antolin\workspace_v7\portable_CC3220S_LAUNCHXL_tirtos_ccs\Debug\portable_CC3220S_LAUNCHXL_tirtos_ccs.bin
    Could Not Find C:\Users\Antolin\workspace_v7\portable_CC3220S_LAUNCHXL_tirtos_ccs\Debug\CC3220S_LAUNCHXL.obj
    Could Not Find C:\Users\Antolin\workspace_v7\portable_CC3220S_LAUNCHXL_tirtos_ccs\Debug\CC3220S_LAUNCHXL.d
    'Finished clean'

    **** Build Finished ****

    **** Build of configuration Debug for project portable_CC3220S_LAUNCHXL_tirtos_ccs ****

    "C:\\ti\\ccsv7\\utils\\bin\\gmake" -k -j 4 all -O

    'Building file: "../httpget.c"'
    'Invoking: ARM Compiler'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me --include_path="/source/ti/net/httpclient" --include_path="/source/ti/drivers/net/wifi" --include_path="/source/ti/drivers/net/wifi/slnetif" --include_path="C:/Users/Antolin/workspace_v7/portable_CC3220S_LAUNCHXL_tirtos_ccs" --include_path="C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source/ti/posix/ccs" --include_path="C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/include" --define=CC32XX --define=ONBOARD_TMP006 -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --preproc_with_compile --preproc_dependency="httpget.d_raw" --cmd_file="C:/Users/Antolin/workspace_v7/tirtos_builds_CC3220S_LAUNCHXL_release_ccs/Debug/configPkg/compiler.opt" "../httpget.c"
    'Finished building: "../httpget.c"'

    'Building file: "../CC3220S_LAUNCHXL.c"'
    'Invoking: ARM Compiler'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me --include_path="/source/ti/net/httpclient" --include_path="/source/ti/drivers/net/wifi" --include_path="/source/ti/drivers/net/wifi/slnetif" --include_path="C:/Users/Antolin/workspace_v7/portable_CC3220S_LAUNCHXL_tirtos_ccs" --include_path="C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source/ti/posix/ccs" --include_path="C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/include" --define=CC32XX --define=ONBOARD_TMP006 -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --preproc_with_compile --preproc_dependency="CC3220S_LAUNCHXL.d_raw" --cmd_file="C:/Users/Antolin/workspace_v7/tirtos_builds_CC3220S_LAUNCHXL_release_ccs/Debug/configPkg/compiler.opt" "../CC3220S_LAUNCHXL.c"
    'Finished building: "../CC3220S_LAUNCHXL.c"'

    'Building file: "../main_tirtos.c"'
    'Invoking: ARM Compiler'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me --include_path="/source/ti/net/httpclient" --include_path="/source/ti/drivers/net/wifi" --include_path="/source/ti/drivers/net/wifi/slnetif" --include_path="C:/Users/Antolin/workspace_v7/portable_CC3220S_LAUNCHXL_tirtos_ccs" --include_path="C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source/ti/posix/ccs" --include_path="C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/include" --define=CC32XX --define=ONBOARD_TMP006 -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --preproc_with_compile --preproc_dependency="main_tirtos.d_raw" --cmd_file="C:/Users/Antolin/workspace_v7/tirtos_builds_CC3220S_LAUNCHXL_release_ccs/Debug/configPkg/compiler.opt" "../main_tirtos.c"
    'Finished building: "../main_tirtos.c"'

    'Building file: "../platform.c"'
    'Invoking: ARM Compiler'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me --include_path="/source/ti/net/httpclient" --include_path="/source/ti/drivers/net/wifi" --include_path="/source/ti/drivers/net/wifi/slnetif" --include_path="C:/Users/Antolin/workspace_v7/portable_CC3220S_LAUNCHXL_tirtos_ccs" --include_path="C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source/ti/posix/ccs" --include_path="C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/include" --define=CC32XX --define=ONBOARD_TMP006 -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on --preproc_with_compile --preproc_dependency="platform.d_raw" --cmd_file="C:/Users/Antolin/workspace_v7/tirtos_builds_CC3220S_LAUNCHXL_release_ccs/Debug/configPkg/compiler.opt" "../platform.c"
    'Finished building: "../platform.c"'

    'Building target: "portable_CC3220S_LAUNCHXL_tirtos_ccs.out"'
    'Invoking: ARM Linker'
    "C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=vfplib -me --define=CC32XX --define=ONBOARD_TMP006 -g --diag_warning=225 --diag_warning=255 --diag_wrap=off --display_error_number --gen_func_subsections=on -z -m"portable_CC3220S_LAUNCHXL_tirtos_ccs.map" -i"C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source/ti/drivers/net/wifi/ccs/rtos" -i"C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/lib" -i"C:/ti/simplelink_cc32xx_sdk_1_60_00_04/source" -i"C:/ti/simplelink_cc32xx_sdk_1_60_00_04/kernel/tirtos/packages" -i"C:/ti/ccsv7/tools/compiler/ti-cgt-arm_16.9.7.LTS/include" --reread_libs --diag_wrap=off --display_error_number --warn_sections --xml_link_info="portable_CC3220S_LAUNCHXL_tirtos_ccs_linkInfo.xml" --rom_model -o "portable_CC3220S_LAUNCHXL_tirtos_ccs.out" "./CC3220S_LAUNCHXL.obj" "./httpget.obj" "./main_tirtos.obj" "./platform.obj" "../CC3220S_LAUNCHXL_TIRTOS.cmd" -l"C:/Users/Antolin/workspace_v7/tirtos_builds_CC3220S_LAUNCHXL_release_ccs/Debug/configPkg/linker.cmd" -l"ti/display/lib/display.aem4" -l"ti/drivers/lib/drivers_cc32xx.aem4" -l"third_party/fatfs/lib/fatfs.aem4" -l"ti/dpl/lib/dpl_cc32xx.aem4" -l"ti/devices/cc32xx/driverlib/ccs/Release/driverlib.a" -llibc.a -l"ti/drivers/net/wifi/ccs/rtos/simplelink.a"
    <Linking>

    undefined first referenced
    symbol in file
    --------- ----------------
    HTTPClient_connect ./httpget.obj
    HTTPClient_create ./httpget.obj
    HTTPClient_destroy ./httpget.obj
    HTTPClient_disconnect ./httpget.obj
    HTTPClient_readResponseBody ./httpget.obj
    HTTPClient_sendRequest ./httpget.obj
    HTTPClient_setHeader ./httpget.obj
    HTTP_METHOD_GET ./httpget.obj
    SlNetIfConfigWifi ./platform.obj
    SlNetIf_add ./platform.obj
    SlNetIf_init ./platform.obj
    SlNetSock_init ./platform.obj
    SlNetUtil_init ./platform.obj

    error #10234-D: unresolved symbols remain
    error #10010: errors encountered during linking; "portable_CC3220S_LAUNCHXL_tirtos_ccs.out" not built

    >> Compilation failure
    makefile:155: recipe for target 'portable_CC3220S_LAUNCHXL_tirtos_ccs.out' failed
    gmake[1]: *** [portable_CC3220S_LAUNCHXL_tirtos_ccs.out] Error 1
    makefile:148: recipe for target 'all' failed
    gmake: *** [all] Error 2

    **** Build Finished ****

    //=================================================================

    regards,

    Antolin

  • hi I've posted my latest linker related errors after adding the libraries, please look at my latest errors posting at bottom
  • Hi Anotlin,

    Looks like you are still missing some of the libraries in you linker settings. Check to make sure you have these included in Properties->Build->ARM Linker->File Search Path:

    * httpclient.a (from source/ti/net/httpclient/ccs/Release)

    * slnetsock_release.a (from source/ti/net/lib/ccs/m4)

    * slnetifwifi.a (from source/ti/drivers/net/wifi/slnetif/ccs/Release)

    Refer to screenshot below (note that in the screenshot the path is split between the library search path and the library file):

  • Hi Ben,

     thanks for the additional info above and how do I change the C files you provided to target and work as a basic https client? 

    -Antolin-

  • Hi Antolin,

    I'm not sure I understand the question. Please confirm that the example above is running correctly (i.e. GET action succeeds and the data is printed to the console).

    Best Regards,
    Ben M
  • Hi Ben,

    How do I see the print out from the Display_printf() functions? 

    I tried opening several of the CCS consoles but I see none of the output messages?

    -Antolin-

  • Hi Antolin,

    This should print to a serial terminal through the UART just like UART_PRINT.

    Best Regards,
    Ben M
  • Thanks Ben,
    I got my Putty hooked up to COM4 where the Launchpad showed up and at 115kbaud 8 bits no parity, the basic http client is getting a response from httpbin.org

    my next question is:

    How do you to enable the https client connectivity? -- a basic one that uses the https:// but no certificates?
  • Hi Antolin,

    You should be able to enable HTTPS by doing the following things -

    1. Change the HOSTNAME to something with https, for example:

    #define HOSTNAME              "https://www.example.com"

    2. Create an instance of HTTPClient_extSecParams, for example:

    HTTPClient_extSecParams httpClientSecParams;

    3. You should verify the server, so set the rootCa element of your HTTPClient_extSecParams to the file name of the root CA on the device file system and make sure the unused fields (clientCert/privateKey) are set to NULL, for example:

    httpClientSecParams.rootCa = "ca.der";
    httpClientSecParams.clientCert = NULL;
    httpClientSecParams.privateKey = NULL;

    5. Update the HTTPClient_connect() call to use the security parameters, for example:

    HTTPClient_connect(httpClientHandle, HOSTNAME, &httpClientSecParams, 0);


    Note that this requires you to program the server Root CA to the file system using a tool like UniFlash. For this example, the file is added with the name "ca.der".


    Best Regards,

    Ben M

  • Hi Ben,

    I have further question on the cert file, its appreciated if you can give advice

    1) do the cert file need to save into specific folder?
    2) if i need to file the cert to a folder, is it i just put the file name together with the path,
    eg, i save the file in folder, serverA, i should save the file name as below?

    httpClientSecParams.rootCa = "serverA/ca.der";

    3) if i have assigned the file name of rootCa successfully, is the SlNetSock library would load the cert from file system directly?

    4) beside the UniFlash, is it support to create the cert file using fs library?
    i am using ccs7 in deubg mode with fs library, its able to open, read and wirte file during debugging. However, i am not able to review the created file using UniFlash. It seems the file is deleted once exit debug mode.

    Thanks

    Nick

    Nicky

  • Hi Nick,

    1) No, the cert file does not need to be in specific folder. You can put it in a folder of your choosing.
    2) Yes, you prepend the folder name to the file name. However, you'll want it to look like this "/serverA/ca.der".
    3) Yes, the netsock library will call the SimpleLink Wi-Fi API for assigning that file name as the CA file for the socket (underlying call is sl_SetSockOpt()). Then when the connection attempt is made, the network processor will access the file based on the file name given to verify the server cert chain.
    4) Yes, you can also use the file system (fs) commands to write the file using your application. This is how the file would be updated over time on the system. If you create the file this way, you should be able to access the file through UniFlash by connecting to the device and selecting "User File Browser". Once the file system is shown, you can use the "Get File" option to save the file. This requires the system to be in Development mode though because access to the file system is locked out in Production mode as a security measure. For a secured file, you will have to provide the necessary token to be able to read it and save it on your computer.

    Best Regards,
    Ben M
  • Also note that you should set the device time to the current date when using secure sockets (i.e. HTTPS client). The time will be needed for verifying the validity of the server certs.

    Best Regards,
    Ben M
  • Ben

    thanks for the reply

    Q4)
    I tested the file system based on the network terminal trrtos version. When using UniFlash, i can only find the default files of network terminal project such as cert, .bin.

    when i user sl_FsGetFileList(), i can see the new created files from the list.

    Regards

    Nicky

  • Hello Benjamin,

                I have tried this httpget code given by you and it is working fine . I also want to post the data from CC3220SF to server.

                I am setting http header -  "Content-type = "application/json" . However I am getting error - 400 - bad request.

                Kindly let me know what changes do I have to make in httpget.c  code to post the data and also information required from my side.

    Regards,

    Omkar

  • hi Ben,
    A couple of questions:
    the code changes you specified compile the modified http client into the https client without error
    but
    it is not connecting to https://httpbin.org

    How do I use the default dummy-ca-cert.der file already in the cc3220s launchpad?
    and
    do I need to generate the ca.der file you refer to? how to do that and do you have a link to show how to put that into the cc3220s ?

    thanks,
    Antolin
  • Hi Nicky,

    Since this question is not related to the http client library, can you open a new thread to discuss it? We will look for the new post and make sure it gets answered.

    Thanks,

    Ben M

  • Hi Antolin,

    Please refer to Table 6-2 in the CC3220 Network Processor Programmers guide for a description of the Root CA file from the perspective of a client device -

    http://www.ti.com/lit/ug/swru455d/swru455d.pdf

    This will be the peer's Root CA certificate. The dummy CA file will not work because it is an example file and not an actual CA. You do not need to generate the CA file. You need to find the one used by httpbin.org, download it, and program it to the CC3220 file system using UniFlash Image Creator. There is a guide on how to add a User File to the file system using UniFlash ImageCreator here:

    http://www.ti.com/lit/ug/swru469a/swru469a.pdf

    There are multiple tools that can be used to get the Root Ca, one example for how to do this is ssltools.com. However, a best practice is to try to connect and check the common name returned through the asynchronous socket event handler for the SL_SSL_NOTIFICATION_WRONG_ROOT_CA case.

    Best Regards,

    Ben M

  • hi Ben,

    I'm getting the following errors after following those steps:

    Connecting to : Anova Private.

    Sending a HTTP GET request to 'https://httpbin.org'

    Error! code = -456, desc = httpTask: connect failed


    -Antolin-
  • Hi Antolin,

    Error -456 indicates that the CA file used during the connect is bad. Possibly because the name the file was given when it was programmed to the flash does not match what was indicated to the socket, or because the file is not a valid PEM/DER file, or lastly because it is the wrong root CA file.

    Please see section 6.7.2 of the CC3220 Network Processor Programmers Guide -

    http://www.ti.com/lit/ug/swru455e/swru455e.pdf

    Best Regards,

    Ben M

  • hi Ben,
    perhaps do I need to copy both the .der and .pem from the peer (ie server which is httpbin.org) ?

    here is the code snippets relating to the steps, I've copied the .der file into the user area :

    /*
    * ======== httpget.c ========
    * HTTP Client GET example application
    */

    /* BSD support */
    #include "string.h"
    #include <ti/display/Display.h>
    #include <ti/net/httpclient/httpclient.h>
    #include "semaphore.h"


    #define HOSTNAME "https://httpbin.org"
    #define REQUEST_URI "/get"
    #define USER_AGENT "HTTPClient (ARM; TI-RTOS)"

    extern Display_Handle display;
    extern sem_t ipEventSyncObj;
    extern void printError(char *errString, int code);

    /*
    * ======== httpTask ========
    * Makes a HTTP GET request
    */
    void* httpTask(void* pvParameters)
    {
    bool moreDataFlag = false;
    char data[256];
    int16_t ret = 0;
    int16_t len = 0;
    sem_wait(&ipEventSyncObj);
    Display_printf(display, 0, 0, "Sending a HTTPS GET request to '%s'\n",
    HOSTNAME);

    HTTPClient_Handle httpClientHandle;
    int16_t statusCode;

    // https enabling
    HTTPClient_extSecParams httpClientSecParams;

    httpClientSecParams.rootCa = "dst-root-ca-x3.der"; //"dummy-ca-cert.der";
    httpClientSecParams.clientCert = NULL;
    httpClientSecParams.privateKey = NULL;

    httpClientHandle = HTTPClient_create(&statusCode,0);
    if (statusCode < 0)
    {
    printError("httpTask: creation of http client handle failed", ret);
    }

    ret = HTTPClient_setHeader(httpClientHandle, HTTPClient_HFIELD_REQ_USER_AGENT,USER_AGENT,strlen(USER_AGENT),HTTPClient_HFIELD_PERSISTENT);
    if (ret < 0) {
    printError("httpTask: setting request header failed", ret);
    }

    //ret = HTTPClient_connect(httpClientHandle,HOSTNAME,0,0);
    // https enabling
    //Update the HTTPClient_connect() call to use the security parameters
    ret = HTTPClient_connect(httpClientHandle, HOSTNAME, &httpClientSecParams, 0);
    if (ret < 0) {
    printError("httpTask: connect failed", ret);
    }
    ret = HTTPClient_sendRequest(httpClientHandle,HTTP_METHOD_GET,REQUEST_URI,NULL,0,0);
    if (ret < 0) {
    printError("httpTask: send failed", ret);
    }

    if (ret != HTTP_SC_OK) {
    printError("httpTask: cannot get status", ret);
    }

    Display_printf(display, 0, 0, "HTTP Response Status Code: %d\n", ret);

    len = 0;
    do {
    ret = HTTPClient_readResponseBody(httpClientHandle, data, sizeof(data), &moreDataFlag);
    if (ret < 0) {
    printError("httpTask: response body processing failed", ret);
    }
    Display_printf(display, 0, 0, "%.*s \r\n",ret ,data);
    len += ret;
    }while (moreDataFlag);

    Display_printf(display, 0, 0, "Received %d bytes of payload\n", len);

    ret = HTTPClient_disconnect(httpClientHandle);
    if (ret < 0)
    {
    printError("httpTask: disconnect failed", ret);
    }

    HTTPClient_destroy(httpClientHandle);
    return(0);
    }
  • do you have a .der and .pem files you can share to test with a known good https website?

    -Antolin-
  • Hi Antolin,

    The file for httpbin.org that I pulled from ssltools.com seems to work. This is not a guaranteed method for acquiring all root certs, but it does seem fine in this case. Similarly, the default http://www.example.com/ can be used with https and you should be able to find the root for it the same way.

    Best,
    Ben M

  • Ben,
    I'm still getting that same error I mentioned and
    I changed the url to: https://www.example.com and then used the ssltools.com to download the cert as a .der and specified it simply as "ca.der" file.
    I saved the ca.der file under the "/" using uniflash and clicking "add"

    Is there a path to this file I need to specify?
  • Hi Antolin,

    These steps are correct. You do not need to add anything else to the specified file path. Please make sure you also set the device time to the current date and time using sl_DeviceSet().

    Best Regards,
    Ben M
  • hi Ben,

    Does sl_DeviceSet() need to be called before the HTTPClient_setHeader() function?
    Does it have certain parameters that need to be set?
    Any values returned that need saving? assigning to some other functions?

    regards,
    -Antolin-
  • Should be fine as long as it is called after the network processor is started and before the HTTPClient_connect() call.
    There is an example of using it to set the device time in the doxygen. Open up <SDK Install Location>/docs/wifi_host_driver_api/index.html and look at Modules->Device->sl_DeviceSet.

    Best Regards,
    Ben M
  • hi Ben,

    I placed the code in the platform.c file and the code snippet looks like below:
    void mainThread(void *pvParameters)
    {
    int32_t status = 0;
    pthread_attr_t pAttrs_spawn;
    pthread_attr_t pAttrs;
    struct sched_param priParam;
    int32_t mode;
    int16_t ret;

    SlDateTime_t dateTime= {0};
    dateTime.tm_day = (_u32)7; // Day of month (DD format) range 1-31
    dateTime.tm_mon = (_u32)3; // Month (MM format) in the range of 1-12
    dateTime.tm_year = (_u32)2018; // Year (YYYY format)
    dateTime.tm_hour = (_u32)18; // Hours in the range of 0-23
    dateTime.tm_min = (_u32)6; // Minutes in the range of 0-59
    dateTime.tm_sec = (_u32)22; // Seconds in the range of 0-59

    sl_DeviceSet(SL_DEVICE_GENERAL,
    SL_DEVICE_GENERAL_DATE_TIME,
    sizeof(SlDateTime_t),
    (_u8 *)(&dateTime));

    SPI_init();
    ...

    but now I'm getting an error that says:

    Connecting to : Anova Private.

    Sending a HTTPS GET request to 'https://httpbin.org'

    Error! code = -2050, desc = Connection failed , error code : %d


    -Antolin-
  • Hi Antolin,

    You can find the error codes in the "errors.h" file of simplelink host driver (<SDK Install Location>/source/ti/drivers/net/wifi/errors.h). Error (-2050) indicates that the device is in the incorrect role, possibly the role was changed by another application and not set back to station. 

    To eliminate this issue, you can add code to make sure the device is in the station role before running the rest of the demo. For example:

    int32_t             ret = -1;
    int32_t             mode = -1;
    
        /* If the device is not in STA mode, try configuring it in STA mode
         in case device is already started (got SL_RET_CODE_DEV_ALREADY_STARTED error code), then mode would remain -1 and in this case we do not know the role. Move to STA role anyway */
    if (ROLE_STA != mode)
    {
       /* Switch to STA role and restart */
       ret = sl_WlanSetMode(ROLE_STA);
    
       ret = sl_Stop(100);
    
       ret = sl_Start(0, 0, 0);
    
       /* Check if the device is in STA again */
       if (ROLE_STA != ret)
       {
          printError("Failed to set device in STA role, %d", ret);
       }
    }

    Best Regards,
    Ben M

  • hi Ben,

    I'm getting the following error:

    Error! code = 2, desc = Failed to set device in STA role, %d
    after putting the above code lines in platform.c in the connect() function.

    Could you please post and send a copy of your working code, thanks as we're out of time on this and we need the https client working.
    please include the changes to the platform.c and httpget.c that made it work for you, thanks
  • Hi Antolin,

    The fix should be as simple as making sure the device is started (sl_Start(0,0,0)) before calling the code shown in the previous post.

    Code 2 printed in the error indicates the device is still in AP mode. It is most likely that the call to set the device to station mode failed because the network processor was not started before that command was run.

    To verify if this was the issue, check the return codes from the sl_WlanSetMode() and sl_Stop() calls. They will return an error stating that the device is not started if that was the issue.

    Best Regards,
    Ben M
  • hi Ben,

    I'm getting a new error after correcting the above:

    Connecting to : Anova Private.

    Sending a HTTPS GET request to 'https://httpbin.org'

    Error! code = -380, desc = httpTask: connect failed

    The corrected code changes in platform.c are the following (right after where the httpTask thread gets created):

      status = pthread_create(&httpThread, &pAttrs, httpTask, NULL);
      if(status)
      {
        printError("Task create failed, error code : %d \r\n", status);
      }
      /* initialize the device */
      mode = sl_Start(0, 0, 0);
      if (mode < 0)
      {
        printError("Sl_start failed, error code : %d \r\n", status);
      }

      /* If the device is not in STA mode, try configuring it in STA mode
      in case device is already started (got SL_RET_CODE_DEV_ALREADY_STARTED error code), then mode would remain -1 and in this case we do not   know the role. Move to STA role anyway */

      if (ROLE_STA != mode)
      {
        /* Switch to STA role and restart */
        ret = sl_WlanSetMode(ROLE_STA);

        ret = sl_Stop(100);

        ret = sl_Start(0, 0, 0);

        /* Check if the device is in STA again */
        if (ROLE_STA != ret)
        {
          printError("Failed to set device in STA role, %d", ret);
        }
      }

      Connect();
    }

    Any ideas?  what else is missing do you think? 


    -Antolin-

  • Hi Antolin,

    Where you have the code to configure the role and connect to the local network should be fine because the httpTask will pend on semaphore until the device acquires an IP address, but the way I did it was to have that before I create the httpTask.

    Attached is my latest platform.c and httpget.c for your reference (note that not all of the configuration in ConfigureSimpleLinkToDefaultState() is needed).

    Are you testing on a corporate network?

    Best Regards,

    Ben M

    platform.c

    httpget.c

  • hi Ben,

    Thanks for the files and I'll try them out.

    yes I'm testing in a corporate network( I put in the password in previous platform.c in the plain http client and it connected - verified that connects).

    regards,

    Antolin

  • hi Ben,

    Thanks, the code works!

    and

    I would like to add that the user has to click "Connect" to connect to the cc3220s/sf launchpad and the right-hand side "User file folder" has to be used and that's where the ca.der file has to be saved into, [otherwise if you use the one on the left-hand side, it doesn't get seen ]

  • Hi

    I also got the bad request error when get data from https server

    I taraced the code and the cert name  is succesfully port to httpclient_handle when first creat and connect. Then I call sendrequest, it will autoconnect to the server again I found the sec value is change.

    Please see if you have idra on this issue

    Regards

    Nicky

  • Hi Nicky,

    Please confirm what server you are using and if you are performing the default get request. Please also share how you are seeing the "auto-connect" to server with the security value changed.

    Thanks,

    Ben M