Lora模块界面
rak811的Python项目详细描述
rak811覆盆子pi的python 3库
关于
rak811 python 3库和命令行接口,用于覆盆子pi lora phat。
库公开at命令,如RAK811 Lora AT Command User Guide V1.5中所述。
命令行接口向命令行公开所有api调用。
当前执行的命令:
- 系统命令
- 罗兰万命令
- lorapp命令
- 收音机
尚未实现:
- 外围设备
要求
- 树莓皮!
- RAK811罗兰模块(PiSupply IoT LoRa Node pHAT for Raspberry Pi )
- 在raspberry pi上,必须启用硬件串行端口,并禁用串行控制台(使用
raspi-config
) - 运行应用程序的用户必须在
dialout
和gpio
组中(这是pi
用户的默认值)
安装RAK811组件
软件包是从pypi安装的:
sudo pip3 install rak811
pip3
命令是python3-pip
包的一部分。如果系统中缺少,请运行:
sudo apt-get install python3-pip
PiSupply提供用于配置覆盆子pi的detailed instructions。
用法
快速启动物联网
注册设备
使用rak811模块(设备eui)的唯一id在TheThingsNetwork上注册设备。
您可以使用以下命令检索设备eui:
rak811 hard-reset
rak811 get-config dev_eui
note:只有在(重新)启动覆盆子pi以激活模块之后,才需要rak811 hard-reset
命令。
你好世界
使用以下python代码片段发送第一条lorawan消息:
(应用程序EUI和应用程序密钥从TTN控制台逐字复制)
#!/usr/bin/env python3
from 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()
您的第一条消息应该出现在TTN控制台上!
下一步
请参阅example directory on GitHub:
api_demo.py
:演示大多数api调用otaa.py
:otaa示例abp.py
:abp示例p2p.py
:p2p示例p2p.sh
:基于命令行界面的p2p示例(见下文)
要运行这些示例,首先将ttn_secrets_template.py
复制到ttn_secrets.py
,然后输入lorawan TheThingsNetwork键。
note:每次运行脚本时不需要hard_reset
模块。
但是,您必须在(重新)引导后第一次执行此操作才能激活模块。
巴莱纳云
将库与balenaCloud: Basic RAK811 example with balenaCloud一起使用的示例代码。
命令行界面
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
note:对于启动后的第一个会话,需要执行hard-reset
而不是reset lora
命令来激活模块。