Atom DTU NBIoT2 V11
这是 ATOM DTU NBIoT2 V11 的驱动程序库,用于接收和发送来自 DTU NBIoT 的数据。
支持以下产品:
备注
请在使用前确认设备是否支持您所在地区的 NB-IoT 频段。
备注
请确保 SIM7028 的固件版本大于或等于 2110B07SIM7028。
可以使用
来检查固件版本。
UiFlow2 示例
NBIoT HTTP 示例
在 UiFlow2 中打开 atoms3_base_nbiot2v11_http_example.m5f2 项目。
此示例展示了如何使用 Atom DTU NBIoT2 V11 发送 HTTP 请求。
UiFlow2 代码块:
示例输出:
通过串口接收到的 NBIoT 消息输出数据。
MQTT 示例
在 UiFlow2 中打开 atoms3_base_nbiot2v11_mqtt_example.m5f2 项目。
此示例展示了如何使用 Atom DTU NBIoT2 V11 发送 MQTT 消息。
UiFlow2 代码块:
示例输出:
屏幕上显示接收到的NBIoT消息数据。
MicroPython 示例
NBIoT HTTP 示例
此示例展示了如何使用 Atom DTU NBIoT2 V11 发送 HTTP 请求。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import UART 9from base import AtomRS485 10from base import AtomDTUNBIoT2V11 11 12 13uart2 = None 14base_rs485 = None 15base_nbiot2v11 = None 16base_nbiot2v11_http_req = None 17 18 19def setup(): 20 global uart2, base_rs485, base_nbiot2v11, base_nbiot2v11_http_req 21 22 M5.begin() 23 Widgets.fillScreen(0x000000) 24 25 uart2 = UART(2, baudrate=115200, bits=8, parity=None, stop=1, tx=5, rx=6) 26 base_rs485 = AtomRS485( 27 1, 28 baudrate=115200, 29 bits=8, 30 parity=None, 31 stop=1, 32 tx=7, 33 rx=8, 34 txbuf=256, 35 rxbuf=256, 36 timeout=0, 37 timeout_char=0, 38 invert=0, 39 flow=0, 40 ) 41 base_nbiot2v11 = AtomDTUNBIoT2V11(uart2, verbose=False) 42 while not (base_nbiot2v11.isconnected()): 43 pass 44 base_nbiot2v11_http_req = base_nbiot2v11.post( 45 "http://httpbin.org/post", 46 json={"message": "Hello from M5Stack!", "status": "active"}, 47 headers={ 48 "Content-Type": "application/json", 49 "Custom-Header": "MyHeaderValue", 50 }, 51 ) 52 print((str("status code: ") + str((base_nbiot2v11_http_req.status_code)))) 53 print((str("content: ") + str((base_nbiot2v11_http_req.content)))) 54 55 56def loop(): 57 global uart2, base_rs485, base_nbiot2v11, base_nbiot2v11_http_req 58 M5.update() 59 60 61if __name__ == "__main__": 62 try: 63 setup() 64 while True: 65 loop() 66 except (Exception, KeyboardInterrupt) as e: 67 try: 68 from utility import print_error_msg 69 70 print_error_msg(e) 71 except ImportError: 72 print("please update to latest firmware")
示例输出:
通过串口接收到的 NBIoT 消息输出数据。
MQTT 示例
此示例展示了如何使用 Atom DTU NBIoT2 V11 发送 MQTT 消息。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import UART 9from base import AtomRS485 10from base import AtomDTUNBIoT2V11 11 12 13label0 = None 14base_nbiot2v11 = None 15uart2 = None 16base_rs485 = None 17base_nbiot2v11_mqtt = None 18 19 20def base_nbiot2v11_testtopic_a_event(data): 21 global label0, base_nbiot2v11, uart2, base_rs485, base_nbiot2v11_mqtt 22 label0.setText(str(data[1])) 23 24 25def setup(): 26 global label0, base_nbiot2v11, uart2, base_rs485, base_nbiot2v11_mqtt 27 28 M5.begin() 29 Widgets.fillScreen(0x000000) 30 label0 = Widgets.Label("label0", 1, 5, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 31 32 uart2 = UART(2, baudrate=115200, bits=8, parity=None, stop=1, tx=5, rx=6) 33 base_rs485 = AtomRS485( 34 1, 35 baudrate=115200, 36 bits=8, 37 parity=None, 38 stop=1, 39 tx=7, 40 rx=8, 41 txbuf=256, 42 rxbuf=256, 43 timeout=0, 44 timeout_char=0, 45 invert=0, 46 flow=0, 47 ) 48 base_nbiot2v11 = AtomDTUNBIoT2V11(uart2, verbose=False) 49 while not (base_nbiot2v11.isconnected()): 50 pass 51 base_nbiot2v11_mqtt = base_nbiot2v11.MQTTClient( 52 "uiflow2-client", "mqtt.m5stack.com", port=1883, user="", password="", keepalive=120 53 ) 54 base_nbiot2v11_mqtt.connect(clean_session=True) 55 base_nbiot2v11_mqtt.subscribe("testtopic/a", base_nbiot2v11_testtopic_a_event, qos=0) 56 57 58def loop(): 59 global label0, base_nbiot2v11, uart2, base_rs485, base_nbiot2v11_mqtt 60 M5.update() 61 base_nbiot2v11_mqtt.check_msg() 62 63 64if __name__ == "__main__": 65 try: 66 setup() 67 while True: 68 loop() 69 except (Exception, KeyboardInterrupt) as e: 70 try: 71 from utility import print_error_msg 72 73 print_error_msg(e) 74 except ImportError: 75 print("please update to latest firmware")
示例输出:
屏幕上显示接收到的NBIoT消息数据。
API参考
AtomDTUNBIoT2V11
- class base.dtu_nbiot2_v11.AtomDTUNBIoT2V11(uart, verbose=False)
基类:
SIM7028创建一个 AtomDTUNBIoT2V11 对象。
- 参数:
uart (machine.UART) – 要使用的UART对象。
verbose (bool) – 是否打印调试信息。
UiFlow2 代码块:

MicroPython 代码块:
from base import AtomDTUNBIoT2V11 from hardware import UART uart2 = UART(2, baudrate=115200, bits=8, parity=None, stop=1, tx=22, rx=19) base_nbiot2v11 = AtomDTUNBIoT2V11(uart2, verbose=False)
备注
更多详细信息请参阅
NBIOT2Unit。- power_on()
打开DTU NB-IoT模块的电源。
UiFlow2 代码块:

MicroPython 代码块:
base_nbiot2v11.power_on()
- power_off()
关闭DTU NB-IoT模块的电源。
UiFlow2 代码块:

MicroPython 代码块:
base_nbiot2v11.power_off()
AtomRS485
备注
更多详细信息请参阅 AtomRS485。



