基于Raspberry Pi Pico+SX1262实现LoRaWAN Class C的技术问询
问题描述
- 硬件配置:Raspberry Pi Pico 搭配 SX1262 LoRa扩展板
- 当前状态:已基于Waveshare的Class A OTAA示例代码实现定时发送功能,且在TTN(欧洲频段863-870MHz,LoRaWAN 1.0.2)完成Class A设备注册
- 需求:升级为同时支持定时发送与持续接收,根据LoRaWAN规范需采用Class C模式(除发送时段外,始终保持接收窗口打开)
- 问题:已在TTN注册时切换为Class C设备,但修改原Class A代码后,仅能实现类似Class B的延长接收窗口效果,无法达到Class C的持续监听要求
- 疑问:
- 如何通过代码实现真正的Class C模式?有没有可用的Class C参考代码?
- TTN的Class C设备注册流程是否正确?
现有参考代码
#include <stdio.h> #include <string.h> #include "pico/stdlib.h" #include "pico/lorawan.h" #include "tusb.h" // Edit with LoRaWAN Node Region and OTAA settings #include "config.h" // Pin configuration for SX1276 radio module const struct lorawan_sx1276_settings sx1276_settings = { .spi = { .inst = PICO_DEFAULT_SPI_INSTANCE, .mosi = PICO_DEFAULT_SPI_TX_PIN, .miso = PICO_DEFAULT_SPI_RX_PIN, .sck = PICO_DEFAULT_SPI_SCK_PIN, .nss = 8 }, .reset = 9, .dio0 = 7, .dio1 = 10 }; // OTAA settings const struct lorawan_otaa_settings otaa_settings = { .device_eui = LORAWAN_DEVICE_EUI, .app_eui = LORAWAN_APP_EUI, .app_key = LORAWAN_APP_KEY, .channel_mask = LORAWAN_CHANNEL_MASK }; // Variables for receiving data int receive_length = 0; uint8_t receive_buffer[242]; uint8_t receive_port = 0; int main( void ) { // Initialize stdio and wait for USB CDC connect stdio_init_all(); while (!tud_cdc_connected()) { tight_loop_contents(); } printf("Pico LoRaWAN - Hello OTAA\n\n"); // Uncomment the following line to enable debugging // lorawan_debug(true); // Initialize the LoRaWAN stack printf("Initilizating LoRaWAN ... "); if (lorawan_init_otaa(&sx1276_settings, LORAWAN_REGION, &otaa_settings) < 0) { printf("failed!!!\n"); while (1) { tight_loop_contents(); } } else { printf("success!\n"); } // Start the join process and wait printf("Joining LoRaWAN network ... "); lorawan_join(); while (!lorawan_is_joined()) { lorawan_process(); } printf("joined successfully!\n"); uint32_t last_message_time = 0; // Loop forever while (1) { // Let the LoRaWAN library process pending events lorawan_process(); // Get the current time and see if 5 seconds have passed // since the last message was sent uint32_t now = to_ms_since_boot(get_absolute_time()); if ((now - last_message_time) > 5000) { const char* message = "hello world!"; // Try to send an unconfirmed uplink message printf("sending unconfirmed message '%s' ... ", message); if (lorawan_send_unconfirmed(message, strlen(message), 2) < 0) { printf("failed!!!\n"); } else { printf("success!\n"); } last_message_time = now; } // Check if a downlink message was received receive_length = lorawan_receive(receive_buffer, sizeof(receive_buffer), &receive_port); if (receive_length > -1) { printf("received a %d byte message on port %d: ", receive_length, receive_port); for (int i = 0; i < receive_length; i++) { printf("%02x", receive_buffer[i]); } printf("\n"); } } return 0; }
内容的提问来源于stack exchange,提问作者frabbit
相关产品推荐
相关产品推荐

