Digi IX20W-PR User Manual page 836

Table of Contents

Advertisement

Applications
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()
def send_sms(destination, msg):
print("sending SMS message", msg)
if len(destination) == 10:
destination = "+1" + destination
send(destination, msg)
if __name__ == '__main__':
IX20 User Guide
Use Python to control the color of multi-colored LEDs
Performing as CLI
836

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ix20Ix20wIx20-pr

Table of Contents