Skip to content

Commit

Permalink
samples: drivers: Add LoRa receiver sample
Browse files Browse the repository at this point in the history
Add sample application for receiving data packets over LoRa.

Signed-off-by: Manivannan Sadhasivam <[email protected]>
  • Loading branch information
Mani-Sadhasivam authored and carlescufi committed Dec 21, 2019
1 parent 72f5806 commit e43fdb0
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
9 changes: 9 additions & 0 deletions samples/drivers/lora/receive/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
1 change: 1 addition & 0 deletions samples/drivers/lora/receive/boards/96b_wistrio.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_SPI_1=y
7 changes: 7 additions & 0 deletions samples/drivers/lora/receive/prj.conf
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions samples/drivers/lora/receive/sample.yaml
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions samples/drivers/lora/receive/src/main.c
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit e43fdb0

Please sign in to comment.