LoRaWAN-EU868 Module
The Module LoRaWAN868 is a LoRaWAN programmable data transfer unit based on the STM32WLE5 chip. The module supports long-range communication, low-power operation, and high sensitivity characteristics, making it suitable for IoT communication needs in a variety of complex environments.
Support the following products:
Micropython LoRaWAN-EU868 P2P Mode TX Example:
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 module import LoRaWANModule_RUI3 9import time 10 11 12title0 = None 13label0 = None 14module_lorawaneu868_0 = None 15 16 17def setup(): 18 global title0, label0, module_lorawaneu868_0 19 20 M5.begin() 21 Widgets.setRotation(1) 22 Widgets.fillScreen(0x222222) 23 title0 = Widgets.Title( 24 "LoraWAN868 P2P Send", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.Montserrat18 25 ) 26 label0 = Widgets.Label( 27 "Press BtnA to Send", 1, 105, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18 28 ) 29 30 module_lorawaneu868_0 = LoRaWANModule_RUI3(2, tx=17, rx=16, rst=13) 31 module_lorawaneu868_0.set_network_mode(0) 32 module_lorawaneu868_0.set_p2p_frequency(868000000) 33 module_lorawaneu868_0.set_p2p_spreading_factor(8) 34 module_lorawaneu868_0.set_p2p_bandwidth(0) 35 module_lorawaneu868_0.set_p2p_tx_power(22) 36 module_lorawaneu868_0.set_p2p_code_rate(0) 37 module_lorawaneu868_0.set_p2p_preamble_length(8) 38 39 40def loop(): 41 global title0, label0, module_lorawaneu868_0 42 M5.update() 43 label0.setText(str("Press BtnA to Send")) 44 if BtnA.wasPressed(): 45 module_lorawaneu868_0.send_p2p_data("abcdef", timeout=0, to_hex=False) 46 label0.setText(str("Sent")) 47 time.sleep(1) 48 49 50if __name__ == "__main__": 51 try: 52 setup() 53 while True: 54 loop() 55 except (Exception, KeyboardInterrupt) as e: 56 try: 57 from utility import print_error_msg 58 59 print_error_msg(e) 60 except ImportError: 61 print("please update to latest firmware")
Micropython LoRaWAN-EU868 P2P Mode RX Example:
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 module import LoRaWANModule_RUI3 9 10 11title0 = None 12label0 = None 13module_lorawaneu868_0 = None 14 15 16def setup(): 17 global title0, label0, module_lorawaneu868_0 18 19 M5.begin() 20 Widgets.setRotation(1) 21 Widgets.fillScreen(0x222222) 22 title0 = Widgets.Title( 23 "LoraWAN868 P2P Receive", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.Montserrat18 24 ) 25 label0 = Widgets.Label( 26 "Touch to Receive", 2, 37, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.Montserrat18 27 ) 28 29 M5.Lcd.setTextScroll(True) 30 M5.Lcd.setTextColor(0xFFFFFF, 0x330000) 31 module_lorawaneu868_0 = LoRaWANModule_RUI3(2, tx=17, rx=18, rst=7) 32 module_lorawaneu868_0.set_network_mode(0) 33 module_lorawaneu868_0.set_p2p_frequency(868000000) 34 module_lorawaneu868_0.set_p2p_spreading_factor(8) 35 module_lorawaneu868_0.set_p2p_bandwidth(0) 36 module_lorawaneu868_0.set_p2p_tx_power(22) 37 module_lorawaneu868_0.set_p2p_code_rate(0) 38 module_lorawaneu868_0.set_p2p_preamble_length(8) 39 40 41def loop(): 42 global title0, label0, module_lorawaneu868_0 43 M5.update() 44 if M5.Touch.getCount(): 45 M5.Lcd.printf( 46 (str((str((module_lorawaneu868_0.get_p2p_receive_data(5000, False))))) + str("\n")) 47 ) 48 49 50if __name__ == "__main__": 51 try: 52 setup() 53 while True: 54 loop() 55 except (Exception, KeyboardInterrupt) as e: 56 try: 57 from utility import print_error_msg 58 59 print_error_msg(e) 60 except ImportError: 61 print("please update to latest firmware")
UIFLOW2 LoRaWAN-EU868 P2P Mode TX Example:
UIFLOW2 LoRaWAN-EU868 P2P Mode RX Example:
API
LoRaWANModule_RUI3
- class module.lorawan_rui3.LoRaWANModule_RUI3(id=1, tx=-1, rx=-1, rst=-1, debug=False)
基类:
RUI3Create an AtomDTULoRaWANRUI3Base object.
- 参数:
MicroPython Code Block:
from base import AtomDTULoRaWANRUI3Base lorawan_rui3 = AtomDTULoRaWANRUI3Base(2, port=(19, 22))
- set_abp_config(dev_addr, apps_key, nwks_key)
Configure the device for ABP (Activation By Personalization) mode.
- 参数:
- 返回类型:
None
MicroPython Code Block:
lorawan_rui3.set_abp_config( dev_addr="26011D89", apps_key="2B7E151628AED2A6ABF7158809CF4F3C", nwks_key="2B7E151628AED2A6ABF7158809CF4F3C" )
- get_abp_config()
Retrieve the current ABP configuration.
MicroPython Code Block:
print(lorawan_rui3.get_abp_config())
- set_otaa_config(device_eui, app_key, app_eui)
Configure the device for OTAA (Over-The-Air Activation) mode.
- 参数:
- 返回类型:
None
MicroPython Code Block:
lorawan_rui3.set_otaa_config( device_eui="2CF7F1C0420000AA", app_key="2B7E151628AED2A6ABF7158809CF4F3C" app_eui="80000000000000AA", )
- get_otaa_config()
Retrieve the current OTAA configuration.
MicroPython Code Block:
print(lorawan_rui3.get_otaa_config())
- get_device_eui()
Get the device EUI.
- 返回:
The device EUI.
- 返回类型:
MicroPython Code Block:
lorawan_rui3.get_device_eui()
- get_join_state()
Check whether the module has successfully joined the network.
- 返回:
True if joined, otherwise False.
- 返回类型:
MicroPython Code Block:
if lorawan_rui3.get_join_state(): print("Module is joined to the network.") else: print("Module is not joined to the network.")
- get_last_receive()
Retrieve the data from the last received message.
- 返回:
A tuple containing the port number (int) and the received data (bytes), or False if no data was received.
- 返回类型:
MicroPython Code Block:
last_data = lorawan_rui3.get_last_receive() if last_data: port, data = last_data print(f"Received data on port {port}: {data}") else: print("No data received.")
- get_p2p_bandwidth()
Retrieve the current P2P bandwidth.
- 返回:
The current P2P bandwidth as an integer.
- 返回类型:
MicroPython Code Block:
bw = lorawan_rui3.get_p2p_bandwidth() print(f"Current P2P bandwidth: {bw}")
- get_p2p_code_rate()
Retrieve the current P2P code rate.
- 返回:
The current P2P code rate as an integer.
- 返回类型:
MicroPython Code Block:
code_rate = lorawan_rui3.get_p2p_code_rate() print(f"Current P2P code rate: {code_rate}")
- get_p2p_frequency()
Retrieve the current P2P frequency.
- 返回:
The current P2P frequency as an integer.
- 返回类型:
MicroPython Code Block:
frequency = lorawan_rui3.get_p2p_frequency() print(f"Current P2P frequency: {frequency} Hz")
- get_p2p_fsk_bitrate()
Retrieve the current P2P FSK bitrate.
- 返回:
The result of the AT command execution.
- 返回类型:
MicroPython Code Block:
fsk_bitrate = lorawan_rui3.get_p2p_fsk_bitrate() print(f"Current P2P FSK bitrate: {fsk_bitrate} b/s")
- get_p2p_preamble_length()
Retrieve the current P2P preamble length.
- 返回:
The current P2P preamble length as an integer.
- 返回类型:
MicroPython Code Block:
preamble_length = lorawan_rui3.get_p2p_preamble_length() print(f"Current P2P preamble length: {preamble_length}")
- get_p2p_receive_data(timeout=500, to_str=False)
Receive data in P2P mode, including RSSI, SNR, and payload.
- 参数:
- 返回:
A tuple (RSSI, SNR, Payload) if data is received; False if no data is received.
- 返回类型:
MicroPython Code Block:
result = lorawan_rui3.get_p2p_receive_data(timeout=1000, to_str=True) if result: rssi, snr, payload = result print(f"Received data - RSSI: {rssi}, SNR: {snr}, Payload: {payload}") else: print("No data received.")
- get_p2p_spreading_factor()
Retrieve the current P2P spreading factor.
- 返回:
The current P2P spreading factor as an integer.
- 返回类型:
MicroPython Code Block:
sf = lorawan_rui3.get_p2p_spreading_factor() print(f"Current P2P spreading factor: {sf}")
- get_p2p_sync_word()
Get the current sync word in P2P mode.
- 返回:
The sync word as a string.
- 返回类型:
MicroPython Code Block:
sync_word = lorawan_rui3.get_p2p_sync_word() print(f"Current P2P sync word: {sync_word}")
- get_p2p_tx_power()
Retrieve the current P2P transmission power.
- 返回:
The current P2P transmission power as an integer.
- 返回类型:
MicroPython Code Block:
tx_power = lorawan_rui3.get_p2p_tx_power() print(f"Current P2P transmission power: {tx_power} dBm")
- get_received_data()
Retrieve the data from the last received message.
- 返回:
A tuple containing the port number (int) and the received data (bytes), or False if no data was received.
- 返回类型:
MicroPython Code Block:
data = lorawan_rui3.get_received_data() if data: print(f"Received data: {data}") else: print("No data received.")
- get_received_data_count()
Retrieve the number of received data.
- 返回:
The number of received data.
- 返回类型:
MicroPython Code Block:
count = lorawan_rui3.get_received_data_count() print(f"Received data count: {count}")
- get_received_data_string()
Retrieve the received data as a string.
- 返回:
The received data as a string, or an empty string if no data was received.
- 返回类型:
MicroPython Code Block:
data = lorawan_rui3.get_received_data_string() if data: print(f"Received data: {data}") else: print("No data received.")
- join_network(timeout=8000)
Join the LoRa network using predefined join parameters.
- 参数:
timeout (int) – The timeout duration in milliseconds for the join command. Default is 8000ms.
- 返回:
True if the command is successfully set, else False.
- 返回类型:
bool

MicroPython Code Block:
if lorawan_rui3.join_network(timeout=10000): print("Network joined successfully!") else: print("Failed to join network.")
- reset_module_to_default()
Reset the module to its factory default settings.
MicroPython Code Block:
rui3.reset_module_to_default()
- send_data(port, data, timeout=600)
Send data through a specific port.
- 参数:
- 返回:
True if the data was sent successfully, otherwise False.
- 返回类型:
bool


MicroPython Code Block:
success = lorawan_rui3.send_data(port=1, data=b"HelloLoRa", timeout=800) if success: print("Data sent successfully!") else: print("Failed to send data.")
- send_p2p_data(payload, timeout=1000, to_hex=False)
Send P2P data with a given payload.
- 参数:
payload (str) –
The payload to send.
Length must be between 2 and 500 characters.
Must consist of an even number of characters composed of 0-9, a-f, A-F, representing 1 to 256 hexadecimal values.
timeout (int) – The timeout for the data transmission, in milliseconds. Default is 1000 ms.
to_hex (bool) – Indicates whether to convert the payload to hexadecimal format. Default is False.
- 返回:
True if the data was sent successfully (“TXFSK DONE” or “TXP2P DONE”), False otherwise.
- 返回类型:
bool


MicroPython Code Block:
success = lorawan_rui3.send_p2p_data("abcdef", timeout=2000, to_hex=True) if success: print("P2P data sent successfully!") else: print("Failed to send P2P data.")
- set_join_config(state, auto_join, reattempt_interval=8, max_attempts=0, timeout=8000)
Configure the join parameters for LoRaWAN.
The configuration does not confirm network join success.
- 参数:
state (int) – The join state to configure, as an integer.
auto_join (int) – The auto-join flag, as an integer.
reattempt_interval (int) – The interval between join retries, in seconds. Default is 8.
max_attempts (int) – The maximum number of retries. Default is 0 (no limit).
timeout (int) – The timeout duration in milliseconds for the command. Default is 8000ms.
- 返回:
True if the command is successfully set, else False.
- 返回类型:
MicroPython Code Block:
lorawan_rui3.set_join_config( state=1, auto_join=1, reattempt_interval=10, max_attempts=5, timeout=10000 )
- set_join_mode(mode)
Set the join mode for the LoRa module.
- 参数:
mode (int) – The join mode to set, 0 for ABP or 1 for OTAA.
- 返回:
True if the command is successfully set, else False.
- 返回类型:
MicroPython Code Block:
lorawan_rui3.set_join_mode(1) # Set to OTAA mode
- set_network_mode(mode)
Set the network mode for the device.
- 返回:
The result of the AT command execution.
- 返回类型:
- 参数:
mode (int) –
The mode to set for the network:
0 = P2P_LORA
1 = LoRaWAN
2 = P2P_FSK
MicroPython Code Block:
lorawan_rui3.set_network_mode(0) # Set to P2P_LORA mode
- set_p2p_bandwidth(bandwidth)
Set the P2P bandwidth.
- 参数:
bandwidth (int) –
The bandwidth to set for P2P communication.
- For LoRa:
0 = 125 kHz
1 = 250 kHz
2 = 500 kHz
3 = 7.8 kHz
4 = 10.4 kHz
5 = 15.63 kHz
6 = 20.83 kHz
7 = 31.25 kHz
8 = 41.67 kHz
9 = 62.5 kHz
- For FSK:
Range: 4800-467000 Hz
- 返回:
The result of the AT command execution.
- 返回类型:
MicroPython Code Block:
success = lorawan_rui3.set_p2p_bandwidth(1) # Set to 250 kHz if success: print("P2P bandwidth set successfully!") else: print("Failed to set P2P bandwidth.")
- set_p2p_code_rate(code_rate)
Set the P2P code rate.
- 参数:
code_rate (int) –
The code rate to set for P2P communication.
0 = 4/5
1 = 4/6
2 = 4/7
3 = 4/8
- 返回:
The result of the AT command execution.
- 返回类型:
MicroPython Code Block:
success = lorawan_rui3.set_p2p_code_rate(1) # Set to 4/6 if success: print("P2P code rate set successfully!") else: print("Failed to set P2P code rate.")
- set_p2p_frequency(frequency)
Set the P2P frequency for the device.
- 返回:
The result of the AT command execution.
- 返回类型:
- 参数:
frequency (int) –
The frequency to set for P2P communication.
Low-frequency range: 150000000-600000000
High-frequency range: 600000000-960000000
MicroPython Code Block:
success = lorawan_rui3.set_p2p_frequency(433000000) if success: print("P2P frequency set successfully!") else: print("Failed to set P2P frequency.")
- set_p2p_fsk_bitrate(bitrate)
Set the P2P FSK bitrate.
- 参数:
bitrate (int) –
The bitrate to set for P2P FSK communication.
Range is 600 to 300000 b/s.
- 返回:
The result of the AT command execution.
- 返回类型:
MicroPython Code Block:
success = lorawan_rui3.set_p2p_fsk_bitrate(9600) # Set to 9600 b/s if success: print("P2P FSK bitrate set successfully!") else: print("Failed to set P2P FSK bitrate.")
- set_p2p_preamble_length(length)
Set the P2P preamble length.
- 返回:
The result of the AT command execution.
- 返回类型:
- 参数:
length (int) –
The preamble length to set for P2P communication.
Range is 5 to 65535.
MicroPython Code Block:
success = lorawan_rui3.set_p2p_preamble_length(16) if success: print("P2P preamble length set successfully!") else: print("Failed to set P2P preamble length.")
- set_p2p_spreading_factor(spreading_factor)
Set the P2P spreading factor.
- 参数:
spreading_factor (int) –
The spreading factor to set for P2P communication.
Range is 5 to 12.
- 返回:
The result of the AT command execution.
- 返回类型:
MicroPython Code Block:
success = lorawan_rui3.set_p2p_spreading_factor(10) if success: print("P2P spreading factor set successfully!") else: print("Failed to set P2P spreading factor.")
- set_p2p_sync_word(sync_word)
Set the sync word in P2P mode.
- 参数:
sync_word (int) –
The sync word value.
Must be in the range of 0x0000 to 0xFFFF.
- 返回:
The response from the command execution.
- 返回类型:
MicroPython Code Block:
success = lorawan_rui3.set_p2p_sync_word(0x1234) if success: print("P2P sync word set successfully!") else: print("Failed to set P2P sync word.")
- set_p2p_tx_power(power)
Set the P2P transmission power.
- 参数:
power (int) –
The transmission power to set for P2P communication.
Range is 5 to 22 dBm.
- 返回:
The result of the AT command execution.
- 返回类型:
MicroPython Code Block:
success = lorawan_rui3.set_p2p_tx_power(20) # Set to 20 dBm if success: print("P2P transmission power set successfully!") else: print("Failed to set P2P transmission power.")


