http.c
int m2x_create_device ( const char *api_key_ptr, const char *device_name_ptr,  char * ret_buffer )
{
    int ret = 0;

    if( doM2X ) {
        http_info_t post_req;
        char tmp_buff1[256], tmp_buff2[512];
        char url[256];
        time_t t = time(NULL);;
        struct tm *tm;

        memset(&post_req, 0, sizeof(http_info_t));
        memset(tmp_buff1, 0, sizeof(tmp_buff1));
        memset(tmp_buff2, 0, sizeof(tmp_buff2));
        memset(url, 0, sizeof(url));

        http_init(&post_req, 0);

        sprintf(url, "http://api-m2x.att.com/v2/devices" );
        sprintf(tmp_buff1, "X-M2X-KEY: %s", api_key_ptr);
        sprintf(tmp_buff2, "{ \"name\": \"Global Starter Kit\", \"serial\" : \"%s\", \"description\": \"Demo Device\", "
                             "\"tags\": \"QSTA\", \"visibility\":\"private\" }",  device_name_ptr);

        post_req.header = http_add_field(post_req.header, "Content-Type: application/json");
        post_req.header = http_add_field(post_req.header, tmp_buff1);
        post_req.data_field = http_add_field(post_req.data_field, tmp_buff2);

        ret = http_post(&post_req, url);
        if( post_req.rx_msglen >0) 
            strcpy(ret_buffer,post_req.rx_msg);
        http_deinit(&post_req);
        }
    return ret;
}
//
//=========================================================================
//
// This function is called to create a device
//
This function is called to create a device
This function is called to create a device
int m2x_create_device ( const char *api_key_ptr, const char *device_name_ptr,  char * ret_buffer )
{
    int ret = 0;
    if( doM2X ) {
        http_info_t post_req;
        char tmp_buff1[256], tmp_buff2[512];
        char url[256];
        time_t t = time(NULL);;
        struct tm *tm;
        memset(&post_req, 0, sizeof(http_info_t));
        memset(tmp_buff1, 0, sizeof(tmp_buff1));
        memset(tmp_buff2, 0, sizeof(tmp_buff2));
        memset(url, 0, sizeof(url));
        http_init(&post_req, 0);
        sprintf(url, "http://api-m2x.att.com/v2/devices" );
        sprintf(tmp_buff1, "X-M2X-KEY: %s", api_key_ptr);
        sprintf(tmp_buff2, "{ \"name\": \"Global Starter Kit\", \"serial\" : \"%s\", \"description\": \"Demo Device\", "
                             "\"tags\": \"QSTA\", \"visibility\":\"private\" }",  device_name_ptr);
        post_req.header = http_add_field(post_req.header, "Content-Type: application/json");
        post_req.header = http_add_field(post_req.header, tmp_buff1);
        post_req.data_field = http_add_field(post_req.data_field, tmp_buff2);
        ret = http_post(&post_req, url);
        if( post_req.rx_msglen >0) 
            strcpy(ret_buffer,post_req.rx_msg);
        http_deinit(&post_req);
        }
    return ret;
}
int m2x_create_device ( const char * api_key_ptr , const char * device_name_ptr , char * ret_buffer ) { int ret = 0 ; if ( doM2X ) { http_info_t post_req ; char tmp_buff1 [ 256 ] , tmp_buff2 [ 512 ] ; char url [ 256 ] ; time_t t = time ( NULL ) ; ; struct tm * tm ; memset ( & post_req , 0 , sizeof ( http_info_t ) ) ; memset ( tmp_buff1 , 0 , sizeof ( tmp_buff1 ) ) ; memset ( tmp_buff2 , 0 , sizeof ( tmp_buff2 ) ) ; memset ( url , 0 , sizeof ( url ) ) ; http_init ( & post_req , 0 ) ; sprintf ( url , " " ) ; sprintf ( tmp_buff1 , " " , api_key_ptr ) ; sprintf ( tmp_buff2 , " \" \" \" \" \" \" \" \" \" \" \" \" " " \" \" \" \" \" \" \" \" " , device_name_ptr ) ; post_req . header = http_add_field ( post_req . header , " " ) ; post_req . header = http_add_field ( post_req . header , tmp_buff1 ) ; post_req . data_field = http_add_field ( post_req . data_field , tmp_buff2 ) ; ret = http_post ( & post_req , url ) ; if ( post_req . rx_msglen > 0 ) strcpy ( ret_buffer , post_req . rx_msg ) ; http_deinit ( & post_req ) ; } return ret ; }
This function is called to create a device
This function is called to create a device