Atom DTU NBIoT Base

This is the driver library for the ATOM DTU NBIoT Base to accept and send data from the DTU NBIoT.

Support the following products:

Atom DTU NBIoT

Atom DTU NBIoT CN

UiFlow2 Example

NBIoT HTTP Example

Open the base_nbiot_atoms3_http_example.m5f2 project in UiFlow2.

This example shows how to send HTTP request using the Atom DTU NBIoT Base.

UiFlow2 Code Block:

http_example.png

Example output:

Output of received NBIoT message data via serial port.

MicroPython Example

NBIoT HTTP Example

This example shows how to send HTTP request using the Atom DTU NBIoT Base.

MicroPython Code Block:

 1# SPDX-FileCopyrightText: 2025 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 AtomDTUNBIoT
10
11
12title0 = None
13label0 = None
14label1 = None
15uart2 = None
16base_nbiot = None
17
18
19def setup():
20    global title0, label0, label1, uart2, base_nbiot
21
22    M5.begin()
23    title0 = Widgets.Title("NBIoT HTTP", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
24    label0 = Widgets.Label("Press to", 23, 43, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
25    label1 = Widgets.Label("Request", 23, 74, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
26
27    uart2 = UART(2, baudrate=115200, bits=8, parity=None, stop=1, tx=5, rx=6)
28    base_nbiot = AtomDTUNBIoT(uart2)
29
30
31def loop():
32    global title0, label0, label1, uart2, base_nbiot
33    M5.update()
34    if BtnA.wasPressed():
35        base_nbiot.http_request(
36            1,
37            "http://httpbin.org/post",
38            {"Content-Type": "application/json", "Custom-Header": "MyHeaderValue"},
39            {"message": "Hello from M5Stack!", "status": "active"},
40        )
41        print(base_nbiot.data_content)
42        print(base_nbiot.response_code)
43
44
45if __name__ == "__main__":
46    try:
47        setup()
48        while True:
49            loop()
50    except (Exception, KeyboardInterrupt) as e:
51        try:
52            from utility import print_error_msg
53
54            print_error_msg(e)
55        except ImportError:
56            print("please update to latest firmware")

Example output:

Output of received NBIoT message data via serial port.

MQTT Example

Open the base_nbiot_atoms3_mqtt_example.m5f2 project in UiFlow2.

This example shows how to send MQTT message using the Atom DTU NBIoT Base.

UiFlow2 Code Block:

mqtt_example.png

Example output:

Output of received NBIoT message data via serial port.

MicroPython Example

MQTT Example

This example shows how to send MQTT message using the Atom DTU NBIoT Base.

MicroPython Code Block:

 1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from base import AtomDTUNBIoT
 9from hardware import UART
10
11
12title0 = None
13base_nbiot = None
14uart2 = None
15
16
17def base_nbiot_SubTopic_event(_topic, _msg):  # noqa: N802
18    global title0, base_nbiot, uart2
19    print(_topic)
20    print(_msg)
21
22
23def setup():
24    global title0, base_nbiot, uart2
25
26    M5.begin()
27    title0 = Widgets.Title("NBIoT MQTT", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
28
29    uart2 = UART(2, baudrate=115200, bits=8, parity=None, stop=1, tx=5, rx=6)
30    base_nbiot = AtomDTUNBIoT(uart2)
31    base_nbiot.mqtt_server_connect("mqtt.m5stack.com", 1883, "m5-mqtt-2024", "", "", 120)
32    base_nbiot.mqtt_subscribe_topic("SubTopic", base_nbiot_SubTopic_event, 0)
33
34
35def loop():
36    global title0, base_nbiot, uart2
37    M5.update()
38    base_nbiot.mqtt_polling_loop()
39
40
41if __name__ == "__main__":
42    try:
43        setup()
44        while True:
45            loop()
46    except (Exception, KeyboardInterrupt) as e:
47        try:
48            from utility import print_error_msg
49
50            print_error_msg(e)
51        except ImportError:
52            print("please update to latest firmware")

Example output:

Output of received NBIoT message data via serial port.

API

AtomDTUNBIoT

class base.dtu_nbiot.AtomDTUNBIoT(uart, verbose=False)

基类:SIM7020, Modem

Create an AtomDTUNBIoT object

参数:
  • id (int) – The UART ID to use (0, 1, or 2). Default is 2.

  • port (list | tuple) – A list or tuple containing the TX and RX pin numbers.

UiFlow2 Code Block:

init.png

MicroPython Code Block:

from base import AtomDTUNBIoT

dtu_nbiot = AtomDTUNBIoT(0, (22, 19))

See base.AtomDTUNBIoT.Methods for more details.