CloudPlugs REST Library  1.0.0
for ANSI C
cp_rest.h File Reference
#include <stddef.h>
Include dependency graph for cp_rest.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CP_OK   0
 
#define CP_FAIL   1
 
#define CP_TRUE   1
 
#define CP_FALSE   0
 

Typedefs

typedef struct _cloudplugs_session * cp_session
 
typedef int cp_res
 
typedef int cp_bool
 
typedef enum _CP_HTTP_RESULT CP_HTTP_RESULT
 
typedef enum _CP_ERR_CODE CP_ERR_CODE
 

Enumerations

enum  _CP_HTTP_RESULT {
  CP_HTTP_OK = 200, CP_HTTP_CREATED = 201, CP_HTTP_MULTI_STATUS = 207, CP_HTTP_BAD_REQUEST = 400,
  CP_HTTP_UNAUTHORIZED = 401, CP_HTTP_PAYMENT_REQUIRED = 402, CP_HTTP_FORBIDDEN = 403, CP_HTTP_NOT_FOUND = 404,
  CP_HTTP_NOT_ALLOWED = 405, CP_HTTP_NOT_ACCEPTABLE = 406, CP_HTTP_SERVER_ERROR = 500, CP_HTTP_NOT_IMPLEMENTED = 501,
  CP_HTTP_BAD_GATEWAY = 502, CP_HTTP_SERVICE_UNAVAILABLE = 503
}
 
enum  _CP_ERR_CODE {
  CP_ERR_INTERNAL_ERROR = -1, CP_ERR_OUT_OF_MEMORY = -2, CP_ERR_INVALID_SESSION = -3, CP_ERR_QUERY_IS_NOT_AN_OBJECT = -4,
  CP_ERR_QUERY_INVALID_TYPE = -5, CP_ERR_HEADERS_MUST_BE_STRING = -6, CP_ERR_INVALID_PARAMETER = -7, CP_ERR_INVALID_LOGIN = -8,
  CP_ERR_JSON_PARSE = -9, CP_ERR_JSON_ENCODE = -10, CP_ERR_INVALID_CONTENT_LENGTH = -11, CP_ERR_HTTP = -12
}
 

Functions

cp_res cloudplugs_global_init ()
 
cp_res cloudplugs_global_shutdown ()
 
cp_res cloudplugs_set_base_url (cp_session cps, const char *url)
 
cp_res cloudplugs_set_cacert (cp_session cps, const char *filename)
 
const char * cloudplugs_get_base_url (cp_session cps)
 
cp_res cloudplugs_set_timeout (cp_session cps, int timeout)
 
int cloudplugs_get_timeout (cp_session cps)
 
const char * cloudplugs_get_last_err_string (cp_session cps)
 
CP_ERR_CODE cloudplugs_get_last_err_code (cp_session cps)
 
const char * cloudplugs_get_last_http_result_string (cp_session cps)
 
CP_HTTP_RESULT cloudplugs_get_last_http_result (cp_session cps)
 
cp_session cloudplugs_create_session ()
 
cp_res cloudplugs_set_auth (cp_session cps, const char *id, const char *pass, cp_bool is_master)
 
cp_res cloudplugs_ssl_verify (cp_session cps, cp_bool is_verified)
 
cp_bool cloudplugs_has_ssl_verify (cp_session cps)
 
cp_res cloudplugs_enable_ssl (cp_session cps, cp_bool is_enabled)
 
cp_bool cloudplugs_has_ssl (cp_session cps)
 
cp_res cloudplugs_get_auth_id (cp_session cps, char *id, size_t size)
 
cp_res cloudplugs_get_auth_pass (cp_session cps, char *password, size_t size)
 
cp_bool cloudplugs_is_auth_master (cp_session cps)
 
cp_res cloudplugs_destroy_session (cp_session cps)
 
cp_bool cloudplugs_extract_string_from_json (char **json, const char *key, char *res, const int n)
 
cp_res cloudplugs_enroll_product (cp_session cps, const char *body, char **result, size_t *result_length)
 
cp_res cloudplugs_enroll_prototype (cp_session cps, const char *body, char **result, size_t *result_length)
 
cp_res cloudplugs_enroll_ctrl (cp_session cps, const char *body, char **result, size_t *result_length)
 
cp_res cloudplugs_control_device (cp_session cps, const char *body, char **result, size_t *result_length)
 
cp_res cloudplugs_uncontrol_device (cp_session cps, const char *plugid, const char *plugid_controlled, char **result, size_t *result_length)
 
cp_res cloudplugs_get_device (cp_session cps, const char *plugid, char **result, size_t *result_length)
 
cp_res cloudplugs_get_device_prop (cp_session cps, const char *plugid, const char *prop, char **result, size_t *result_length)
 
cp_res cloudplugs_set_device_prop (cp_session cps, const char *plugid, const char *prop, const char *value)
 
cp_res cloudplugs_remove_device_prop (cp_session cps, const char *plugid, const char *prop)
 
cp_res cloudplugs_set_device (cp_session cps, const char *plugid, const char *value, char **result, size_t *result_length)
 
cp_res cloudplugs_unenroll (cp_session cps, const char *plugid, char **result, size_t *result_length)
 
cp_res cloudplugs_get_channel (cp_session cps, const char *channel_mask, const char *query, char **result, size_t *result_length)
 
cp_res cloudplugs_retrieve_data (cp_session cps, const char *channel_mask, const char *query, char **result, size_t *result_length)
 
cp_res cloudplugs_publish_data (cp_session cps, const char *channel, const char *body, char **result, size_t *result_length)
 
cp_res cloudplugs_remove_data (cp_session cps, const char *channel_mask, const char *body, char **result, size_t *result_length)
 
cp_res cloudplugs_set_device_location (cp_session cps, const char *plugid, double longitude, double latitude, double altitude, double accuracy, double timestamp)
 
cp_res cloudplugs_get_device_location (cp_session cps, const char *plugid, char **result, size_t *result_length)
 

Macro Definition Documentation

◆ CP_FAIL

#define CP_FAIL   1

◆ CP_FALSE

#define CP_FALSE   0

◆ CP_OK

#define CP_OK   0

◆ CP_TRUE

#define CP_TRUE   1

Typedef Documentation

◆ cp_bool

typedef int cp_bool

Library internal booleans

◆ CP_ERR_CODE

typedef enum _CP_ERR_CODE CP_ERR_CODE

Library internal error codes

◆ CP_HTTP_RESULT

HTTP results returned by the server

◆ cp_res

typedef int cp_res

An integer representing the result of a request

◆ cp_session

typedef struct _cloudplugs_session* cp_session

Reference to a session

Enumeration Type Documentation

◆ _CP_ERR_CODE

Enumerator
CP_ERR_INTERNAL_ERROR 
CP_ERR_OUT_OF_MEMORY 
CP_ERR_INVALID_SESSION 
CP_ERR_QUERY_IS_NOT_AN_OBJECT 
CP_ERR_QUERY_INVALID_TYPE 
CP_ERR_HEADERS_MUST_BE_STRING 
CP_ERR_INVALID_PARAMETER 
CP_ERR_INVALID_LOGIN 
CP_ERR_JSON_PARSE 
CP_ERR_JSON_ENCODE 
CP_ERR_INVALID_CONTENT_LENGTH 
CP_ERR_HTTP 

◆ _CP_HTTP_RESULT

Enumerator
CP_HTTP_OK 
CP_HTTP_CREATED 
CP_HTTP_MULTI_STATUS 
CP_HTTP_BAD_REQUEST 
CP_HTTP_UNAUTHORIZED 
CP_HTTP_PAYMENT_REQUIRED 
CP_HTTP_FORBIDDEN 
CP_HTTP_NOT_FOUND 
CP_HTTP_NOT_ALLOWED 
CP_HTTP_NOT_ACCEPTABLE 
CP_HTTP_SERVER_ERROR 
CP_HTTP_NOT_IMPLEMENTED 
CP_HTTP_BAD_GATEWAY 
CP_HTTP_SERVICE_UNAVAILABLE 

Function Documentation

◆ cloudplugs_control_device()

cp_res cloudplugs_control_device ( cp_session  cps,
const char *  body,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for controlling a device and place the response in *result and *result_length.

Parameters
cpsThe session reference.
bodyA buffer containing a json object like this:
{
"model" : PLUG_ID, // model id of the device to control
"ctrl" : HWID, // serial number (hwid) of the device to control
"pass" : String,
}
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_create_session()

cp_session cloudplugs_create_session ( )

Initializes a HTTP persistent connection.

Returns
The session reference, NULL if occurred an error.

◆ cloudplugs_destroy_session()

cp_res cloudplugs_destroy_session ( cp_session  cps)

Closes and cleans a session.

Parameters
cpsThe session reference.
Returns
CP_OK if the session is correctly closed, CP_FAIL otherwise.

◆ cloudplugs_enable_ssl()

cp_res cloudplugs_enable_ssl ( cp_session  cps,
cp_bool  is_enabled 
)

Enable or disable ssl protocol.

Parameters
cpsThe session reference.
is_enabledBoolean state of ssl.
Returns
CP_OK if success, CP_FAIL otherwise.

◆ cloudplugs_enroll_ctrl()

cp_res cloudplugs_enroll_ctrl ( cp_session  cps,
const char *  body,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for enrolling a new or already existent controller device and place the response in *result and *result_length.

Parameters
cpsThe session reference without authentication if it's the first enroll.
bodyA buffer containing a json object like this:
{
"model" : PLUG_ID, // model id of the device to control
"ctrl" : HWID, // serial number (hwid) of the device to control
"pass" : String,
"hwid" : HWID, // unique string to identify this controller device
"name" : String // the name of this device
}
resultIf not NULL, then a pointer such that *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_enroll_product()

cp_res cloudplugs_enroll_product ( cp_session  cps,
const char *  body,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for enrolling a new production device and place the response in *result and *result_length.

Parameters
cpsThe session reference without authentication.
bodyA buffer containing a json object like this:
{
"model" : PLUG_ID, // the model of this device
"hwid" : HWID, // the serial number
"pass" : String,
"props" : JSON // optional, to initialize the custom properties
}
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_enroll_prototype()

cp_res cloudplugs_enroll_prototype ( cp_session  cps,
const char *  body,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for enrolling a prototype and place the response in *result and *result_length.

Parameters
cpsThe session reference without authentication.
bodyA buffer containing a json object like this:
{
"hwid" : HWID, // optional, if absent it will be set as a random unique string
"pass" : String, // optional, if absent set as the X-Plug-Master of the company
"name" : String,
"perm" : PERM_FILTER, // optional, if absent permit all
"props" : JSON // optional, to initialize the custom properties
}
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_extract_string_from_json()

cp_bool cloudplugs_extract_string_from_json ( char **  json,
const char *  key,
char *  res,
const int  n 
)

Extract a string value from a json object

Parameters
jsonThe JSON string.
keyThe key.
resThe destination buffer where the string value will be written.
nSize of the destination buffer.
Returns
CP_TRUE if succeeds, CP_FALSE otherwise.

◆ cloudplugs_get_auth_id()

cp_res cloudplugs_get_auth_id ( cp_session  cps,
char *  id,
size_t  size 
)

Get the authentication id (PLUG_ID or email) of the session.

Parameters
cpsThe session reference.
idThe destination buffer where the authentication id will be written.
sizeSize of the destination buffer.
Returns
CP_OK if the buffer was correctly written, CP_FAIL otherwise.

◆ cloudplugs_get_auth_pass()

cp_res cloudplugs_get_auth_pass ( cp_session  cps,
char *  password,
size_t  size 
)

Get the authentication password of the session.

Parameters
cpsThe session reference.
passwordThe destination buffer where the authentication password will be written.
sizeSize of the destination buffer.
Returns
CP_OK if the buffer was correctly written, CP_FAIL otherwise.

◆ cloudplugs_get_base_url()

const char* cloudplugs_get_base_url ( cp_session  cps)

Get the current base url.

Parameters
cpsThe session reference.
Returns
The base url.

◆ cloudplugs_get_channel()

cp_res cloudplugs_get_channel ( cp_session  cps,
const char *  channel_mask,
const char *  query,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for retrieving list channels/channels about already published data and place the response in *result and *result_length.

Parameters
cpsThe session reference.
channel_maskCHMASK The channel mask.
queryIf not NULL, must be a url-encode string containing those values:
before: Optional, TIMESTAMP or OBJECT_ID timestamp valid if greater than zero
after: Optional, TIMESTAMP or OBJECT_ID timestamp valid if greater than zero
at: Optional, TIMESTAMP_CSV timestamp valid if greater than zero
of: Optional, PLUG_ID_CSV
offset: Optional Number: positive integer (including 0)
limit: Optional Number: positive integer (including 0)
resultA pointer such that *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_get_device()

cp_res cloudplugs_get_device ( cp_session  cps,
const char *  plugid,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for reading a device and place the response in *result and *result_length.

Parameters
cpsThe session reference.
plugidThe PLUG_ID of the device.
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_get_device_location()

cp_res cloudplugs_get_device_location ( cp_session  cps,
const char *  plugid,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for writing or deleting device location and place the response in *result and *result_length.

Parameters
cpsThe session reference.
plugidIf not NULL, then the PLUG_ID of the device, otherwise the device referenced in the session.
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_get_device_prop()

cp_res cloudplugs_get_device_prop ( cp_session  cps,
const char *  plugid,
const char *  prop,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for reading the device properties and place the response in *result and *result_length.

Parameters
cpsThe session reference.
plugidThe PLUG_ID of the device.
propIf NULL, then all properties value; otherwise the single property value.
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_get_last_err_code()

CP_ERR_CODE cloudplugs_get_last_err_code ( cp_session  cps)

Return a human-readable string that describes the last error.

Parameters
cpsThe session reference.
Returns
A human-readable string that describes the last error.

◆ cloudplugs_get_last_err_string()

const char* cloudplugs_get_last_err_string ( cp_session  cps)

Return a human-readable string that describes the last error.

Parameters
cpsThe session reference.
Returns
A human-readable string that describes the last error.

◆ cloudplugs_get_last_http_result()

CP_HTTP_RESULT cloudplugs_get_last_http_result ( cp_session  cps)

Return a human-readable string that describes the last error.

Parameters
cpsThe session reference.
Returns
A human-readable string that describes the last error.

◆ cloudplugs_get_last_http_result_string()

const char* cloudplugs_get_last_http_result_string ( cp_session  cps)

Return a human-readable string that describes the last error.

Parameters
cpsThe session reference.
Returns
A human-readable string that describes the last error.

◆ cloudplugs_get_timeout()

int cloudplugs_get_timeout ( cp_session  cps)

Get the current timeout.

Parameters
cpsThe session reference.
Returns
The current timeout in seconds.

◆ cloudplugs_global_init()

cp_res cloudplugs_global_init ( )

Must be called at least once within a program (a program is all the code that shares a memory space) before the program calls any other function of CloudPlugs library. The environment it sets up is constant for the life of the program and is the same for every program, so multiple calls have the same effect as one call. This function is not thread safe. You must not call it when any other thread in the program (i.e. a thread sharing the same memory) is running. This doesn't just mean no other thread that is using CloudPlugs library.

Returns
CP_OK on success, CP_FAIL otherwise.

◆ cloudplugs_global_shutdown()

cp_res cloudplugs_global_shutdown ( )

Must be called once for each call made to cloudplugs_global_init(), after you are done using CloudPlugs library. This function is not thread safe. You must not call it when any other thread in the program (i.e. a thread sharing the same memory) is running. This doesn't just mean no other thread that is using CloudPlugs library.

Returns
CP_OK on success, CP_FAIL otherwise.

◆ cloudplugs_has_ssl()

cp_bool cloudplugs_has_ssl ( cp_session  cps)

State of ssl protocol.

Parameters
cpsThe session reference.
Returns
CP_TRUE if ssl is enable, CP_FALSED otherwise.

◆ cloudplugs_has_ssl_verify()

cp_bool cloudplugs_has_ssl_verify ( cp_session  cps)

State of ssl verification.

Parameters
cpsThe session reference.
Returns
CP_TRUE if ssl is enable, CP_FALSED otherwise.

◆ cloudplugs_is_auth_master()

cp_bool cloudplugs_is_auth_master ( cp_session  cps)

Return the authentication mode in the session.

Parameters
cpsThe session reference.
Returns
CP_TRUE if using master authentication in the session; CP_FALSE if using regular authentication.

◆ cloudplugs_publish_data()

cp_res cloudplugs_publish_data ( cp_session  cps,
const char *  channel,
const char *  body,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for publishing data and [optionally] place the response in *result and *result_length.

Parameters
cpsThe session reference.
channelAn optional CHANNEL , if NULL data need to contain a couple "channel":"channel"
bodyA json object or an array of objects like this:
{
"id" : “PLUG_ID”,
"channel" : CHANNEL, // optional, to override the channel in the url
"data" : JSON,
"at" : TIMESTAMP,
"of" : PLUG_ID, // optional, check if the X-Plug-Id is authorized for setting this field
"is_priv" : Boolean, // optional, default false
"expire_at" : TIMESTAMP, // optional, expire date of this data entry
"ttl" : Number // optional, how many seconds this data entry will live (if "expire_at" is present, then this field is ignored)
}
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_remove_data()

cp_res cloudplugs_remove_data ( cp_session  cps,
const char *  channel_mask,
const char *  body,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for deleting already published data and [optionally] place the response in *result and *result_length.

Parameters
cpsThe session reference.
channel_maskThe CHMASK
bodyA buffer containing a json object like this (at least one param is required: id, before, after or at):
{
"id" : OBJECT_ID_CSV ,
"before" : TIMESTAMP or PLUG_ID,
"after" : TIMESTAMP or PLUG_ID,
"at" : TIMESTAMP_CSV or ,
"of" : PLUG_ID_CSV or
}
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_remove_device_prop()

cp_res cloudplugs_remove_device_prop ( cp_session  cps,
const char *  plugid,
const char *  prop 
)

This function performs an HTTP request to the server for deleting device property and [optionally] place the response in *result and *result_length.

Parameters
cpsThe session reference.
plugidThe PLUG_ID of the device.
propThe single property to be remove.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_retrieve_data()

cp_res cloudplugs_retrieve_data ( cp_session  cps,
const char *  channel_mask,
const char *  query,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for retrieving already published data and place the response in *result and *result_length.

Parameters
cpsThe session reference.
channel_maskCHMASK The channel mask.
queryIf not NULL, must be a url-encode string containing those values:
before: Optional, TIMESTAMP or OBJECT_ID timestamp valid if greater than zero
after: Optional, TIMESTAMP or OBJECT_ID timestamp valid if greater than zero
at: Optional, TIMESTAMP_CSV timestamp valid if greater than zero
of: Optional,PLUG_ID_CSV
offset: Optional Number: positive integer (including 0)
limit: Optional Number: positive integer (including 0)
resultA pointer such that *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_set_auth()

cp_res cloudplugs_set_auth ( cp_session  cps,
const char *  id,
const char *  pass,
cp_bool  is_master 
)

Set the session authentication credentials.

Parameters
cpsThe session reference.
idA string containing the PLUG_ID or the master email.
passA string containing the authentication code.
is_masterCP_TRUE for using master authentication in the session; CP_FALSE for using regular authentication.
Returns
CP_OK if the authentication is set correctly, CP_FAIL otherwise.

◆ cloudplugs_set_base_url()

cp_res cloudplugs_set_base_url ( cp_session  cps,
const char *  url 
)

Change the default base url.

Parameters
cpsThe session reference.
urlHttp or https url string.
Returns
CP_OK if the new base url is set correctly, CP_FAIL otherwise.

◆ cloudplugs_set_cacert()

cp_res cloudplugs_set_cacert ( cp_session  cps,
const char *  filename 
)

Set the certification authority for verify ssl connections.

Parameters
cpsThe session reference.
filenameString naming a file holding one or more certificates to verify the peer with.
Returns
CP_OK if the certificate authority is set correctly, CP_FAIL otherwise.

◆ cloudplugs_set_device()

cp_res cloudplugs_set_device ( cp_session  cps,
const char *  plugid,
const char *  value,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for modifying device and [optionally] place the response in *result and *result_length.

Parameters
cpsThe session reference.
plugidThe PLUG_ID of the device.
valueA json object like this:
{
"perm" : PERM_FILTER, // optional, it contains just the sharing filters to modify
"name" : String, // optional
"status" : STATUS, // optional
"props" : Object // optional, it contains just the properties to modify
}
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_set_device_location()

cp_res cloudplugs_set_device_location ( cp_session  cps,
const char *  plugid,
double  longitude,
double  latitude,
double  altitude,
double  accuracy,
double  timestamp 
)

This function performs an HTTP request to the server for writing or deleting device location and [optionally] place the response in *result and *result_length.

Parameters
cpsThe session reference.
plugidIf not NULL, then the PLUG_ID of the device, otherwise the device referenced in the session.
longitude
latitude
altitude//optional
accuracy//optional
timestamp//optional
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_set_device_prop()

cp_res cloudplugs_set_device_prop ( cp_session  cps,
const char *  plugid,
const char *  prop,
const char *  value 
)

This function performs an HTTP request to the server for writing or deleting device properties and [optionally] place the response in *result and *result_length.

Parameters
cpsThe session reference.
plugidThe PLUG_ID of the device.
propIf NULL, then value must be an object; otherwise the single property value is written.
valueA json value, use null to delete one or all device properties.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_set_timeout()

cp_res cloudplugs_set_timeout ( cp_session  cps,
int  timeout 
)

Change the default timeout.

Parameters
cpsThe session reference.
timeoutTimeout in seconds.
Returns
CP_OK if the new timeout is set correctly, CP_FAIL otherwise.

◆ cloudplugs_ssl_verify()

cp_res cloudplugs_ssl_verify ( cp_session  cps,
cp_bool  is_verified 
)

Enable or disable ssl verification.

Parameters
cpsThe session reference.
is_verifiedBoolean state of ssl verification.
Returns
CP_OK if success, CP_FAIL otherwise.

◆ cloudplugs_uncontrol_device()

cp_res cloudplugs_uncontrol_device ( cp_session  cps,
const char *  plugid,
const char *  plugid_controlled,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for uncontrol a device and [optionally] place the response in *result and *result_length.

Parameters
cpsThe session reference.
plugidIf NULL, then is the PLUG_ID in the session.
plugid_controlledIf not NULL, then the device(s) to uncontroll (default all associated devices).
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.

◆ cloudplugs_unenroll()

cp_res cloudplugs_unenroll ( cp_session  cps,
const char *  plugid,
char **  result,
size_t *  result_length 
)

This function performs an HTTP request to the server for removing any device (development, product or controller) and [optionally] place the response in *result and *result_length.

Parameters
cpsThe session reference.
plugidThe PLUG_ID_CSV of the device(s) to remove; if NULL then remove the device referenced in the session.
resultIf not NULL, then *result will contain the dynamically allocated json string of the retrieved response body. The caller is responsible to free memory in *result.
result_lengthThe length of the string stored in *result.
Returns
CP_OK if the request succeeds, CP_FAIL otherwise.