8 check services available, 9 api coding, 1 example code – Dovado PRO User Manual

Page 28: 1 php, Check services available, Api coding

Advertising
background image

T h e M o b i l e C h o i c e f o r y o u r B r o a d b a n d I n t e r n e t

Reference Manual 7.1.5

28

© 2014 Dovado FZ-LLC

>>

4.8

Check services available

Services available in current session:
To display which services that are available in current session, execute the command:

services

It will respond with the services (Home Automation and SMS) that are currently available
Example:
HOMEAUTOMATION=enabled
SMS=enabled

4.9

API Coding

The API can easily be extended with a custom front-end. When implementing a front-end, mind the
following:

The router might be behind a high-latency connection. Set a high timeout for your connection.
When logging in to the API, the password must be encoded either ISO-8859-1or UTF-8
When executing a command (for example ts aliases), each line of output from the API is
terminated with LF (Line Feed, ASCII character 10d) and the last line of output from the
command is ETB (End of Transmission Block, ASCII character 23d).
Since there can only be one instance of the API running on the Router, a session that has been
inactive for more than 60 seconds will be dropped in favor of a new session.

4.9.1

Example code

API example code for different platforms are available on http://www.dovado.mobi/

4.9.1.1

PHP

Below is a sample php script that will connect to the router and then send a SMS via the API

<?php
error_reporting(E_ALL);

echo "Code example on how to send a SMS via the Dovado router API\n";

/* The following variables are set
$username= your username to the router with API access
$password= your password for the above username
$ipaddress = ipaddress of your router
$api_port = 6435;
$smsnr = Number to send SMS to
$smstxt = Message content for your SMS
*/
$username = "admin";
$password = "password";
$api_port = 6435;
$ipaddress = ('192.168.0.1');
$smsnr = "Enter your phonenumber in international format (4670000000)";
$smstxt = "Enter Text Here";
$readbuf = '';

/* Function to wait for >> answers */
function respons_wait($insocket)
{
do {
$readbuf = socket_read($insocket, 4096, PHP_BINARY_READ) ;
}while (strpos($readbuf,'>>') === false);
$readbuf = '';
}


/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

Advertising