[ENG] 11.11. [DKSF 70/71.5 IU] How to Send Random SMS?

Information in the section is related to the device UniPing server solution v3/SMS with a built-in GSM modem.

A feature of sending random SMS notifications via an SNMP protocol and third party web applications (HTTP API) is implemented in the firmware of a device UniPing server solution v3/SMS in the DKSF 70.5.version.

Sending SMS Notifications via an SNMP Protocol

A maximum length of random SMS notifications cannot exceed 70 Latin or Cyrillic characters.

To send random SMS in Cyrillic letters via an SNMP protocol, there is a need to use UTF-8 encoding in the text of an SMS notification. To do this, there is a need to use the methods, described in the article «Converting files to UTF-8».

To send SMS using an SNMP protocol, there is a need to use the variable «npGsmSendSms», into which a destination phone number and an SMS text are written. To do this, see the MIB file, which can be downloaded from the page with a description of a device, the tab «Files».

OID

Name

Type

Access

.1.3.6.1.4.1.25728.3800.1.9.0npGsmSendSMSDisplayStringREAD/WRITE

A format of a random SMS notification:

[phone_number,phone_number,...] Message

where:

phone_number – is a destination number in square brackets.

Message – is a text of a message (must be divided by space from a destination number).

It is possible to send SMS to several destination numbers, having indicated them in square brackets divided by a comma, without spaces. If destination numbers are not specified, SMS will be sent to numbers, programmed in the settings of SMS notifications.

An Example of a Command Sequence for Sending a Random SMS through an SNMP Using the NET-SNMP Package

1. To send a random SMS, it is possible to use a special package NET-SNMP. To do this, there is a need to download a distributive of the NET-SNMP package from the section Download at the website: http://net-snmp.sourceforge.net/download.html

2. After installing the NET-SNMP package, run a utility snmpset.exe in a command line. To start a command line, use a button combination «Windows+L». After a window «Execute» has been opened, enter a command «cmd» and click the button «Enter». Next, go to the installation directory of the utility snmpset.exe using a command line:

В командной строке перейти в директорию установки утилиты snmpset.exe

3. Start the utility snmpset.exe with the next parameters of the command line:

snmpset.exe -v 1 -c COMMUNITY IP OID TYPE VALUE

where:

COMMUNITY – is a specified password, which is set in the page «SETUP» of a device web interface. Netping devices are set to community=SWITCH on default; 

IP – is an IP address of a NetPing device, through which a random SMS message will be sent; 

OID – is an SNMP identifier of a variable «npGsmSendSms», which is used to send a random SMS notification;

TYPE – is a type of a written value of an SNMP identifier of a variable. Symbols of types are given in the picture:

Тип записываемого значения SNMP идентификатора переменной

VALUE – is a written value, i.e, a text of an SMS message

According to the description represented above, a command for sending a random SMS using the utility snmpset.exe is as follows:

C:\Program Files (x86)\net-snmp\usr\bin>snmpset.exe -v 1 -c SWITCH 192.168.0.100 .1.3.6.1.4.1.25728.3800.1.9.0 s "[+79130000000] Hello! Test SMS!"

4. After a command has been successfully completed, the next response should be received:

SNMPv2-SMI::enterprises.25728.3800.1.9.0 = STRING: "[+79130000000] Hello! Test SMS!"

Sending SMS Notifications through Third-Party Web Applications (HTTP API)

A maximum length of random SMS notifications must not exceed 70 Latin or Cyrillic characters.

An Example of Sending a Random SMS Using a JavaScript Code

To send SMS through third-party web applcations, it is possible to use the next JavaScript code:

var r = new XMLHttpRequest();
r.open('POST', 'http://192.168.0.100/sendsms.cgi?utf8', true, 'visor', 'ping'); // visor:ping – a username and a password
r.withCredentials = true;
r.send('[+79130000000] Huston, we have a problem');

where:

192.168.0.100 – is a default IP address of a device.

visor – is a default username for connecting to a web interface of a device.

ping – is a default password for connecting to a web interface of a device.

It is possible to send SMS to several destination numbers, having indicated them in square brackets divided by a comma without spaces. If destination addresses are not chosen, then SMS will be sent to the numbers programmed in the settings of SMS notifications.

If a data format is correct, then a JavaScript code is returned as a result:

sendsms_result('ok');

A result of sending a message does not influence a returned CGI (Common Gateway Interface) response. CGI only initiates sending a message.

An Example of Sending a Random SMS Using a PowerShell Script

To send SMS through third-party web applications, it is possible to use the next PowerShell script:

$url = "http://192.168.0.100/sendsms.cgi?utf8"
$username = "visor"
$password = "ping"

$reqBody = "[+79136895423] Huston, we have a problem!"

$req = [System.Net.WebRequest]::Create($url)
$req.Method = "POST";

$req.Credentials = new-object System.Net.NetworkCredential($username, $password)

$Body = [System.Text.Encoding]::UTF8.GetBytes($reqBody);

$stream = $req.GetRequestStream();
$stream.Write($Body, 0, $Body.Length);

$stream.Flush();
$stream.Close();

$resp = $req.GetResponse().GetResponseStream()
$resp.Close()

where:

$url – is a variable, in which an  IP address of a Netping device is set as well as a script for sending random SMS notifications.

$username – is a variable, in which a username is set for authorisation at a NetPing device.

$password – is a variable, in which a password is set for authorisation at a NetPing device.

$reqBody – is a variable in which a destination number is set in square brackets as well as a text of an SMS notification (it is written divided by space from the destination number). It is possible to send SMS to several destination addresses, having indicated them in square brackets divided by a comma without spaces.