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:
1import os, sys, io 2import M5 3from M5 import * 4from module import LoRaWAN868Module 5import time 6 7 8lorawan868_0 = None 9 10 11def setup(): 12 global lorawan868_0 13 14 M5.begin() 15 Widgets.fillScreen(0x222222) 16 17 lorawan868_0 = LoRaWAN868Module(1, (17, 16)) 18 lorawan868_0.wake_up() 19 lorawan868_0.set_parameters(0, 0, 5, 0, 1, 8, 0, 0, 0) 20 lorawan868_0.set_auto_low_power(False) 21 print(lorawan868_0.query_chip_id()) 22 print(lorawan868_0.query_lorawan_mode()) 23 print(lorawan868_0.any()) 24 lorawan868_0.set_mode(LoRaWAN868Module.MODE_LORA) 25 26 27def loop(): 28 global lorawan868_0 29 M5.update() 30 lorawan868_0.send_hex("Hello Lora!") 31 time.sleep(1) 32 33 34if __name__ == "__main__": 35 try: 36 setup() 37 while True: 38 loop() 39 except (Exception, KeyboardInterrupt) as e: 40 try: 41 from utility import print_error_msg 42 43 print_error_msg(e) 44 except ImportError: 45 print("please update to latest firmware")
Micropython RX Example:
1import os, sys, io 2import M5 3from M5 import * 4from module import LoRaWAN868Module 5 6 7lorawan868_0 = None 8 9 10def setup(): 11 global lorawan868_0 12 13 M5.begin() 14 Widgets.fillScreen(0x222222) 15 16 lorawan868_0 = LoRaWAN868Module(1, (17, 16)) 17 lorawan868_0.wake_up() 18 lorawan868_0.set_parameters(0, 0, 5, 0, 1, 8, 0, 0, 0) 19 lorawan868_0.set_auto_low_power(False) 20 print(lorawan868_0.query_chip_id()) 21 print(lorawan868_0.query_lorawan_mode()) 22 print(lorawan868_0.any()) 23 lorawan868_0.set_mode(LoRaWAN868Module.MODE_LORA) 24 lorawan868_0.enable_rx(0) 25 26 27def loop(): 28 global lorawan868_0 29 M5.update() 30 if lorawan868_0.any(): 31 print(lorawan868_0.receive_data()) 32 lorawan868_0.enable_rx(0) 33 34 35if __name__ == "__main__": 36 try: 37 setup() 38 while True: 39 loop() 40 except (Exception, KeyboardInterrupt) as e: 41 try: 42 from utility import print_error_msg 43 44 print_error_msg(e) 45 except ImportError: 46 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: