<syntaxhighlight lang="php">

  1. !/usr/bin/php

<?php

  1. //This example logs into OpenSPOT, shows some information (if 'debug' is set to true)
  2. // and sends an SMS to a local tranceiver (via the modem, not via the network)
  1. // ----------- configuration :
  2. $debug = false;
  3. $server = "http://my.openspot.ip.address";
  4. $password = "openspot";
  1. $sms_dst = 0000000; // THE DESTINATION DMRid GOES HERE;
  2. $sms_src = 0000000; // THE SOURCE DMRid GOES HERE;
  3. $sms_fmt = 2; // format: 0 - ETSI, 1 - UDP, 2 - UDP/Chinese
  1. $msg="This is a test message from ON7LDS";
  2. // ---------------------------------------------------------------------------------
  1. $token=file_get_contents ("$server/gettok.cgi");
  2. $data=json_decode($token,true);
  3. if ($debug) print_r($data);
  4. $digest = hash("sha256", $data['token'].$password); //binair
  5. if ($debug) echo "Digest : $digest\n\n";
  1. $data = array(
  2. 'token' => $data['token'],
  3. 'digest' => $digest
  4. );
  1. $opts=array(
  2. "http" => array(
  3. // http://www.php.net/manual/en/context.http.php
  4. 'method' => 'POST',
  5. 'header' => "Authorization: Bearer null\r\n".
  6. "Content-type: application/json\r\n",
  7. 'content' => json_encode($data)
  8. )
  9. );
  10. // Create the context for the request
  11. $context = stream_context_create($opts);
  1. $response = @file_get_contents("$server/login.cgi", false, $context);
  1. // Check for errors
  2. if($response === false){
  3. if ($debug) die('Failed '.print_r(error_get_last(),true)."\n");
  4. die("Login failed\n");
  5. }
  6. // Decode the response
  7. $responseData = json_decode($response, true);
  8. if ($debug) print_r($responseData);
  9. $jwt=$responseData['jwt'];
  1. if ($debug) echo "\njwt = $jwt\n\n";
  1. if ($debug) print "Authorisation status : \n" . @file_get_contents("$server/checkauth.cgi")."\n";


  1. $opts=array(
  2. "http" => array(
  3. 'method' => 'GET',
  4. 'header' => "Authorization: Bearer $jwt\r\n"
  5. )
  6. );
  7. $context = stream_context_create($opts);


  1. if ($debug) {
  2. $response = file_get_contents("$server/info.cgi", false, $context);
  3. $responseData = json_decode($response, true);
  4. print "Openspot Device Info :\n";
  5. print_r($responseData);
  6. }


  1. if ($debug) {
  2. $response = file_get_contents("$server/modemfreq.cgi", false, $context);
  3. $responseData = json_decode($response, true);
  4. print "Openspot Modem Frequency : \n";
  5. print_r($responseData);
  6. }
  1. $response = file_get_contents("$server/status-dmrsms.cgi", false, $context);
  2. $responseData = json_decode($response, true);
  3. if ($debug) { print "Openspot SMS status : \n"; print_r($responseData); }
  1. $data = array(
  2. "only_save" => 0,
  3. "intercept_net_msgs" => 1,
  4. "send_dstid" => $sms_dst,
  5. "send_calltype" => 0,<-><------>// 0 = private, 1 = group
  6. "send_srcid" => $sms_src,
  7. "send_format" => $sms_fmt,<---><------>// 0 - ETSI, 1 - UDP, 2 - UDP/Chinese
  8. "send_tdma_channel" => 0,
  9. "send_to_modem" => 1,
  10. "send_msg" => bin2hex(mb_convert_encoding($msg, "UTF-16"))
  11. );
  12. $opts=array(
  13. "http" => array(
  14. 'method' => 'POST',
  15. 'header' => "Authorization: Bearer $jwt\r\n".
  16. "Content-type: application/json\r\n",
  17. 'content' => json_encode($data)
  18. )
  19. );
  20. $smscontext = stream_context_create($opts);
  1. $response = @file_get_contents("$server/status-dmrsms.cgi", false, $smscontext);
  1. if ($response===false) {
  2. print "Send SMS failed\n\n";
  3. } else {
  4. print "SMS sent\n\n";
  5. }

?> </syntaxhighlight>