Rak811 Python 3 Library and Command Line Interface للاستخدام مع قبعة Raspberry Pi Lora (P).
تكشف المكتبة وحدة RAK811 في الأوامر كما هو موضح في المستندات التالية:
تعرض واجهة سطر الأوامر جميع مكالمات API إلى سطر الأوامر.
raspi-config )dialout و gpio (هذا هو الافتراضي لمستخدم pi ) تم تثبيت الحزمة من PYPI:
sudo pip3 install rak811 أمر pip3 هو جزء من حزمة python3-pip . إذا كان مفقودًا على نظامك ، فقم بتشغيله:
sudo apt-get install python3-pipيوفر Pisupply تعليمات مفصلة لتكوين Raspberry Pi.
إذا كنت لا تعرف أن مستوى البرامج الثابتة لوحدةك قم بتشغيل الأوامر التالية:
rak811 hard-reset
rak811 version للبرامج الثابتة v2.0.x استخدم أمر rak811 ووحدة Python ، ل V3.0.x استخدم أمر rak811v3 ووحدة rak811_v3 Python.
قم بتسجيل جهازك على thethingsnetwork باستخدام المعرف الفريد لوحدة RAK811 الخاصة بك (الجهاز EUI).
يمكنك استرداد جهازك EUI مع الأمر التالي (v2.0.x):
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 أرسل رسالة لوراوان الأولى مع مقتطف كود بيثون التالي:
(يتم نسخ App 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!
انظر دليل المثال على جيثب:
api_demo.py : العرض التوضيحي معظم مكالمات API V2.0.xotaa.py / otaa_v3.py : otaa مثالotaa_v3_class_c.py : مثال OTAA مع الجهاز في وضع الفئة Cabp.py / abp_v3.py : مثال ABPp2p.py / p2p_v3.py : مثال P2Pp2p.sh / p2p_v3.sh : مثال P2P استنادًا إلى واجهة سطر الأوامر (انظر أدناه) لتشغيل الأمثلة ، قم أولاً بنسخ ttn_secrets_template.py إلى ttn_secrets.py وأدخل مفاتيح LoRawan thethingsnetwork.
ملاحظة : لا تحتاج إلى hard_reset للوحدة في كل مرة تقوم فيها بتشغيل برنامج نصي. ومع ذلك ، يجب أن تفعل ذلك في المرة الأولى بعد التمهيد (إعادة) لتفعيل الوحدة النمطية.
نموذج رمز لاستخدام المكتبة مع Balenacloud: مثال RAK811 الأساسي مع Balenacloud (v2.0.x البرامج الثابتة).
يعرض أمر 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