https://github.com/ubidots/ubidots-c
C API client for Ubidots
https://github.com/ubidots/ubidots-c
Last synced: 3 months ago
JSON representation
C API client for Ubidots
- Host: GitHub
- URL: https://github.com/ubidots/ubidots-c
- Owner: ubidots
- License: mit
- Created: 2013-11-20T21:14:23.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-02-10T15:04:37.000Z (about 2 years ago)
- Last Synced: 2023-03-23T02:56:05.586Z (about 2 years ago)
- Language: C
- Size: 36.1 KB
- Stars: 3
- Watchers: 18
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Ubidots-C
=========Ubidots-C is a pure C library for interacting with Ubidots_ through its API. It depends on libjansson and libcurl.
* Preview Release: v0.9.0_
.. _Ubidots: http://ubidots.com
.. _v0.9.0: https://github.com/ubidots/ubidots-c/releases/tag/v0.9.0A Quick Look...
---------------
A quick example of how to use the library follows:.. code-block:: c
#include
int main() {
UbidotsClient *client = ubidots_init(API_KEY);while ( keepGoing() ) {
double value = getValue();
ubidots_save_value(client, VARIABLE_ID, value, TIMESTAMP_NOW);
}
ubidots_cleanup(client);return 0;
}Collections, a feature of Ubidots which allows saving of multiple values with a single request, are supported. A quick example of how to use collections follows:
.. code-block:: c
#include
int main() {
UbidotsClient *client = ubidots_init(API_KEY);while ( keepGoing() ) {
double firstValue = getFirstValue();
double secondValue = getSecondValue();
double thirdValue = getThirdValue();UbidotsCollection *coll = ubidots_collection(3);
ubidots_collection_add(coll, FIRST_VARIABLE_ID, firstValue);
ubidots_collection_add(coll, SECOND_VARIABLE_ID, secondValue);
ubidots_collection_add(coll, THIRD_VARIABLE_ID, thirdValue);
ubidots_collection_save(client, coll);
ubidots_collection_cleanup(coll);
}ubidots_cleanup(client);
return 0;
}API Reference
-------------ubidots_init()
``````````````
.. code-block:: cUbidotsClient* ubidots_init(char *api_key)
===== ======== =================================
Type Argument Description
===== ======== =================================
char* api_key Your API key for the Ubidots API
===== ======== =================================Initialize a Ubidots client. This is most likely the first Ubidots library function you will call. Upon success, returns a pointer to a UbidotsClient. Upon error, returns NULL.
ubidots_save_value()
````````````````````
.. code-block:: cint ubidots_save_value(UbidotsClient *client, char *variable_id, double value, long long timestamp)
============== =========== =================================
Type Argument Description
============== =========== =================================
UbidotsClient* client Pointer to UbidotsClient
char* variable_id The ID of the variable to save to
double value The value to save with this call
long long timestamp Timestamp (millesconds since epoch). Pass constant TIMESTAMP_NOW to have the timestamp automatically calculated.
============== =========== =================================Save a value to Ubidots. Returns zero upon success. Returns non-zero upon error.
ubidots_cleanup()
`````````````````
.. code-block:: cvoid ubidots_cleanup(UbidotsClient *client)
================== =========== =================================
Type Argument Description
================== =========== =================================
UbidotsClient* client Pointer to the Ubidots client made by ubidots_init()
================== =========== =================================Free a client after it is no longer needed.
ubidots_collection_init()
`````````````````````````
.. code-block:: cUbidotsCollection* ubidots_collection_init(int n)
============== =========== =================================
Type Argument Description
============== =========== =================================
int n Number of values that will be stored in this collection
============== =========== =================================Create a collection. If the number of values added to the collecion does not equal the about specified here when ubidots_save_collection() is called, undefinded behaviour will occur.
Returns a pointer to a collection.
ubidots_collection_add()
````````````````````````
.. code-block:: cvoid ubidots_collection_add(UbidotsCollection *coll, char *variable_id, double value)
================== =========== =================================
Type Argument Description
================== =========== =================================
UbidotsCollection* coll Pointer to the collection made by ubidots_collection_init()
char* variable_id The ID of the variable this value is associated with
double value The value to add to the collection
================== =========== =================================Add a value to a collection.
ubidots_collection_save()
`````````````````````````
.. code-block:: cint ubidots_collection_save(UbidotsClient *client, UbidotsCollection *coll)
================== =========== =================================
Type Argument Description
================== =========== =================================
UbidotsClient* client Pointer to the ubidots client made by ubidots_init()
UbidotsCollection* coll Pointer to the collection made by ubidots_collection_init()
================== =========== =================================Save a collection. If the number of values added to this collection using ubidots_collection_add() does not equal the number specified when created with ubidots_collection_init(), undefined behaviour will occur.
Returns zero if the save was successful. If an error occurred, returns non-zero.
ubidots_collection_cleanup()
````````````````````````````
.. code-block:: cvoid ubidots_collection_cleanup(UbidotsCollection *coll)
================== =========== =================================
Type Argument Description
================== =========== =================================
UbidotsCollection* coll Pointer to the collection made by ubidots_collection_init()
================== =========== =================================Free a collection after it is no longer needed.