Applications
Use the Paho MQTT python library
TX54 User Guide
719
Use the Paho MQTT python library
Your TX54 device includes support for the Paho MQTT python library. MQTT is a lightweight messaging
protocol used to communicate with various applications including cloud-based applications such as
Amazon Web Services and Microsoft Azure. The following is example code that reads CPU and RAM
usage on the device, updates the device firmware, then publishes information about DHCP clients and
system information to the MQTT server at 192.168.1.100. The MQTT server IP is configurable.
"""
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)
try:
urllib.request.urlretrieve(fw_uri, fname)
except:
print("Failed to download FW file from URI {}".format(fw_uri))
return HTTPStatus.NOT_FOUND
try:
ret = cli.execute("system firmware update file " + fname, 60)
Summary of Contents for TX54
Page 1: ...TX54 User Guide Firmware version 22 2 ...
Page 190: ...Interfaces Bridging TX54 User Guide 190 ...
Page 293: ...Hotspot Hotspot configuration TX54 User Guide 293 ...
Page 332: ...Hotspot Show hotspot status and statistics TX54 User Guide 332 ...
Page 584: ...Services Simple Network Management Protocol SNMP TX54 User Guide 584 4 Click Download ...