http.c
int m2x_update_stream_value ( const char *device_id_ptr, const char *api_key_ptr, const char *stream_name_ptr, const char *stream_value_ptr)
{
    int ret = 0;

    if( doM2X ) {
        http_info_t post_req;
        char tmp_buff1[256], tmp_buff2[256], tmp_buff3[64];;
        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));

        tm = localtime(&t);
        http_init(&post_req, 0);

        sprintf(url, "http://api-m2x.att.com/v2/devices/%s/streams/%s/values", device_id_ptr, stream_name_ptr);
        sprintf(tmp_buff1, "X-M2X-KEY: %s", api_key_ptr);
        sprintf(tmp_buff3, "%4d-%02d-%02dT%02d:%02d:%02dZ", (tm->tm_year+1900), (tm->tm_mon+1), tm->tm_mday,
                                                            tm->tm_hour, tm->tm_min, tm->tm_sec);
        sprintf(tmp_buff2, "{ \"values\": [ { \"timestamp\": \"%s\", \"value\": %s } ] }", tmp_buff3, stream_value_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);

        if( dbg_flag & DBG_M2X ) {
            printf("\n\n\nupdate_stream_value\n", url);
            printf("sending to URL: %s\n", url);
            printf("Content-Type: application/json");
            printf("%s\n", tmp_buff1);
            printf("%s\n", tmp_buff2);
            }
        ret = http_post(&post_req, url);
        if( post_req.rx_msglen >0) {
            if( strcmp(post_req.rx_msg,"{\"status\":\"accepted\"}") &&  dbg_flag & DBG_M2X ) 
                printf("\nUNEXPECTED REPLY WAS: %s\n",post_req.rx_msg);
            }
        http_deinit(&post_req);
        }
    return ret;

}
//
// This function is called to update a stream value.
//
This function is called to update a stream value.
This function is called to update a stream value .
int m2x_update_stream_value ( const char *device_id_ptr, const char *api_key_ptr, const char *stream_name_ptr, const char *stream_value_ptr)
{
    int ret = 0;
    if( doM2X ) {
        http_info_t post_req;
        char tmp_buff1[256], tmp_buff2[256], tmp_buff3[64];;
        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));
        tm = localtime(&t);
        http_init(&post_req, 0);
        sprintf(url, "http://api-m2x.att.com/v2/devices/%s/streams/%s/values", device_id_ptr, stream_name_ptr);
        sprintf(tmp_buff1, "X-M2X-KEY: %s", api_key_ptr);
        sprintf(tmp_buff3, "%4d-%02d-%02dT%02d:%02d:%02dZ", (tm->tm_year+1900), (tm->tm_mon+1), tm->tm_mday,
                                                            tm->tm_hour, tm->tm_min, tm->tm_sec);
        sprintf(tmp_buff2, "{ \"values\": [ { \"timestamp\": \"%s\", \"value\": %s } ] }", tmp_buff3, stream_value_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);
        if( dbg_flag & DBG_M2X ) {
            printf("\n\n\nupdate_stream_value\n", url);
            printf("sending to URL: %s\n", url);
            printf("Content-Type: application/json");
            printf("%s\n", tmp_buff1);
            printf("%s\n", tmp_buff2);
            }
        ret = http_post(&post_req, url);
        if( post_req.rx_msglen >0) {
            if( strcmp(post_req.rx_msg,"{\"status\":\"accepted\"}") &&  dbg_flag & DBG_M2X ) 
                printf("\nUNEXPECTED REPLY WAS: %s\n",post_req.rx_msg);
            }
        http_deinit(&post_req);
        }
    return ret;
}
int m2x_update_stream_value ( const char * device_id_ptr , const char * api_key_ptr , const char * stream_name_ptr , const char * stream_value_ptr ) { int ret = 0 ; if ( doM2X ) { http_info_t post_req ; char tmp_buff1 [ 256 ] , tmp_buff2 [ 256 ] , tmp_buff3 [ 64 ] ; ; 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 ) ) ; tm = localtime ( & t ) ; http_init ( & post_req , 0 ) ; sprintf ( url , " " , device_id_ptr , stream_name_ptr ) ; sprintf ( tmp_buff1 , " " , api_key_ptr ) ; sprintf ( tmp_buff3 , " " , ( tm -> tm_year + 1900 ) , ( tm -> tm_mon + 1 ) , tm -> tm_mday , tm -> tm_hour , tm -> tm_min , tm -> tm_sec ) ; sprintf ( tmp_buff2 , " \" \" \" \" \" \" \" \" " , tmp_buff3 , stream_value_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 ) ; if ( dbg_flag & DBG_M2X ) { printf ( " \n \n \n \n " , url ) ; printf ( " \n " , url ) ; printf ( " " ) ; printf ( " \n " , tmp_buff1 ) ; printf ( " \n " , tmp_buff2 ) ; } ret = http_post ( & post_req , url ) ; if ( post_req . rx_msglen > 0 ) { if ( strcmp ( post_req . rx_msg , " \" \" \" \" " ) && dbg_flag & DBG_M2X ) printf ( " \n \n " , post_req . rx_msg ) ; } http_deinit ( & post_req ) ; } return ret ; }
This function is called to update a stream value.
This function is called to update a stream value .