Skip to content

Commit dfa3994

Browse files
samples: drivers: Add LoRa receiver sample
Add sample application for receiving data packets over LoRa. Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
1 parent 0b02983 commit dfa3994

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
5+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
6+
project(lora_receive)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_SPI_1=y
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CONFIG_LOG=y
2+
CONFIG_SPI=y
3+
CONFIG_GPIO=y
4+
CONFIG_LORA=y
5+
CONFIG_LORA_SX1276=y
6+
CONFIG_PRINTK=y
7+
CONFIG_COUNTER=y
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
common:
2+
tags: lora
3+
sample:
4+
description: Demonstration of LoRa Receive functionality
5+
name: LoRa Receive Sample
6+
tests:
7+
sample.driver.lora.receive:
8+
platform_whitelist: 96b_wistrio
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2019 Manivannan Sadhasivam
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <device.h>
8+
#include <drivers/lora.h>
9+
#include <errno.h>
10+
#include <sys/util.h>
11+
#include <zephyr.h>
12+
13+
#define MAX_DATA_LEN 255
14+
15+
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
16+
#include <logging/log.h>
17+
LOG_MODULE_REGISTER(lora_receive);
18+
19+
void main(void)
20+
{
21+
struct device *lora_dev;
22+
struct lora_modem_config config;
23+
int ret, len;
24+
u8_t data[MAX_DATA_LEN] = {0};
25+
26+
lora_dev = device_get_binding(DT_INST_0_SEMTECH_SX1276_LABEL);
27+
if (!lora_dev) {
28+
LOG_ERR("%s Device not found", DT_INST_0_SEMTECH_SX1276_LABEL);
29+
return;
30+
}
31+
32+
config.frequency = 865100000;
33+
config.bandwidth = BW_125_KHZ;
34+
config.datarate = SF_10;
35+
config.preamble_len = 8;
36+
config.coding_rate = CR_4_5;
37+
config.tx_power = 14;
38+
config.tx = false;
39+
40+
ret = lora_config(lora_dev, &config);
41+
if (ret < 0) {
42+
LOG_ERR("LoRa config failed");
43+
return;
44+
}
45+
46+
while (1) {
47+
/* Block until data arrives */
48+
len = lora_recv(lora_dev, data, MAX_DATA_LEN, K_FOREVER);
49+
if (len < 0) {
50+
LOG_ERR("LoRa receive failed");
51+
return;
52+
}
53+
54+
LOG_INF("Received data: %s", log_strdup(data));
55+
}
56+
}

0 commit comments

Comments
 (0)