COMX LTE Module

LTEModule Class provides a set of methods to control the LTE module. Through the chat script of AT commands, the module is set to PPP mode and then the data is sent to the Internet through the serial port.

Support the following products:

COMX LTE

UiFlow2 Example

HTTP GET over LTE

Open the core2_lte_http_example.m5f2 project in UiFlow2.

This example demonstrates how to use PPP dial-up on the LTE module and then use the requests2 library to send an HTTP GET request.

UiFlow2 Code Block:

example_http.png

Example output:

None

Chat script

Open the core2_lte_chat_example.m5f2 project in UiFlow2.

Set the LTE module to PPP mode through a custom AT command chat script.

UiFlow2 Code Block:

example_chat.png

Example output:

None

MicroPython Example

HTTP GET over LTE

This example demonstrates how to use PPP dial-up on the LTE module and then use the requests2 library to send an HTTP GET request.

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 module import LTEModule
  9import requests2
 10
 11
 12label0 = None
 13label1 = None
 14label2 = None
 15label3 = None
 16label4 = None
 17label5 = None
 18label6 = None
 19label7 = None
 20label8 = None
 21label9 = None
 22label10 = None
 23title0 = None
 24comlte_0 = None
 25http_req = None
 26
 27
 28def setup():
 29    global \
 30        label0, \
 31        label1, \
 32        label2, \
 33        label3, \
 34        label4, \
 35        label5, \
 36        label6, \
 37        label7, \
 38        label8, \
 39        label9, \
 40        label10, \
 41        title0, \
 42        comlte_0, \
 43        http_req
 44
 45    M5.begin()
 46    Widgets.fillScreen(0x222222)
 47    label0 = Widgets.Label("Connecting", 16, 47, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 48    label1 = Widgets.Label("IPv4:", 16, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 49    label2 = Widgets.Label("Netmask:", 16, 112, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 50    label3 = Widgets.Label("Gateway:", 16, 144, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 51    label4 = Widgets.Label("DNS:", 16, 176, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 52    label5 = Widgets.Label("HTTP Code:", 16, 208, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 53    label6 = Widgets.Label("label6", 80, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 54    label7 = Widgets.Label("label7", 120, 112, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 55    label8 = Widgets.Label("label8", 120, 144, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 56    label9 = Widgets.Label("label9", 80, 176, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 57    label10 = Widgets.Label("label10", 140, 208, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 58    title0 = Widgets.Title("COM.LTE Sample Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
 59
 60    comlte_0 = LTEModule(2, 14, 13, verbose=True)
 61    comlte_0.chat2("IP", "CMNET")
 62    comlte_0.active(True)
 63    comlte_0.connect(authmode=comlte_0.AUTH_NONE, username="", password="")
 64    while not (comlte_0.isconnected()):
 65        pass
 66    label0.setText(str("Connected"))
 67    label6.setText(str(comlte_0.ifconfig()[0]))
 68    label7.setText(str(comlte_0.ifconfig()[1]))
 69    label8.setText(str(comlte_0.ifconfig()[2]))
 70    label9.setText(str(comlte_0.ifconfig()[3]))
 71    http_req = requests2.get(
 72        "https://httpbin.org/get", headers={"Content-Type": "application/json"}
 73    )
 74    label10.setText(str(http_req.status_code))
 75    http_req.close()
 76
 77
 78def loop():
 79    global \
 80        label0, \
 81        label1, \
 82        label2, \
 83        label3, \
 84        label4, \
 85        label5, \
 86        label6, \
 87        label7, \
 88        label8, \
 89        label9, \
 90        label10, \
 91        title0, \
 92        comlte_0, \
 93        http_req
 94    M5.update()
 95
 96
 97if __name__ == "__main__":
 98    try:
 99        setup()
100        while True:
101            loop()
102    except (Exception, KeyboardInterrupt) as e:
103        try:
104            comlte_0.deinit()
105            from utility import print_error_msg
106
107            print_error_msg(e)
108        except ImportError:
109            print("please update to latest firmware")

Example output:

None

Chat script

Set the LTE module to PPP mode through a custom AT command chat script.

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 module import LTEModule
  9import requests2
 10
 11
 12label0 = None
 13label1 = None
 14label2 = None
 15label3 = None
 16label4 = None
 17label5 = None
 18label6 = None
 19label7 = None
 20label8 = None
 21label9 = None
 22label10 = None
 23title0 = None
 24comlte_0 = None
 25http_req = None
 26
 27
 28def setup():
 29    global \
 30        label0, \
 31        label1, \
 32        label2, \
 33        label3, \
 34        label4, \
 35        label5, \
 36        label6, \
 37        label7, \
 38        label8, \
 39        label9, \
 40        label10, \
 41        title0, \
 42        comlte_0, \
 43        http_req
 44
 45    M5.begin()
 46    Widgets.fillScreen(0x222222)
 47    label0 = Widgets.Label("Connecting", 16, 47, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 48    label1 = Widgets.Label("IPv4:", 16, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 49    label2 = Widgets.Label("Netmask:", 16, 112, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 50    label3 = Widgets.Label("Gateway:", 16, 144, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 51    label4 = Widgets.Label("DNS:", 16, 176, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 52    label5 = Widgets.Label("HTTP Code:", 16, 208, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 53    label6 = Widgets.Label("label6", 80, 80, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 54    label7 = Widgets.Label("label7", 120, 112, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 55    label8 = Widgets.Label("label8", 120, 144, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 56    label9 = Widgets.Label("label9", 80, 176, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 57    label10 = Widgets.Label("label10", 140, 208, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18)
 58    title0 = Widgets.Title("COM.LTE Sample Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
 59
 60    comlte_0 = LTEModule(2, 14, 13, verbose=True)
 61    comlte_0.chat(
 62        [
 63            ["ABORT", "BUSY"],
 64            ["ABORT", "NO ANSWER"],
 65            ["ABORT", "NO CARRIER"],
 66            ["ABORT", "NO DIALTONE"],
 67            ["ABORT", "\\nRINGING\\r\\n\\r\\nRINGING\\r"],
 68            ["SAY", "modem init: press <ctrl>-C to disconnect\\n"],
 69            ["", "+++ATH"],
 70            ["SAY", "Before Connecting\\n"],
 71            ["OK", 'AT+CGDCONT=1,"IP","CMNET"'],
 72            ["SAY", "\\n + defining PDP context\\n"],
 73            ["", "ATD*99#"],
 74            ["SAY", "Number Dialled\\n"],
 75            ["SAY", "\\n + attaching"],
 76            ["SAY", "\\n + requesting data connection"],
 77            ["CONNECT", "\\d\\c"],
 78            ["SAY", "\\n + connected"],
 79        ]
 80    )
 81    comlte_0.active(True)
 82    comlte_0.connect(authmode=comlte_0.AUTH_NONE, username="", password="")
 83    while not (comlte_0.isconnected()):
 84        pass
 85    label0.setText(str("Connected"))
 86    label6.setText(str(comlte_0.ifconfig()[0]))
 87    label7.setText(str(comlte_0.ifconfig()[1]))
 88    label8.setText(str(comlte_0.ifconfig()[2]))
 89    label9.setText(str(comlte_0.ifconfig()[3]))
 90    http_req = requests2.get(
 91        "https://httpbin.org/get", headers={"Content-Type": "application/json"}
 92    )
 93    label10.setText(str(http_req.status_code))
 94    http_req.close()
 95
 96
 97def loop():
 98    global \
 99        label0, \
100        label1, \
101        label2, \
102        label3, \
103        label4, \
104        label5, \
105        label6, \
106        label7, \
107        label8, \
108        label9, \
109        label10, \
110        title0, \
111        comlte_0, \
112        http_req
113    M5.update()
114
115
116if __name__ == "__main__":
117    try:
118        setup()
119        while True:
120            loop()
121    except (Exception, KeyboardInterrupt) as e:
122        try:
123            comlte_0.deinit()
124            from utility import print_error_msg
125
126            print_error_msg(e)
127        except ImportError:
128            print("please update to latest firmware")

Example output:

None

API

LTEModule

class module.lte.LTEModule(id, tx, rx, verbose=False)

Bases: object

LTE module class.

Parameters:
  • id (int) – UART ID connected to the LTE module.

  • tx (int) – Connect to the UART TX pin of the LTE module.

  • rx (int) – Connect to the UART RX pin of the LTE module.

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

UiFlow2 Code Block:

init.png

MicroPython Code Block:

from module import LTEModule

comlte_0 = LTEModule(2, 14, 13, verbose=True)
active([is_active])

Activate (“up”) or deactivate (“down”) the network interface, if a boolean argument is passed. Otherwise, query current state if no argument is provided.

Parameters:

is_active (bool) – If True, the LTE module is enabled, if False, the LTE module is disabled.

Returns:

Returns the activation status of the LTE module.

Return type:

bool

UiFlow2 Code Block:

active.png

MicroPython Code Block:

comlte_0.active(True)
comlte_0.active(False)
comlte_0.active()
connect(authmode=AUTH_NONE, username='', password='')

Initiate a PPP connection with the given parameters.

Parameters:
  • authmode (int) – Authentication Mode, either LTEModule.AUTH_NONE, LTEModule.AUTH_PAP, or LTEModule.AUTH_CHAP.

  • username (str) – An optional user name to use with the authentication mode.

  • password (str) – An optional password to use with the authentication mode.

Returns:

None

UiFlow2 Code Block:

connect.png

MicroPython Code Block:

comlte_0.connect(authmode=AUTH_NONE, username="", password="")
comlte_0.connect()
isconnected()

Returns True if the PPP link is connected and up. Returns False otherwise.

Returns:

True if the PPP link is connected and up, False otherwise.

Return type:

bool

UiFlow2 Code Block:

isconnected.png

MicroPython Code Block:

comlte_0.isconnected()
ifconfig()

Get IP-level network interface parameters: IP address, subnet mask, gateway and DNS server. This method returns a 4-tuple with the above information.

Returns:

A 4-tuple with IP address, subnet mask, gateway and DNS server.

UiFlow2 Code Block:

get_localip.png

get_subnet.png

get_gateway.png

get_dns.png

MicroPython Code Block:

comlte_0.ifconfig()
comlte_0.ifconfig()[0] # IP address
comlte_0.ifconfig()[1] # network
comlte_0.ifconfig()[2] # gateway
comlte_0.ifconfig()[3] # DNS server
chat(script)

Chat with the LTE module.

Parameters:

script (tuple) – A tuple of commands to chat with the LTE module. Each command is a tuple of two elements: the first element is the expect value, and the second element is the command. For example, ((“OK”, “AT”).

Return type:

None

UiFlow2 Code Block:

chat.png

MicroPython Code Block:

comlte_0.chat((("OK", "AT"), ("OK", "AT+CGDCONT=1,"IP","CMNET""), ("OK", "ATD*99#")))
chat2(pdp_type, apn)

Chat with the LTE module to establish a PPP connection.

Parameters:
  • pdp_type (str) – PDP type. For example, “IP”, “PPP”, “IPV4V6”, “IPV6”.

  • apn (str) – Access Point Name. For example, “CMNET”.

Return type:

None

UiFlow2 Code Block:

chat2.png

MicroPython Code Block:

comlte_0.chat2("IP", "CMNET")
deinit()

Deinitialize the LTE module.

UiFlow2 Code Block:

deinit.png

MicroPython Code Block:

comlte_0.deinit()
Return type:

None