Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite2fb6ab

Browse files
committed
merge: Merge branch 'feature/unit-mqttpoe' into develop.
Signed-off-by: lbuque <1102390310@qq.com>
2 parentsfe0d0e4 +82d2149 commite2fb6ab

File tree

8 files changed

+388
-0
lines changed

8 files changed

+388
-0
lines changed

‎docs/en/refs/unit.mqttpoe.ref‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. |MqttPoeUnit| image:: https://static-cdn.m5stack.com/resource/docs/products/unit/mqtt_poe/mqtt_poe_01.webp
2+
:target: https://docs.m5stack.com/en/unit/mqtt_poe
3+
:height: 200px
4+
:width: 200 px
5+
6+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/init.png
7+
.. |example.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/example.png
8+
.. |modem_is_ready.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/check_modem_is_ready.png
9+
.. |get_firmware_version.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/get_firmware_version.png
10+
.. |get_baudrate.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/get_baudrate.png
11+
.. |get_network_status.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/get_network_status.png
12+
.. |get_network_parameters.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/get_network_parameters.png
13+
.. |get_mac_address.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/get_mac_address.png
14+
.. |get_static_ip.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/get_static_ip.png
15+
.. |get_dhcp_status.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/get_dhcp_status.png
16+
.. |set_dhcp_state.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/set_dhcp_state.png
17+
.. |set_static_ip.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/set_static_ip.png
18+
.. |set_client.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/set_client.png
19+
.. |set_connect.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/set_connect.png
20+
.. |set_disconnect.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/set_disconnect.png
21+
.. |set_publish.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/set_publish.png
22+
.. |set_subscribe.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/set_subscribe.png
23+
.. |check_msg.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/check_msg.png
24+
.. |get_topic.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/get_topic.png
25+
.. |get_msg.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/mqtt_poe/get_msg.png
26+
27+
.. |mqttpoeunit_demo.m5f2| raw:: html
28+
29+
<a
30+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/mqtt_poe/mqttpoeunit_demo.m5f2"
31+
target="_blank"
32+
>
33+
mqttpoeunit_demo.m5f2
34+
</a>
35+
36+

‎docs/en/units/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Unit
3737
minioled.rst
3838
miniscale.rst
3939
mqtt.rst
40+
mqttpoe.rst
4041
ncir.rst
4142
oled.rst
4243
op90.rst

‎docs/en/units/mqttpoe.rst‎

Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
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+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"V2.0","versionNumber":"V2.0.8","type":"cores3","components":[{"name":"screen","type":"screen","layer":0,"screenId":"builtin","screenName":"","id":"__cores3_screen","createTime":1720057503088,"x":0,"y":0,"width":320,"height":240,"backgroundColor":"#222222","size":0,"isSelected":true}],"resources":[{"hardware":["hardware_button","hardware_pin_button","imu","speaker","touch","als","mic"]},{"unit":["unit_mqttpoe"]}],"units":[{"type":"unit_mqttpoe","name":"mqttpoe_0","portList":["A","B","C","Custom"],"portType":"C","userPort":[22,21],"id":"dckd$9yJ0yVjL*Je","createTime":1720057554512,"initBlockId":"eB38WZ$xZ_*@vr*Vh%Qi"}],"hats":[],"bases":[],"i2cs":[],"blockly":"<block type=\"basic_on_setup\" id=\"setup_block\" deletable=\"false\" x=\"-310\" y=\"-290\"><mutation isBegin=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_begin\" id=\"system_m5_begin\"><next><block type=\"unit_mqttpoe_init\" id=\"eB38WZ$xZ_*@vr*Vh%Qi\"><field name=\"NAME\">mqttpoe_0</field><next><block type=\"unit_mqttpoe_set_server_config\" id=\"j=}Wt++xB`%xJxoy}rj-\"><field name=\"NAME\">mqttpoe_0</field><value name=\"ID\"><shadow type=\"text\" id=\"R_.*;64J3Nv$MV7d6dKO\"><field name=\"TEXT\">m5-mqtt-xxx</field></shadow></value><value name=\"SERVER\"><shadow type=\"text\" id=\"vB:z@fvpF1U%061HUWf+\"><field name=\"TEXT\">mqtt.m5stack.com</field></shadow></value><value name=\"PORT\"><shadow type=\"math_number\" id=\"xd;:X(yx3{OaFgUd]szn\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1883</field></shadow></value><value name=\"USERNAME\"><shadow type=\"text\" id=\"pU7#$,)uN*Oq[/4*?L?7\"><field name=\"TEXT\"></field></shadow></value><value name=\"PASSWORD\"><shadow type=\"text_password\" id=\"n[W.v]})A?u96PL1^d+r\"><mutation show=\"true\"></mutation><field name=\"TEXT\"></field></shadow></value><value name=\"KEEPALIVE\"><shadow type=\"math_slider\" id=\"nr6(s@D,40*l/jx-~U+S\"><mutation max=\"65535\" min=\"0\" step=\"1\" precision=\"1\"></mutation><field name=\"NUM\">120</field></shadow></value><next><block type=\"unit_mqttpoe_set_connect\" id=\"-DV1u9ik-fA-JhPt,4L9\"><field name=\"NAME\">mqttpoe_0</field></block></next></block></next></block></next></block></statement></block><block type=\"unit_mqttpoe_subscribe_callback\" id=\"V!lQD^RR]n^v;V*%Vk*j\" x=\"-310\" y=\"110\"><field name=\"NAME\">mqttpoe_0</field><value name=\"MSG\"><shadow type=\"text\" id=\"Vni)t$67U*t@xDI?).U2\"><field name=\"TEXT\">SubTopic</field></shadow></value><value name=\"QOS\"><shadow type=\"math_slider\" id=\"2S$##E@;7on5=7R~=s_o\"><mutation max=\"2\" min=\"0\" step=\"1\" precision=\"1\"></mutation><field name=\"NUM\">0</field></shadow></value><statement name=\"FUNC\"><block type=\"text_print\" id=\"7dHHw_(wv!;,3iFu4drt\"><value name=\"TEXT\"><shadow type=\"text\" id=\"`yvG%sCX/*-}h:Tp(.s;\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"unit_mqttpoe_get_topic\" id=\"+aN~HL4xt9-*50FZ0:DW\"></block></value><next><block type=\"text_print\" id=\"0N=mNRl(-._^;*#=3^qo\"><value name=\"TEXT\"><shadow type=\"text\" id=\"MGBWxY_4fsmJVr!6e|Wm\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"unit_mqttpoe_get_msg\" id=\"LPThKiW%Sp.5zapy`b,H\"></block></value></block></next></block></statement></block><block type=\"basic_on_loop\" id=\"loop_block\" deletable=\"false\" x=\"-310\" y=\"290\"><mutation isUpdate=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_update\" id=\"system_m5_update\"><next><block type=\"unit_mqttpoe_check_msg\" id=\"3wpDkh?V-p1`EE4fmniw\"><field name=\"NAME\">mqttpoe_0</field><next><block type=\"time_sleep_millisecond\" id=\"Q@6:UWI=$1R$taSKgRx~\"><value name=\"MS\"><shadow type=\"math_number\" id=\"{,hz^=Qe{nCM;O^X%eIe\"><mutation max=\"Infinity\" min=\"0\" precision=\"0\"></mutation><field name=\"NUM\">50</field></shadow></value></block></next></block></next></block></statement></block>","screen":[{"simulationName":"Built-in","type":"builtin","width":320,"height":240,"scale":0.78,"screenName":"","blockId":"","screenColorType":0,"id":"builtin","createTime":1720057503081}],"logicWhenNum":0,"customList":[]}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
importos,sys,io
2+
importM5
3+
fromM5import*
4+
fromunitimportMQTTPoEUnit
5+
importtime
6+
7+
8+
mqttpoe_0=None
9+
10+
11+
defmqttpoe_0_SubTopic_event(data):# noqa: N802
12+
globalmqttpoe_0
13+
print(data[0])
14+
print(data[1])
15+
16+
17+
defsetup():
18+
globalmqttpoe_0
19+
20+
M5.begin()
21+
Widgets.fillScreen(0x222222)
22+
23+
mqttpoe_0=MQTTPoEUnit(port=(18,17))
24+
mqttpoe_0.set_client("m5-mqtt-xxx","mqtt.m5stack.com",1883,"","",120)
25+
mqttpoe_0.set_subscribe("SubTopic",mqttpoe_0_SubTopic_event,0)
26+
mqttpoe_0.set_connect()
27+
28+
29+
defloop():
30+
globalmqttpoe_0
31+
M5.update()
32+
mqttpoe_0.check_msg()
33+
time.sleep_ms(50)
34+
35+
36+
if__name__=="__main__":
37+
try:
38+
setup()
39+
whileTrue:
40+
loop()
41+
except (Exception,KeyboardInterrupt)ase:
42+
try:
43+
fromutilityimportprint_error_msg
44+
45+
print_error_msg(e)
46+
exceptImportError:
47+
print("please update to latest firmware")

‎m5stack/libs/unit/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"MiniOLEDUnit":"minioled",
6464
"MiniScaleUnit":"miniscale",
6565
"MQTTUnit":"mqtt",
66+
"MQTTPoEUnit":"mqttpoe",
6667
"NCIRUnit":"ncir",
6768
"NCIR2Unit":"ncir2",
6869
"NECOUnit":"neco",

‎m5stack/libs/unit/manifest.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"minioled.py",
6565
"miniscale.py",
6666
"mqtt.py",
67+
"mqttpoe.py",
6768
"ncir.py",
6869
"ncir2.py",
6970
"neco.py",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp