The PHP class makes it easy to access Zenner IoT's ELEMENT IoT platform. It was builded for usage at Stadtwerke Karlsruhe GmbH , but can easily adapted to any other Servers / Systems.
require "element_iot.inc.php";
$element_iot = new element_iot("api_key_found_on_settings->api_keys", "your.domain", "proxy_if_needed");//__construct($api_key, $domain = NULL, $proxy = NULL)
There is no need for declaring an Transfer Protocol. It's always replaced with https://! The domain has a default value setted up for the usage at swka.
In the first version are six accessible functions implemented. I will list them in the following, with Parameters and description:
$element_iot->get($tp = ["devices","readings"], [
"id" => "1234567890"
])// public function get($tp = [], $configuration = []);
The get function starts an GET Request to the given domain and returns the answered data formatted as PHP Array, for easy access. IMORTANT: If you use the ["devices", "readings"], ["devices", "packets"], ["devices", "interfaces"], ["drivers", "instances"], ["mandates", "stats", "packets"] or ["mandates", "stats", "created_devices"] parameter an Device ID is requiered.
( i ) tp stands for type and should define your request. The configuration is the same as listed on the official api documentation.
The Array is directly converted into the GET Request. Pro: It's dynamic builded for the future.
- So use the key that you want to use as GET-Key as key for the Array and the GET-Value as Array value.
$configuration = [
"limit" => 10,
"sort" => "name",
"sort_direction" => "ascending",
"retrieve_after" => "ID of the last paginated item",
"before" => "YYYY-MM-DD",
"after" => "YYYY-MM-DD"
]
All currently possible possibilities are listed and explained in the following:
$element_iot->get(["devices"]);
# Returns an array of all devices, filled up with information like: name, interfaces, etc. (without readings!)
# > Can be directed to one device - if needed just add an id in the configuration.
$element_iot->get(["devices", "readings"], ["id" => "device_id_requiered"]);
# Returns an array of readings.
# > configuration
$element_iot->get(["devices", "packets"], ["id" => "device_id_requiered"]);
# Returns an array of packets.
# > configuration
$element_iot->get(["devices", "interfaces"], ["id" => "device_id_requiered"]);
# Returns an array of interfaces.
# > configuration
Configuration of: Devices | Configuration of: Readings | Configuration of: Packets | Configuration of: Interfaces
$element_iot->get(["tags"]);
# Returns an array of tags.
# > configuration
Configuration of: Tags
$element_iot->get(["parsers"]);
# Returns an array of parsers.
# > configuration
Configuration of: Parsers
$element_iot->get(["drivers"]); //returns an HTTP 500 Error at the current ELEMENT Version!
# Returns an array of tags.
# > configuration
$element_iot->get(["drivers", "instances"], ["id" => "device_id_requiered"]);
# Returns an array of driver instances.
# > configuration
Configuration of: Drivers | Configuration of: Driver-Instances
$element_iot->get(["groups"]);
# Returns an array of groups.
# > configuration
Configuration of: Groups
$element_iot->get(["api_keys"]);
# Returns an array of api_keys (if you are allowed to see them).
# > configuration
Configuration of: Api_keys
$element_iot->get(["mandates"]);
# Returns an array of all mandates.
# > configuration
$element_iot->get(["mandates", "stats", "packets"], ["id" => "device_id_requiered"]);
# Returns an array of driver instances.
# > configuration
$element_iot->get(["mandates", "stats", "created_devices"], ["id" => "device_id_requiered"]);
# Returns an array of driver instances.
# > configuration
Configuration of: Mandates | Configuration of: stats / Statistics
$element_iot->set_api_key("you_new_api_key");
Renew the API Key of an already initialized object.
$element_iot->set_api_key("you_new_api_key");
Returns an String with the length of 32 characters, where 24 are invisible.
For Identification if you use it for productiv systems with customers, etc.
$element_iot->get_cached_data();
Returns the answer of the last request.
$element_iot->set_domain("your_new_domain");
Sets an new domain.
$element_iot->get_domain();
Returns the current domain.
If you want to setup curl you can do this or other defaults on the attributes in the class or an proxy can also set during the initialization of the object.