Digi IX10 User Manual page 364

Hide thumbs Also See for IX10:
Table of Contents

Advertisement

Applications
client.subscribe(PREFIX_CMD + "/system")
def on_message(client, userdata, msg):
""" Supporting only a single topic for now, no need for filters
Expects the following message format:
{
"cid": "<client-id>",
"cmd": "<command>",
"params": {
<optional_parameters>
}
}
Supported commands:
- "fw-update"
params:
- "uri": "<firmware_file_URL>"
- "reboot"
params:
"""
try:
m = json.loads(msg.payload)
cid = m["cid"]
cmd = m["cmd"]
try:
payload = m["params"]
except:
payload = None
except:
print("Invalid command format: {}".format(msg.payload))
if not cid:
# Return if client-ID not passed
return None
send_cmd_reply(client, msg.topic, cid, cmd, HTTPStatus.BAD_REQUEST)
try:
status = CMD_HANDLERS[cmd](payload)
except:
print("Invalid command: {}".format(cmd))
status = HTTPStatus.NOT_IMPLEMENTED
send_cmd_reply(client, msg.topic, cid, cmd, status)
def publish_dhcp_leases():
leases = []
try:
with open('/etc/config/dhcp.leases', 'r') as f:
for line in f:
[3]})
if leases:
client.publish(PREFIX_EVENT + "/leases", json.dumps(leases,
separators=(',',':')))
except:
print("Failed to open DHCP leases file")
IX10 User Guide
elems = line.split()
if len(elems) != 5:
continue
leases.append({"mac": elems[1], "ip": elems[2], "host": elems
Use the Paho MQTT python library
364

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents