Esempio n. 1
0
int main()
{
   // Create the Xively context
   xi_context_t* xi_context = xi_create_context(XI_HTTP, DEVICE_KEY, FEED_ID);
   if(xi_context==NULL){
      perror("XIVELY: Problem in creating the context");
      return 1;
   }
   // Create the feed and clear its contents
   xi_feed_t feed;
   memset(&feed, 0, sizeof(xi_feed_t));
   // Set the properties of the feed (id, number of streams and datstream)
   feed.feed_id           = FEED_ID;
   feed.datastream_count  = 1;  //only sending a single stream, datastream 0
   // Get a reference to the datastream
   xi_datastream_t* data  = &feed.datastreams[0];
   // Only going to send a single data point in the stream
   data->datapoint_count = 1;
   // Set up the data stream identifier "tempSensor"
   int size = sizeof(data->datastream_id);
   xi_str_copy_untiln(data->datastream_id, size, "tempSensor", '\0' );
   // Set up the data point and setting a floating point value
   xi_datapoint_t* point = &data->datapoints[0];
   xi_set_value_f32(point, getTemperature(readAnalog(0)));
   // Update the feed
   xi_feed_update(xi_context, &feed);
   xi_delete_context(xi_context);
   return 0;
}
Esempio n. 2
0
// NOTE - based on code example on StackOverflow: http://stackoverflow.com/questions/17661058/include-libraries-with-g/17700233#17700233
int GMXively::SendData(uint32_t feedID, const char *dataStreamID, float value)
{
	xi_context_t* xi_context;
	xi_feed_t feed;
	memset(&feed, NULL, sizeof(xi_feed_t));

	feed.feed_id = feedID;
	feed.datastream_count = 1;

	feed.datastreams[0].datapoint_count = 1;
	xi_datastream_t* datastream = &feed.datastreams[0];
	strcpy(datastream->datastream_id, dataStreamID);
	xi_datapoint_t* datapoint = &datastream->datapoints[0];

	try
	{
	
	    // create the xively library context
		xi_context  = xi_create_context(XI_HTTP, _apiKey, feed.feed_id);
	}
	catch (...)
	{
		GMUtils::Log("Exception creating context for feed %d, datastream %s", feedID, dataStreamID);
		return -1;
	}
	        // check if everything works
	if (xi_context == NULL)
	{
		return -1;
	}

	try
	{
		xi_set_value_f32(datapoint, value);
	}
	catch (...)
	{
		GMUtils::Log("Exception setting value for feed %d, datastream %s", feedID, dataStreamID);
		return -2;
	}
	
	try
	{
	
		const xi_response_t *result = xi_feed_update(xi_context, &feed);
		GMUtils::Debug("Sent %s = %.2f, result %s", dataStreamID, value, result->http.http_status_string);
	}
	catch (...)
	{
		GMUtils::Log("Exception sending to feed %d, datastream %s", feedID, dataStreamID);	
		return -3;
	}

	return 0;
}
Esempio n. 3
0
int main( int argc, const char* argv[] )
{
#ifdef XI_NOB_ENABLED
    XI_UNUSED( argc );
    XI_UNUSED( argv );
#else
    if( argc < REQUIRED_ARGS )
    {
        print_usage();
        exit( 0 );
    }

    // create the xi library context
    xi_context_t* xi_context
        = xi_create_context(
                  XI_HTTP, argv[ 1 ]
                , atoi( argv[ 2 ] ) );

    // check if everything works
    if( xi_context == 0 )
    {
        return -1;
    }

    // create feed
    xi_feed_t f;
    memset( &f, 0, sizeof( xi_feed_t ) );

    xi_feed_get_all( xi_context, &f );

    printf( "\n" );

    for( size_t i = 0; i < f.datastream_count; ++i )
    {
        xi_datastream_t* d = &f.datastreams[ i ];
        printf( "datasream_id: %s ", d->datastream_id );

        for( size_t j = 0; j < d->datapoint_count; ++j )
        {
            xi_datapoint_t* p = &d->datapoints[ j ];
            print_datapoint( p );
        }
    }

    // destroy the context cause we don't need it anymore
    xi_delete_context( xi_context );
#endif
    return 0;
}
Esempio n. 4
0
void test_create_and_delete_context(void* data)
{
    (void)(data);

#define TEST_API_KEY_STRING "abcXYZ2398138172jckajf39djas_dasd-TyX"
#define TEST_FEED_ID_NUMBER 123456

    xi_context_t* xi_context
        = xi_create_context( XI_HTTP
                             , TEST_API_KEY_STRING
                             , TEST_FEED_ID_NUMBER );

    tt_assert( xi_context != 0 );
    tt_assert( strcmp( xi_context->api_key, TEST_API_KEY_STRING ) == 0 );
    tt_assert( xi_context->feed_id == TEST_FEED_ID_NUMBER );

    xi_delete_context( xi_context );

end:
    xi_set_err( XI_NO_ERR );
    ;
}
Esempio n. 5
0
int main( int argc, const char* argv[] )
{
    if( argc < 5 )
    {
        print_usage();
        exit( 0 );
    }

    // create the xi library context
    xi_context_t* xi_context
        = xi_create_context(
                  XI_HTTP, argv[ 1 ]
                , atoi( argv[ 2 ] ) );

    // check if everything works
    if( xi_context == 0 )
    {
        return -1;
    }

    xi_datapoint_t datapoint;
    xi_set_value_i32( &datapoint, atoi( argv[ 4 ] ) );

    { // get actual timestamp
        time_t timer = 0;
        time( &timer );
        datapoint.timestamp.timestamp = timer;
    }

    xi_datastream_create( xi_context
            , atoi( argv[ 2 ] ), argv[ 3 ]
            , &datapoint.value );

    // destroy the context cause we don't need it anymore
    xi_delete_context( xi_context );

    return 0;
}
Esempio n. 6
0
int main( int argc, const char* argv[] )
{
#ifdef XI_NOB_ENABLED
    XI_UNUSED( argc );
    XI_UNUSED( argv );
#else
    if( argc < 4 )
    {
        print_usage();
        exit( 0 );
    }

    // create the xi library context
    xi_context_t* xi_context
        = xi_create_context(
                  XI_HTTP, argv[ 1 ]
                , atoi( argv[ 2 ] ) );

    // check if everything works
    if( xi_context == 0 )
    {
        return -1;
    }

    xi_datapoint_t ret;
    xi_datastream_get( xi_context
            , atoi( argv[ 2 ] ), argv[ 3 ], &ret );

    printf( "timestamp = %ld.%ld, value = %d\n"
        , ret.timestamp.timestamp, ret.timestamp.micro
        , ret.value.i32_value );

    // destroy the context cause we don't need it anymore
    xi_delete_context( xi_context );
#endif
    return 0;
}
Esempio n. 7
0
int main( int argc, const char* argv[] )
{

    if( argc < REQUIRED_ARGS )
    {
        print_usage();
        exit( 0 );
    }

    // create the xi library context
    xi_context_t* xi_context
        = xi_create_context(
                  XI_HTTP, argv[ 1 ]
                , atoi( argv[ 2 ] ) );

    // check if everything works
    if( xi_context == 0 )
    {
        return -1;
    }

    // remember the count for pairs
    size_t datapoints_count = argc - REQUIRED_ARGS;

    // create feed
    xi_feed_t f;
    memset( &f, 0, sizeof( xi_feed_t ) );

    // set datastream count
    f.feed_id           = atoi( argv[ 2 ] );
    f.datastream_count  = datapoints_count;

    // for each
    for( size_t i = 0; i < datapoints_count; i++ )
    {
        // get the datastream pointer
        xi_datastream_t* d = &f.datastreams[ i ];

        // set the datastream id
        int size = sizeof( d->datastream_id );
        int s = xi_str_copy_untiln( d->datastream_id, size
            , argv[ REQUIRED_ARGS + i ], '\0' );

        if( s >= size )
        {
            perror( "datastream name too long " );
        }
    }

    xi_feed_get( xi_context, &f );

    for( size_t i = 0; i < f.datastream_count; ++i )
    {
        xi_datastream_t* d = &f.datastreams[ i ];
        printf( "datasream_id: %s ", d->datastream_id );

        for( size_t j = 0; j < d->datapoint_count; ++j )
        {
            xi_datapoint_t* p = &d->datapoints[ j ];
            print_datapoint( p );
        }
    }

    // destroy the context cause we don't need it anymore
    xi_delete_context( xi_context );

    return 0;
}
Esempio n. 8
0
int main( int argc, const char* argv[] )
{
#ifdef XI_NOB_ENABLED
    XI_UNUSED( argc );
    XI_UNUSED( argv );
#else
    if( argc < REQUIRED_ARGS )
    {
        print_usage();
        exit( 0 );
    }

    // create the xi library context
    xi_context_t* xi_context
        = xi_create_context(
                  XI_HTTP, argv[ 1 ]
                , atoi( argv[ 2 ] ) );

    // check if everything works
    if( xi_context == 0 )
    {
        return -1;
    }

    // remember the count for pairs
    size_t pairs_count = ( argc - REQUIRED_ARGS ) / 2;

    // create feed
    xi_feed_t f;
    memset( &f, 0, sizeof( xi_feed_t ) );

    // set datastream count
    f.feed_id           = atoi( argv[ 2 ] );
    f.datastream_count  = pairs_count;

    // for each pair
    for( size_t i = 0; i < pairs_count; i++ )
    {
        // get the datastream pointer
        xi_datastream_t* d = &f.datastreams[ i ];

        // set the datapoint count
        d->datapoint_count   = 1;

        int size = sizeof( d->datastream_id );
        int s = xi_str_copy_untiln( d->datastream_id, size
            , argv[ REQUIRED_ARGS + ( i * 2 ) ], '\0' );

        if( s >= size )
        {
            printf( "datastream id too long: %s\n", argv[ REQUIRED_ARGS + ( i * 2 ) ] );
        }

        // get the datpoint counter
        xi_datapoint_t* p = &d->datapoints[ 0 ];

        // set the datapoint
        xi_set_value_i32( p, atoi( argv[ REQUIRED_ARGS + ( i  * 2 ) + 1 ] ) );
    }

    for( int i = 0; i < 20; ++i )
    {
        xi_feed_update( xi_context, &f );
    }

    // destroy the context cause we don't need it anymore
    xi_delete_context( xi_context );
#endif
    return 0;
}