Atom DTU LoRaWAN-Series(RAK3172) Base
SKU: A152-CN470, A152-US915, A152-EU868
Atom DTU LoRaWAN-Series 是一款基于 STM32WLE5 芯片的 LoRaWAN 可编程数据传输单元(DTU)。该模块支持远距离通信、低功耗运行,并具备高灵敏度特性,适用于多种复杂环境的物联网通信需求。
频段支持:CN470(470MHz),EU868(868MHz),US915(915MHz)
通信协议:
支持 LoRaWAN Class A、Class B、Class C 模式
支持 LoRa 点对点(P2P)通信模式
通信接口:
UART 接口:用于发送 AT 指令,控制 LoRaWAN 入网、数据发送/接收、P2P 模式通信等
RS485 接口:支持工业设备有线通信,可靠性高
入网方式:
OTAA(Over-The-Air Activation,空中激活)
ABP(Activation By Personalization,手动激活)
支持以下产品:
Micropython LoRaWAN-EU868 LoRaWAN OTAA 模式示例程序:
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 RGB 9from base import AtomDTULoRaWANRUI3Base 10 11 12rgb = None 13base_lorawaneu868 = None 14 15 16def setup(): 17 global rgb, base_lorawaneu868 18 19 M5.begin() 20 rgb = RGB() 21 base_lorawaneu868 = AtomDTULoRaWANRUI3Base(2, port=(19, 22)) 22 base_lorawaneu868.set_network_mode(1) 23 base_lorawaneu868.set_otaa_config( 24 "70B3D57ED007006A", "A843ECB026197C981D67AEFACC72D01E", "70B3D57ED0063472" 25 ) 26 base_lorawaneu868.set_rx_delay_on_window1(1) 27 base_lorawaneu868.set_rx_delay_on_window2(2) 28 base_lorawaneu868.set_rx_data_rate_on_windows2(0) 29 base_lorawaneu868.set_lorawan_node_class("C") 30 if base_lorawaneu868.join_network(10000): 31 print("Success join the network") 32 rgb.fill_color(0x33FF33) 33 base_lorawaneu868.send_data(1, "AABBCC", 0) 34 else: 35 print("Failed Join to the network") 36 rgb.fill_color(0xFF0000) 37 38 39def loop(): 40 global rgb, base_lorawaneu868 41 M5.update() 42 if BtnA.wasPressed(): 43 if (base_lorawaneu868.get_received_data_count()) != 0: 44 print(base_lorawaneu868.get_received_data_string()) 45 else: 46 print("Message queue is empty") 47 48 49if __name__ == "__main__": 50 try: 51 setup() 52 while True: 53 loop() 54 except (Exception, KeyboardInterrupt) as e: 55 try: 56 from utility import print_error_msg 57 58 print_error_msg(e) 59 except ImportError: 60 print("please update to latest firmware")
Micropython LoRaWAN-EU868 P2P 模式 TX 示例程序:
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 RGB 9from base import AtomDTULoRaWANRUI3Base 10 11 12rgb = None 13base_lorawaneu868 = None 14 15 16def setup(): 17 global rgb, base_lorawaneu868 18 19 M5.begin() 20 rgb = RGB() 21 base_lorawaneu868 = AtomDTULoRaWANRUI3Base(2, port=(19, 22)) 22 base_lorawaneu868.set_network_mode(0) 23 base_lorawaneu868.set_p2p_frequency(600000000) 24 base_lorawaneu868.set_p2p_spreading_factor(7) 25 base_lorawaneu868.set_p2p_bandwidth(0) 26 base_lorawaneu868.set_p2p_tx_power(14) 27 base_lorawaneu868.set_p2p_code_rate(0) 28 base_lorawaneu868.set_p2p_preamble_length(8) 29 print("Press the button to send P2P message") 30 31 32def loop(): 33 global rgb, base_lorawaneu868 34 M5.update() 35 if BtnA.wasPressed(): 36 base_lorawaneu868.send_p2p_data("AABBCC", timeout=0, to_hex=False) 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")
Micropython LoRaWAN-EU868 P2P 模式 RX 示例程序:
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 RGB 9from base import AtomDTULoRaWANRUI3Base 10 11 12rgb = None 13base_lorawaneu868 = None 14 15 16def setup(): 17 global rgb, base_lorawaneu868 18 19 M5.begin() 20 rgb = RGB() 21 base_lorawaneu868 = AtomDTULoRaWANRUI3Base(2, port=(19, 22)) 22 base_lorawaneu868.set_network_mode(0) 23 base_lorawaneu868.set_p2p_frequency(600000000) 24 base_lorawaneu868.set_p2p_spreading_factor(7) 25 base_lorawaneu868.set_p2p_bandwidth(0) 26 base_lorawaneu868.set_p2p_tx_power(14) 27 base_lorawaneu868.set_p2p_code_rate(0) 28 base_lorawaneu868.set_p2p_preamble_length(8) 29 print("Press the button to send P2P message") 30 31 32def loop(): 33 global rgb, base_lorawaneu868 34 M5.update() 35 if BtnA.wasPressed(): 36 base_lorawaneu868.send_p2p_data("AABBCC", timeout=0, to_hex=False) 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 LoRaWAN-EU868 LoRaWAN OTAA 模式示例程序:
UIFLOW2 LoRaWAN-EU868 P2P 模式 TX 示例程序:
UIFLOW2 LoRaWAN-EU868 P2P 模式 RX 示例程序:
API
AtomDTULoRaWANRUI3Base
- class base.dtu_lorawan_rui3.AtomDTULoRaWANRUI3Base(id=2, port=None, debug=False)
基类:
RUI3创建 AtomDTULoRaWANRUI3Base 对象。
- 参数:
MicroPython 代码块:
from base import AtomDTULoRaWANRUI3Base lorawan_rui3 = AtomDTULoRaWANRUI3Base(2, port=(19, 22))
- get_abp_config()
Retrieve the current ABP configuration.
MicroPython 代码块:
print(lorawan_rui3.get_abp_config())
- get_otaa_config()
获取当前 OTAA 配置。
MicroPython 代码块:
print(lorawan_rui3.get_otaa_config())
- set_abp_config(dev_addr, apps_key, nwks_key)
Configure the device for ABP (Activation By Personalization) mode.
- 参数:
- 返回类型:
None
MicroPython 代码块:
lorawan_rui3.set_abp_config( dev_addr="26011D89", apps_key="2B7E151628AED2A6ABF7158809CF4F3C", nwks_key="2B7E151628AED2A6ABF7158809CF4F3C" )
- set_otaa_config(device_eui, app_key, app_eui)
配置设备为 OTAA(Over-The-Air Activation,空中激活)模式。
- 参数:
- 返回类型:
None
MicroPython 代码块:
lorawan_rui3.set_otaa_config( device_eui="2CF7F1C0420000AA", app_key="2B7E151628AED2A6ABF7158809CF4F3C" app_eui="80000000000000AA", )
- class driver.rui3.RUI3(id, tx, rx, debug=False)
基类:
object- get_received_data()
检索最后一次接收到的消息数据。
MicroPython 代码块:
data = lorawan_rui3.get_received_data() if data: print(f"Received data: {data}") else: print("No data received.")
- get_received_data_string()
检索接收到的数据作为字符串。
- 返回:
接收到的数据作为字符串,如果没有数据接收,返回空字符串。
- 返回类型:
MicroPython 代码块:
data = lorawan_rui3.get_received_data_string() if data: print(f"Received data: {data}") else: print("No data received.")
- get_received_data_count()
检索接收到的数据数量。
- 返回:
接收到的数据数量。
- 返回类型:
MicroPython 代码块:
count = lorawan_rui3.get_received_data_count() print(f"Received data count: {count}")
- reset_module_to_default()
将模块重置为出厂默认设置。
MicroPython 代码块:
rui3.reset_module_to_default()
- set_join_config(state, auto_join, reattempt_interval=8, max_attempts=0, timeout=8000)
为 LoRaWAN 配置连接参数。
配置不确认网络连接成功。
- 参数:
- 返回:
如果命令设置成功,返回 True,否则返回 False。
- 返回类型:
MicroPython 代码块:
lorawan_rui3.set_join_config( state=1, auto_join=1, reattempt_interval=10, max_attempts=5, timeout=10000 )
- join_network(timeout=8000)
使用预定义的连接参数加入 LoRa 网络。
- 参数:
timeout (int) – 连接命令超时时间,单位为毫秒。默认值为 8000ms。
- 返回:
如果命令设置成功,返回 True,否则返回 False。
- 返回类型:
bool

MicroPython 代码块:
if lorawan_rui3.join_network(timeout=10000): print("Network joined successfully!") else: print("Failed to join network.")
- set_join_mode(mode)
设置 LoRa 模块的连接模式。
MicroPython 代码块:
lorawan_rui3.set_join_mode(1) # Set to OTAA mode
- get_join_state()
检查模块是否成功加入网络。
- 返回:
如果已加入网络,返回 True,否则返回 False。
- 返回类型:
MicroPython 代码块:
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()
检索最后一次接收到的消息数据。
MicroPython 代码块:
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.")
- send_data(port, data, timeout=600)
通过特定端口发送数据。
- 参数:
- 返回:
如果数据发送成功,返回 True,否则返回 False。
- 返回类型:
bool

MicroPython 代码块:
success = lorawan_rui3.send_data(port=1, data=b"HelloLoRa", timeout=800) if success: print("Data sent successfully!") else: print("Failed to send data.")
- set_network_mode(mode)
设置设备网络模式。
MicroPython 代码块:
lorawan_rui3.set_network_mode(0) # Set to P2P_LORA mode
- get_p2p_frequency()
检索当前 P2P 频率。
- 返回:
当前 P2P 频率作为整数。
- 返回类型:
MicroPython 代码块:
frequency = lorawan_rui3.get_p2p_frequency() print(f"Current P2P frequency: {frequency} Hz")
- set_p2p_frequency(frequency)
设置设备 P2P 频率。
- 返回:
AT 命令执行结果。
- 返回类型:
- 参数:
frequency (int) –
要设置的 P2P 通信频率。
低频率范围:150000000-600000000
高频率范围:600000000-960000000
MicroPython 代码块:
success = lorawan_rui3.set_p2p_frequency(433000000) if success: print("P2P frequency set successfully!") else: print("Failed to set P2P frequency.")
- get_p2p_spreading_factor()
获取当前 P2P 扩展因子。
- 返回:
当前 P2P 扩展因子作为整数。
- 返回类型:
MicroPython 代码块:
sf = lorawan_rui3.get_p2p_spreading_factor() print(f"Current P2P spreading factor: {sf}")
- set_p2p_spreading_factor(spreading_factor)
设置 P2P 扩展因子。
MicroPython 代码块:
success = lorawan_rui3.set_p2p_spreading_factor(10) if success: print("P2P spreading factor set successfully!") else: print("Failed to set P2P spreading factor.")
- get_p2p_bandwidth()
获取当前 P2P 带宽。
- 返回:
当前 P2P 带宽作为整数。
- 返回类型:
MicroPython 代码块:
bw = lorawan_rui3.get_p2p_bandwidth() print(f"Current P2P bandwidth: {bw}")
- set_p2p_bandwidth(bandwidth)
Set the P2P bandwidth.
- 参数:
bandwidth (int) –
用于 P2P 通信的带宽。
- 对于 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
- 对于 FSK:
范围:4800-467000 Hz
- 返回:
AT 命令执行结果。
- 返回类型:
bool


MicroPython 代码块:
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.")
- get_p2p_code_rate()
获取当前 P2P 编码速率。
- 返回:
当前 P2P 编码速率作为整数。
- 返回类型:
MicroPython 代码块:
code_rate = lorawan_rui3.get_p2p_code_rate() print(f"Current P2P code rate: {code_rate}")
- set_p2p_code_rate(code_rate)
设置 P2P 编码速率。
MicroPython 代码块:
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.")
- get_p2p_preamble_length()
获取当前 P2P 前导码长度。
- 返回:
当前 P2P 前导码长度作为整数。
- 返回类型:
MicroPython 代码块:
preamble_length = lorawan_rui3.get_p2p_preamble_length() print(f"Current P2P preamble length: {preamble_length}")
- set_p2p_preamble_length(length)
设置 P2P 前导码长度。
MicroPython 代码块:
success = lorawan_rui3.set_p2p_preamble_length(16) if success: print("P2P preamble length set successfully!") else: print("Failed to set P2P preamble length.")
- get_p2p_tx_power()
获取当前 P2P 发射功率。
- 返回:
当前 P2P 发射功率作为整数。
- 返回类型:
MicroPython 代码块:
tx_power = lorawan_rui3.get_p2p_tx_power() print(f"Current P2P transmission power: {tx_power} dBm")
- set_p2p_tx_power(power)
设置 P2P 发射功率。
MicroPython 代码块:
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.")
- get_p2p_fsk_bitrate()
获取当前 P2P FSK 比特率。
- 返回:
AT 命令执行结果。
- 返回类型:
MicroPython 代码块:
fsk_bitrate = lorawan_rui3.get_p2p_fsk_bitrate() print(f"Current P2P FSK bitrate: {fsk_bitrate} b/s")
- set_p2p_fsk_bitrate(bitrate)
设置 P2P FSK 比特率。
MicroPython 代码块:
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.")
- send_p2p_data(payload, timeout=1000, to_hex=False)
发送带有给定负载的 P2P 数据。
- 参数:
- 返回:
如果数据发送成功,则返回 True(”TXFSK DONE” 或 “TXP2P DONE”),否则返回 False。
- 返回类型:
bool

MicroPython 代码块:
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.")
- get_p2p_receive_data(timeout=500, to_str=False)
在 P2P 模式下接收数据,包括 RSSI、SNR 和负载。
- 参数:
- 返回:
如果收到数据,则返回一个元组 (RSSI, SNR, Payload);如果没有收到数据,则返回 False。
- 返回类型:
MicroPython 代码块:
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_sync_word()
获取当前 P2P 同步字。
- 返回:
当前 P2P 同步字作为字符串。
- 返回类型:
MicroPython 代码块:
sync_word = lorawan_rui3.get_p2p_sync_word() print(f"Current P2P sync word: {sync_word}")





