Digi TX40 User Manual page 809

Table of Contents

Advertisement

Applications
if len(sys.argv) > 1:
dest = sys.argv[1]
else:
dest = '+15005550006'
my_callback = Callback(sms_test_callback, metadata=True)
send_sms(dest, 'Hello World!')
print("Please send an SMS message now.")
print("Execution halted until a message is received or 60 seconds have
passed.")
# acquire the semaphore and wait until a callback occurs
COND.acquire()
try:
COND.wait(60.0)
except Exception as err:
print("exception occured while waiting")
print(err)
COND.release()
my_callback.unregister_callback()
Example script using digidevice.sms to send CLI commands
The following example script listens for an incoming SMS message from a specific phone number
(2223334444) and then executes the SMS message as a CLI command. If the CLI command being run
has output, it will send that output as a response SMS message. If the CLI command being run has no
output but ran successfully, the script will instead send an OK response SMS message. Errors in
running the CLI will have those error messages sent as a SMS response.
#!/usr/bin/python
# Take an incoming SMS message from a specified phone number and run it as
# a CLI command. Send a reponse SMS to the sender before running the command
import os
import threading
import sys
from digidevice import cli
from digidevice.sms import Callback, send
COND = threading.Condition()
allowed_incoming_phone_number = '2223334444'
def sms_test_callback(sms, info):
if info['content.number'] == allowed_incoming_phone_number:
print(f"SMS message from {info['content.number']} received")
print(sms)
print(info)
#if sms == "Reboot":
#
send_sms(dest, 'Reboot message received, rebooting device...')
#
response = cli.execute("reboot")
#
print (response)
send_sms(dest, 'Message received (' + sms + ').
command...')
response = cli.execute(sms)
if not response:
response = 'OK'
send_sms(dest, 'CLI results: ' + response)
print (response)
COND.acquire()
COND.notify()
COND.release()
TX40 User Guide
Develop Python applications
Performing as CLI
809

Advertisement

Table of Contents
loading

Table of Contents