RAK811 Python 3库和命令行界面,可与Raspberry Pi Lora(P)帽子一起使用。
如下所述,该库在命令处公开RAK811模块:
命令行接口将所有API调用曝光到命令行。
raspi-config )dialout和gpio组中(这是pi用户的默认值) 该软件包是从PYPI安装的:
sudo pip3 install rak811 pip3命令是python3-pip软件包的一部分。如果您的系统缺少它,请运行:
sudo apt-get install python3-pipPisupply提供了配置Raspberry Pi的详细说明。
如果您不知道模块的固件级别运行以下命令:
rak811 hard-reset
rak811 version对于v2.0.x,固件使用rak811命令和python模块,对于v3.0.x,使用rak811v3命令和rak811_v3 python模块。
使用RAK811模块(设备EUI)的唯一ID在Thethingsnetwork上注册您的设备。
您可以使用以下命令(v2.0.x)检索设备EUI:
rak811 hard-reset
rak811 get-config dev_eui注意:(重新)启动覆盆子Pi以激活模块后,仅需要一次rak811 hard-reset命令。
或(v3.0.x):
rak811v3 set-config lora:join_mode:0
rak811v3 get-config lora:status | grep DevEui发送您的第一个Lorawan消息,以下python代码段:
(App EUI和App键从TTN控制台逐字复制)
#!/usr/bin/env python3
# V2.0.x firmware
from rak811 . rak811 import Mode , Rak811
lora = Rak811 ()
lora . hard_reset ()
lora . mode = Mode . LoRaWan
lora . band = 'EU868'
lora . set_config ( app_eui = '70B3D5xxxxxxxxxx' ,
app_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' )
lora . join_otaa ()
lora . dr = 5
lora . send ( 'Hello world' )
lora . close () #!/usr/bin/env python3
# V3.0.x firmware
from rak811 . rak811_v3 import Rak811
lora = Rak811 ()
lora . set_config ( 'lora:work_mode:0' )
lora . set_config ( 'lora:join_mode:0' )
lora . set_config ( 'lora:region:EU868' )
lora . set_config ( 'lora:app_eui:70B3D5xxxxxxxxxx' )
lora . set_config ( 'lora:app_key:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' )
lora . join ()
lora . set_config ( 'lora:dr:5' )
lora . send ( 'Hello world' )
lora . close ()您的第一条消息应出现在TTN控制台上!
请参阅GitHub上的示例目录:
api_demo.py :演示大多数v2.0.x API调用otaa.py / otaa_v3.py示例otaa_v3_class_c.py :在类C模式下设备的OTAA示例abp.py / abp_v3.py示例p2p.py / p2p_v3.py示例p2p.sh / p2p_v3.sh :基于命令行接口的P2P示例(见下文)要运行示例,请首先将ttn_secrets_template.py复制到ttn_secrets.py ,然后输入您的lorawan thethingsnetwork键。
注意:每次运行脚本时,您都不需要hard_reset 。但是,您必须在启动(RE)引导后的第一次激活模块。
示例代码与Balenacloud一起使用库:BALENACLOUD(v2.0.x固件)的基本RAK811示例。
rak811命令将所有库的电话公开到命令行:
$ rak811 --help
Usage: rak811 [OPTIONS] COMMAND [ARGS]...
Command line interface for the RAK811 module.
Options:
-v, --verbose Verbose mode
--help Show this message and exit.
Commands:
abp-info Get ABP info.
band Get/Set LoRaWan region.
clear-radio-status Clear radio statistics.
dr Get/set next send data rate.
get-config Get LoraWan configuration.
hard-reset Hardware reset of the module.
join-abp Join the configured network in ABP mode.
join-otaa Join the configured network in OTAA mode.
link-cnt Get up & downlink counters.
mode Get/Set mode to LoRaWan or LoRaP2P.
radio-status Get radio statistics.
recv-ex RSSI & SNR report on receive.
reload Set LoRaWan or LoRaP2P configurations to default.
reset Reset Module or LoRaWan stack.
send Send LoRaWan message and check for downlink.
set-config Set LoraWAN configuration.
signal Get (RSSI,SNR) from latest received packet.
sleep Enter sleep mode.
version Get module version.
wake-up Wake up.会话示例:
$ rak811 -v reset lora
LoRa reset complete.
$ rak811 -v set-config app_eui=70B3D5xxxxxxxxxx app_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LoRaWan parameters set
$ rak811 -v join-otaa
Joined in OTAA mode
$ rak811 -v dr
5
$ rak811 -v dr 4
Data rate set to 4.
$ rak811 -v send Hello
Message sent.
No downlink available.
$ rak811 -v send --port 4 --binary ' 01020211 '
Message sent.
Downlink received:
Port: 1
RSSI: -56
SNR: 31
Data: 123456注意:对于启动后的第一个会话,您需要进行hard-reset而不是reset lora命令来激活模块。
rak811v3命令将以下库调用曝光到命令行:
$ rak811v3 --help
Usage: rak811v3 [OPTIONS] COMMAND [ARGS]...
Command line interface for the RAK811 module.
Options:
-v, --verbose Verbose mode
-d, --debug Debug mode
--version Show the version and exit.
--help Show this message and exit.
Commands:
get-config Execute get_config RAK811 command.
hard-reset Hardware reset of the module.
help Print module help.
join Join the configured network.
receive-p2p Get LoraP2P message.
run Exit boot mode and enter normal mode.
send Send LoRaWan message and check for downlink.
send-p2p Send LoRa P2P message.
send-uart Send data to UART.
set-config Execute set_config RAK811 command.
version Get module version.会话示例:
$ rak811v3 -v set-config lora:work_mode:0
Configuration done
LoRa (R) is a registered trademark or service mark of Semtech Corporation or its affiliates. LoRaWAN (R) is a licensed mark.
RAK811 Version:3.0.0.14.H
UART1 work mode: RUI_UART_NORMAL, 115200, N81
UART3 work mode: RUI_UART_NORMAL, 115200, N81
LoRa work mode:LoRaWAN, join_mode:OTAA, MulticastEnable: false, Class: A
$ # The following is not necessary as in this case the module is already in OTAA mode!
$ rak811v3 -v set-config lora:join_mode:0
Configuration done
$ rak811v3 -v set-config lora:app_eui:70B3D5xxxxxxxxxx
Configuration done
$ rak811v3 -v set-config lora:app_key:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Configuration done
$ rak811v3 -v join
Joined!
$ rak811v3 get-config lora:status | grep ' Current Datarate '
Current Datarate: 4
$ rak811v3 -v set-config lora:dr:5
Configuration done
$ rak811v3 -v send ' Hello '
Message sent.
No downlink available.
$ rak811v3 -v set-config lora:confirm:1
Configuration done
$ rak811v3 -v send --port 4 --binary ' 01020211 '
Message sent.
Send confirmed.
RSSI: -66
SNR: 6