Setting up GSM modem

The modem is used in the system to send SMS notifications and receive SMS commands.

To operate with a modem:

  1. Install the SIM card in the mobile phone and make sure that it is functional, check the PIN code;

  2. Insert the SIM card in the modem;

  3. Turn on the power of the monitoring system;

  4. Configure the modem;

  5. Add SMS notifications and configure the logic or group notifications.

Configuring the modem for sending and receiving SMS

To configure the modem, use the modem settings tab (Main Menu→SMS messages):

image-20240226-090435.png

Fields characterizing the properties of the modem element in a system:

  • Status – the state of the cellular network;

  • Operator – the state of the cellular network;

  • Signal level – the signal level;

  • PIN code – pin-code of sim-card;

  • Choose an operator – an actual list of operators present on the GSM network and the button for refreshing this list;

  • SMS center number – SMS service center number, leave it blank to auto-detect;

     

  • Request current balance – the number on which the account balance is requested, to see the answer, click on the "OK" button and wait for an answer, which will be shown in the log;

     

     

  • Clear SMS list – clear list of SMS messages.

The "List of SMS messages" contains up to 100 recent SMS messages (1000 for VT9xx systems) that the system or user attempted to send. When the device is rebooted, the list is not saved.

If the sim card has a pin, you must specify this pin in the corresponding field in the configuration form.

Attention!

After 3 incorrect attempts, you must remove the sim card and use the PUK code to unlock it.

 

If an error occurs during the operation of the modem, or the SIM card is not installed, or the PIN code is not correct, the message written into the log queue ("GSM modem: Error, check your SIM card and PIN code" or "GSM modem: modem error, restart smsd"). The message is displayed only 5 times in order not to overflow the log.

GSM operators list

The list of operators is updated once a few minutes after the system is turned on. Next time the list can be updated by the button. Getting the list is a long procedure and can take several minutes. When successfully receiving the list the corresponding message is displayed in the log.

If it is not possible to set up the connection with the network of the selected operator, then the modem switches to the automatic selection mode.

The name of the operator on the network that works the modem is shown in the Operator field.

GSM modem elements

The “System Tree” menu has elements corresponding to the status of the modem. These elements do not affect the state of the element "System". Elements can be used in logical schemes.

image-20240226-090555.png

 

  • GSM Signal Level - analog value, shows the signal level in percent from 0 to 100%;

  • GSM State - discrete value, shows the state of the GSM network:

    • Not connected - if the connection has not yet been established;

    • Alarm - if an error has occurred;

    • Normal - if the connection is established successfully.

  • LTE State - discrete value, shows the state of the LTE connection if the modem supports it:

    • Not connected - if the connection has not yet been established or disabled;

    • Alarm - if an error has occurred;

    • Normal - if the connection is established successfully.

SMS messages

To add an SMS notification recipient, first, open the System Tree menu, further open the window →SMS:

  • Name – name of the notification. Can be arbitrary (name, the position of the recipient, ...);

  • Phone number – the telephone number to which the notification has to be sent.  

  • Message text – text messages can be in any language. Also in this field, you can use various macros (%1 - %8), which insert the current values of variables into the text.

To apply the settings, click the "Save" button. To test SMS, click the "Test" button.

When You press "Test", the system sends a message to test if the SMS is sent correctly. Test SMS may contain incorrect information about sensors (macros %1 and %2) for testing purposes only.

After filling in the notification parameters, you must specify the event (events) by which the SMS message will be sent. To do this, open the Preferences → Logic schemes → Add window and specify the condition for sending the SMS message in the logic. In one logic, it is possible to send SMS notifications to not more than 15 recipients for one or more events. If you need to send SMS notifications to more than 15 recipients in the same logic, then create new logic with the same input condition.

SMS messages are sent to the queue, which allows you not to wait until the end of sending the previous message. The information about the sent messages is displayed in the monitoring system log. The capacity of the queue is 100 messages, if overflowed, the sent messages are automatically deleted.

If an error occurs while the message is being sent, the message with the status of SMS send error is displayed in the log, the reasons of which may be:

  • the negative balance on the SIM card account.

  • low signal level;

  • the wrong format or nonexistent recipient phone number.

If these items do not fit your situation, try to restart the monitoring system. Also, check the sending of messages from your mobile phone.

Sending SMS using third-party programs

To send SMS, you can use, for example, the cURL utility. Either other programs with similar functionality.

To send an SMS, use the following command in the console:

gcc -O2 -o sendsms sendsms.c

 

Script for sending SMS

#!/bin/bash

# SMS sending script for version 2.4.x and higher

 

usage()

{

cat << EOF

usage: $0 options

 

OPTIONS:

   -?,-h   Show this message

   -H      Hostname or IP address

   -u      User name

   -p      Password

   -P      Phone for sending

   -m      Message for sending

EOF

}

 

HOSTIP=

USERNAME=

PASSWORD=

TOPHONE=

MESSAGE='Test'

 

while getopts “hH:u:p:P:m:” OPTION

do

     case $OPTION in

         h)

             usage

             exit 1

             ;;

         H)

             HOSTIP=$OPTARG

             ;;

         u)

             USERNAME=$OPTARG

             ;;

         p)

             PASSWORD=$OPTARG

             ;;

         P)

             TOPHONE=$OPTARG

             ;;

         m)

             MESSAGE=$OPTARG

             ;;

         ?)

             usage

             exit

             ;;

     esac

done

 

if [[ -z $HOSTIP ]] || [[ -z $USERNAME ]] || [[ -z $PASSWORD ]] || [[ -z $TOPHONE ]] || [[ -z $MESSAGE ]]

then

     usage

     exit 1

fi

 

# 1) password hash

HASH=`echo -n ${PASSWORD} | openssl dgst -sha1 | awk '{print $NF}'`

 

# 2) authorization

RESPONSE=`curl -s -d "querytype=auth&name=${USERNAME}&h=${HASH}" "${HOSTIP}/engine.htm"`

# or for HTTPS case

#RESPONSE=`curl -s -d "querytype=auth&name=${USERNAME}&h=${HASH}" -k "https://${HOSTIP}/engine.htm"`

 

# 3) session key

KEY=`echo -n  ${RESPONSE} | awk -F"\"" '{print $4}'`

 

# 4) send SMS

curl -d "querytype=send_sms_message&k=${KEY}" --data-urlencode "to_phone=${TOPHONE}" --data-urlencode "message=${MESSAGE}" ${HOSTIP}/engine.htm > /dev/null 2>&1

# or for HTTPS case

#curl -d "querytype=send_sms_message&k=${KEY}" --data-urlencode "to_phone=${TOPHONE}" --data-urlencode "message=${MESSAGE}" -k https://${HOSTIP}/engine.htm > /dev/null 2>&1

In case of errors, leave comments below on the page or at our forum. Please indicate in the message the current version of the firmware of the monitoring system (System menu → About this system → Firmware version).