forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: drivers: Add LoRa receiver sample
Add sample application for receiving data packets over LoRa. Signed-off-by: Manivannan Sadhasivam <[email protected]>
- Loading branch information
1 parent
72f5806
commit e43fdb0
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_SPI_1=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |