Raspberry Pi Lora (P) 모자와 함께 사용할 RAK811 Python 3 라이브러리 및 명령 줄 인터페이스.
라이브러리는 다음 문서에 설명 된대로 명령에 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 펌웨어의 경우 v3.0.x의 경우 rak811 명령 및 rak811_v3 모듈 rak811v3 사용하십시오.
RAK811 모듈 (Device EUI)의 고유 ID를 사용하여 TheThingsNetwork에 장치를 등록하십시오.
다음 명령 (v2.0.x)으로 장치 EUI를 검색 할 수 있습니다.
rak811 hard-reset
rak811 get-config dev_eui 참고 : rak811 hard-reset 명령은 모듈을 활성화하기 위해 Raspberry Pi를 부팅 한 후에 만 필요합니다.
또는 (v3.0.x) :
rak811v3 set-config lora:join_mode:0
rak811v3 get-config lora:status | grep DevEui 다음 파이썬 코드 스 니펫으로 첫 Lorawan 메시지를 보내십시오.
(앱 EUI 및 앱 키는 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 예제otaa_v3_class_c.py : 클래스 C 모드에서 장치가있는 OTAA 예제abp.py / abp_v3.py : abp 예제p2p.py / p2p_v3.py : p2p 예제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.Session example:
$ 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 참고 : 부팅 후 첫 세션의 경우 모듈을 활성화하려면 reset lora 대신 hard-reset 수행해야합니다.
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.Session example:
$ 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