Applications UsePython to control thecolor of multi-colored LEDs
IX20 User Guide
838
>>> s = serial.Serial("/dev/serial/port1", 115200)
>>> s.write(b"Hello from serial port")
26
>>>
6. Use Ctrl-Dto exit the Python session. You can also exit the session using exit() or quit().
Use the Paho MQTT python library
Your IX20 device includes support for the Paho MQTTpython library. MQTT isa lightweight messaging
protocol used to communicate with variousapplicationsincluding cloud-based applicationssuch as
Amazon Web Servicesand Microsoft Azure. The following isexample codethat reads CPUand RAM
usage on the device, updatesthe device firmware, then publishes information about DHCPclientsand
system information to the MQTT server at 192.168.1.100. TheMQTT server IPisconfigurable.
"""
MQTT client example:
- Reporting some device metrics from runt
- Reporting DHCP clients
- Firmware update feature (simple implementation, read TODO in cmd_fwupdate)
"""
import sys
import time
import paho.mqtt.client as mqtt
import json
from acl import runt, config
from http import HTTPStatus
import urllib.request
import tempfile
import os
from digidevice import cli
POLL_TIME = 60
def cmd_reboot(params):
print("Rebooting unit...")
try:
cli.execute("reboot", 10)
except:
print("Failed to run 'reboot' command")
return HTTPStatus.INTERNAL_SERVER_ERROR
return HTTPStatus.OK
def cmd_fwupdate(params):
try:
fw_uri = params["uri"]
except:
print("Firmware file URI not passed")
return HTTPStatus.BAD_REQUEST
print("Request to update firmware with URI: {}".format(fw_uri))
try:
fd, fname = tempfile.mkstemp()
os.close(fd)