NB-IoT2 Unit

The NB-IOT2 Unit is a wireless communication module suitable for global Cat-NB frequency bands. It features an integrated SIM7028 communication module, utilizing serial communication (controlled via AT commands).

Support the following products:

NB-IOT2Unit

Note

Please ensure that the device supports the NB-IoT frequency bands in your area before use.

Note

Please ensure that the firmware version of SIM7028 is greater than or equal to 2110B07SIM7028.

get_version.png can be used to check the firmware version.

UiFlow2 Example

NBIoT HTTP Example

Open the cores3_unit_nbiot2_http_example.m5f2 project in UiFlow2.

This example shows how to send HTTP request using the NBIoT2 Unit.

click Send button to send HTTP request. Response data will be printed in the textarea.

UiFlow2 Code Block:

cores3_unit_nbiot2_http_example.png

Example output:

Output of received NBIoT message data on screen.

MQTT Example

Open the cores3_unit_nbiot2_mqtt_example.m5f2 project in UiFlow2.

This example shows how to send MQTT message using the NBIoT2 Unit.

UiFlow2 Code Block:

cores3_unit_nbiot2_mqtt_example.png

Example output:

Output of received NBIoT message data on screen.

MicroPython Example

NBIoT HTTP Example

This example shows how to send HTTP request using the NBIoT2 Unit.

MicroPython Code Block:

  1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
  2#
  3# SPDX-License-Identifier: MIT
  4
  5import os, sys, io
  6import M5
  7from M5 import *
  8import m5ui
  9import lvgl as lv
 10from unit import NBIOT2Unit
 11
 12
 13page0 = None
 14label0 = None
 15label1 = None
 16button0 = None
 17textarea0 = None
 18textarea1 = None
 19nbiot2_0_http_req = None
 20nbiot2_0 = None
 21
 22
 23def button0_short_clicked_event(event_struct):
 24    global page0, label0, label1, button0, textarea0, textarea1, nbiot2_0_http_req, nbiot2_0
 25    nbiot2_0_http_req = nbiot2_0.post(
 26        "http://httpbin.org/post",
 27        json={"message": "Hello from M5Stack!", "status": "active"},
 28        headers={
 29            "Content-Type": "application/json",
 30            "Custom-Header": "MyHeaderValue",
 31        },
 32    )
 33    textarea1.set_text(str(nbiot2_0_http_req.text))
 34
 35
 36def button0_event_handler(event_struct):
 37    global page0, label0, label1, button0, textarea0, textarea1, nbiot2_0_http_req, nbiot2_0
 38    event = event_struct.code
 39    if event == lv.EVENT.SHORT_CLICKED and True:
 40        button0_short_clicked_event(event_struct)
 41    return
 42
 43
 44def setup():
 45    global page0, label0, label1, button0, textarea0, textarea1, nbiot2_0_http_req, nbiot2_0
 46
 47    M5.begin()
 48    Widgets.setRotation(1)
 49    m5ui.init()
 50    page0 = m5ui.M5Page(bg_c=0xFFFFFF)
 51    textarea0 = m5ui.M5TextArea(
 52        text="http://httpbin.org/post",
 53        placeholder="Placeholder...",
 54        x=46,
 55        y=10,
 56        w=195,
 57        h=21,
 58        font=lv.font_montserrat_14,
 59        bg_c=0xFFFFFF,
 60        border_c=0xE0E0E0,
 61        text_c=0x212121,
 62        parent=page0,
 63    )
 64    textarea1 = m5ui.M5TextArea(
 65        text="textarea1",
 66        placeholder="Placeholder...",
 67        x=10,
 68        y=68,
 69        w=300,
 70        h=162,
 71        font=lv.font_montserrat_14,
 72        bg_c=0xFFFFFF,
 73        border_c=0xE0E0E0,
 74        text_c=0x212121,
 75        parent=page0,
 76    )
 77    label0 = m5ui.M5Label(
 78        "url:",
 79        x=10,
 80        y=10,
 81        text_c=0x000000,
 82        bg_c=0xFFFFFF,
 83        bg_opa=0,
 84        font=lv.font_montserrat_16,
 85        parent=page0,
 86    )
 87    label1 = m5ui.M5Label(
 88        "Response",
 89        x=10,
 90        y=44,
 91        text_c=0x000000,
 92        bg_c=0xFFFFFF,
 93        bg_opa=0,
 94        font=lv.font_montserrat_14,
 95        parent=page0,
 96    )
 97    button0 = m5ui.M5Button(
 98        text="Send",
 99        x=251,
100        y=10,
101        bg_c=0x2196F3,
102        text_c=0xFFFFFF,
103        font=lv.font_montserrat_14,
104        parent=page0,
105    )
106
107    button0.add_event_cb(button0_event_handler, lv.EVENT.ALL, None)
108
109    nbiot2_0 = NBIOT2Unit(1, port=(18, 17), verbose=False)
110    page0.screen_load()
111    nbiot2_0.connect(apn="cmnbiot")
112    while not (nbiot2_0.isconnected()):
113        pass
114    textarea0.set_one_line(True)
115
116
117def loop():
118    global page0, label0, label1, button0, textarea0, textarea1, nbiot2_0_http_req, nbiot2_0
119    M5.update()
120
121
122if __name__ == "__main__":
123    try:
124        setup()
125        while True:
126            loop()
127    except (Exception, KeyboardInterrupt) as e:
128        try:
129            m5ui.deinit()
130            from utility import print_error_msg
131
132            print_error_msg(e)
133        except ImportError:
134            print("please update to latest firmware")

Example output:

Output of received NBIoT message data on screen.

MQTT Example

This example shows how to send MQTT message using the NBIoT2 Unit.

MicroPython Code Block:

 1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8import m5ui
 9import lvgl as lv
10from unit import NBIOT2Unit
11
12
13page0 = None
14label0 = None
15nbiot2_0_mqtt = None
16nbiot2_0 = None
17
18
19def nbiot2_0__testtopic_a_event(data):
20    global page0, label0, nbiot2_0_mqtt, nbiot2_0
21    label0.set_text(str(data[1]))
22
23
24def setup():
25    global page0, label0, nbiot2_0_mqtt, nbiot2_0
26
27    M5.begin()
28    Widgets.setRotation(1)
29    m5ui.init()
30    page0 = m5ui.M5Page(bg_c=0xFFFFFF)
31    label0 = m5ui.M5Label(
32        "label0",
33        x=130,
34        y=105,
35        text_c=0x000000,
36        bg_c=0xFFFFFF,
37        bg_opa=0,
38        font=lv.font_montserrat_14,
39        parent=page0,
40    )
41
42    nbiot2_0 = NBIOT2Unit(1, port=(18, 17), verbose=False)
43    page0.screen_load()
44    nbiot2_0.connect(apn="cmnbiot")
45    while not (nbiot2_0.isconnected()):
46        pass
47    nbiot2_0_mqtt = nbiot2_0.MQTTClient(
48        "uiflow2-client", "mqtt.m5stack.com", port=1883, user="", password="", keepalive=0
49    )
50    nbiot2_0_mqtt.connect(clean_session=False)
51    nbiot2_0_mqtt.subscribe("testtopic/a", nbiot2_0__testtopic_a_event, qos=0)
52
53
54def loop():
55    global page0, label0, nbiot2_0_mqtt, nbiot2_0
56    M5.update()
57    nbiot2_0_mqtt.check_msg()
58
59
60if __name__ == "__main__":
61    try:
62        setup()
63        while True:
64            loop()
65    except (Exception, KeyboardInterrupt) as e:
66        try:
67            m5ui.deinit()
68            from utility import print_error_msg
69
70            print_error_msg(e)
71        except ImportError:
72            print("please update to latest firmware")

Example output:

Output of received NBIoT message data on screen.

API

NBIOT2Unit

class unit.nbiot2.NBIOT2Unit(id=1, port=None, verbose=False)

Bases: SIM7028

Create an NBIOT2Unit object.

Parameters:
  • id (int) – The UART ID.

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

  • verbose (bool) – Whether to print debug information.

UiFlow2 Code Block:

init.png

MicroPython Code Block:

from unit import NBIOT2Unit

# Using UART ID 1 and pins (rx=16, tx=17)
nbiot2 = NBIOT2Unit(1, port=(16, 17))

Note

See NBIOTUnit for more details.