Applications
Use the Paho MQTT python library
TX54 User Guide
721
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:
elems = line.split()
if len(elems) != 5:
continue
leases.append({"mac": elems[1], "ip": elems[2], "host": elems
[3]})
if leases:
client.publish(PREFIX "/leases", json.dumps(leases,
separators=(',',':')))
except:
print("Failed to open DHCP leases file")
def publish_system():
avg1, avg5, avg15 = runt.get("system.load_avg").split(', ')
ram_used = runt.get("system.ram.per")
disk_opt = runt.get("system.disk./opt.per")
disk_config = runt.get("system.disk./etc/config.per")
msg = json.dumps({
"load_avg": {
"1min": avg1,
"5min": avg5,
"15min": avg15
},
"disk_usage": {
"/opt": disk_opt,
"/etc/config:": disk_config,
"ram": ram_used
}
})
Содержание TX54
Страница 1: ...TX54 User Guide Firmware version 22 2 ...
Страница 190: ...Interfaces Bridging TX54 User Guide 190 ...
Страница 293: ...Hotspot Hotspot configuration TX54 User Guide 293 ...
Страница 332: ...Hotspot Show hotspot status and statistics TX54 User Guide 332 ...
Страница 584: ...Services Simple Network Management Protocol SNMP TX54 User Guide 584 4 Click Download ...
Страница 1069: ...Command line interface Command line reference TX54 User Guide 1069 reboot Reboot the system Parameters None ...