CC3220SF-LAUNCHXL: Azure HTTP- GET/POST method

Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: CC3220SF
Hi,

1. I am trying to do HTTP/s based OTA - Update using Azure SDK. (Please suggest any other best way to perform OTA over Azure SDK).

Able to compile and run "simplesample_http" example from Azure sdk <C:\ti\azure_cc32xx_4_10_01_01\examples\rtos\CC3220SF_LAUNCHXL\azure\simplesample_http>.
 
Based on this example (IOTHUB_CLIENT_LL), Is it possible to perform HTTP GET / POST operation, so that I can download the binary from the Azure -cloud?
I mean looking for HTTPAPI_ExecuteRequest() equivalent API for  IOTHUB_CLIENT_LL.
Because of MOCKABLE API Not able to map the actual client API calls. Please give some reference to map azure MOCKABLE_FUNCTION APi to Actual HTTP / MQTT Client API.
   
  
2. Also, tried HTTP Client API direct accessing (from azure's httpapi_sl.c & httpapi.h). by taking the reference "uhttp" example code (C:\ti\azure_cc32xx_4_10_01_01\source\third_party\azure-iot-pal-simplelink\sdk\deps\uhttp\samples\uhttp_sample) 
But I am facing the "HTTPAPI_OPEN_REQUEST_FAILED".
  
Please find the code snippet below.
#define HTTP_PORT_NUM       80
#define HTTPS_PORT_NUM      443
#define TEST_SETOPTIONS_CERTIFICATE    (const unsigned char*)"blah!blah!blah!"
#define host_name (const char*)"i.imgur.com"
#define REQUEST_RELATIVE_PATH "/z4d4kWk.jpg"

typedef struct BUFFER_TAG* BUFFER_HANDLE;
typedef struct HTTP_HEADERS_HANDLE_DATA_TAG* HTTP_HEADERS_HANDLE;
typedef struct HTTP_HANDLE_DATA_TAG* HTTP_CLIENT_HANDLE;

static BUFFER_HANDLE TestBufferHandle;
static HTTP_HEADERS_HANDLE requestHttpHeaders;
static HTTP_HEADERS_HANDLE responseHttpHeaders;

static void createHttpObjects(HTTP_HEADERS_HANDLE* requestHttpHeaders, HTTP_HEADERS_HANDLE* responseHttpHeaders)
{
    /*assumed to never fail*/
    *requestHttpHeaders = HTTPHeaders_Alloc();
    *responseHttpHeaders = HTTPHeaders_Alloc();
    if (
        (*requestHttpHeaders == NULL) ||
        (*responseHttpHeaders == NULL)
        )
    {
        //ASSERT_FAIL("unable to build test prerequisites");
    }
}

static void test_http_get(void)
{
    int port_num = HTTP_PORT_NUM;
    HTTP_SAMPLE_INFO sample_info;
    sample_info.stop_running = 0;
    unsigned int statusCode = 0;    
    unsigned int minimumPollingTime = 9;
    int result;

    createHttpObjects(&requestHttpHeaders, &responseHttpHeaders);

    result = HTTPAPI_Init();
    Display_printf(display, 0, 0, "HTTPAPI_Init %d",result );

    HTTP_CLIENT_HANDLE http_handle = HTTPAPI_CreateConnection(host_name);

    if (http_handle == NULL)
    {
        Display_printf(display, 0, 0, "HTTPAPI_CreateConnection Failed");
    }
    else
    {
        Display_printf(display, 0, 0, "HTTPAPI_CreateConnection Success");

        //HTTPAPI_SetOption(http_handle, "TrustedCerts", TEST_SETOPTIONS_CERTIFICATE);
        HTTPAPI_SetOption(http_handle, "MinimumPollingTime", &minimumPollingTime);

        int retval = HTTPAPI_ExecuteRequest(http_handle, 
                                HTTPAPI_REQUEST_GET, 
                                REQUEST_RELATIVE_PATH, 
                                requestHttpHeaders, 
                                NULL, 
                                0, 
                                &statusCode,
                                responseHttpHeaders,
                                TestBufferHandle );
        if(retval != HTTPAPI_OK)          
        {
            Display_printf(display, 0, 0, "HTTPAPI_ExecuteRequest Failed.%d", retval); //Error >> retval = HTTPAPI_OPEN_REQUEST_FAILED
        }
        else
        {
            Display_printf(display, 0, 0, "HTTPAPI_ExecuteRequest Success.");
        }

        HTTPAPI_CloseConnection(http_handle);
        HTTPAPI_Deinit();
    }
}


void simplesample_http_run(void)
{
    if (platform_init() != 0)
    {
        Display_printf(display, 0, 0, "Failed to initialize the platform.");
    }
    else
    {
        if (serializer_init(NULL) != SERIALIZER_OK)
        {
            Display_printf(display, 0, 0, "Failed on serializer_init");
        }
        else
        {
            Display_printf(display, 0, 0, "Sending HTTP GET");
            test_http_get();
            serializer_deinit();
        }
		
        platform_deinit();
    }
}


 
This way can I perform HTTP calls? If Yes, Where I am missing please guide me to override "HTTPAPI_OPEN_REQUEST_FAILED".
 
 
 
Regards,
Suresh
  • Hi Suresh,

    Is there any additional debug output beyond the "HTTPAPI_OPEN_REQUEST_FAILED" return that you get?

    Looking through your sample code provided it should work, in theory.

    Alternatively, you can also use the httpget sample from the main CC32xx SDK for OTA purposes, which uses the TI-implemented HTTP library. Would that solution work for you?

    Regards,

    Michael

  • HI Michael,

    Thanks a lot for your response. 

    By default Azure examples working on TLS authentication, so because of communication certificates my sample code didn't work. Now my point 2 is working fine.

      

    My point 1 - (with MOCKABLE API) still I am not clear. I understand that, some of the MOCKABLE API's like IoTHubClient_LL_CreateFromConnectionString to establish MQTT/ HTTP protocol by using connection string.

     

    But, If I wanted to perform HTTP-GET operation with IOTHUB_CLIENT_LL, what will be the HTTPAPI_ExecuteRequest() equivalent MOCKABLE API and how I am going to select HTTP-Methods(POST / GET / DELETE etc).
    Please give help me to get more info.

    Regards,

    Suresh

  • Hi Suresh,

    Taking a look at the code architecture of the Azure SDK, at least within the components included in the CC32xx distribution there doesn't appear to be any obvious MOCKABLE API to perform a basic standalone HTTP request. This is most likely since the emphasis is on having the low level HTTP/MQTT be abstracted away for you, and have the focus be on your application interacting with the IoTHub. So while those IoTHub APIs can create an HTTP request, you cannot use it outside of that IoTHub context.

    It does seem like you will need to either use the underlying low-level HTTP APIs, or the TI-provided HTTP library for your use case.

    Also, for such in-depth questions on the Azure SDK APIs, I suggest you seek out Azure's support channels, as since it is a third-party library that they will have the most familiarity with.

    Regards,

    Michael