10 External APIs
55
10.8.2
MQTT outlet bindings
MQTT client outlet binding configuration
#
Topic subtree
Allow read
Allow write
QoS
1
outlets/0
2
outlets/1
3
outlets/2
4
outlets/3
5
outlets/4
6
outlets/5
7
outlets/6
8
outlets/7
Submit
At least once
At least once
At least once
At least once
At least once
At least once
At least once
At least once
MQTT outlet bindings
Every outlet can be mapped to an MQTT topic subtree, which will be prefixed by the topic root and '/'; the outlet will
report its state with a message with that topic if 'Allow read' is checked and honor requests to change its state if it
receives a message with that topic suffixed by '/set' and 'Allow write' is checked. The quality of service determines
the mode of delivery to request from the broker for messages on reporting outlet state; not all brokers may support
all delivery modes; the default should be sufficient for most purposes.
Note that there is no explicit way to request the states of outlets. MQTT brokers are expected to keep track of the
most recent payload of the topics.
10.8.3
MQTT payload formats
MQTT payload format is not defined by a standard, so we explicitly define it here. Everything that can be controlled
via MQTT in LPC9 is an outlet state, which can be ON or OFF. We encode ON as '1' (the single ASCII character '1')
and OFF as '0'. For compatibility, in addition to decoding '1' as ON and '0' as OFF, we accept '\0' (the ASCII NUL
character) and the strings 'off' and 'false' as OFF, and '\1' (the ASCII SOH character) and the strings 'on' and 'true' as
ON. Additionally, the empty string '' is used to indicate topic erasure (on topic changes or read access revocation).
10.8.4
MQTT sample commands
These examples assume you have an MQTT broker at 192.168.0.5, it doesn't require authentication and you have
the LPC9 set up like shown on screenshots above.
You'll need the mosquitto MQTT client to run these samples; analogous commands should be available for other
clients. mosquitto also has an MQTT broker implementation.
If you run the command:
mosquitto_sub -h 192.168.0.5 -C 1 -t pcr12345/outlets/0
it'll print the current state of the first outlet as known to the broker (as '0' or '1') and exit. The '-C 1' flags disable
waiting for more state changes; if you run the command with them removed:
mosquitto_sub -h 192.168.0.5 -t pcr12345/outlets/0
DLI LPC9 User’s Guide: 1.7.24.0
Содержание LPC9
Страница 1: ...DLI LPC9 User s Guide 1 7 24 0 ...
Страница 81: ......