IoTool MQTT API guidelines
These are the guidelines that will help you send external data to an IoTool server using the IoTool MQTT API.
Introduction
Readings can also be sent to an IoTool server via MQTT messages.
The sub-domain at which you already have your IoTool account should be used.
Access restriction
Username and password to access the IoTool database should be specified in the JSON message.
Provide your MQTT client with the username "iotool_pub" and password "publishiotool".
JSON
Reading should be in JSON format and must include your IoTool username and password. Username, password, sensor, reading and datetimems are all mandatory. Sensor should be named as reading_name@sensor_name. Reading should be a number. Datetimems is the timestamp of the reading in UNIX epoch time in seconds followed by 3 digits for milliseconds.
Sample code
PHP
<?php
$client = new Mosquitto\Client();
$client--->setCredentials('iotool_pub', 'publishiotool');
$client->setTlsCertificates('/etc/ssl/certs');
$client->onConnect(function($code, $message) use ($client, $publish) {
$client->publish('iotool/readings', '[
{"username": "<your_username>"}
,
{"password": "<your_password>"}
,
{ "sensor": "temperature@my_sensor", "reading": "1", "datetimems": 1419876021778 }
,
{ "sensor": "temperature@my_sensor", "reading": "2.3", "datetimems": 1419876022778 }
,
{ "sensor": "posture@my_sensor", "reading": "3", "datetimems": 1419876023778 }
]', 1);
});
$client->connect('<your_subdomain>.iotool.io',8883);</your_subdomain>;
Bash
#!/bin/bash
/usr/bin/mosquitto_pub\
-h <your_subdomain>.iotool.io -p 8883\
-u iotool_pub -P publishiotool -t iotool/readings -q 1 -r\
--capath /etc/ssl/certs\
-m '['\
'{"username": "<your_username>"}, '\
'{"password": "<your_password>"}, '\
'{ "sensor": "temperature@my_sensor", "reading": "1", "datetimems": 1419876021778 }, '\
'{ "sensor": "temperature@my_sensor", "reading": "2.3", "datetimems": 1419876022778 }, '\
'{ "sensor": "posture@my_sensor", "reading": "3", "datetimems": 1419876023778 }'\
']'