| /* |
| * Copyright (c) 2019 Manivannan Sadhasivam |
| * |
| * SPDX-License-Identifier: Apache-2.0 |
| */ |
| |
| #include <zephyr/device.h> |
| #include <zephyr/drivers/lora.h> |
| #include <errno.h> |
| #include <zephyr/sys/util.h> |
| #include <zephyr/kernel.h> |
| |
| #define DEFAULT_RADIO_NODE DT_ALIAS(lora0) |
| BUILD_ASSERT(DT_NODE_HAS_STATUS(DEFAULT_RADIO_NODE, okay), |
| "No default LoRa radio specified in DT"); |
| |
| #define MAX_DATA_LEN 10 |
| |
| #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL |
| #include <zephyr/logging/log.h> |
| LOG_MODULE_REGISTER(lora_send); |
| |
| char data[MAX_DATA_LEN] = {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'}; |
| |
| int main(void) |
| { |
| const struct device *const lora_dev = DEVICE_DT_GET(DEFAULT_RADIO_NODE); |
| struct lora_modem_config config; |
| int ret; |
| |
| if (!device_is_ready(lora_dev)) { |
| LOG_ERR("%s Device not ready", lora_dev->name); |
| return 0; |
| } |
| |
| config.frequency = 865100000; |
| config.bandwidth = BW_125_KHZ; |
| config.datarate = SF_10; |
| config.preamble_len = 8; |
| config.coding_rate = CR_4_5; |
| config.iq_inverted = false; |
| config.public_network = false; |
| config.tx_power = 4; |
| config.tx = true; |
| |
| ret = lora_config(lora_dev, &config); |
| if (ret < 0) { |
| LOG_ERR("LoRa config failed"); |
| return 0; |
| } |
| |
| while (1) { |
| ret = lora_send(lora_dev, data, MAX_DATA_LEN); |
| if (ret < 0) { |
| LOG_ERR("LoRa send failed"); |
| return 0; |
| } |
| |
| LOG_INF("Data sent!"); |
| |
| /* Send data at 1s interval */ |
| k_sleep(K_MSEC(1000)); |
| } |
| return 0; |
| } |