samples: drivers: Add LoRa receiver sample

Add sample application for receiving data packets over LoRa.

Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
This commit is contained in:
Manivannan Sadhasivam 2019-07-21 01:50:59 +05:30 committed by Carles Cufí
parent 72f5806cec
commit e43fdb0428
5 changed files with 81 additions and 0 deletions

View file

@ -0,0 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(lora_receive)
FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

View file

@ -0,0 +1 @@
CONFIG_SPI_1=y

View file

@ -0,0 +1,7 @@
CONFIG_LOG=y
CONFIG_SPI=y
CONFIG_GPIO=y
CONFIG_LORA=y
CONFIG_LORA_SX1276=y
CONFIG_PRINTK=y
CONFIG_COUNTER=y

View file

@ -0,0 +1,8 @@
common:
tags: lora
sample:
description: Demonstration of LoRa Receive functionality
name: LoRa Receive Sample
tests:
sample.driver.lora.receive:
platform_whitelist: 96b_wistrio

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2019 Manivannan Sadhasivam
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <device.h>
#include <drivers/lora.h>
#include <errno.h>
#include <sys/util.h>
#include <zephyr.h>
#define MAX_DATA_LEN 255
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(lora_receive);
void main(void)
{
struct device *lora_dev;
struct lora_modem_config config;
int ret, len;
u8_t data[MAX_DATA_LEN] = {0};
lora_dev = device_get_binding(DT_INST_0_SEMTECH_SX1276_LABEL);
if (!lora_dev) {
LOG_ERR("%s Device not found", DT_INST_0_SEMTECH_SX1276_LABEL);
return;
}
config.frequency = 865100000;
config.bandwidth = BW_125_KHZ;
config.datarate = SF_10;
config.preamble_len = 8;
config.coding_rate = CR_4_5;
config.tx_power = 14;
config.tx = false;
ret = lora_config(lora_dev, &config);
if (ret < 0) {
LOG_ERR("LoRa config failed");
return;
}
while (1) {
/* Block until data arrives */
len = lora_recv(lora_dev, data, MAX_DATA_LEN, K_FOREVER);
if (len < 0) {
LOG_ERR("LoRa receive failed");
return;
}
LOG_INF("Received data: %s", log_strdup(data));
}
}