CloudPlugs REST Library  1.0.0
for PHP
RestClient Class Reference

The PHP Client library is used to communicate with Cloudplugs platform with HTTP REST requests to the server. More...

Public Member Functions

 __construct ($options=NULL)
 
 __destruct ()
 
 setOptions ($optionsArray)
 
 enableSSL ($enabled)
 
 hasSSL ()
 
 setAuthId ($id)
 
 setDebugMode ($enabled)
 
 setOutputFormat ($format)
 
 getLastHttpResultCode ()
 
 getLastHttpResultString ()
 
 getLastErrorString ()
 
 getLastErrorCode ()
 
 setBaseUrl ($url)
 
 getBaseUrl ()
 
 setTimeout ($seconds)
 
 getTimeout ()
 
 setCACert ($certPath=NULL)
 
 setAuth ($id, $pass, $is_master=FALSE)
 
 getAuthId ()
 
 getAuthPass ()
 
 isAuthMaster ()
 
 getServerResponse ()
 
 enrollProductEx ($model, $hwid, $pass, $props=NULL, $propLinks=NULL)
 
 enrollProduct ($data, $outputFormat=NULL)
 
 enrollPrototypeEx ($name, $pass=NULL, $hwid=NULL, $perm=NULL, $props=NULL, $propLinks=NULL)
 
 enrollPrototype ($data=NULL, $outputFormat=NULL)
 
 getDevice ($plugid=NULL, $outputFormat=NULL)
 
 setDeviceLocationEx ($plugid, $longitude, $latitude, $altitude, $accuracy, $timestamp)
 
 setDeviceLocation ($data, $outputFormat=NULL)
 
 getDeviceLocationEx ($plugid=NULL)
 
 getDeviceLocation ($data=NULL, $outputFormat=NULL)
 
 setDeviceProp ($plugid=NULL, $prop=NULL, $value, $outputFormat=NULL)
 
 removeDeviceProp ($plugid, $prop, $outputFormat=NULL)
 
 getDeviceProp ($plugid=NULL, $prop=NULL, $outputFormat=NULL)
 
 publishData ($data, $channel=NULL, $outputFormat=NULL)
 
 removeDataEx ($channelMask, $id=NULL, $before=NULL, $after=NULL, $at=NULL, $of=NULL)
 
 removeData ($data, $outputFormat=NULL)
 
 retrieveDataEx ($channelMask, $before=NULL, $after=NULL, $at=NULL, $of=NULL, $offset=NULL, $limit=NULL)
 
 retrieveData ($data, $outputFormat=NULL)
 
 listChannelsEx ($channelMask, $before=NULL, $after=NULL, $at=NULL, $of=NULL, $offset=NULL, $limit=NULL)
 
 listChannels ($data, $outputFormat=NULL)
 
 unenroll ($data=NULL, $outputFormat=NULL)
 
 setDeviceEx ($id=NULL, $perm=NULL, $name=NULL, $status=NULL, $props=NULL, $propLinks=NULL)
 
 setDevice ($data=NULL, $outputFormat=NULL)
 
 enrollControllerEx ($model, $ctrl, $pass, $hwid, $name)
 
 enrollController ($data=NULL, $outputFormat=NULL)
 
 uncontrolDevice ($plugid=NULL, $plugidControlled=NULL, $outputFormat=NULL)
 
 controlDeviceEx ($model, $ctrl, $pass, $hwid=NULL, $name=NULL)
 
 controlDevice ($data, $outputFormat=NULL)
 

Public Attributes

const TIMEOUT = 60
 
const BASEURL = "https://api.cloudplugs.com/iot/"
 
const HTTP_STR = "http://"
 
const HTTPS_STR = "https://"
 
const PLUG_AUTH_HEADER = "X-Plug-Auth: "
 
const PLUG_ID_HEADER = "X-Plug-Id: "
 
const PLUG_EMAIL_HEADER = "X-Plug-Email: "
 
const PLUG_MASTER_HEADER = "X-Plug-Master: "
 
const CONTENT_TYPE_JSON = "Content-type: application/json"
 
const PATH_DATA = "data"
 
const PATH_DEVICE = "device"
 
const PATH_CHANNEL = "channel"
 
const CTRL = "ctrl"
 
const HWID = "hwid"
 
const NAME = "name"
 
const MODEL = "model"
 
const PASS = "pass"
 
const PERM = "perm"
 
const PROPS = "props"
 
const STATUS = "status"
 
const PROP_LINKS = "prop_links"
 
const DATA = "data"
 
const BEFORE = "before"
 
const AFTER = "after"
 
const OF = "of"
 
const OFFSET = "offset"
 
const LIMIT = "limit"
 
const AUTH = "auth"
 
const ID = "id"
 
const AT = "at"
 
const CHMASK = "channel_mask"
 
const LOCATION = "location"
 
const LONGITUDE = "x"
 
const LATITUDE = "y"
 
const ACCURACY = "r"
 
const ALTITUDE = "z"
 
const TIMESTAMP = "t"
 
const MAX_LONGITUDE = 180.0
 
const MIN_LONGITUDE = -180.0
 
const MAX_LATITUDE = 90.0
 
const MIN_LATITUDE = -90.0
 
const TYPE_CTRL = 1
 
const TYPE_HWID = 2
 
const TYPE_NAME = 3
 
const TYPE_MODEL = 4
 
const TYPE_PASS = 5
 
const TYPE_PERM = 6
 
const TYPE_PROPS = 7
 
const TYPE_STATUS = 8
 
const TYPE_PROP_LINKS = 9
 
const TYPE_DATA = 10
 
const TYPE_BEFORE = 11
 
const TYPE_AFTER = 12
 
const TYPE_OF = 13
 
const TYPE_OFFSET = 14
 
const TYPE_LIMIT = 15
 
const TYPE_AUTH = 16
 
const TYPE_ID = 17
 
const TYPE_OID = 18
 
const TYPE_AT = 19
 
const TYPE_CHMASK = 20
 
const TYPE_LOCATION = 21
 
const TYPE_LONGITUDE = 22
 
const TYPE_LATITUDE = 23
 
const TYPE_ACCURACY = 24
 
const TYPE_ALTITUDE = 25
 
const TYPE_TIMESTAMP = 26
 
const TYPE_PLUG_ID = 27
 
const TYPE_PLUG_ID_ARR = 28
 
const TYPE_PLUG_ID_CSV = 29
 
const TYPE_TIMESTAMP_ARR = 30
 
const TYPE_TIMESTAMP_CSV = 31
 
const TYPE_OID_ARR = 32
 
const TYPE_OID_CSV = 33
 
const FORMAT_JSON = 0
 
const FORMAT_ARRAY = 1
 
const FORMAT_OBJECT = 2
 
const HTTP_GET = 0
 
const HTTP_POST = 1
 
const HTTP_PUT = 2
 
const HTTP_DELETE = 3
 
const HTTP_PATCH = 4
 
const ERR_INTERNAL = -1
 
const ERR_OUT_OF_MEMORY = -2
 
const ERR_INVALID_SESSION = -3
 
const ERR_QUERY_IS_NOT_OBJECT = -4
 
const ERR_QUERY_INVALID_TYPE = -5
 
const ERR_HEADER_MUST_BE_STRING = -6
 
const ERR_INVALID_PARAMETER = -7
 
const ERR_INVALID_LOGIN = -8
 
const ERR_JSON_PARSE = -9
 
const ERR_JSON_ENCODE = -10
 
const ERR_INVALID_CONTENT_LENGTH = -11
 
const ERR_HTTP = -12
 
const ERR_NETWORK = -13
 
const HTTP_RES_OK = 200
 
const HTTP_RES_CREATED = 201
 
const HTTP_RES_MULTISTATUS = 207
 
const HTTP_RES_BAD_REQUEST = 400
 
const HTTP_RES_UNAUTHORIZED = 401
 
const HTTP_RES_PAYMENT_REQUIRED = 402
 
const HTTP_RES_FORBIDDEN = 403
 
const HTTP_RES_NOT_FOUND = 404
 
const HTTP_RES_NOT_ALLOWED =405
 
const HTTP_RES_NOT_ACCEPTABLE = 406
 
const HTTP_RES_SERVER_ERROR = 500
 
const HTTP_RES_NOT_IMPLEMENTED = 501
 
const HTTP_RES_BAD_GATEWAY = 502
 
const HTTP_RES_SERVICE_UNAVAILABLE = 503
 

Static Public Attributes

static $HTTP_METHODS = array ( "GET", "POST", "PUT", "DELETE", "PATCH" )
 

Detailed Description

The PHP Client library is used to communicate with Cloudplugs platform with HTTP REST requests to the server.

This class contains basically two sets of methods: a set of configuration functions used to configure the class's parameters, and a set of functions used to perform HTTP requests to Cloudplugs server. A set of configuration options are available: for example it is possible to force the library to return server response in a specific output (json, array, object) or run the library in debug mode (display debugging information). All HTTP requests to the server are synchronous. Many functions are provided in two different forms: an explicit parameters version and a compact parameter version (passed within an array or a JSON encoded string).

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = NULL)
Parameters
array$options(optional) an associative array (option => value). Supported options:
"outputFormat" => "json" or "array" or "object" (forces following requests output to be returned in that format)
"debugMode" => TRUE or FALSE (show/hide debug information)
"timeout" => int (max number of milliseconds to wait for server response)
"id" => String (set the authentication ID to use)
"pass" => String (set the authentication password to use)
"isMaster" => TRUE or FALSE (if authentication refers to a master password)
"baseUrl" => String (the base URL to be used to perform remote HTTP requests)
"enableSSL" => TRUE or FALSE (whether to enable SSL or not)

◆ __destruct()

__destruct ( )

Member Function Documentation

◆ controlDevice()

controlDevice (   $data,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to obtain the privileges to control a device (read or publish data for that device) (compact parameters version)

Parameters
array | string$dataarray or JSON string containing the following parameters:
"model" => PLUG_ID model id of the device to control
"ctrl" => HWID serial number of the device to control
"pass" => password value
"hwid" => (optional) HWID unique string to identify this controller device
"name" => (optional) the name of this device
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ controlDeviceEx()

controlDeviceEx (   $model,
  $ctrl,
  $pass,
  $hwid = NULL,
  $name = NULL 
)

This function performs an HTTP request to the server to obtain the privileges to control a device (read or publish data for that device) (explicit parameters version)

Parameters
string$modelPLUG_ID model id of the device to control
string$ctrlHWID serial number of the device to control
string$passpassword value
string$hwid(optional) HWID unique string to identify this controller device
string$name(optional) the name of this device
Returns
Formatted server output on success, false otherwise.

◆ enableSSL()

enableSSL (   $enabled)

Sets SSL on/off.

Parameters
bool$enabledSSL operating mode value.
Returns
TRUE if success, FALSE otherwise.

◆ enrollController()

enrollController (   $data = NULL,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to enroll a controller device. This function can be invoked only if no ID set or if id is an Xplug email. After request, authentication credentials are automatically set to controller (compact parameters version)

Parameters
array | string$dataarray or JSON string containing the following parameters:
"model" => PLUG_ID model id of the device to control
"ctrl" => HWID serial number of the device to control
"pass" => password value
"hwid" => HWID unique string to identify this controller device
"name" => the name of this device
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, FALSE otherwise.

◆ enrollControllerEx()

enrollControllerEx (   $model,
  $ctrl,
  $pass,
  $hwid,
  $name 
)

This function performs an HTTP request to the server to enroll a controller device. This function can be invoked only if no ID set or if id is an Xplug email. After request, authentication credentials are automatically set to controller (explicit parameters version)

Parameters
string$modelPLUG_ID model id of the device to control
string$ctrlHWID serial number of the device to control
string$passpassword value
string$hwidHWID unique string to identify this controller device
string$namethe name of this device
Returns
Formatted server output on success, FALSE otherwise.

◆ enrollProduct()

enrollProduct (   $data,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to enroll a new production device (compact parameters version). After request auth credentials are authomatically set to enrolled device.

Parameters
array | string$dataarray or json encoded string containing the following parameters:
"model" => PLUG_ID
"hwid" => HWID
"pass" => String
"props" => array, optional, to initializa custom properties
"prop_links" => PROP_LINKS optional, to inizialize the properties links (not supported yet, present only for future use)
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ enrollProductEx()

enrollProductEx (   $model,
  $hwid,
  $pass,
  $props = NULL,
  $propLinks = NULL 
)

This function performs an HTTP request to the server to enroll a new production device (explicit parameters version). After request auth credentials are automatically set to enrolled device.

Parameters
string$modelPLUG_ID the model of this device
string$hwidHWID the serial number
string$passpassword value
array$props(optional), to initialize the custom properties
array | object$propLinks(optional) PROP_LINKS to inizialize the properties links (not supported yet, present only for future use)
Returns
Formatted server output on success, false otherwise.

◆ enrollPrototype()

enrollPrototype (   $data = NULL,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to creates a new (prototype) device (X-Plug-Master header required. Compact parameters version)

Parameters
array | string$dataarray or json encoded string containing the following parameters:
"name" => String
"pass" => String (optional) if absent set as the X-Plug-Master of the company
"hwid" => HWID (optional) if absent it will be set as a random unique string
"perm" => PERM_FILTER (optional) if absent permit all
"props" => array, optional, to initializa custom properties
"props_links" => PROP_LINKS optional, to inizialize the properties links (not supported yet, present only for future use)
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ enrollPrototypeEx()

enrollPrototypeEx (   $name,
  $pass = NULL,
  $hwid = NULL,
  $perm = NULL,
  $props = NULL,
  $propLinks = NULL 
)

This function performs an HTTP request to the server to create a new (prototype) device (X-Plug-Master header required) (explicit parameters version)

Parameters
string$name
string$pass(optional), if absent set as the X-Plug-Master of the company
string$hwidHWID the serial number
array$perm(optional) PERM_FILTER if absent permit all
array$props(optional) to initialize the custom properties
array$propLinks(optional) PROP_LINKS to initialize properties links (not supported yet, present only for future use)
Returns
Formatted server output on success, false otherwise.

◆ getAuthId()

getAuthId ( )

get authentication ID value.

Returns
The ID value.

◆ getAuthPass()

getAuthPass ( )

get authentication password value.

Returns
The password value.

◆ getBaseUrl()

getBaseUrl ( )

Gets the base REST server URL.

Returns
the base URL value.

◆ getDevice()

getDevice (   $plugid = NULL,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to read device's information and properties

Parameters
string$plugidPLUG_ID
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ getDeviceLocation()

getDeviceLocation (   $data = NULL,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to get device location property (compact parameters version)

Parameters
array | string$dataarray or JSON containing the following parameters:
"id" => PLUG_ID
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ getDeviceLocationEx()

getDeviceLocationEx (   $plugid = NULL)

This function performs an HTTP request to the server to get device location property (explicit parameters version)

Parameters
string$plugid(optional) PLUG_ID the device id
Returns
Formatted server output on success, false otherwise.

◆ getDeviceProp()

getDeviceProp (   $plugid = NULL,
  $prop = NULL,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to read a device's properties (if "prop" is specified) or get all device's properties (if "prop" is not specified)

Parameters
string$plugid(optional) PLUG_ID the device id
string$propproperty name
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ getLastErrorCode()

getLastErrorCode ( )

get the last error code ancountered.

Returns
The last error code.

◆ getLastErrorString()

getLastErrorString ( )

Switches the last encountered error code into a human readable message.

Returns
The error message.

◆ getLastHttpResultCode()

getLastHttpResultCode ( )

Gets the HTTP response status code of the last request.

Returns
The last HTTP status code.

◆ getLastHttpResultString()

getLastHttpResultString ( )

Switches the HTTP response status code of the last request into a human readable message.

Returns
The last HTTP status message.

◆ getServerResponse()

getServerResponse ( )

returns the server response output of the last HTTP REST request

Returns
The server response output

◆ getTimeout()

getTimeout ( )

get the timeout value.

Returns
The timeout value (in seconds).

◆ hasSSL()

hasSSL ( )

Checks whether SSL is enabled or not.

Returns
TRUE id SSL enabled, FALSE otherwise.

◆ isAuthMaster()

isAuthMaster ( )

Returns true if the requests will be performed as a master user, false otherwise

Returns
TRUE / FALSE

◆ listChannels()

listChannels (   $data,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to retrieve a list of channels refer already published data matching some criteria (compact parameters version)

Parameters
array | string$dataarray or JSON string containing the following parameters:
"channel_mask" => CHMASK
"before" => (optional) TIMESTAMP or OBJECT_ID (OID of published data)
"after" => (optional) TIMESTAMP or OBJECT_ID (OID of published data)
"at" => (optional) TIMESTAMP_CSV
"of" => (optional) PLUG_ID_CSV
"offset" => (optional) Number: positive integer (including 0)
"limit" => (optional) Number: positive integer (including 0)
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ listChannelsEx()

listChannelsEx (   $channelMask,
  $before = NULL,
  $after = NULL,
  $at = NULL,
  $of = NULL,
  $offset = NULL,
  $limit = NULL 
)

This function performs an HTTP request to the server to retrieve a list of channels refer already published data matching some criteria (explicit parameters version)

Parameters
string$channelMask(see: CHMASK)
int | string$before(optional) TIMESTAMP or OBJECT_ID (OID of published data)
int | string$after(optional) TIMESTAMP or OBJECT_ID (OID of published data)
int | string$at(optional) TIMESTAMP_CSV
string$of(optional) PLUG_ID_CSV
int$offset(optional) Number: positive integer (including 0)
int$limit(optional) Number: positive integer (including 0)
Returns
Formatted server output on success, false otherwise.

◆ publishData()

publishData (   $data,
  $channel = NULL,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to publish data on the platform

Parameters
array | string$dataarray or json encoded string containing the following keys:
[
[ "id" => OBJECT_ID (optional), OID of the published data to update
"channel" => CHANNEL, (optional), to override the channel in the url
"data" => any valid JSON encodable value,
"at" => TIMESTAMP,(optional)
"of" => PLUG_ID, (optional), check if the X-Plug-Id is authorized for setting this field
"expire_at" => TIMESTAMP, // (optional), expire date of this data entry
"ttl" => int (optional), how many seconds this data entry will live (if "expire_at" is present, then this field is ignored)
],
... ]
Note: the outer array is optional!
string$channel(optional) if absent "channel" parameter is required in the data
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ removeData()

removeData (   $data,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to delete data ( Note: at least one of the following param is required: id, before, after or at) (compact parameters version)

Parameters
array | string$dataarray or JSON string containing the following parameters:
"channel_mask" => CHMASK
"id" => (optional) OBJECT_ID_CSV or [OBJECT_ID,...]
"before" => (optional) TIMESTAMP or OBJECT_ID (OID of published data)
"after" => (optional) TIMESTAMP or OBJECT_ID (OID of published data)
"at" => (optional) TIMESTAMP_CSV or [TIMESTAMP,...]
"of" => (optional) PLUG_ID_CSV or [PLUG_ID,...]
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ removeDataEx()

removeDataEx (   $channelMask,
  $id = NULL,
  $before = NULL,
  $after = NULL,
  $at = NULL,
  $of = NULL 
)

This function performs an HTTP request to the server to delete data ( Note: at least one of the following param is required: id, before, after or at) (explicit parameters version)

Parameters
string$channelMaskCHMASK
string | array$id(optional) OBJECT_ID_CSV or [OBJECT_ID,...]
int | string$before(optional) TIMESTAMP or OBJECT_ID (OID of published data)
int | string$after(optional) TIMESTAMP or OBJECT_ID (OID of published data)
int | string | array$at(optional) TIMESTAMP_CSV or [TIMESTAMP,...]
string | array$of(optional) PLUG_ID_CSV or [PLUG_ID,...]
Returns
Formatted server output on success, false otherwise.

◆ removeDeviceProp()

removeDeviceProp (   $plugid,
  $prop,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to remove a device's property

Parameters
string$plugidPLUG_ID
string$propproperty name
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ retrieveData()

retrieveData (   $data,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to read published data (compact parameters version)

Parameters
array | string$dataarray or JSON string containing the following parameters:
"channel_mask" => CHMASK
"before" => (optional) TIMESTAMP or OBJECT_ID (OID of published data)
"after" => (optional) TIMESTAMP or OBJECT_ID (OID of published data)
"at" => (optional) TIMESTAMP_CSV
"of" => (optional) PLUG_ID_CSV
"offset" => (optional) Number: positive integer (including 0)
"limit" => (optional) Number: positive integer (including 0)
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ retrieveDataEx()

retrieveDataEx (   $channelMask,
  $before = NULL,
  $after = NULL,
  $at = NULL,
  $of = NULL,
  $offset = NULL,
  $limit = NULL 
)

This function performs an HTTP request to the server to read published data (explicit parameters version)

Parameters
string$channelMask(see: CHMASK)
int | string$before(optional) TIMESTAMP or OBJECT_ID (OID of published data)
int | string$after(optional) TIMESTAMP or OBJECT_ID (OID of published data)
int | string$at(optional) TIMESTAMP_CSV
string$of(optional) PLUG_ID_CSV
int$offset(optional) Number: positive integer (including 0)
int$limit(optional) Number: positive integer (including 0)
Returns
Formatted server output on success, false otherwise.

◆ setAuth()

setAuth (   $id,
  $pass,
  $is_master = FALSE 
)

Set the authentication credentials to be included in the requests headers.

Parameters
string$idthe id value.
string$passpassword value.
bool$is_masterspecifies if the requests are performed as a master user or not.
Returns
TRUE if success, FALSE otherwise.

◆ setAuthId()

setAuthId (   $id)

Sets Authentication ID value.

Parameters
string$idThe new ID value.
Returns
TRUE if success, FALSE otherwise.

◆ setBaseUrl()

setBaseUrl (   $url)

Sets the base REST server URL.

Parameters
string$urlthe base URL value.
Returns
TRUE if success, FALSE otherwise.

◆ setCACert()

setCACert (   $certPath = NULL)

Attempts to load an external certificate to verify the peer with when running over SSL

Parameters
string$certPathThe path to the certificate file
Returns
bool

◆ setDebugMode()

setDebugMode (   $enabled)

Sets debug mode on/off.

Parameters
bool$enabledThe new debug mode value.
Returns
TRUE.

◆ setDevice()

setDevice (   $data = NULL,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to modify a device's information or properties (compact parameters version)

Parameters
array | string$dataarray or JSON string containing the following parameters:
"id" => PLUG_ID (optional)
"perm" => PERM_FILTER (optional) it contains just the sharing filters to modify
"name" => String (optional) the device name
"status" => STATUS (optional)
"props" => array (optional) it contains just the properties to modify
"prop_links" =>(optional), it contains a link reference to the published data (not supported yet, present only for future use. See: PROP_LINKS)
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ setDeviceEx()

setDeviceEx (   $id = NULL,
  $perm = NULL,
  $name = NULL,
  $status = NULL,
  $props = NULL,
  $propLinks = NULL 
)

This function performs an HTTP request to the server to modify a device's information or properties (explicit parameters version)

Parameters
string$id(see: PLUG_ID)
array$perm(optional), it contains just the sharing filters to modify (see: PERM_FILTER)
string$name(optional) the device name
string$status(optional) (see: STATUS)
array$props(optional), it contains just the properties to modify
array$propLinks(optional), it contains a link reference to the published data (not supported yet, present only for future use. See: PROP_LINKS)
Returns
Formatted server output on success, false otherwise.

◆ setDeviceLocation()

setDeviceLocation (   $data,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to set device location property (compact parameters version)

Parameters
array | string$dataarray or JSON string containing the following parameters:
"id" => PLUG_ID
"x" => double (longitude)
"y" => double (latitude)
"r" => double (accuracy)
"z" => double (altitude)
"t" => string|int TIMESTAMP
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ setDeviceLocationEx()

setDeviceLocationEx (   $plugid,
  $longitude,
  $latitude,
  $altitude,
  $accuracy,
  $timestamp 
)

This function performs an HTTP request to the server to set device location property (explicit parameters version)

Parameters
string$plugidPLUG_ID
double$longitude
double$latitude
double$altitude
double$accuracy
string | number$timestampTIMESTAMP
Returns
Formatted server output on success, false otherwise.

◆ setDeviceProp()

setDeviceProp (   $plugid = NULL,
  $prop = NULL,
  $value,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to write or delete device properties It can accept a single property ($prop = property name, $value = property value) or a set of properties ($prop = null, $value = object or array of all name=>value to write)

Parameters
string$plugid(optional) PLUG_ID
string$prop(optional), property name
string | object | array$valueproperties values
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

◆ setOptions()

setOptions (   $optionsArray)

Sets class options.

Parameters
array$optionsArrayAn associative array: "option name"=> value.
Supported options:
"outputFormat" => "json" or "array" or "object" (forces following requests ouput to be returned in that format)
"debugMode"=> TRUE or FALSE (show/hide debug information)
"timeout"=> int (max number of milliseconds to wait for server response)
"id"=> String (set the authentication ID for following request)
"pass" => String (set the authentication password to use)
"isMaster"=> TRUE or FALSE (if authentication password refers to a master password)
"baseUrl"=> String (the base URL to be used to perform remote HTTP requests)
"enableSSL" => TRUE or FALSE (whether to enable SSL or not)
Returns
TRUE if all parameters have been successfully set, FALSE otherwise.

◆ setOutputFormat()

setOutputFormat (   $format)

Forces all requests to return server output in a specific data format.

Parameters
string$formatThe new output format value. Can be "array", "object" or "json".
Returns
TRUE

◆ setTimeout()

setTimeout (   $seconds)

Sets the timeout value for REST requests.

Parameters
int$secondsthe maximum waiting time (in seconds) for requests.
Returns
TRUE if success, FALSE otherwise.

◆ uncontrolDevice()

uncontrolDevice (   $plugid = NULL,
  $plugidControlled = NULL,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to unenroll a (controller) device

Parameters
string$plugid(optional) PLUG_ID the controller PLUG_ID
string | array$plugidControlled(optional) PLUG_ID or [ PLUG_ID, ... ] the device(s) to disassociate (default: all associated devices).
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, FALSE otherwise.

◆ unenroll()

unenroll (   $data = NULL,
  $outputFormat = NULL 
)

This function performs an HTTP request to the server to remove a device (any: development, product or controller):

Parameters
string | array$dataPLUG_ID or [PLUG_ID,...] or PLUG_ID_CSV : The ids of the devices to be removed
string$outputFormat(optional) the expected output format (will be overwritten if default outputFormat value is set)
Returns
Formatted server output on success, false otherwise.

Member Data Documentation

◆ $HTTP_METHODS

$HTTP_METHODS = array ( "GET", "POST", "PUT", "DELETE", "PATCH" )
static

◆ ACCURACY

const ACCURACY = "r"

◆ AFTER

const AFTER = "after"

◆ ALTITUDE

const ALTITUDE = "z"

◆ AT

const AT = "at"

◆ AUTH

const AUTH = "auth"

◆ BASEURL

const BASEURL = "https://api.cloudplugs.com/iot/"

◆ BEFORE

const BEFORE = "before"

◆ CHMASK

const CHMASK = "channel_mask"

◆ CONTENT_TYPE_JSON

const CONTENT_TYPE_JSON = "Content-type: application/json"

◆ CTRL

const CTRL = "ctrl"

◆ DATA

const DATA = "data"

◆ ERR_HEADER_MUST_BE_STRING

const ERR_HEADER_MUST_BE_STRING = -6

◆ ERR_HTTP

const ERR_HTTP = -12

◆ ERR_INTERNAL

const ERR_INTERNAL = -1

◆ ERR_INVALID_CONTENT_LENGTH

const ERR_INVALID_CONTENT_LENGTH = -11

◆ ERR_INVALID_LOGIN

const ERR_INVALID_LOGIN = -8

◆ ERR_INVALID_PARAMETER

const ERR_INVALID_PARAMETER = -7

◆ ERR_INVALID_SESSION

const ERR_INVALID_SESSION = -3

◆ ERR_JSON_ENCODE

const ERR_JSON_ENCODE = -10

◆ ERR_JSON_PARSE

const ERR_JSON_PARSE = -9

◆ ERR_NETWORK

const ERR_NETWORK = -13

◆ ERR_OUT_OF_MEMORY

const ERR_OUT_OF_MEMORY = -2

◆ ERR_QUERY_INVALID_TYPE

const ERR_QUERY_INVALID_TYPE = -5

◆ ERR_QUERY_IS_NOT_OBJECT

const ERR_QUERY_IS_NOT_OBJECT = -4

◆ FORMAT_ARRAY

const FORMAT_ARRAY = 1

◆ FORMAT_JSON

const FORMAT_JSON = 0

◆ FORMAT_OBJECT

const FORMAT_OBJECT = 2

◆ HTTP_DELETE

const HTTP_DELETE = 3

◆ HTTP_GET

const HTTP_GET = 0

◆ HTTP_PATCH

const HTTP_PATCH = 4

◆ HTTP_POST

const HTTP_POST = 1

◆ HTTP_PUT

const HTTP_PUT = 2

◆ HTTP_RES_BAD_GATEWAY

const HTTP_RES_BAD_GATEWAY = 502

◆ HTTP_RES_BAD_REQUEST

const HTTP_RES_BAD_REQUEST = 400

◆ HTTP_RES_CREATED

const HTTP_RES_CREATED = 201

◆ HTTP_RES_FORBIDDEN

const HTTP_RES_FORBIDDEN = 403

◆ HTTP_RES_MULTISTATUS

const HTTP_RES_MULTISTATUS = 207

◆ HTTP_RES_NOT_ACCEPTABLE

const HTTP_RES_NOT_ACCEPTABLE = 406

◆ HTTP_RES_NOT_ALLOWED

const HTTP_RES_NOT_ALLOWED =405

◆ HTTP_RES_NOT_FOUND

const HTTP_RES_NOT_FOUND = 404

◆ HTTP_RES_NOT_IMPLEMENTED

const HTTP_RES_NOT_IMPLEMENTED = 501

◆ HTTP_RES_OK

const HTTP_RES_OK = 200

◆ HTTP_RES_PAYMENT_REQUIRED

const HTTP_RES_PAYMENT_REQUIRED = 402

◆ HTTP_RES_SERVER_ERROR

const HTTP_RES_SERVER_ERROR = 500

◆ HTTP_RES_SERVICE_UNAVAILABLE

const HTTP_RES_SERVICE_UNAVAILABLE = 503

◆ HTTP_RES_UNAUTHORIZED

const HTTP_RES_UNAUTHORIZED = 401

◆ HTTP_STR

const HTTP_STR = "http://"

◆ HTTPS_STR

const HTTPS_STR = "https://"

◆ HWID

const HWID = "hwid"

◆ ID

const ID = "id"

◆ LATITUDE

const LATITUDE = "y"

◆ LIMIT

const LIMIT = "limit"

◆ LOCATION

const LOCATION = "location"

◆ LONGITUDE

const LONGITUDE = "x"

◆ MAX_LATITUDE

const MAX_LATITUDE = 90.0

◆ MAX_LONGITUDE

const MAX_LONGITUDE = 180.0

◆ MIN_LATITUDE

const MIN_LATITUDE = -90.0

◆ MIN_LONGITUDE

const MIN_LONGITUDE = -180.0

◆ MODEL

const MODEL = "model"

◆ NAME

const NAME = "name"

◆ OF

const OF = "of"

◆ OFFSET

const OFFSET = "offset"

◆ PASS

const PASS = "pass"

◆ PATH_CHANNEL

const PATH_CHANNEL = "channel"

◆ PATH_DATA

const PATH_DATA = "data"

◆ PATH_DEVICE

const PATH_DEVICE = "device"

◆ PERM

const PERM = "perm"

◆ PLUG_AUTH_HEADER

const PLUG_AUTH_HEADER = "X-Plug-Auth: "

◆ PLUG_EMAIL_HEADER

const PLUG_EMAIL_HEADER = "X-Plug-Email: "

◆ PLUG_ID_HEADER

const PLUG_ID_HEADER = "X-Plug-Id: "

◆ PLUG_MASTER_HEADER

const PLUG_MASTER_HEADER = "X-Plug-Master: "

◆ PROP_LINKS

const PROP_LINKS = "prop_links"

◆ PROPS

const PROPS = "props"

◆ STATUS

const STATUS = "status"

◆ TIMEOUT

const TIMEOUT = 60

◆ TIMESTAMP

const TIMESTAMP = "t"

◆ TYPE_ACCURACY

const TYPE_ACCURACY = 24

◆ TYPE_AFTER

const TYPE_AFTER = 12

◆ TYPE_ALTITUDE

const TYPE_ALTITUDE = 25

◆ TYPE_AT

const TYPE_AT = 19

◆ TYPE_AUTH

const TYPE_AUTH = 16

◆ TYPE_BEFORE

const TYPE_BEFORE = 11

◆ TYPE_CHMASK

const TYPE_CHMASK = 20

◆ TYPE_CTRL

const TYPE_CTRL = 1

◆ TYPE_DATA

const TYPE_DATA = 10

◆ TYPE_HWID

const TYPE_HWID = 2

◆ TYPE_ID

const TYPE_ID = 17

◆ TYPE_LATITUDE

const TYPE_LATITUDE = 23

◆ TYPE_LIMIT

const TYPE_LIMIT = 15

◆ TYPE_LOCATION

const TYPE_LOCATION = 21

◆ TYPE_LONGITUDE

const TYPE_LONGITUDE = 22

◆ TYPE_MODEL

const TYPE_MODEL = 4

◆ TYPE_NAME

const TYPE_NAME = 3

◆ TYPE_OF

const TYPE_OF = 13

◆ TYPE_OFFSET

const TYPE_OFFSET = 14

◆ TYPE_OID

const TYPE_OID = 18

◆ TYPE_OID_ARR

const TYPE_OID_ARR = 32

◆ TYPE_OID_CSV

const TYPE_OID_CSV = 33

◆ TYPE_PASS

const TYPE_PASS = 5

◆ TYPE_PERM

const TYPE_PERM = 6

◆ TYPE_PLUG_ID

const TYPE_PLUG_ID = 27

◆ TYPE_PLUG_ID_ARR

const TYPE_PLUG_ID_ARR = 28

◆ TYPE_PLUG_ID_CSV

const TYPE_PLUG_ID_CSV = 29

◆ TYPE_PROP_LINKS

const TYPE_PROP_LINKS = 9

◆ TYPE_PROPS

const TYPE_PROPS = 7

◆ TYPE_STATUS

const TYPE_STATUS = 8

◆ TYPE_TIMESTAMP

const TYPE_TIMESTAMP = 26

◆ TYPE_TIMESTAMP_ARR

const TYPE_TIMESTAMP_ARR = 30

◆ TYPE_TIMESTAMP_CSV

const TYPE_TIMESTAMP_CSV = 31