lora.stats()
lora.radio_params()
lora.callback()
lora.send()
lora.recv()
lora.recv_cont_start()
lora.recv_cont_stop()
lora.tx_continuous_wave_start()
lora.tx_continuous_wave_stop()
To display the current settings of the lora RAW, use lora.stats(), Then you will experience something like this:
>>> lora.stats() regional params region : EU-868 frequency : 868000000 Hz freq_khz : 868000.000 KHz freq_mhz : 868.000 MHz modulation params sf : 12 bandwidth : 125 KHz coding_rate : 4_7 packet params preamble : 8 payload : 51 crc_on : False lora tranceiver chip : SX1262 max tx_power : +22 dBm tx params tx_power : +10 dBm antenna_gain : +1.00 dBi tx_power_eff : +9 dBm tx_timeout : 6000 msec tx_iq : False rx params rx_timeout : 6000 msec rx_iq : False
Here is the meaning of each displayed parameter:
regional params: The parameters corresponding to the current region
regional params
region
frequency
freq_khz
freq_mhz
modulation params: The current modulation parameters which are; spreading-factor sf, bandwidth and coding_rate
modulation params
sf
bandwidth
coding_rate
packet params: parameters related to the packet data constraints such as preamble length, current maximum payload size, and if the crc_on is applied to the payload or not
packet params
preamble
payload
crc_on
lora tranceiver: shows the current info about the current used tranceiver such as the chip used and the maximum tx_power it can produce.
lora tranceiver
chip
tx_power
tx params: the current tx settings;
tx params
antenna_gain
tx_power_eff
tx_timeout
tx_iq
rx params: the current rx settings;
rx params
rx_timeout
rx_iq
To reset all parameters to the region defaults, provide reset_all flag like:
reset_all
lora.radio_params(reset_all=True)
To change any radio parameter, use lora.radio_params() which takes its parameters as in the following BNF formatted description:
::= "lora.radio_params(" ")" ::= "," | | "" ::= reset_all "=" ; reset to factory settings | region "=" ; change the region | frequency "=" ; desired freq in Hz | freq_khz "=" ; desired freq in KHz | freq_mhz "=" ; desired freq in MHz | tx_power "=" ; desired tx power | sf "=" ; spreading factor | coding_rate "=" ; coding rate | preamble "=" ; preamble length | bandwidth "=" ; band-width | tx_iq "=" ; inverted IQ feature ::= "True" | "False" ::= "lora._region." ::= "REGION_AS923" | "REGION_AU915" | "REGION_EU868" | "REGION_IN865" | "REGION_KR920" | "REGION_RU864" | "REGION_US915" ::= ::= ::= ::= "7" | "8" | "9" | "10" | "11" | "12" ::= "lora._bw." ::= "BW_125KHZ" | "BW_250KHZ" | "BW_500KHZ" ::= "lora._cr." ::= "CODING_4_5" | "CODING_4_6" | "CODING_4_7" | "CODING_4_8"
Examples:
# set the tx power to 5 dBm lora.radio_params(tx_power=5) lora.stats() # tx_power : +5 dBm --> desired tx-power # antenna_gain : +2.15 dBi --> current set antenna-gain # tx_power_eff : +2 dBm --> actual effective lora chip output power lora.radio_params(antenna_gain=1) # the effective power will change accordingly lora.stats() # tx_power : +5 dBm --> desired tx-power # antenna_gain : +1.00 dBi --> current set antenna-gain # tx_power_eff : +4 dBm --> actual effective lora chip output power # setting out of region valid tx power will be regicted for saftey lora.radio_params(tx_power=45) # error: invalid chip power +45 dBm -- chip SX1262 tx power range ( -8 ~ +23 ) dBm considering antenna gain 1.00 dBi # error: invalid tx-power 45 # setting spreading factor to 8 and BW to 250 and coding rate to 4/6 lora.radio_params(sf = 8, bandwidth = lora._bw.BW_250KHZ, coding_rate = lora._cr.CODING_4_6) # modulation params # sf : 8 # bandwidth : 250 # coding_rate : 4_6 # setting wrong values will be regected and the whole parameters will be ignored lora.radio_params(bandwidth=9, tx_power=44, sf=90) # gived the following reported errors error: invalid chip power +44 dBm -- chip SX1262 tx power range ( -7 ~ +24 ) dBm considering antenna gain 2.15 dBi error: invalid argument value 'tx_power' error: invalid argument value 'sf' error: invalid argument value 'bandwidth'
Note: Changing the region, will reset the entire radio parameters to the defaults of this new region
Note: The lora interface provides some class constants for some radio parameters:
lora._bw
lora._cr
lora._region
# Example # you can see the allowed values constans, by pressing the class names # followed by double >>> lora._bw. # press to see the following list BW_125KHZ BW_250KHZ BW_500KHZ >>> lora._cr. # press to see the following list CODING_4_5 CODING_4_6 CODING_4_7 CODING_4_8 >>> lora._region. # press to see the following list REGION_AS923 REGION_AU915 REGION_EU868 REGION_IN865 REGION_KR920 REGION_RU864 REGION_US915
Note: To change the frequency value, it can be done through one of these parameters (frequency, freq_khz or freq_mhz), however it is possible to specify one or more of those parameters. Hence in that case, the specified parameters will be considered in a priority fashion. frequency parameter has highest consideration priority and freq_mhz has lowest consideration priority.
# consider the current radio frequency parameter is 868.000 MHz >>> lora.radio_params(frequency=868000000, freq_mhz=868.3) # the specified `frequency` parameter will be considered first, but because # it has the same value of the current frequency, it will be bypassed, # then the next specified `freq_mhz` parameter will be considered, and # the radio frequency will be changed accordingly. # --> hence the current radio frequency parameter becomes 868.300 MHz >>> lora.radio_params(freq_mhz=868.3, frequency=868000000) # the highest priority parameter `frequency` will be considered first. # and because it holds newer value than the current radio frequency, the # radio frequency will be modified accordingly. # --> hence the current radio frequency parameter becomes 868.000 MHz # --> and the next specified `freq_mhz` parameter is neglicted
To set a user level callback to listen the RX events, see the following example to know the available events that can come in the callback
Example:
def get_event_str(event, bytes): if event == lora._event.EVENT_TX_CONFIRM: return 'EVENT_TX_CONFIRM' elif event == lora._event.EVENT_TX_DONE: return 'EVENT_TX_DONE' elif event == lora._event.EVENT_TX_TIMEOUT: return 'EVENT_TX_TIMEOUT' elif event == lora._event.EVENT_TX_FAILED: return 'EVENT_TX_FAILED' elif event == lora._event.EVENT_TX_CONFIRM: return 'EVENT_TX_CONFIRM' elif event == lora._event.EVENT_RX_DONE: return 'EVENT_RX_DONE' elif event == lora._event.EVENT_RX_TIMEOUT: return 'EVENT_RX_TIMEOUT' elif event == lora._event.EVENT_RX_FAIL: return 'EVENT_RX_FAIL' else: return 'UNKNOWN' pass def lora_callback(event, evt_data): print('lora event [ {} ] --> data: {}' .format(get_event_str(event), evt_data)) lora.callback( handler = lora_callback )
To send a specific data message, it takes the following parameters:
message
timeout
sync
sync=False
lora.send(“test message”) # sends a message asynchronously and with tx_timeout # as a full tx operation timeout
# send a message asynchronously and the full tx operation shall canceled after 1 second lora.send(“test message”, timeout=1000)
# send a message synchronously and the full tx operation shall canceled after 1 second # in this case, the caller will be blocked until tx succeeded or timeout is over lora.send(“test message”, timeout=1000, sync=True)
To receive a data and it takes the following parameters:
sync=True
async
lora.recv() # waits for `rx_timeout` radio parameter or until a data is received # wait for maximum 2 second or until a data is received lora.recv(timeout=2000) # place a receive request and return immediately # - if a data is received before 3 second timeout, it will be returned in the callback # - if timeout happened, the rx operation will be canceled and a timeout event will be # fed back in the callback lora.recv(timeout=3000, sync=True)
LoRa RAW can operate in continuous reception mode and any received data will be thrown in the registered user callback
lora.recv_cont_start() # starting the RX continuous mode lora.recv_cont_stop() # exiting the RX continuous mode
Sets the radio tranciver to continuous transmission mode for testing.
The tx continuous wave mode does not use the normal parameters set by the lora.radio_params() method, but instead it uses the following parameters
Remark: if the system is in sending or receiving operation, the operation will be cancelled and the system will start serving the tx continuous wave test command. After timeout is over, the system will go to its IDLE state.
lora.tx_continuous_wave_start( # starting the TX continuous wave mode tx_power = 20, # use tx_power = 20dBm frequency = 868000000, # test frequency 868 MHz timeout = 20000) # timeout for the tx continuous wave 20 sec lora.tx_continuous_wave_stop() # exiting the TX continuous wave mode