![]() | ![]() | ![]() | ![]() | ![]() |
|---|
针对低功耗的目标,这个用于Rakwireless Wisblock Core模块的Arduino库会在命令功能上照顾所有Lora P2P,Lorawan,Ble,Ble。您可以专注于应用程序,然后将其余的留给API。它是作为SX126X-Arduino Lorawan图书馆的伴侣
它需要对Arduino应用程序进行一些重新思考,因为您没有setup()或loop()函数。相反,一切都是事件驱动的。 MCU正在睡觉,直到需要采取行动。这可以是洛杉矶事件,在USB端口或应用程序事件上接收到的AT命令,例如传感器中断。
这种方法使创建专为低功率使用设计的应用程序变得容易。在睡眠期间,Wisblock Base + Wisblock Core Rak4631仅消耗40UA。
此外,API提供了两个设置Lora P2P / Lorawan设置的选项,而无需将它们硬编码为源代码。
库的V2更改了AT命令格式,以与rui3 commands兼容。请检查AT命令手册中的RUI3是否有差异。
V2发布仅支持Rakwireless Wisblock Rak4631核心模块
将来可能会添加对RAK11310和RAK1200的支持
API正在处理从setup() , loop() ,Lorawan初始化,Lorawan事件处理,BLE初始化,BLE事件处理到AT命令界面的所有内容。
评论!
用户应用程序不得具有函数setup()和loop() !
用户应用程序具有两个初始化函数,一个在setup()的开头称为一个函数,另一个在最后一个。其他功能是从loop()调用的事件回调。也可以定义自定义事件(例如传感器中断)。
传感器读取,执行器控制或其他应用程序任务在app_event_handler()中处理。 app_event_handler()经常调用,呼叫之间的时间由应用程序定义。另外, app_event_handler()在自定义事件上调用。
ble_data_handler()在loop()的ble uart rx事件中都调用。它可用于通过BLE UART实现自定义通信。
评论!
RAK11310上不需要此功能!
lora_data_handler()在不同的Lorawan事件上调用
图TD
一个[引导] - > |启动| B(设置)
B-> | 1 | D(setup_app)
D-> B(设置)
B-> | 2 | E [初始化Lora和Ble]
E-> B(设置)
B-> | 3 | g(init_app)
g-> k(设置完成)
K-> |开始循环|我(循环)
Q [Lora事件] - > |唤醒| j
o [传感器事件] - > |唤醒| JP [BLE事件] - > |唤醒| JR [在命令] - > |唤醒| JT [计时器] - > |唤醒| ji-> J(睡觉)
K-> |启动计时器| t
j - > l(app_event_handler)
J-> m(lora_data_handler)
j - > n(ble_data_handler)
J-> s(在命令处理程序)
l-> u(读取传感器)
M-> V(JOIN,TX和RX事件)
n-> w(命令时处理ble)
s-> aa(命令的用户)
u - > l
V-> m
W-> n
aa-> s
l-> j
M->J。
n-> j
S->J。

可以在“命令手册”中找到所有命令,并非支持所有命令的RUI3。可以检索AT的可用命令列表?从设备
在命令集的默认RUI3中添加了两个自定义命令的自定义:
说明:设置自动传输间隔
此命令允许在自动数据包传输之间以秒为单位设置间隔。如果设置为0,则禁用自动数据包传输。
| 命令 | 输入参数 | 返回值 | 返回代码 |
|---|---|---|---|
| ATC+sendint? | - | ATC+SENDINT: "Get or Set the automatic send interval | OK |
| atc+sendint =? | - | <interval in seconds> | OK |
atc+sendint = <Input Parameter> | <interval in seconds> | - | OK或AT_PARAM_ERROR |
示例:
ATC+SENDINT?
ATC+SENDINT: Get or Set the automatic send interval
OK
ATC+SENDINT=?
ATC+SENDINT:60
OK
ATC+SENDINT=60
OK
描述:显示设备状态
此命令允许用户获得当前的设备状态。
| 命令 | 输入参数 | 返回值 | 返回代码 |
|---|---|---|---|
| ATC+状态? | - | ATC+STATUS: Show LoRaWAN status | OK |
| ATC+状态=? | - | <status> | OK |
示例:
ATC+STATUS?
ATC+STATUS: Show LoRaWAN status
OK
// When in LoRaWAN mode:
ATC+STATUS=?
Device status:
RAK4631
Mode LPWAN
Auto join enabled
Network joined
LPWAN status:
Dev EUI AC1F09FFFE09016C
App EUI 70B3D57ED00201E1
App Key 2B84E0B09B68E5CB42176FE753DCEE79
Dev Addr 26021FB4
NWS Key 323D155A000DF335307A16DA0C9DF53F
Apps Key 3F6A66459D5EDCA63CBC4619CD61A11E
OTAA enabled
ADR disabled
Public Network
Dutycycle disabled
Join trials 5
TX Power 0
DR 3
Class 0
Subband 1
Fport 2
Unconfirmed Message
Region AS923-3
Send Frequency 300
// When in LoRa P2P mode:
ATC+STATUS=?
Device status:
RAK4631
Mode P2P
P2P frequency 916000000
P2P TX Power 22
P2P BW 125
P2P SF 7
P2P CR 0
P2P Preamble length 8
P2P Symbol Timeout 0
Send Frequency 300
描述:端口设置
此命令允许用户访问和配置端口设置。
| 命令 | 输入参数 | 返回值 | 返回代码 |
|---|---|---|---|
| ATC+端口? | - | AT+PORT=<Port><CR>. Get or Set the Port | OK |
| ATC+端口=? | - | 1-223 | 好的 |
ATC+端口= <Input Parameter> | 1-223 | - | 好的或at_param_error |
示例:
ATC+PORT?
ATC+PORT: Get or Set the Port=[1..223]
OK
ATC+PORT=?
ATC+PORT:2
OK
ATC+PORT=2
OK
后退
从Wisblock API v1.1.2开始,可以通过在命令上定义的用户扩展AT命令。该新实现使用命令函数的Wisblock API的解析器函数。此外,如果AT?使用。
评论!在RUI3中,命令的自定义与ATC一起调用,而不是AT !
要扩展AT命令,需要三个步骤:
命令的自定义列表以struct atcmd_t格式列出。每个条目由AT命令组成,当命令调用a时显示的说明文本。并指示查询功能,使用参数执行并执行无参数。这是两个自定义命令的示例:
atcmd_t g_user_at_cmd_list_example[] = {
/* | CMD | AT+CMD? | AT+CMD=? | AT+CMD=value | AT+CMD | Permissions | */
// GNSS commands
{ " +SETVAL " , " Get/Set custom variable " , at_query_value, at_exec_value, NULL , " RW " },
{ " +LIST " , " Show last packet content " , at_query_packet, NULL , NULL , " R " },
};
atcmd_t *g_user_at_cmd_list = g_user_at_cmd_list_example;备注1
命令定制的结构扩展了RUI3兼容性。为Wisblock-API V1.X编写的较旧代码需要调整为此新结构。
备注2
对于不受AT命令支持的功能,必须将NULL放入数组中。
备注3
名称g_user_at_cmd_list已固定,无法更改或未检测到自定义命令。
备注4
权限作为字符串给出。有效条目是“ R”(仅读),“ W”(仅写),“ RW”(读写)
必须提供带有自定义命令数量的变量:
/* * Number of user defined AT commands */
uint8_t g_user_at_cmd_num = sizeof (g_user_at_cmd_list_example) / sizeof ( atcmd_t );评论
名称g_user_at_cmd_num已修复,无法更改或未检测到自定义命令。
对于每个自定义命令,必须编写查询和执行命令。这些功能的名称必须匹配命令自定义数组中使用的函数名称。 execute命令作为参数接收到=之后的at命令的值。
查询函数( =? )未接收和参数,必须始终以0。查询函数保存在全局char数组g_at_query_buffer中查询的结果,该数组的最大大小的ATQUERY_SIZE大小为128个字符。
用参数( =<value> )执行函数接收值或设置作为指向char数组的指针。此数组仅包含没有AT命令本身的值或参数。例如,执行功能处理ATC+SETDEV=12000只会接收120000 。必须检查接收值或参数的有效性,如果格式的值不匹配,则必须返回AT_ERRNO_PARA_VAL 。如果值或参数正确,则该函数应返回0 。
执行功能无参数执行操作,并将操作的成功返回为0如果执行失败,则执行操作,如果成功或AT_ERRNO_EXEC_FAIL失败。
此示例用于在应用程序中设置变量。
/* ******************************************************************* */
// Example AT command to change the value of the variable new_val:
// Query the value AT+SETVAL=?
// Set the value AT+SETVAL=120000
// Second AT command to show last packet content
// Query with AT+LIST=?
/* ******************************************************************* */
int32_t new_val = 3000 ;
/* *
* @brief Returns the current value of the custom variable
*
* @return int always 0
*/
static int at_query_value ()
{
snprintf (g_at_query_buf, ATQUERY_SIZE, " Custom Value: %d " , new_val);
return 0 ;
}
/* *
* @brief Command to set the custom variable
*
* @param str the new value for the variable without the AT part
* @return int 0 if the command was succesfull, 5 if the parameter was wrong
*/
static int at_exec_value ( char *str)
{
new_val = strtol (str, NULL , 0 );
MYLOG ( " APP " , " Value number >>%ld<< " , new_val);
return 0 ;
}
/* *
* @brief Example how to show the last LoRa packet content
*
* @return int always 0
*/
static int at_query_packet ()
{
snprintf (g_at_query_buf, ATQUERY_SIZE, " Packet: %02X%02X%02X%02X " ,
g_lpwan_data. data_flag1 ,
g_lpwan_data. data_flag2 ,
g_lpwan_data. batt_1 ,
g_lpwan_data. batt_2 );
return 0 ;
}
/* *
* @brief List of all available commands with short help and pointer to functions
*
*/
atcmd_t g_user_at_cmd_list_example[] = {
/* | CMD | AT+CMD? | AT+CMD=? | AT+CMD=value | AT+CMD | Permission | */
// GNSS commands
{ " +SETVAL " , " Get/Set custom variable " , at_query_value, at_exec_value, NULL , " RW " },
{ " +LIST " , " Show last packet content " , at_query_packet, NULL , NULL , " R " },
};
atcmd_t *g_user_at_cmd_list = g_user_at_cmd_list_example;
/* * Number of user defined AT commands */
uint8_t g_user_at_cmd_num = sizeof (g_user_at_cmd_list_example) / sizeof ( atcmd_t );这五个示例说明了API的用法。在所有示例中,API回调和其他功能(传感器读数,IRQ处理,GNSS位置服务)都分为自己的草图。
Wisblock-api-V2也已在以下平台项目中使用:
当与RAK4631一起使用时,库中的固件更新已包含在库中。可以使用Nordic NRF工具箱(可用于Android和iOS)或Wisblock Toolbox(我的Android应用程序)来完成RAK4631的固件更新。
有关更新,请从.pio/build/{设备}文件夹中复制创建的更新文件(通常称为controwware.zip),将其复制到您的电话中,并使用其中一个应用程序来更新固件。
如果通过BLE的固件更新失败,请使用版本v0.4.3将设备更新为RAK4631的最新引导加载程序。您可以在Wisblock Repo中找到最新的引导加载程序
API提供了一些呼吁管理,以发送Lorawan数据包,发送ble uart数据并触发事件。
void api_set_version(uint16_t sw_1 = 1, uint16_t sw_2 = 0, uint16_t sw_3 = 0);
可以调用此功能设置应用程序版本。应用程序可以由AT命令请求。版本编号是由三位数字构建的:
sw_1 ==>主要版本增加了API更改 /不向后兼容sw_2 ==>次要版本增加了API更改 /向后兼容sw_3 ==>修补版本在BugFix上增加,对API没有影响
如果未调用api_set_version ,则应用程序版本默认为1.0.0 。
void api_reset(void);
执行重置Wisblock核心模块
void api_wake_loop(uint16_t reason);
这用于用事件唤醒循环。 reason必须在app.h中定义。循环唤醒应用程序后,它将在g_task_event_type中调用具有reason值的app_event_handler() 。
例如,这可以用来从加速度计传感器中断唤醒设备。在这里,作为accelerometer的示例示例示例代码的示例。
在accelerometer.ino中,该事件已定义。第一个定义是设置信号,第二个是在处理事件后清除事件。
/* * Define additional events */
# define ACC_TRIGGER 0b1000000000000000
# define N_ACC_TRIGGER 0b0111111111111111然后在lis3dh_acc.ino中,在中断回调函数中void acc_int_handler(void)用信号ACC_TRIGGER唤醒环路
void acc_int_handler ( void )
{
// Wake up the task to handle it
api_wake_loop (ACC_TRIGGER);
}最后在accelerometer.ino中app_event_handler()
// ACC triggered event
if ((g_task_event_type & ACC_TRIGGER) == ACC_TRIGGER)
{
g_task_event_type &= N_ACC_TRIGGER;
MYLOG ( " APP " , " ACC IRQ wakeup " );
// Reset ACC IRQ register
get_acc_int ();
// Set Status flag, it will trigger sending a packet
g_task_event_type = STATUS;
}void api_log_settings(void);
可以调用此功能以列出USB上Wisblock设备的完整设置。输出看起来像:
Device status:
RAK11310
Auto join enabled
Mode LPWAN
Network joined
Send Frequency 120
LPWAN status:
Dev EUI AC1F09FFFE0142C8
App EUI 70B3D57ED00201E1
App Key 2B84E0B09B68E5CB42176FE753DCEE79
Dev Addr 26021FB4
NWS Key 323D155A000DF335307A16DA0C9DF53F
Apps Key 3F6A66459D5EDCA63CBC4619CD61A11E
OTAA enabled
ADR disabled
Public Network
Dutycycle disabled
Join trials 30
TX Power 0
DR 3
Class 0
Subband 1
Fport 2
Unconfirmed Message
Region AS923-3
LoRa P2P status:
P2P frequency 916000000
P2P TX Power 22
P2P BW 125
P2P SF 7
P2P CR 1
P2P Preamble length 8
P2P Symbol Timeout 0void api_timer_stop(void)
停止经常唤醒MCU的计时器。
void api_timer_restart(uint32_t new_time)
以新值重新启动计时器。价值以毫秒为单位
void api_read_credentials(void);
void api_set_credentials(void);如果需要对Lora P2P设置进行硬编码(例如频率,带宽等),则可以在setup_app()中完成。首先,保存的设置必须使用api_read_credentials(); ,然后可以更改设置。更改设置后,必须使用api_set_credentials()保存。由于Wisblock API检查是否需要保存任何更改,因此更改值仅在刷新应用程序后才保存在第一个引导中。
例子:
// Read credentials from Flash
api_read_credentials ();
// Make changes to the credentials
g_lorawan_settings.p2p_frequency = 916000000 ; // Use 916 MHz to send and receive
g_lorawan_settings.p2p_bandwidth = 0 ; // Bandwidth 125 kHz
g_lorawan_settings.p2p_sf = 7 ; // Spreading Factor 7
g_lorawan_settings.p2p_cr = 1 ; // Coding Rate 4/5
g_lorawan_settings.p2p_preamble_len = 8 ; // Preample Length 8
g_lorawan_settings.p2p_tx_power = 22 ; // TX power 22 dBi
// Save hard coded LoRaWAN settings
api_set_credentials ();备注1
硬编码设置必须在void setup_app(void)中设置!
备注2
请记住,可以通过此方法更改的参数可以在命令或BLE上更改,但重新启动后将重置!
api_ble_printf()可用于通过BLE UART发送数据。支持print , println和printf 。
评论
此命令在RAK11310上不可用!
默认情况下,BLE广告仅在加电/重置后的30秒钟才能降低功耗。通过调用void restart_advertising(uint16_t timeout);广告可以重新启动timeout几秒钟。
评论
此命令在RAK11310上不可用!
lmh_error_status send_lora_packet(uint8_t *data, uint8_t size, uint8_t fport = 0);用于将数据包发送到Lorawan服务器。 *data是指向包含数据的缓冲区的指针, size是数据包的大小。如果FPORT为0,则使用G_LORAWAN_SETTINGS结构中的FPORTDEFED。
bool send_p2p_packet(uint8_t *data, uint8_t size);用于通过Lora P2P发送数据包。 *data是指向包含数据的缓冲区的指针, size是数据包的大小。
在完成TX周期(包括RX1和RX2 Windows)之后,结果保存在全局标志g_rx_fin_result中,事件LORA_TX_FIN被触发,lora_data_handler()调用lora_data_handler()呼叫。在此回调中,可以检查结果,并在必要时采取措施。
Cayennelpp是由MyDevices设计的一种格式,旨在将Lorawan节点集成到其物联网平台中。
Cayennelpp库扩展了可用的数据类型,其中几种IPSO数据类型在Johan Stokking或其他人的大多数叉子和侧面作品的原始作品中未包含,这些其他数据类型不受MyDevices Cayenne的支持。
Wisblock API使用了更多数据类型,这些数据类型可以扩展原始和电子猫的数据类型,以更好地支持广泛的Wisblock传感器模块。
要使用扩展数据类型Wisblock API已经包含所需的标头文件。
为了能够使用Cayenne LPP功能,需要该类的实例。
/* * LoRaWAN packet */
WisCayenne g_solution_data ( 255 );在添加数据之前,需要重置数据包缓冲区
// Reset the packet
g_solution_data.reset();Cayennelpp库的API呼吁支持所支持的不同数据类型。有关详细信息,请参见Cayennelpp API。除了这些API调用外,Wisblock API还向其增加了5个调用。这些API调用适用于不同的GNSS格式和VOC传感器数据:
uint8_t addGNSS_4 ( uint8_t channel, int32_t latitude, int32_t longitude, int32_t altitude);
uint8_t addGNSS_6 ( uint8_t channel, int32_t latitude, int32_t longitude, int32_t altitude);
uint8_t addGNSS_H ( int32_t latitude, int32_t longitude, int16_t altitude, int16_t accuracy, int16_t battery);
uint8_t addGNSS_T ( int32_t latitude, int32_t longitude, int16_t altitude, float accuracy, int8_t sats);
uint8_t addVoc_index ( uint8_t channel, uint32_t voc_index); /* *
* @brief Add GNSS data in Cayenne LPP standard format
*
* @param channel LPP channel
* @param latitude Latitude as read from the GNSS receiver
* @param longitude Longitude as read from the GNSS receiver
* @param altitude Altitude as read from the GNSS receiver
* @return uint8_t bytes added to the data packet
*/
uint8_t WisCayenne::addGNSS_4 ( uint8_t channel, int32_t latitude, int32_t longitude, int32_t altitude) /* *
* @brief Add GNSS data in custom Cayenne LPP format
* Requires changed decoder in LNS and visualization
* Does not work with Cayenne LPP MyDevices
*
* @param channel LPP channel
* @param latitude Latitude as read from the GNSS receiver
* @param longitude Longitude as read from the GNSS receiver
* @param altitude Altitude as read from the GNSS receiver
* @return uint8_t bytes added to the data packet
*/
uint8_t WisCayenne::addGNSS_6 ( uint8_t channel, int32_t latitude, int32_t longitude, int32_t altitude) /* *
* @brief Add GNSS data in Helium Mapper format
*
* @param channel LPP channel
* @param latitude Latitude as read from the GNSS receiver
* @param longitude Longitude as read from the GNSS receiver
* @param altitude Altitude as read from the GNSS receiver
* @param accuracy Accuracy of reading from the GNSS receiver
* @param battery Device battery voltage in V
* @return uint8_t bytes added to the data packet
*/
uint8_t WisCayenne::addGNSS_H ( int32_t latitude, int32_t longitude, int16_t altitude, int16_t accuracy, int16_t battery) /* *
* @brief Add GNSS data in Field Tester format
*
* @param latitude Latitude as read from the GNSS receiver
* @param longitude Longitude as read from the GNSS receiver
* @param altitude Altitude as read from the GNSS receiver
* @param accuracy Accuracy of reading from the GNSS receiver
* @param sats Number of satellites of reading from the GNSS receiver
* @return uint8_t bytes added to the data packet
*/
uint8_t WisCayenne::addGNSS_T ( int32_t latitude, int32_t longitude, int16_t altitude, float accuracy, int8_t sats) /* *
* @brief Add the VOC index
*
* @param channel VOC channel
* @param voc_index VOC index
* @return uint8_t bytes added to the data packet
*/
uint8_t WisCayenne::addVoc_index ( uint8_t channel, uint32_t voc_index)cayennelpp数据包始终为格式<Channel #><Channel ID><data bytes> 。
为了使在Lorawan服务器中使用的数据编码器和Wisblock传感器收集的集成数据中更容易(如果使用这些API)始终具有相同的通道编号。这是当前分配的通道号,通道ID和哪些模块使用该组合的列表。
| 数据 | 渠道 # | 通道ID | 长度 | 评论 | 所需的模块 | 解码字段名称 |
|---|---|---|---|---|---|---|
| 电池价值 | 1 | 116 | 2个字节 | 0.01 V未签名的MSB | RAK4631 | 电压_1 |
| 湿度 | 2 | 104 | 1字节 | 在%rh中 | RAK1901 | 湿度_2 |
| 温度 | 3 | 103 | 2个字节 | 在°C | RAK1901 | 温度_3 |
| 气压 | 4 | 115 | 2个字节 | 在HPA(MBAR)中 | RAK1902 | 气压表_4 |
| 照明 | 5 | 101 | 2个字节 | 1个未签名 | RAK1903 | Illuminance_5 |
| 湿度2 | 6 | 104 | 1字节 | 在%rh中 | RAK1906 | 湿度_6 |
| 温度2 | 7 | 103 | 2个字节 | 在°C | RAK1906 | 温度_7 |
| 气压2 | 8 | 115 | 2个字节 | 在HPA(MBAR)中 | RAK1906 | 气压表_8 |
| 气电2 | 9 | 2 | 2个字节 | 0.01签名(KOHM) | RAK1906 | 模拟_9 |
| GNSS站立。解决 | 10 | 136 | 9个字节 | 3个字节LON/LAT 0.0001°,3个字节ALT 0.01米 | RAK1910,RAK12500 | GPS_10 |
| GNSS增强了分辨率 | 10 | 137 | 11个字节 | 4个字节LON/LAT 0.000001°,3个字节ALT 0.01米 | RAK1910,RAK12500 | GPS_10 |
| 土壤温度 | 11 | 103 | 2个字节 | 在°C | RAK12023/RAK12035 | 温度_11 |
| 土壤湿度 | 12 | 104 | 1字节 | 在%rh中 | RAK12023/RAK12035 | 湿度_12 |
| 土壤湿度生 | 13 | 2 | 2个字节 | 0.01签名 | RAK12023/RAK12035 | 模拟_in_13 |
| 土壤数据有效 | 14 | 102 | 1字节 | 布尔 | RAK12023/RAK12035 | 存在_14 |
| 照明2 | 15 | 101 | 2个字节 | 1个未签名 | RAK12010 | Illuminance_15 |
| VOC | 16 | 138 | 2个字节 | VOC索引 | RAK12047 | VOC_16 |
| MQ2气体 | 17 | 2 | 2个字节 | 0.01签名 | RAK12004 | 模拟_in_17 |
| MQ2气体百分比 | 18 | 120 | 1字节 | 1-100%未签名 | RAK12004 | 百分比_18 |
| MG812气体 | 19 | 2 | 2个字节 | 0.01签名 | RAK12008 | 模拟_in_19 |
| MG812气体百分比 | 20 | 120 | 1字节 | 1-100%未签名 | RAK12008 | 百分比_20 |
| MQ3酒精气 | 21 | 2 | 2个字节 | 0.01签名 | RAK12009 | 模拟_in_21 |
| MQ3酒精气perc。 | 22 | 120 | 1字节 | 1-100%未签名 | RAK12009 | 百分比_22 |
| TOF距离 | 23 | 2 | 2个字节 | 0.01签名 | RAK12014 | 模拟_in_23 |
| TOF数据有效 | 24 | 102 | 1字节 | 布尔 | RAK12014 | 存在_24 |
| 陀螺仪触发 | 25 | 134 | 6个字节 | 每个轴2个字节,0.01°/s | RAK12025 | Gyrometer_25 |
| 检测到手势 | 26 | 0 | 1字节 | 1个字节带有手势的身份证 | RAK14008 | Digital_in_26 |
| LTR390 UVI值 | 27 | 2 | 2个字节 | 0.01签名 | RAK12019 | 模拟_in_27 |
| ltr390紫外线值 | 28 | 101 | 2个字节 | 1个未签名 | RAK12019 | Illuminance_28 |
| ina219电流 | 29 | 2 | 2个字节 | 0.01签名 | RAK16000 | 模拟_29 |
| ina219电压 | 30 | 2 | 2个字节 | 0.01签名 | RAK16000 | 模拟_30 |
| ina219电源 | 31 | 2 | 2个字节 | 0.01签名 | RAK16000 | 模拟_31 |
| 触摸板左 | 32 | 102 | 1字节 | 布尔 | RAK14002 | 存在_32 |
| 触摸板中间 | 33 | 102 | 1字节 | 布尔 | RAK14002 | 存在_33 |
| 触摸板右 | 34 | 102 | 1字节 | 布尔 | RAK14002 | 存在_34 |
| SCD30 CO2浓度 | 35 | 125 | 2个字节 | 1 ppm未签名 | RAK12037 | 浓度_35 |
| SCD30温度 | 36 | 103 | 2个字节 | 在°C | RAK12037 | 温度_36 |
| SCD30湿度 | 37 | 104 | 1字节 | 在%rh中 | RAK12037 | 湿度_37 |
| MLX90632传感器温度 | 38 | 103 | 2个字节 | 在°C | RAK12003 | 温度_38 |
| MLX90632对象温度 | 39 | 103 | 2个字节 | 在°C | RAK12003 | 温度_39 |
| PM 1.0值 | 40 | 103 | 2个字节 | 在UG/M3中 | RAK12003 | VOC_40 |
| PM 2.5值 | 41 | 103 | 2个字节 | 在UG/M3中 | RAK12003 | VOC_41 |
| PM 10值 | 42 | 103 | 2个字节 | 在UG/M3中 | RAK12003 | VOC_42 |
| 地震事件 | 43 | 102 | 1字节 | 布尔 | RAK12027 | 存在_43 |
| 地震Si值 | 44 | 2 | 2个字节 | 模拟10 * m/s | RAK12027 | 模拟_44 |
| 地震PGA值 | 45 | 2 | 2个字节 | 模拟10 * m/s2 | RAK12027 | 模拟_45 |
| 地震关闭警报 | 46 | 102 | 1字节 | 布尔 | RAK12027 | 存在_46 |
| lpp_channel_eq_collapse | 47 | 102 | 1字节 | 布尔 | RAK12027 | 存在_47 |
| 切换状态 | 48 | 102 | 1字节 | 布尔 | RAK13011 | 存在_48 |
草书中的通道ID是扩展格式,并且不受标准Cayenne LPP数据解码器的支持。
可以在我们的rakwireless_standardized_payload中找到完整的已使用数据格式列表
rakwireless_standardized_payload存储库还包括匹配的解码器。
这里使用的代码是API-TEST.ino示例。
这些是用户应用程序和API接口的必需品和定义
在此示例中,我们对Lorawan证书进行了核对。强烈建议不要这样做以避免重复的节点凭据
设置凭据的替代选项是
# include < Arduino.h >
/* * Add you required includes after Arduino.h */
# include < Wire.h >
// Debug output set to 0 to disable app debug output
# ifndef MY_DEBUG
# define MY_DEBUG 1
# endif
# ifdef NRF52_SERIES
# if MY_DEBUG > 0
# define MYLOG (tag, ...)
do
{
if (tag)
PRINTF ( " [%s] " , tag);
PRINTF (__VA_ARGS__);
PRINTF ( " n " );
if (g_ble_uart_is_connected)
{
g_ble_uart. printf (__VA_ARGS__);
g_ble_uart. printf ( " n " );
}
} while ( 0 )
# else
# define MYLOG (...)
# endif
# endif
# ifdef ARDUINO_ARCH_RP2040
# if MY_DEBUG > 0
# define MYLOG (tag, ...)
do
{
if (tag)
Serial. printf ( " [%s] " , tag);
Serial. printf (__VA_ARGS__);
Serial. printf ( " n " );
} while ( 0 )
# else
# define MYLOG (...)
# endif
# endif
/* * Include the WisBlock-API-V2 */
# include < WisBlock-API-V2.h > // Click to install library: http://librarymanager/All#WisBlock-API-V2
/* * Define the version of your SW */
# define SW_VERSION_1 1 // major version increase on API change / not backwards compatible
# define SW_VERSION_2 0 // minor version increase on API change / backward compatible
# define SW_VERSION_3 0 // patch version increase on bugfix, no affect on API
/* *
Optional hard-coded LoRaWAN credentials for OTAA and ABP.
It is strongly recommended to avoid duplicated node credentials
Options to setup credentials are
- over USB with AT commands
- over BLE with My nRF52 Toolbox
*/
uint8_t node_device_eui[ 8 ] = { 0x00 , 0x0D , 0x75 , 0xE6 , 0x56 , 0x4D , 0xC1 , 0xF3 };
uint8_t node_app_eui[ 8 ] = { 0x70 , 0xB3 , 0xD5 , 0x7E , 0xD0 , 0x02 , 0x01 , 0xE1 };
uint8_t node_app_key[ 16 ] = { 0x2B , 0x84 , 0xE0 , 0xB0 , 0x9B , 0x68 , 0xE5 , 0xCB , 0x42 , 0x17 , 0x6F , 0xE7 , 0x53 , 0xDC , 0xEE , 0x79 };
uint8_t node_nws_key[ 16 ] = { 0x32 , 0x3D , 0x15 , 0x5A , 0x00 , 0x0D , 0xF3 , 0x35 , 0x30 , 0x7A , 0x16 , 0xDA , 0x0C , 0x9D , 0xF5 , 0x3F };
uint8_t node_apps_key[ 16 ] = { 0x3F , 0x6A , 0x66 , 0x45 , 0x9D , 0x5E , 0xDC , 0xA6 , 0x3C , 0xBC , 0x46 , 0x19 , 0xCD , 0x61 , 0xA1 , 0x1E };某些功能的正向声明(使用Platformio时需要)
/* * Application function definitions */
void setup_app ( void );
bool init_app ( void );
void app_event_handler ( void );
void ble_data_handler ( void ) __attribute__((weak));
void lora_data_handler ( void );在这里,应用程序名称设置为RAK检验。该名称将使用NRF52唯一的芯片ID扩展。此名称用于BLE广告中。
/* * Application stuff */
/* * Set the device name, max length is 10 characters */
char g_ble_dev_name[ 10 ] = " RAK-TEST " ;需要一些标志和信号
/* * Flag showing if TX cycle is ongoing */
bool lora_busy = false ;
/* * Send Fail counter * */
uint8_t send_fail = 0 ;该功能在应用程序启动的一开始。在此函数中,应设置所有在执行Arduino setup()之前所需的一切。例如,这可能是Lorawan的凭证。在此示例中,我们对Lorawan证书进行了核对。强烈建议不要这样做以避免重复的节点凭据
设置凭据的替代选项是
g_enable_ble 。如果为true,则将BLE接口初始化。如果是错误的,则不会激活BLE界面,从而降低功耗。 void setup_app ( void )
{
Serial. begin ( 115200 );
time_t serial_timeout = millis ();
// On nRF52840 the USB serial is not available immediately
while (!Serial)
{
if (( millis () - serial_timeout) < 5000 )
{
delay ( 100 );
digitalWrite (LED_GREEN, ! digitalRead (LED_GREEN));
}
else
{
break ;
}
}
digitalWrite (LED_GREEN, LOW);
MYLOG ( " APP " , " Setup WisBlock API Example " );
# ifdef NRF52_SERIES
// Enable BLE
g_enable_ble = true ;
# endif
// Set firmware version
api_set_version (SW_VERSION_1, SW_VERSION_2, SW_VERSION_3);
// Optional
// Setup LoRaWAN credentials hard coded
// It is strongly recommended to avoid duplicated node credentials
// Options to setup credentials are
// -over USB with AT commands
// -over BLE with My nRF52 Toolbox
// Read LoRaWAN settings from flash
api_read_credentials ();
// Change LoRaWAN settings
g_lorawan_settings. auto_join = true ; // Flag if node joins automatically after reboot
g_lorawan_settings. otaa_enabled = true ; // Flag for OTAA or ABP
memcpy (g_lorawan_settings. node_device_eui , node_device_eui, 8 ); // OTAA Device EUI MSB
memcpy (g_lorawan_settings. node_app_eui , node_app_eui, 8 ); // OTAA Application EUI MSB
memcpy (g_lorawan_settings. node_app_key , node_app_key, 16 ); // OTAA Application Key MSB
memcpy (g_lorawan_settings. node_nws_key , node_nws_key, 16 ); // ABP Network Session Key MSB
memcpy (g_lorawan_settings. node_apps_key , node_apps_key, 16 ); // ABP Application Session key MSB
g_lorawan_settings. node_dev_addr = 0x26021FB4 ; // ABP Device Address MSB
g_lorawan_settings. send_repeat_time = 120000 ; // Send repeat time in milliseconds: 2 * 60 * 1000 => 2 minutes
g_lorawan_settings. adr_enabled = false ; // Flag for ADR on or off
g_lorawan_settings. public_network = true ; // Flag for public or private network
g_lorawan_settings. duty_cycle_enabled = false ; // Flag to enable duty cycle (validity depends on Region)
g_lorawan_settings. join_trials = 5 ; // Number of join retries
g_lorawan_settings. tx_power = 0 ; // TX power 0 .. 15 (validity depends on Region)
g_lorawan_settings. data_rate = 3 ; // Data rate 0 .. 15 (validity depends on Region)
g_lorawan_settings. lora_class = 0 ; // LoRaWAN class 0: A, 2: C, 1: B is not supported
g_lorawan_settings. subband_channels = 1 ; // Subband channel selection 1 .. 9
g_lorawan_settings. app_port = 2 ; // Data port to send data
g_lorawan_settings. confirmed_msg_enabled = LMH_UNCONFIRMED_MSG; // Flag to enable confirmed messages
g_lorawan_settings. resetRequest = true ; // Command from BLE to reset device
g_lorawan_settings. lora_region = LORAMAC_REGION_AS923_3; // LoRa region
// Save LoRaWAN settings
api_set_credentials ();BLE和LORA已经初始化后调用此功能。理想情况下,这是初始化应用程序特定内容(例如传感器或执行器)的地方。在此示例中,它没有使用
/* *
* @brief Application specific initializations
*
* @return true Initialization success
* @return false Initialization failure
*/
bool init_app ( void )
{
MYLOG ( " APP " , " init_app " );
return true ;
}该回调是在状态事件上调用的。状态事件经常触发,时间是由send_repeat_time设置的。用户定义的事件也触发了它。请参阅示例RAK1904_example _如何定义用户定义的事件。 _重要的是要重置事件标志。例如,通过此代码序列重置状态事件:
if ((g_task_event_type & STATUS) == STATUS)
{
g_task_event_type &= N_STATUS;
...
}状态事件用于经常将上行链路数据包发送到Lorawan服务器。
在此示例代码中,我们还重新启动了BLE广告15秒钟。否则,BLE副词仅在加电/重置后活跃30秒。
void app_event_handler ( void )
{
// Timer triggered event
if ((g_task_event_type & STATUS) == STATUS)
{
g_task_event_type &= N_STATUS;
MYLOG ( " APP " , " Timer wakeup " );
# ifdef NRF52_SERIES
// If BLE is enabled, restart Advertising
if (g_enable_ble)
{
restart_advertising ( 15 );
}
# endif
if (lora_busy)
{
MYLOG ( " APP " , " LoRaWAN TX cycle not finished, skip this event " );
}
else
{
// Dummy packet
uint8_t dummy_packet[] = { 0x10 , 0x00 , 0x00 };
lmh_error_status result = send_lora_packet (dummy_packet, 3 );
switch (result)
{
case LMH_SUCCESS:
MYLOG ( " APP " , " Packet enqueued " );
// Set a flag that TX cycle is running
lora_busy = true ;
break ;
case LMH_BUSY:
MYLOG ( " APP " , " LoRa transceiver is busy " );
break ;
case LMH_ERROR:
MYLOG ( " APP " , " Packet error, too big to send with current DR " );
break ;
}
}
}
}此回调用于处理通过BLE UART收到的数据。如果您不需要BLE UART功能,则可以完全删除此功能。在此示例中,我们将收到的uart数据转发到AT命令解释器。这样,我们可以在USB端口或BLE UART端口上方提交命令。
BLE通信仅在RAK4631上支持。 RAK11310没有BLE。
# ifdef NRF52_SERIES
void ble_data_handler ( void )
{
if (g_enable_ble)
{
/* ************************************************************ */
/* ************************************************************ */
// / todo BLE UART data arrived
// / todo or forward them to the AT command interpreter
// / todo parse them here
/* ************************************************************ */
/* ************************************************************ */
if ((g_task_event_type & BLE_DATA) == BLE_DATA)
{
MYLOG ( " AT " , " RECEIVED BLE " );
// BLE UART data arrived
// in this example we forward it to the AT command interpreter
g_task_event_type &= N_BLE_DATA;
while (g_ble_uart. available () > 0 )
{
at_serial_input ( uint8_t (g_ble_uart. read ()));
delay ( 5 );
}
at_serial_input ( uint8_t ( ' n ' ));
}
}
}
# endif 该回调在三个不同的事件中被调用:
如果已到达Lorawan服务器或Lora P2P数据包的下行链路数据包,则会触发事件Lora_data 。在此示例中,我们不是在解析数据,而仅将它们打印到日志上,并通过BLE UART(如果连接设备已连接)
在发送上行链路数据包完成后,包括RX1和RX2 Windows,将触发事件lora_tx_fin 。如果发送确认的数据包,则全局标志g_rx_fin_result包含已确认传输的结果。如果g_rx_fin_result为TRUE,则Lorawan服务器通过发送ACK来确认上行链路数据包。否则, g_rx_fin_result设置为false,表明该数据包未由Lorawan服务器接收到该数据包(范围内没有网关,数据包在空中损坏。如果发送未确认的数据包,或者使用Lora P2P模式,则使用flag g_rx_fin_result是正确的。
在加入请求/加入Accept/拒绝周期完成后,将调用事件Lora_join_fin 。全局标志g_task_event_type包含加入请求的结果。如果是真的,节点已加入网络。如果false连接没有成功。在这种情况下,连接周期可以重新启动,或者节点可能会报告错误。
void lora_data_handler ( void )
{
// LoRa data handling
if ((g_task_event_type & LORA_DATA) == LORA_DATA)
{
/* ************************************************************ */
/* ************************************************************ */
// / todo LoRa data arrived
// / todo parse them here
/* ************************************************************ */
/* ************************************************************ */
g_task_event_type &= N_LORA_DATA;
MYLOG ( " APP " , " Received package over LoRa " );
char log_buff[g_rx_data_len * 3 ] = { 0 };
uint8_t log_idx = 0 ;
for ( int idx = 0 ; idx < g_rx_data_len; idx++)
{
sprintf (&log_buff[log_idx], " %02X " , g_rx_lora_data[idx]);
log_idx += 3 ;
}
lora_busy = false ;
MYLOG ( " APP " , " %s " , log_buff);
}
// LoRa TX finished handling
if ((g_task_event_type & LORA_TX_FIN) == LORA_TX_FIN)
{
g_task_event_type &= N_LORA_TX_FIN;
MYLOG ( " APP " , " LPWAN TX cycle %s " , g_rx_fin_result ? " finished ACK " : " failed NAK " );
if (!g_rx_fin_result)
{
// Increase fail send counter
send_fail++;
if (send_fail == 10 )
{
// Too many failed sendings, reset node and try to rejoin
delay ( 100 );
sd_nvic_SystemReset ();
}
}
// Clear the LoRa TX flag
lora_busy = false ;
}
// LoRa Join finished handling
if ((g_task_event_type & LORA_JOIN_FIN) == LORA_JOIN_FIN)
{
g_task_event_type &= N_LORA_JOIN_FIN;
if (g_join_result)
{
MYLOG ( " APP " , " Successfully joined network " );
}
else
{
MYLOG ( " APP " , " Join network failed " );
// / todo here join could be restarted.
// lmh_join();
}
}
}在Arduino中,不可能在.ino文件中定义可以控制随附库的行为的设置。要更改蓝色BLE LED的调试日志和使用情况,您必须在库源文件夹中打开文件WisBlock-API-V2.h 。
要启用/禁用API调试( API_LOG() )在库源文件夹中打开文件WisBlock-API-V2.h 。
寻找
# define API_DEBUG 1在文件中。
0 -> No debug output
1 -> API debug output
要在示例中启用/禁用应用程序调试( MY_LOG() )(在.ino文件或app.h中)
# define MY_DEBUG 1在文件中。
0 -> No debug output
1 -> Application debug output
寻找
# define NO_BLE_LED 1在文件中WisBlock-API-V2中
0 -> the blue LED will be used to indicate BLE status
1 -> the blue LED will not used
评论
RAK11310没有BLE,可以将蓝色LED用于其他目的。
调试输出可以通过platform.ini API_DEBUG控制Wisblock API的调试输出来控制。
0 -> No debug outpuy
1 -> WisBlock API debug output
MY_DEBUG控制应用程序本身的调试输出
0 -> No debug outpuy
1 -> Application debug output
NO_BLE_LED控制蓝色BLE LED的使用。
0 -> the blue LED will be used to indicate BLE status
1 -> the blue LED will not used
没有调试输出的示例,没有蓝色LED
build_flags =
- DAPI_DEBUG =0 ; 0 Disable WisBlock API debug output
- DMY_DEBUG =0 ; 0 Disable application debug output
- DNO_BLE_LED =1 ; 1 Disable blue LED as BLE notificator根据MIT许可发布的图书馆
学分:
在命令功能:泰勒·李([email protected])
代码发布
api_read_credentials()api_set_credentials()保存到flashWisBlock API LoRaWAN而不是GNSS