1 /*
2 * Copyright (c) 2019 Manivannan Sadhasivam
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/device.h>
8 #include <zephyr/drivers/lora.h>
9 #include <errno.h>
10 #include <zephyr/sys/util.h>
11 #include <zephyr/kernel.h>
12
13 #define DEFAULT_RADIO_NODE DT_ALIAS(lora0)
14 BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DEFAULT_RADIO_NODE),
15 "No default LoRa radio specified in DT");
16
17 #define MAX_DATA_LEN 10
18
19 #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
20 #include <zephyr/logging/log.h>
21 LOG_MODULE_REGISTER(lora_send);
22
23 char data[MAX_DATA_LEN] = {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'};
24
main(void)25 int main(void)
26 {
27 const struct device *const lora_dev = DEVICE_DT_GET(DEFAULT_RADIO_NODE);
28 struct lora_modem_config config;
29 int ret;
30
31 if (!device_is_ready(lora_dev)) {
32 LOG_ERR("%s Device not ready", lora_dev->name);
33 return 0;
34 }
35
36 config.frequency = 865100000;
37 config.bandwidth = BW_125_KHZ;
38 config.datarate = SF_10;
39 config.preamble_len = 8;
40 config.coding_rate = CR_4_5;
41 config.iq_inverted = false;
42 config.public_network = false;
43 config.tx_power = 4;
44 config.tx = true;
45
46 ret = lora_config(lora_dev, &config);
47 if (ret < 0) {
48 LOG_ERR("LoRa config failed");
49 return 0;
50 }
51
52 while (1) {
53 ret = lora_send(lora_dev, data, MAX_DATA_LEN);
54 if (ret < 0) {
55 LOG_ERR("LoRa send failed");
56 return 0;
57 }
58
59 LOG_INF("Data sent!");
60
61 /* Send data at 1s interval */
62 k_sleep(K_MSEC(1000));
63 }
64 return 0;
65 }
66