LoRaWAN868 Module
COM.LoRaWAN is a LoRaWAN communication module in the M5Stack stackable module series, supporting node-to-node or LoRaWAN communication.
Support the following products:
Micropython TX Example:
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 LoRaWAN868Module 9import time 10 11 12lorawan868_0 = None 13 14 15def setup(): 16 global lorawan868_0 17 18 M5.begin() 19 Widgets.fillScreen(0x222222) 20 21 lorawan868_0 = LoRaWAN868Module(1, (17, 16)) 22 lorawan868_0.wake_up() 23 lorawan868_0.set_parameters(0, 0, 5, 0, 1, 8, 0, 0, 0) 24 lorawan868_0.set_auto_low_power(False) 25 print(lorawan868_0.query_chip_id()) 26 print(lorawan868_0.query_lorawan_mode()) 27 print(lorawan868_0.any()) 28 lorawan868_0.set_mode(LoRaWAN868Module.MODE_LORA) 29 30 31def loop(): 32 global lorawan868_0 33 M5.update() 34 lorawan868_0.send_hex("Hello Lora!") 35 time.sleep(1) 36 37 38if __name__ == "__main__": 39 try: 40 setup() 41 while True: 42 loop() 43 except (Exception, KeyboardInterrupt) as e: 44 try: 45 from utility import print_error_msg 46 47 print_error_msg(e) 48 except ImportError: 49 print("please update to latest firmware")
Micropython RX Example:
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 LoRaWAN868Module 9 10 11lorawan868_0 = None 12 13 14def setup(): 15 global lorawan868_0 16 17 M5.begin() 18 Widgets.fillScreen(0x222222) 19 20 lorawan868_0 = LoRaWAN868Module(1, (17, 16)) 21 lorawan868_0.wake_up() 22 lorawan868_0.set_parameters(0, 0, 5, 0, 1, 8, 0, 0, 0) 23 lorawan868_0.set_auto_low_power(False) 24 print(lorawan868_0.query_chip_id()) 25 print(lorawan868_0.query_lorawan_mode()) 26 print(lorawan868_0.any()) 27 lorawan868_0.set_mode(LoRaWAN868Module.MODE_LORA) 28 lorawan868_0.enable_rx(0) 29 30 31def loop(): 32 global lorawan868_0 33 M5.update() 34 if lorawan868_0.any(): 35 print(lorawan868_0.receive_data()) 36 lorawan868_0.enable_rx(0) 37 38 39if __name__ == "__main__": 40 try: 41 setup() 42 while True: 43 loop() 44 except (Exception, KeyboardInterrupt) as e: 45 try: 46 from utility import print_error_msg 47 48 print_error_msg(e) 49 except ImportError: 50 print("please update to latest firmware")
UIFLOW2 TX Example:
UIFLOW2 RX Example:
class LoRaWAN868Module
Constructors
Methods
- LoRaWAN868Module.set_mode(mode)
Set the mode of the LoRaWAN module.
- Parameters:
mode – The mode to set.
UIFLOW2:
- LoRaWAN868Module.set_parameters(freq, power, sf, bw, cr, preamble, crc, iq_inv, save)
Set the parameters of the LoRaWAN module.
- Parameters:
freq – Set LoRa listening/sending frequency in Hz.
power – LoRa signal output power in dBm;
sf – Spreading factor, from 5~12
bw – Bandwidth 0 – 125K, 1 – 250K, 2 – 500K;
cr – 1 – 4/5, 2 – 4/6, 3 – 4/7, 4 – 4/8;
preamble – Preamble Length from 8~65535 bit;
crc – 0 – disable CRC check, 1 – enable CRC check;
iq_inv – 0 – not inverted, 1 – inverted;
save – Save parameters to FLASH, 0 – not save, 1 – save.
UIFLOW2:
- LoRaWAN868Module.wake_up()
Wake up the device through a serial port interrupt. After resetting, the device is in sleep state. In theory, sending any data through the serial port can trigger the interrupt and wake up the device.
UIFLOW2:
- LoRaWAN868Module.sleep()
Put the device into low-power mode.
UIFLOW2:
- LoRaWAN868Module.reset()
Reset the device.
UIFLOW2:
- LoRaWAN868Module.restore_factory_settings()
Restore the device to factory settings. The parameters will reset and the device will enter sleep mode after response ends.
UIFLOW2:
- LoRaWAN868Module.set_copyright(enable)
Enable or disable copyright information print when boot loader mode begins. Default is enable.
- Parameters:
enable (bool) – Set True to enable, False to disable.
UIFLOW2:
- LoRaWAN868Module.set_auto_low_power(enable)
Enable or disable automatic low-power mode. Default is enable.
- Parameters:
enable (bool) – Set True to enable, False to disable.
UIFLOW2:
- LoRaWAN868Module.query_chip_id()
Query the unique ID of the chip, which can be used to query the corresponding serial number.
UIFLOW2:
- LoRaWAN868Module.enable_rx(timeout)
Enable the LoRaWAN module to receive data.
- Parameters:
timeout (int) – The timeout for the receive operation.
UIFLOW2:
- LoRaWAN868Module.set_deveui(deveui)
Set or query the DevEui. DevEui must be 16 hex characters (0-9, A-F).
- Parameters:
deveui – The DevEui to set. If None, query the current DevEui.
UIFLOW2:
- LoRaWAN868Module.set_appeui(appeui)
Set or query the AppEui. AppEui must be 16 hex characters (0-9, A-F).
- Parameters:
appeui – The AppEui to set. If None, query the current AppEui.
UIFLOW2:
- LoRaWAN868Module.set_appkey(appkey)
Set or query the AppKey. AppKey must be 32 hex characters (0-9, A-F).
- Parameters:
appkey – The AppKey to set. If None, query the current AppKey.
UIFLOW2:
- LoRaWAN868Module.set_nwkskey(nwkskey)
Set or query the NwkSKey. NwkSKey must be 32 hex characters (0-9, A-F).
- Parameters:
nwkskey – The NwkSKey to set. If None, query the current NwkSKey.
UIFLOW2:
- LoRaWAN868Module.set_appskey(appskey)
Set or query the AppSKey. AppSKey must be 32 hex characters (0-9, A-F).
- Parameters:
appskey – The AppSKey to set. If None, query the current AppSKey.
UIFLOW2:
- LoRaWAN868Module.set_devaddr(devaddr)
Set or query the DevAddr. DevAddr must be 8 hex characters (0-9, A-F).
- Parameters:
devaddr – The DevAddr to set. If None, query the current DevAddr.
UIFLOW2:
- LoRaWAN868Module.set_otaa_mode(enable)
Set or query the OTAA mode. 1 for OTAA mode, 0 for ABP mode.
- Parameters:
enable (bool) – Set True for OTAA mode, False for ABP mode.
UIFLOW2:
- LoRaWAN868Module.set_adr(enable)
Enable or disable the ADR (Adaptive Data Rate) function. Default is enabled.
- Parameters:
enable (bool) – Set True to enable ADR, False to disable.
UIFLOW2:
- LoRaWAN868Module.set_channel_mask(mask)
Set or query the LoRaWAN working channel mask.
- Parameters:
mask – The channel mask in hexadecimal format, e.g., 0000000000000000000000FF for channels 0~7.
UIFLOW2:
- LoRaWAN868Module.join_network()
Join the network using OTAA (Over-The-Air Activation). This command triggers the join process.
UIFLOW2:
- LoRaWAN868Module.set_duty_cycle(cycle)
Set or query the communication cycle in milliseconds. For example, 60000 means communication every 60 seconds.
- Parameters:
cycle – The communication cycle in milliseconds.
UIFLOW2:
- LoRaWAN868Module.set_class_mode(mode)
Set or query the device's communication mode. Only Class A or Class C are valid.
- Parameters:
mode – Set "A" for Class A or "C" for Class C.
UIFLOW2:
- LoRaWAN868Module.set_ack(enable)
Enable or disable the ACK receipt function. If enabled, the device waits for acknowledgment from the gateway.
- Parameters:
enable (bool) – Set True to enable ACK, False to disable.
UIFLOW2:
- LoRaWAN868Module.set_app_port(port)
Set or query the application port (fport) for upstream data. Valid range is 0~255.
- Parameters:
port – The application port to set.
UIFLOW2:
- LoRaWAN868Module.set_retransmission_count(count)
Set or query the number of retransmissions if communication fails. The valid range is 3~8.
- Parameters:
count – The number of retransmissions to set. If None, query the current setting.
UIFLOW2:
- LoRaWAN868Module.send_hex(hex_data)
Send hex data in LoRaWAN or LoRa mode. Hex characters must be in pairs (e.g., "AABB").
- Parameters:
hex_data – The hex data to send, up to 64 bytes.
UIFLOW2:
- LoRaWAN868Module.send_string(string_data)
Send string data in LoRaWAN or LoRa mode. The string must consist of ASCII characters.
- Parameters:
string_data – The string data to send, up to 64 bytes.
UIFLOW2:
- LoRaWAN868Module.query_lorawan_mode()
Query if the device is in LoRaWAN or normal LoRa mode.
UIFLOW2:
- LoRaWAN868Module.save_parameters_to_flash()
Save the current LoRa parameters to FLASH memory.
UIFLOW2:
- LoRaWAN868Module.at_cmd(cmd, data)
Send an AT command to the LoRaWAN module.
- Parameters:
cmd – The AT command to send.
data – The data to send with the AT command.
UIFLOW2:
- LoRaWAN868Module.at_query(cmd)
Query the current settings of the LoRaWAN module.
- Parameters:
cmd – The AT command to query.
UIFLOW2:
- LoRaWAN868Module.at_receive()
Receive a response from the LoRaWAN module.
UIFLOW2:
- LoRaWAN868Module.flush()
Clear the UART buffer.
UIFLOW2:
- LoRaWAN868Module.any()
Check if there is any data in the UART buffer.
UIFLOW2:
- LoRaWAN868Module.receive_data()
Receive data from the LoRaWAN module.
UIFLOW2: