CloudPlugs REST Library  1.0.0
for ANSI C
cp_rest_json.h File Reference
#include <jansson.h>
#include "cp_rest.h"
Include dependency graph for cp_rest_json.h:

Go to the source code of this file.

Typedefs

typedef double cp_time
 

Functions

cp_res cloudplugs_enroll_json (cp_session cps, json_t *obj, json_t **result)
 
cp_res cloudplugs_enroll_product_json (cp_session cps, const char *model, const char *hwid, const char *pass, json_t *props, json_t **result)
 
cp_res cloudplugs_enroll_prototype_json (cp_session cps, const char *name, const char *hwid, const char *pass, json_t *perm, json_t *props, json_t **result)
 
cp_res cloudplugs_enroll_ctrl_json (cp_session cps, const char *model, const char *ctrl, const char *pass, const char *hwid, const char *name, json_t **result)
 
cp_res cloudplugs_control_device_json (cp_session cps, const char *model, const char *ctrl, const char *pass, json_t **result)
 
cp_res cloudplugs_uncontrol_device_json (cp_session cps, const char *plugid, json_t *plugid_controlled, json_t **result)
 
cp_res cloudplugs_get_channel_json (cp_session cps, const char *channel_mask, json_t *before, json_t *after, json_t *at, json_t *of, int offset, int limit, json_t **result)
 
cp_res cloudplugs_get_device_json (cp_session cps, const char *plugid, json_t **result)
 
cp_res cloudplugs_get_device_prop_json (cp_session cps, const char *plugid, const char *prop, json_t **result)
 
cp_res cloudplugs_set_device_prop_json (cp_session cps, const char *plugid, const char *prop, json_t *value)
 
cp_res cloudplugs_remove_device_prop_json (cp_session cps, const char *plugid, const char *prop)
 
cp_res cloudplugs_set_device_json (cp_session cps, const char *plugid, json_t *value, json_t **result)
 
cp_res cloudplugs_unenroll_json (cp_session cps, json_t *plugid, json_t **result)
 
cp_res cloudplugs_retrieve_data_json (cp_session cps, const char *channel_mask, cp_time before, cp_time after, cp_time at, const char *of, int offset, int limit, json_t **result)
 
cp_res cloudplugs_publish_data_json (cp_session cps, const char *channel, json_t *body, json_t **result)
 
cp_res cloudplugs_remove_data_json (cp_session cps, const char *channel_mask, json_t *id, json_t *before, json_t *after, json_t *at, json_t *of, json_t **result)
 
cp_res cloudplugs_set_device_location_json (cp_session cps, const char *plugid, double longitude, double latitude, double altitude, double accuracy, cp_time timestamp)
 
cp_res cloudplugs_get_device_location_json (cp_session cps, const char *plugid, json_t **result)
 

Typedef Documentation

◆ cp_time

typedef double cp_time

Number of milliseconds in GMT since the time of Epoch

Function Documentation

◆ cloudplugs_control_device_json()

cp_res cloudplugs_control_device_json ( cp_session  cps,
const char *  model,
const char *  ctrl,
const char *  pass,
json_t **  result 
)

This function performs an HTTP request to the server for enrolling an already existent controller device. It places place the response in *result.

Parameters
cpsThe session reference.
modelThe model PLUG_ID of the device to control.
ctrlThe serial number ( HWID ) of the device to control.
passThe device password's
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_enroll_ctrl_json()

cp_res cloudplugs_enroll_ctrl_json ( cp_session  cps,
const char *  model,
const char *  ctrl,
const char *  pass,
const char *  hwid,
const char *  name,
json_t **  result 
)

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

Parameters
cpsThe session reference without authentication if it's the first enroll.
modelThe model PLUG_ID of the device to control.
ctrlThe serial number ( HWID ) of the device to control.
passThe device password's
hwidHWID unique string to identify this controller device
namestring the name of this device
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_enroll_json()

cp_res cloudplugs_enroll_json ( cp_session  cps,
json_t *  obj,
json_t **  result 
)

This function performs an HTTP request to the server for enrolling a new production device or create new (development) device or enroll new or already existent controller device, that depends on the content of the json. Optionally places the response in *result.

Parameters
cpsThe session reference such that: if it's an prototype enroll, master authentication is required; if it's a product or controller enroll, the session cannot have authentication.
objJson object that contain the info for enroll new production device or create new (development) device (X-Plug-Master header required!) or enroll new or already existent controller device.
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_enroll_product_json()

cp_res cloudplugs_enroll_product_json ( cp_session  cps,
const char *  model,
const char *  hwid,
const char *  pass,
json_t *  props,
json_t **  result 
)

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

Parameters
cpsThe session reference without authentication.
modelPLUG_ID The device model's .
hwidHWID The serial number.
passstring The password.
propsIf not NULL, then initialize the custom properties.
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_enroll_prototype_json()

cp_res cloudplugs_enroll_prototype_json ( cp_session  cps,
const char *  name,
const char *  hwid,
const char *  pass,
json_t *  perm,
json_t *  props,
json_t **  result 
)

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

Parameters
cpsThe session reference without authentication.
namestring The name of the product.
hwidHWID If NULL, then it will be set as a random unique string.
passstring If NULL, then set as the X-Plug-Master of the company
permPERM_FILTER If NULL, then permit all.
propsIf not NULL, then initialize the custom properties.
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result., { "id":"PLUG_ID", "auth":String }
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_get_channel_json()

cp_res cloudplugs_get_channel_json ( cp_session  cps,
const char *  channel_mask,
json_t *  before,
json_t *  after,
json_t *  at,
json_t *  of,
int  offset,
int  limit,
json_t **  result 
)

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

Parameters
cpsThe session reference.
channel_maskThe CHMASK.
before: TIMESTAMP or OBJECT_ID Optional, timestamp valid if greater than zero or OID of published data
after: TIMESTAMP or OBJECT_ID Optional, timestamp valid if greater than zero or OID of published data
at: TIMESTAMP_CSV Optional, timestamp valid if greater than zero //TODO TIMESTAMP_CSV&?
of: PLUG_ID_CSV Optional, PLUG_ID_CSV
offset: N
limit: N
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.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_get_device_json()

cp_res cloudplugs_get_device_json ( cp_session  cps,
const char *  plugid,
json_t **  result 
)

This function performs an HTTP request to the server for reading a device. It places the response in *result.

Parameters
cpsThe session reference.
plugidIf NULL, then is the PLUG_ID in the session.
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_get_device_location_json()

cp_res cloudplugs_get_device_location_json ( cp_session  cps,
const char *  plugid,
json_t **  result 
)

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

Parameters
cpsThe session reference.
plugidIf not NULL, then the PLUG_ID of the device, otherwise the device referenced in the session.
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_get_device_prop_json()

cp_res cloudplugs_get_device_prop_json ( cp_session  cps,
const char *  plugid,
const char *  prop,
json_t **  result 
)

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

Parameters
cpsThe session reference.
plugidIf NULL, then is the PLUG_ID in the session.
propIf NULL, then all properties value; otherwise the single property value.
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_publish_data_json()

cp_res cloudplugs_publish_data_json ( cp_session  cps,
const char *  channel,
json_t *  body,
json_t **  result 
)

This function performs an HTTP request to the server to publish data. Authentication is requested

Parameters
cpsThe session reference.
channelA optional channel, if NULL data need to contain a couple "channel":"channel name"
bodyJSON an object or an array of objects like this:
{
"id" : OBJECT_ID,
"channel" : CHANNEL, // optional, to override the channel in the url
"data" : JSON,
"at" : TIMESTAMP_CSV ,
"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)
}
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_remove_data_json()

cp_res cloudplugs_remove_data_json ( cp_session  cps,
const char *  channel_mask,
json_t *  id,
json_t *  before,
json_t *  after,
json_t *  at,
json_t *  of,
json_t **  result 
)

This function performs an HTTP request to the server to delete some published data

Parameters
cpsThe session reference.
channel_maskThe channel mask
id: OBJECT_ID_CSV ,
before: TIMESTAMP or OBJECT_ID ,
after: TIMESTAMP or OBJECT_ID ,
at: TIMESTAMP_CSV,
of: PLUG_ID_CSV ,
resultThe response returned as a reference
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_remove_device_prop_json()

cp_res cloudplugs_remove_device_prop_json ( 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_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_retrieve_data_json()

cp_res cloudplugs_retrieve_data_json ( cp_session  cps,
const char *  channel_mask,
cp_time  before,
cp_time  after,
cp_time  at,
const char *  of,
int  offset,
int  limit,
json_t **  result 
)

This function performs an HTTP request to the server for retrieving already published data

Parameters
cpsThe session reference.
channel_maskCHMASK The channel mask.
beforeTIMESTAMP or OBJECT_ID Timestamp valid if greater than zero.
afterTIMESTAMP or OBJECT_ID Timestamp valid if greater than zero.
atTIMESTAMP_CSV Timestamp valid if greater than zero.
ofIf not NULL, then PLUG_ID_CSV.
offsetOffset valid if greater than zero.
limitLimit valid if greater than zero.
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_set_device_json()

cp_res cloudplugs_set_device_json ( cp_session  cps,
const char *  plugid,
json_t *  value,
json_t **  result 
)

This function performs an HTTP request to the server for modifying a device and [optionally] it places the response in *result

Parameters
cpsThe session reference.
plugidIf NULL, then is the PLUG_ID in the session.
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
}
resultA pointer such that *result will contain the dynamically allocated json object of the retrieved response body. The caller is responsible to free memory in *result.
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_set_device_location_json()

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

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

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_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_set_device_prop_json()

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

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

Parameters
cpsThe session reference.
plugidIf NULL, then is the PLUG_ID in the session.
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_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_uncontrol_device_json()

cp_res cloudplugs_uncontrol_device_json ( cp_session  cps,
const char *  plugid,
json_t *  plugid_controlled,
json_t **  result 
)

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

Parameters
cpsThe session reference.
plugidIf NULL, then is the PLUG_ID in the session.
plugid_controlledIf not NULL, then a json string or a json array of strings of PLUG_ID device(s) to uncontroll; (default all associated devices).
resultThe response returned as a reference
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.

◆ cloudplugs_unenroll_json()

cp_res cloudplugs_unenroll_json ( cp_session  cps,
json_t *  plugid,
json_t **  result 
)

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

Parameters
cpsThe session reference.
plugidThe PLUG_ID_CSV of the device(s) to remove; if NULL then remove the device referenced in the session.
resultThe response returned as a reference
Returns
CP_SUCCESS if the request succeeds, CP_FAILED otherwise.