How to Use TG SMS API

1. Overview
This protocol allows external programs to control NeoGate to send/receive SMS and send USSD.

Note: Limit your sending speed to 1 SMS per 10 seconds for 1 port when using this API.

2. TG Configuration
API should be enabled in TG. Click SMS tab on the upper right corner, and click API Settings. Tick the box in front of “Enable API”. Enter the IP address that is allowed to run SMS Client. Save and apply changes.

Figure 1 Enable API on TG


3. Connect SMS Client to TG SMS server
SMS Client is connected to TG SMS server through TCP. The IP address is the IP of TG, and the port is the default 5038. User name and password are those configured in the previous step. After TCP connection is established, "Action: Login\r\nUsername: apiuser\r\nSecret: apipass\r\n\r\n" will be sent the server. If the server replies “Response: Success”, it indicates the connection is successful. Other responses indicate unsuccessful connection.

Below is an example using putty to connect SMS server:

Figure 2 Using Putty to Connect TG API


Figure 3 Login Command and Successful

4. Execute smscommand
Check port status:
Client->Server command: “Action: smscommand\r\ncommand: gsm show spans\r\n\r\n”
GSM span 2: Power on, Provisioned, Up, Active,Standard
GSM span 3: Power on, Provisioned, Undetected SIM Card, Active,Standard
GSM span 4: Power on, Provisioned, Undetected SIM Card, Active,Standard
GSM span 5: Power on, Provisioned, Undetected SIM Card, Active,Standard

Figure 4 Example Command

Check specific port information:
If detailed information of a specific port to be checked, use the following command.

command: “Action: smscommand\r\ncommand: gsm show $port+1\r\n\r\n”
$port: the port you want to check

Response: Follows
Privilege: SMSCommand
D-channel: 2
Status: Power on, Provisioned, Up, Active,Standard
Type: CPE
Manufacturer: SIMCOM_Ltd
Model Name: SIMCOM_SIM900
Model IMEI: 013227009596135
Revision: 1137B13SIM900M64_ST
Network Name: CHINA MOBILE
Network Status: Registered (Home network)
Signal Quality (0,31): 30
SIM IMSI: 460021059661838
SIM SMS Center Number: +8613800592500
Send SMS Center Number: Undefined
Last event: Hangup
State: READY
Last send AT: AT+CREG?\r\n--END COMMAND--

Figure 5 Example Command

5. Send & Receive SMS
As the connection is successful, TG SMS server can be used to send SMS and USSD. The server will also send a message to the Client upon receiving a SMS.

Send SMS

Command: “Action: smscommand\r\ncommand: gsm send sms $port+1 $dest \"$message\" $id\r\n\r\n”
$port: the trunk used to send the SMS
$dest: the destination number
$message: contents of the message. Note that if the message contains special characters like \r\n, it is better that the message is encoded using url_encode. The maximum byte before encoding is 1024.

You might find a tool in the Internet like this web tool: URL Encode Decode

$id: the unique identifier of the SMS
Response status: after the SMS is sent, the following message will be sent to the client. In the message, “ID” is the designated unique identifier when sending the SMS, “Smcs” is the SMS center number, “Status: 1” indicates successful sending, and “0” indicates failure.
Event: UpdateSMSSend
Privilege: all,smscommand
ID: 2
Smsc: +8613800592500
Status: 1

Figure 6 Send SMS

Receive SMS

Upon receiving an SMS, TG will send the following contents to the Client, which will integrate the SMS based on the contents. The example is a message from China Mobile service hotline 10086 replying a balance inquiry. It is integrated by 2 pieces of a whole SMS.
“ID”: the unique identifier of these SMS;
“GsmPort”: the port that received the SMS;
“Sender”: the number that sent the SMS;
“Recvtime”: received time;
“Index”: sequence number of the SMS piece
“Total”: how many pieces of SMS is sent as a whole
“Smsc”: SMS center number
Content: SMS content

Event: ReceivedSMS
Privilege: all,smscommand
ID: E9510086
GsmPort: 5
Sender: 10086
Recvtime: 2013-11-13 14:59:13
Index: 2
Total: 2
Smsc: +8613800591551

Figure 7 Receive SMS

6. Send USSD

Command: “Action: SMSCommand \r\ncommand: gsm send ussd $port+1 \"$message\" [$timeout]\r\n\r\n”
$port: the port that sent the USSD
$message: the contents of the USSD
$timeout: timeout period, the default is 30 seconds.
1:Received USSD success on span: 6
\tUSSD Responses: 1
\tUSSD Code: 72
\tUSSD Len: 276
\tUSSD Message: 6B228FCE4F7F7528638C4E0A670D52A15385000A003830014F1860E06D3B52A8000A00313001670065B04F1860E0000A003230018BDD8D3967E58BE2000A003330014E1A52A167E58BE2000A003430014E1A52A1529E7406000A003630016570636E4E1A52A1000A003730015E3875284FE1606F000A00393001004700334ECB7ECD000A002D002D002D
USSD Code: the code value
USSD Message: the encoded content of USSD, the Client needs to decode the USSD with USSD code.
0:Send USSD failed on span 6
0:Send USSD timeout on span 6




Have more questions? Submit a request


Please sign in to leave a comment.