LoRa
Python Library for Microchip RN2XX3 LoRa Module.
Python Library
Turta_LoRa library is responsible for handling all LoRa communication.
To make Raspberry Pi communicate with the LoRa module, you should swap the serial ports of the Raspbian OS. Set "/dev/ttyAMA0" to 'serial0'. Also, disable the console on 'serial0'. For a how-to, visit swapping the serial ports topic.
Initialization
Add the following statement to the top of your Python code.
Then, create an instance of the RN2XX3 class.
Now you're ready to access the library by calling its instance.
Initialization Parameters
RN2XX3
Initiates the RN2XX3 LoRa module to handle LoRa communication.
Parameters
REGIONS region: LoRa Module region. (Default is REGIONS.US_RN2903)
CONFIG_MODES auto_config: LoRa Module operating mode. NONE is for manual configuration. LORA_TX and LORA_RX are for automatic configuration. (Default is MODES.CONFIG_MODES.NONE)
Int freq_us: LoRa radio frequency for US version auto configuration. (Default is 915000000)
Int freq_eu: LoRa radio frequency for EU version auto configuration. (Default is 868000000)
Basic Members
Basic members work on autoconfiguration mode.
Send
Broadcasts data for auto TX mode operation.
Parameters
String data: Data to send (Max 255 characters).
Returns
str: Response from the LoRa module.
Check Data
Checks the serial port buffer for received data.
Parameters
None
Returns
str: If auto mode is selected, the function returns received data. If manual mode is selected, it returns the LoRa module's raw output.
System Commands (Advanced)
System Commands
Sys Sleep
Puts the system to sleep for the specified number of milliseconds.
Parameters
Int length: Number of milliseconds the system is put to sleep (100 to 4294967296).
Returns
String: Response from the module.
Sys Reset
Resets and restarts the LoRa module; stored LoRaWAN protocol settings will be loaded automatically upon reboot.
Parameters
None.
Returns
String: Response from the module.
Sys Factory Reset
Resets the module’s configuration data and user EEPROM to factory default values and restarts the module.
Parameters
None.
Returns
String: Firmware version and release date (RN2XX3 X.Y.Z MMM DD YYYY HH:MM:SS).
Sys Set NVM
Allows the user to modify the user EEPROM at with the value supplied by.
Parameters
String address: Hexadecimal number representing user EEPROM address (300 to 3FF)
String data: Hexadecimal number representing data (00 to FF)
Returns
String: Response from the module.
Sys Get Ver
Returns the information related to the hardware platform, firmware version, release date and time-stamp on firmware creation.
Parameters
None.
Returns
String: Firmware version and release date (RN2XX3 X.Y.Z MMM DD YYYY HH:MM:SS).
Sys Get NVM
Returns the data stored in the user EEPROM of the RN2XX3 module at the requested location.
Parameters
String address: Hexadecimal number representing user EEPROM address (300 to 3FF).
Returns
String: 00–FF (hexadecimal value from 00 to FF) if the address is valid.
Sys Get VDD
Gets the Voltage applied to the VDD pins.
Parameters
None.
Returns
String: mV Measured on the VDD pins (0 to 3600).
Sys Get HWEUI
Reads the preprogrammed EUI node address from the RN2XX3 module.
Parameters
None.
Returns
String: Hexadecimal number representing the preprogrammed EUI node address.
MAC Commands (Advanced)
LoRaWAN Class A and Class C Protocol Commands (MAC)
MAC Reset
Sets default values for most of the LoRaWAN parameters. Everything set prior to this command will lose its set value, being reinitialized to the default value, including setting the cryptographic keys to 0.
Parameters
EU_FREQ_BANDS band: Frequency Band for EU version. Set 'NONE' for US version.
Returns
String: Response from the module.
MAC Tx
Automatically reset the software LoRaWAN stack and initialize it with the default parameters.
Parameters
UPLINK_PAYLOAD_TYPES uplink_payload_type: Uplink payload type, either confirmed or unconfirmed.
Int portno: Port number (1 to 223).
String data: Hexadecimal value; the length of bytes capable of being transmitted are dependent upon the set data rate.
Returns
String: First response from the device; this command may reply with multiple responses.
MAC Join
Informs the RN2XX3 module it should attempt to join the configured network.
Parameters
JOIN_PROCEDURE_TYPES mode: Join procedure type.
Returns
String: First response from the device; this command may reply with two responses.
MAC Save
Saves the LoRaWAN protocol configuration parameters to the EEPROM. Upon the next system reset the LoRaWAN protocol configuration will be initialized with the last saved parameters.
Parameters
None.
Returns
String: Response from the module.
MAC Force Enable
Restores the module’s connectivity by allowing it to send data.
Parameters
None.
Returns
String: Response from the module.
MAC Pause
Pauses the LoRaWAN stack functionality to allow transceiver (radio) configuration.
Parameters
None.
Returns
String: The number of milliseconds the MAC can be paused (0 to 4294967295).
MAC Resume
Resumes LoRaWAN stack functionality, in order to continue normal functionality after being paused.
Parameters
None.
Returns
String: Response from the module.
MAC Set Appkey
Sets the application key for the module. The application key is used to derive the security credentials for communication during over-the-air activation.
Parameters
String appkey: 16-byte hexadecimal number representing the application key.
Returns
String: Response from the module.
MAC Set Appskey
Sets the application session key for the module. This key provides security for communication between module and application server.
Parameters
String appsesskey: 16-byte hexadecimal number representing the application session key.
Returns
String: Response from the module.
MAC Set AR
Sets the state of the automatic reply.
Parameters
AR_STATES state: Automatic reply state.
Returns
String: Response from the module.
MAC Set Bat
Sets the battery level required for Device Status Answer frame in use with the LoRaWAN Class A protocol.
Parameters
Int level: The level of the battery (0 to 255) 0 Means external power, 1 means low level, 254 means high level, 255 means the end device was not able to measure the battery level.
Returns
String: Response from the module.
MAC Set Ch Freq
Sets the operational frequency on the given for the EU version. The default channels (0-2) cannot be modified in terms of frequency.
Parameters
Int channel_id: The channel number (from 3 to 15).
Int frequency: The frequency in Hz (863000000 to 870000000 or 433050000 to 434790000).
Returns
String: Response from the module.
MAC Set Ch Dcycle
Sets the duty cycle used on the given for the EU version.
Parameters
Int channel_id: The channel number (0 to 15).
Int duty_cycle: The duty cycle (0 to 65535).
Returns
String: Response from the module.
MAC Set Ch Drrange
Sets the operating data rate range, min. to max., for the given.
Parameters
Int channel_id: The channel number (0 to 71 for the US, 0 to 15 for the EU).
Int min_range: The minimum data rate (0 to 3 for the US, 0 to 7 for the EU).
Int max_range: The maximum data rate (0 to 3 for the US, 0 to 7 for the EU).
Returns
String: Response from the module.
MAC Set Ch Status
Sets the operation of the given.
Parameters
Int channel_id: The channel number (0 to 71).
CH_STATUS status: The state (on or off).
Returns
String: Response from the module.
MAC Set Class
Sets the end device LoRaWAN operating clas.
Parameters
DEVICE_CLASS device_class: The LoRaWAN device class (a or c).
Returns
String: Response from the module.
MAC Set Devaddr
Configures the module with a 4-byte unique network device address. The address must be unique to the current network.
Parameters
String address: 4-byte hexadecimal number representing the device address (00000000 to FFFFFFFF).
Returns
String: Response from the module.
MAC Set Deveui
Sets the globally unique device identifier for the module.
Parameters
String deveui: 8-byte hexadecimal number representing the device EUI.
Returns
String: Response from the module.
MAC Set Dnctr
Sets the value of the downlink frame counter that will be used for the next downlink reception.
Parameters
Int f_cnt_down: The value of the downlink frame counter that will be used for the next downlink reception (0 to 4294967295).
Returns
String: Response from the module.
MAC Set DR
Sets the data rate to be used for the next transmission.
Parameters
Int datarate: Data rate (0 to 4 for US, 0 to 7 for EU, but within the limits of the data rate range for the defined channels).
Returns
String: Response from the module.
MAC Set Linkchk
Sets the time interval for the link check process to be triggered periodically.
Parameters
Int linkcheck: The time interval in seconds for the link check process (0 to 65535).
Returns
String: Response from the module.
MAC Set Mcast
Sets the end device multicast state (mcast) to either be enabled or disabled.
Parameters
MCAST_STATES state: End device multicast state (on or off).
Returns
String: Response from the module.
MAC Set Mcastappskey
Sets the multicast application session key for the module.
Parameters
String mcast_application_session_key: 16-byte hexadecimal number representing the application session key.
Returns
String: Response from the module.
MAC Set Mcastdevaddr
Configures the module with a 4-byte multicast network device address.
Parameters
String mcast_address: 4-byte hexadecimal number representing the device multicast address (00000000 to FFFFFFFF).
Returns
String: Response from the module.
MAC Set Mcastdnctr
Sets the value of the multicast downlink frame counter that will be used for the next downlink reception.
Parameters
Int f_mcast_cntdown: The value of the multicast downlink frame counter (0 to 4294967295).
Returns
String: Response from the module.
MAC Set Mcastnwkskey
Sets the multicast network session key for the module.
Parameters
String mcast_network_session_key: 16-byte hexadecimal number representing the network session key.
Returns
String: Response from the module.
MAC Set Nwkskey
Sets the network session key for the module.
Parameters
String nwk_sess_key: 16-byte hexadecimal number representing the network session key.
Returns
String: Response from the module.
MAC Set Pwridx
Sets the output power to be used on the next transmissions.
Parameters
Int pwr_index: Index value for the output power (5 to 10 on the US 902-928 frequency band).
Returns
String: Response from the module.
MAC Set Retx
Sets the number of retransmissions to be used for an uplink confirmed packet, if no downlink acknowledgment is received from the server.
Parameters
Int re_tx_nb: The number of retransmissions for an uplink confirmed packet (0 to 255).
Returns
String: Response from the module.
MAC Set Rx2 US
Sets the data rate and frequency used for the second Receive window, for US version.
Parameters
Int data_rate: Data rate (8 to 13).
FREQUENCIES frequency: Frequency (923300000 to 927500000 Hz in 600kHz steps).
Returns
String: Response from the module.
MAC Set Rx2 EU
Sets the data rate and frequency used for the second Receive window, for EU version.
Parameters
Int data_rate: Data rate (0 to 7).
Int frequency: Frequency in Hz (863000000 to 870000000 or 433050000 to 434790000).
Returns
String: Response from the module.
MAC Set Rxdelay1
Sets the delay between the transmission and the first Reception window to the in milliseconds.
Parameters
Int rx_delay: The delay between the transmission and the first Reception window in milliseconds (0 to 65535).
Returns
String: Response from the module.
MAC Set Sync
Sets the synchronization word for the LoRaWAN communication.
Parameters
String synch_word: One byte long hexadecimal number representing the synchronization word for the LoRaWAN communication.
Returns
String: Response from the module.
MAC Set Upctr
Sets the value of the uplink frame counter that will be used for the next uplink transmission.
Parameters
Int f_cnt_up: The value of the uplink frame counter that will be used for the next uplink transmission (0 to 4294967295).
Returns
String: Response from the module.
MAC Get Adr
Returns the state of the adaptive data rate mechanism.
Parameters
None.
Returns
String: State of the adaptive data rate mechanism (on or off).
MAC Get Appeui
Returns the application identifier for the module. The application identifier is a value given to the device by the network.
Parameters
None.
Returns
String: 8-byte hexadecimal number representing the application EUI.
MAC Get AR
Returns the current state for the automatic reply (AR) parameter.
Parameters
None.
Returns
String: The state of the automatic reply (on or off).
MAC Get Ch Freq
Returns the frequency on the requested.
Parameters
Int channel_id: Channel number (0 to 71).
Returns
String: The frequency of the channel.
MAC Get Ch Dcycle
Returns the duty cycle on the requested.
Parameters
Int channel_id: Channel number (0 to 15).
Returns
String: Duty cycle of the channel (0 to 65535).
MAC Get Ch Drrange
Returns the allowed data rate index range on the requested.
Parameters
Int channel_id: Channel number (0 to 71 for US, 0 to 15 for EU).
Returns
String: Minimum and maximum data rate of the channel.
MAC Get Ch Status
Returns if is currently enabled for use.
Parameters
Int channel_id: Channel number (0 to 71 for US, 0 to 15 for EU).
Returns
String: The state of the channel (on or off).
MAC Get Class
Return the LoRaWAN operation class as set in the module.
Parameters
None.
Returns
String: A single letter (A or C).
MAC Get Dcycleps
Returns the duty cycle prescaler.
Parameters
None.
Returns
String: The prescaler value (0 to 65535).
MAC Get Devaddr
Returns the current end-device address of the module.
Parameters
None.
Returns
String: 4-byte hexadecimal number representing the device address (00000000 to FFFFFFFF).
MAC Get Deveui
Returns the globally unique end-device identifier, as set in the module.
Parameters
None.
Returns
String: 8-byte hexadecimal number representing the device EUI.
MAC Get Dnctr
Returns the value of the downlink frame counter that will be used for the next downlink reception.
Parameters
None.
Returns
String: The value of the downlink frame counter that will be used for the next downlink reception (0 to 4294967295).
MAC Get DR
Returns the current data rate.
Parameters
None.
Returns
String: Current data rate.
MAC Get Gwnb
Returns the number of gateways that successfully received the last Link Check Request frame command, as received in the last Link Check Answer.
Parameters
None.
Returns
String: The number of gateways (0 to 255).
MAC Get Mcast
Returns the multicast state as set in the module.
Parameters
None.
Returns
String: The multicast state of the module (on or off).
MAC Get Mcastdevaddr
Returns the current multicast end-device address of the module.
Parameters
None.
Returns
String: 4-byte hexadecimal number representing the device multicast address (00000000 to FFFFFFFF).
MAC Get Mcastdnctr
Returns the value of the downlink frame counter that will be used for the next downlink reception.
Parameters
None.
Returns
String: Value of the downlink frame counter that will be used for the next multilink downlink reception (0 to 4294967295).
MAC Get Mrgn
Returns the demodulation margin as received in the last Link Check Answer frame.
Parameters
None.
Returns
String: The demodulation margin (0 to 255).
MAC Get Pwridx
Returns the current output power index value.
Parameters
None.
Returns
String: Current output power index value.
MAC Get Retx
Returns the currently configured number of retransmissions which are attempted for a confirmed uplink communication when no downlink response has been received.
Parameters
None.
Returns
String: The number of retransmissions (0 to 255).
MAC Get Rx2
Returns the current data rate and frequency configured to be used during the second Receive window.
Parameters
None.
Returns
String: The data rate configured for the second Receive window and the frequency configured for the second Receive window.
MAC Get Rxdelay1
Returns the interval, in milliseconds, for rxdelay1.
Parameters
None.
Returns
String: The interval, in milliseconds, for rxdelay1 (0 to 65535)
MAC Get Rxdelay2
Returns the interval, in milliseconds, for rxdelay2.
Parameters
None.
Returns
String: The interval, in milliseconds, for rxdelay2 (0 to 65535).
MAC Get Status
Returns the synchronization word for the LoRaWAN communication.
Parameters
None.
Returns
String: Response from the module.
MAC Get Sync
Returns the synchronization word for the LoRaWAN communication.
Parameters
None.
Returns
String: One byte long hexadecimal number representing the synchronization word for the LoRaWAN communication.
MAC Get Upctr
Returns the value of the uplink frame counter that will be used for the next uplink transmission.
Parameters
None.
Returns
String: The value of the uplink frame counter that will be used for the next uplink transmission (0 to 4294967295).
Radio Commands (Advanced)
Transceiver Comands (Radio)
Radio Rx
Opens the radio receiver. The mac pause command must be called before any radio transmission or reception, even if no MAC operations have been initiated before.
Parameters
Int rx_window_size: The number of symbols (for LoRa modulation) or time out in milliseconds (for FSK modulation) that the receiver will be opened (0 to 65535); set to 0 in order to enable the Continuous Reception mode. Continuous Reception mode will be exited once a valid packet is received.
Returns
String: First response from the device; this command may reply with two responses.
Radio Tx
Transmits the data passed.
Parameters
String data: Hexadecimal value representing the data to be transmitted (0 to 255 bytes for LoRa modulation and from 0 to 64 bytes for FSK modulation).
Returns
String: First response from the device; this command may reply with two responses.
Radio CW
Enables or disables the CW mode on the module.
Parameters
CW_MODES state: The state of the Continuous Wave (CW) mode (on or off).
Returns
String: Response from the module.
Radio Rxstop
Causes the radio to exit Continuous Receive mode.
Parameters
None.
Returns
String: Response from the module.
Radio Set AFCBW
Modifies the automatic frequency correction bandwidth for receiving/transmitting.
Parameters
FREQ_BANDS auto_freq_band: The automatic frequency correction, in kHz.
Returns
String: Response from the module.
Radio Set Bitrate
Sets the FSK bit rate value.
Parameters
Int fsk_bitrate: The FSK bit rate value (1 to 300000).
Returns
String: Response from the module.
Radio Set Bt
Modifies the data shaping applied to FSK transmissions.
Parameters
GFBTS gf_bt: The Gaussian baseband data shaping, enabling GFSK modulation.
Returns
String: Response from the module.
Radio Set Bw
Sets the operating radio bandwidth for LoRa operation.
Parameters
RADIO_BW bandwidth: The operating radio bandwidth, in kHz.
Returns
String: Response from the module.
Radio Set CR
Modifies the coding rate currently being used by the radio.
Parameters
CODING_RATES coding_rate: The coding rate.
Returns
String: Response from the module.
Radio Set CRC
Enables or disables the CRC header for communications.
Parameters
CRC_HEADER_STATES crc_header: The state of the CRC header (on or off).
Returns
String: Response from the module.
Radio Set Fdev
Sets the frequency deviation during operation.
Parameters
Int freq_dev: Frequency deviation (0 to 200000).
Returns
String: Response from the module.
Radio Set Freq
Changes the communication frequency of the radio transceiver.
Parameters
Int frequency: Frequency in Hz (902000000 to 928000000 for US, 433050000 to 434790000 or 863000000 to 870000000 for EU).
Returns
String: Response from the module.
Radio Set IQI
Enables or disables the Invert IQ for communications.
Parameters
IQI_STATES iq_invert: The state of the invert IQ (on or off).
Returns
String: Response from the module.
Radio Set Mod
The modulation method being used by the module.
Parameters
RADIO_MODES mode: The modulation method (LoRa or FSK).
Returns
String: Response from the module.
Radio Set Prlen
Sets the preamble length for transmit/receive.
Parameters
Int preamble: The preamble length (0 to 65535).
Returns
String: Response from the module.
Radio Set Pwr
Changes the transceiver output power.
Parameters
Int pwr_out: Transceiver output power (2 to 20 for US, -3 to 15 for EU).
Returns
String: Response from the module.
Radio Set RXBW
Sets the signal bandwidth when receiving.
Parameters
FREQ_BANDS rx_bandwidth: The signal bandwidth, in kHz.
Returns
String: Response from the module.
Radio Set SF
Sets the spreading factor used during transmission.
Parameters
SPREADING_FACTORS spreading_factor: Spreading factor.
Returns
String: Response from the module.
Radio Set Sync
Configures the sync word used during communication.
Parameters
String sync_word: The sync word used during communication (For LoRa modulation one byte is used, for FSK up to eight bytes can be entered).
Returns
String: Response from the module.
Radio Set WDT
Updates the time-out length, in milliseconds, applied to the radio Watchdog Timer.
Parameters
String watchdog: The time-out length for the Watchdog Timer (0 to 4294967295; set to 0 to disable this functionality).
Returns
String: Response from the module.
Radio Get AFCBW
Reads back the status of the Automatic Frequency Correction Bandwidth.
Parameters
None.
Returns
String: Automatic frequency correction band, in kHz.
Radio Get Bitrate
Reads back the configured bit rate for FSK communications.
Parameters
None.
Returns
String: The configured bit rate (1 to 300000).
Radio Get Bt
Reads back the current configuration for data shaping applied to FSK transmissions.
Parameters
None.
Returns
String: The configuration for data shaping.
Radio Get BW
Reads back the current operating radio bandwidth used by the transceiver.
Parameters
None.
Returns
String: The current operating radio bandwidth, in kHz.
Radio Get CR
Reads back the current value settings used for the coding rate during communication.
Parameters
None.
Returns
String: The current value settings used for the coding rate.
Radio Get CRC
Reads back the status of the CRC header, to determine if it is to be included during operation.
Parameters
None.
Returns
String: Status of the CRC header (on or off).
Radio Get FDev
Reads frequency deviation setting on the transceiver.
Parameters
None.
Returns
String: Frequency deviation setting (0 to 200000).
Radio Get Freq
Reads back the current operation frequency of the module.
Parameters
None.
Returns
String: Frequency in Hz.
Radio Get IQI
Reads back the status of the Invert IQ functionality.
Parameters
None.
Returns
String: Status of the Invert IQ functionality (on or off).
Radio Get Mod
Reads back the current mode of operation of the module.
Parameters
None.
Returns
String: Current mode of operation of the module (lora or fsk).
Radio Get Prlen
Reads the current preamble length used for communication.
Parameters
None.
Returns
String: The preamble length (0 to 65535).
Radio Get Pwr
Reads back the current power level settings used in operation.
Parameters
None.
Returns
String: Current power level.
Radio Get RSSI
Reads back the radio Received Signal Strength Indication (rssi) value for the last received frame.
Parameters
None.
Returns
String: The rssi for the last received frame.
Radio Get RXBW
Reads back the signal bandwidth used for receiving.
Parameters
None.
Returns
String: The signal bandwidth, in kHz.
Radio Get SF
Reads back the current spreading factor being used by the transceiver.
Parameters
None.
Returns
String: The current spreading factor.
Radio Get SNR
Reads back the Signal Noise Ratio (SNR) for the last received packet.
Parameters
None.
Returns
String: The signal to noise ratio (SNR) (-128 to 127).
Radio Get Sync
Reads back the configured synchronization word used for radio communication.
Parameters
None.
Returns
String: The synchronization word used for radio communication.
Radio Get WDT
Reads back the length used for the watchdog time-out in milliseconds.
Parameters
None.
Returns
String: The length used for the watchdog time-out (0 to 4294967295).
Other Commands
Other commands, including LED controls.
Config LED
Sets the LED pin configuration to digital output.
Parameters
LEDS led: LEDs; Con, Act or Err.
Returns
String: Response from the module.
Set LED
Sets the LED status.
Parameters
LEDS led: LEDs; Con, Act or Err.
LED_STATES state: LED state, on or off.
Returns
String: Response from the module.
Finalizer
When exiting from the program, the library stops the radio operation, turns off the LEDs, and closes the serial port.
Last updated