Applications UsePython to control thecolor of multi-colored LEDs
IX20 User Guide
836
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.smsto send CLI commands
The following example script listensfor an incoming SMSmessage from a specific phonenumber
(2223334444) and then executes the SMSmessage as a CLI command. If the CLI command being run
has output, it will send that output as a response SMSmessage. If the CLI command being run hasno
output but ran successfully, the script will instead send an OKresponse SMSmessage. Errors in
running the CLI will have those error messages sent as a SMSresponse.
#!/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 + '). Performing as CLI
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__':