|
| 1 | +MQTTPoE Unit |
| 2 | +============ |
| 3 | + |
| 4 | +..include::../refs/unit.mqttpoe.ref |
| 5 | + |
| 6 | +The ``MQTTPoE Unit`` is an Ethernet communication module specifically designed for MQTT communication. It features supports PoE power and embedded W5500 Ethernet chip, which enables seamless connectivity to Ethernet networks. The module also includes a UART communication interface, allowing for control via AT commands. In addition, it integrates an RJ45 adaptive 10/100M network port for easy network connectivity. |
| 7 | + |
| 8 | +..NOTE:: |
| 9 | + |
| 10 | + The PoE version has integrated PoE power, with 1.2A@5V (6W) load capability. |
| 11 | + |
| 12 | +Support the following products: |
| 13 | + |
| 14 | + |MqttPoeUnit| |
| 15 | + |
| 16 | +Micropython Example:: |
| 17 | + |
| 18 | + import os, sys, io |
| 19 | + import M5 |
| 20 | + from M5 import * |
| 21 | + from unit import MQTTPoEUnit |
| 22 | + import time |
| 23 | + |
| 24 | + def mqtt_0_SubTopic_event(data): |
| 25 | + global mqttpoe_0 |
| 26 | + print(data[0]) |
| 27 | + print(data[1]) |
| 28 | + |
| 29 | + mqttpoe_0 = MQTTPoEUnit(port=(18, 17)) |
| 30 | + |
| 31 | + mqttpoe_0.set_client('m5-mqtt-2024', 'mqtt.m5stack.com', 1883, '', '', 120) |
| 32 | + mqttpoe_0.set_subscribe('SubTopic', mqtt_0_SubTopic_event, 0) |
| 33 | + mqttpoe_0.set_connect() |
| 34 | + |
| 35 | + while True: |
| 36 | + mqttpoe_0.check_msg() |
| 37 | + time.sleep_ms(50) |
| 38 | + |
| 39 | +UIFLOW2 Example: |
| 40 | + |
| 41 | + |example.png| |
| 42 | + |
| 43 | +..only::builder_html |
| 44 | + |
| 45 | + |mqttpoeunit_demo.m5f2| |
| 46 | + |
| 47 | + |
| 48 | +class MQTTPoEUnit |
| 49 | +----------------- |
| 50 | + |
| 51 | +Constructors |
| 52 | +------------ |
| 53 | + |
| 54 | +..class::MQTTPoEUnit(port=(,)) |
| 55 | + |
| 56 | + Create a MQTTPoEUnit object |
| 57 | + |
| 58 | + The parameters is: |
| 59 | + - ``port`` uart pin tuple, which contains: ``(tx_pin, rx_pin)``. |
| 60 | + |
| 61 | + UIFLOW2: |
| 62 | + |
| 63 | + |init.png| |
| 64 | + |
| 65 | + |
| 66 | +Methods |
| 67 | +------- |
| 68 | + |
| 69 | +..method::MQTTPoEUnit.set_client(client_id, server, port=0, username=None, password=None, keepalive=0) |
| 70 | + |
| 71 | +:param str client_id: the unique client id string used when connecting to |
| 72 | + the broker. |
| 73 | +:param str server: the hostname or IP address of the remote broker. |
| 74 | +:param int port: the network port of the server host to connect to. |
| 75 | +:param username: a username for broker authentication. |
| 76 | +:type username: str or None |
| 77 | +:param password: a password for broker authentication. |
| 78 | +:type password: str or None |
| 79 | +:param int keepalive: maximum period in seconds allowed between |
| 80 | + communications with the broker. If no other messages |
| 81 | + are being exchanged, this controls the rate at which |
| 82 | + the client will send ping messages to the broker. |
| 83 | + |
| 84 | + UIFLOW2: |
| 85 | + |
| 86 | + |set_client.png| |
| 87 | + |
| 88 | + |
| 89 | +..method::MQTTPoEUnit.set_connect() |
| 90 | + |
| 91 | + Connect to a server. |
| 92 | + |
| 93 | + UIFLOW2: |
| 94 | + |
| 95 | + |set_connect.png| |
| 96 | + |
| 97 | +..method::MQTTPoEUnit.set_disconnect() |
| 98 | + |
| 99 | + Disconnect from a server, release resources. |
| 100 | + |
| 101 | + UIFLOW2: |
| 102 | + |
| 103 | + |set_disconnect.png| |
| 104 | + |
| 105 | + |
| 106 | +..method::MQTTPoEUnit.set_publish(topic, msg, qos=0) |
| 107 | + |
| 108 | + Publish a message. |
| 109 | + |
| 110 | +:param topic: the topic that the message should be published on. |
| 111 | +:type topic: str or bytes or bytearray |
| 112 | +:param msg: the message to send as a will. |
| 113 | +:type msg: str or bytes or bytearray |
| 114 | +:param int qos: the quality of service level to use |
| 115 | + |
| 116 | + UIFLOW2: |
| 117 | + |
| 118 | + |set_publish.png| |
| 119 | + |
| 120 | + |
| 121 | +..method::MQTTPoEUnit.set_subscribe(topic, handler, qos=0) |
| 122 | + |
| 123 | + Subscribe to a topic. |
| 124 | + |
| 125 | +:param topic: a string specifying the subscription topic to subscribe to. |
| 126 | +:type topic: str or bytes or bytearray |
| 127 | +:param function handler: called when a message has been received on a topic |
| 128 | + that the client subscribes to and the message does |
| 129 | + match an existing topic filter callback. |
| 130 | +:param int qos: the desired quality of service level for the subscription. |
| 131 | + Defaults to 0. |
| 132 | + |
| 133 | + ..NOTE::1. When using this block, the "MQTT connect" block must be set after this block |
| 134 | + 2. The server can only subscribe to four topics at a time |
| 135 | + |
| 136 | + UIFLOW2: |
| 137 | + |
| 138 | + |set_subscribe.png| |
| 139 | + |
| 140 | + An handler showing a message has been received:: |
| 141 | + |
| 142 | + def mqtt_0_SubTopic_event(data): |
| 143 | + print("topic:", data[0]) |
| 144 | + print("msg:", data[1]) |
| 145 | + |
| 146 | + On uiflow2, you can get the **topic** and **message** of the current handler |
| 147 | + through |get_topic.png| and |get_msg.png|. |
| 148 | + |
| 149 | + |
| 150 | +..method::MQTTPoEUnit.check_msg() |
| 151 | + |
| 152 | + ..important:: |
| 153 | + |
| 154 | +:py:meth:`check_msg()` is "main loop iteration" |
| 155 | + methods, blocking and non-blocking version. They should be called |
| 156 | + periodically in a loop,:py:meth:`check_msg()` if you don't have any |
| 157 | + other foreground tasks to perform (i.e. your app just reacts to |
| 158 | + subscribed MQTT messages). |
| 159 | + |
| 160 | + Note that you don't need to call:py:meth:`check_msg()` if you only |
| 161 | + publish messages. |
| 162 | + |
| 163 | + check for a server message. |
| 164 | + |
| 165 | + UIFLOW2: |
| 166 | + |
| 167 | + |check_msg.png| |
| 168 | + |
| 169 | + |
| 170 | +..method::MQTTPoEUnit.check_modem_is_ready() |
| 171 | + |
| 172 | + To check whether the communication with the MQTT unit has been successful. |
| 173 | + |
| 174 | + - Return: ``bool``: True or False |
| 175 | + |
| 176 | + UIFLOW2: |
| 177 | + |
| 178 | + |modem_is_ready.png| |
| 179 | + |
| 180 | + |
| 181 | +..method::MQTTPoEUnit.get_firmware_version() |
| 182 | + |
| 183 | + Get the current firmware version number. |
| 184 | + |
| 185 | + - Return: ``string`` |
| 186 | + |
| 187 | + UIFLOW2: |
| 188 | + |
| 189 | + |get_firmware_version.png| |
| 190 | + |
| 191 | + |
| 192 | +..method::MQTTPoEUnit.get_baudrate() |
| 193 | + |
| 194 | + Get the current baud rate of the module and the default baud rate is 9600. |
| 195 | + |
| 196 | + - Return: ``int``: 4800, 9600, 19200, 34800, 115200, 230400 |
| 197 | + |
| 198 | + UIFLOW2: |
| 199 | + |
| 200 | + |get_baudrate.png| |
| 201 | + |
| 202 | + |
| 203 | +..method::MQTTPoEUnit.get_network_status() |
| 204 | + |
| 205 | + To check whether the network status is connected or disconnected. |
| 206 | + |
| 207 | + - Return: ``int``: 0 ~ 1 |
| 208 | + |
| 209 | + UIFLOW2: |
| 210 | + |
| 211 | + |get_network_status.png| |
| 212 | + |
| 213 | + |
| 214 | +..method::MQTTPoEUnit.get_network_parameters(param) |
| 215 | + |
| 216 | + Get the current actual IP address, subnet mask, gateway and DNS server of the module. |
| 217 | + |
| 218 | + The parameters is: |
| 219 | + - ``param``: IP address = 0, subnet mask = 1, gateway = 2, DNS server = 3. |
| 220 | + |
| 221 | + UIFLOW2: |
| 222 | + |
| 223 | + |get_network_parameters.png| |
| 224 | + |
| 225 | + |
| 226 | +..method::MQTTPoEUnit.get_mac_address() |
| 227 | + |
| 228 | + Get the current MAC address of the module and MAC address the format is: XX-XX-XX-XX-XX-XX. |
| 229 | + |
| 230 | + - Return: ``string``: "XX-XX-XX-XX-XX-XX" |
| 231 | + |
| 232 | + UIFLOW2: |
| 233 | + |
| 234 | + |get_mac_address.png| |
| 235 | + |
| 236 | + |
| 237 | +..method::MQTTPoEUnit.get_static_ip(param) |
| 238 | + |
| 239 | + Get the current actual IP address, subnet mask and gateway of the module. |
| 240 | + |
| 241 | + The parameters is: |
| 242 | + - ``param``: IP address = 0, subnet mask = 1, gateway = 2, DNS server = 3. |
| 243 | + |
| 244 | + UIFLOW2: |
| 245 | + |
| 246 | + |get_static_ip.png| |
| 247 | + |
| 248 | + |
| 249 | +..method::MQTTPoEUnit.get_dhcp_status() |
| 250 | + |
| 251 | + Get the inquire about enable/disable DHCP status |
| 252 | + |
| 253 | + - Return: ``int``: 1: Enable, 0: Disable |
| 254 | + |
| 255 | + UIFLOW2: |
| 256 | + |
| 257 | + |get_dhcp_status.png| |
| 258 | + |
| 259 | + |
| 260 | +..method::MQTTPoEUnit.set_dhcp_state(state) |
| 261 | + |
| 262 | + Set the enable/disable DHCP |
| 263 | + |
| 264 | + The parameters is: |
| 265 | + - ``state``: Disable = 0, Enable = 1. |
| 266 | + |
| 267 | + UIFLOW2: |
| 268 | + |
| 269 | + |set_dhcp_state.png| |
| 270 | + |
| 271 | + |
| 272 | +..method::MQTTPoEUnit.set_static_ip(ip, subnet, gateway) |
| 273 | + |
| 274 | + Set the static IP address of the MQTT module. |
| 275 | + |
| 276 | + ..NOTE::When the DHCP function is enabled, the static IP setting will not be enabled. |
| 277 | + |
| 278 | + The parameters is: |
| 279 | + - ``ip``: "xxx.xxx.xxx.xxx" |
| 280 | + - ``subnet``: "xxx.xxx.xxx.xxx" |
| 281 | + - ``gateway``: "xxx.xxx.xxx.xxx" |
| 282 | + |
| 283 | + UIFLOW2: |
| 284 | + |
| 285 | + |set_static_ip.png| |
| 286 | + |