attm2x / m2x-php
AT&T’s M2X is a cloud-based fully managed data storage service for network connected machine-to-machine (M2M) devices. From trucks and turbines to vending machines and freight containers, M2X enables the devices that power your business to connect and share valuable data.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 550
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 30
Forks: 14
Open Issues: 2
Requires
- php: >=5.3.2
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is not auto-updated.
Last update: 2021-03-02 19:56:20 UTC
README
AT&T's M2X PHP Client
AT&T M2X is a cloud-based fully managed time-series data storage service for network connected machine-to-machine (M2M) devices and the Internet of Things (IoT).
The AT&T M2X API provides all the needed operations and methods to connect your devices to AT&T's M2X service. This library aims to provide a simple wrapper to interact with the AT&T M2X API for PHP. Refer to the Glossary of Terms to understand the nomenclature used throughout this documentation.
Getting Started
- Signup for an M2X Account.
- Obtain your Master Key from the Master Keys tab of your Account Settings screen.
- Create your first Device and copy its Device ID.
- Review the M2X API Documentation.
Installation
Simply add a dependency on attm2x/m2x-php to your project's composer.json file if you use Composer to manage the dependencies of your project.
{ "require": { "attm2x/m2x-php": "~4.0" } }
Usage
In order to communicate with the M2X API, you need an instance of M2X:. You need to pass your API key in the constructor to access your data.
use Att\M2X\M2X; $m2x = new M2X("<YOUR-API-KEY>"");
This provides an interface to your data in M2X
-
$distribution = $m2x->distribution("<DISTRIBUTION-ID>"); $distributions = $m2x->distributions();
-
$device = $m2x->device("<DEVICE-ID>"); $devices = $m2x->devices();
-
$key = $m2x->key("<KEY-TOKEN>"); $keys = $m2x->keys();
Refer to the documentation on each class for further usage instructions.
Example
In order to run this example, you will need a Device ID
and API Key
. If you don't have any, access your M2X account, create a new Device, and copy the Device ID
and API Key
values. The following script will send your CPU load average to three different streams named load_1m
, load_5m
and load_15
. Check that there's no need to create a stream in order to write values into it.
In order to execute this script, run:
API_KEY= DEVICE= php examples/uptime.php
use Att\M2X\M2X; use Att\M2X\Error\M2XException; $apiKey = getenv("API_KEY"); $deviceId = getenv("DEVICE"); $m2x = new M2X($apiKey); # Get the device $device = $m2x->device($deviceId); # Create the streams if they don't exist yet $device->updateStream('load_1m'); $device->updateStream('load_5m'); $device->updateStream('load_15m'); while (true) { list($load_1m, $load_5m, $load_15m) = sys_getloadavg(); $now = date('c'); $values = array( 'load_1m' => array(array('value' => $load_1m, 'timestamp' => $now)), 'load_5m' => array(array('value' => $load_5m, 'timestamp' => $now)), 'load_15m' => array(array('value' => $load_15m, 'timestamp' => $now)) ); try { $device->postUpdates($values); } catch (M2XException $ex) { echo 'Error: ' . $ex->getMessage(); echo $ex->response->raw; break; } sleep(10); }
Versioning
This lib aims to adhere to Semantic Versioning 2.0.0. As a summary, given a version number MAJOR.MINOR.PATCH
:
MAJOR
will increment when backwards-incompatible changes are introduced to the client.MINOR
will increment when backwards-compatible functionality is added.PATCH
will increment with backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH
format.
Note: the client version does not necessarily reflect the version used in the AT&T M2X API.
License
This lib is provided under the MIT license. See LICENSE for applicable terms.