1 example code, 1 php – Dovado 4GR User Manual
Page 26

T h e M o b i le C h o ic 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 6.2.6
26
© 2013 Dovado FZ-LLC
4.9.1
Example code
API example code for different platforms are available on
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
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);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
echo "OK.\n";
}
echo "Attempting to connect to '$ipaddress' on port '$api_port'...";
$result = socket_connect($socket, $ipaddress, $api_port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
echo "\nConnected to router\n";
}
respons_wait($socket);
/* Sending username to the API */
echo "Sending User Name...\n";
socket_write($socket, "user $username \r\n", strlen($username)+8);
echo "OK.\n";
respons_wait($socket);
/* Sending password to the API */
echo "Sending password...\n";
socket_write($socket, "pass $password \r\n", strlen($password)+8);
echo "OK.\n";
respons_wait($socket);
/* Setting up destination SMS number */
echo "Sending SMS number...\n";
socket_write($socket, "sms sendtxt $smsnr \r\n", strlen($smsnr)+15);