summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-03-10 18:16:23 +0100
committerxengineering <me@xengineering.eu>2024-03-10 18:24:41 +0100
commitafa66ca4430deecb98a1283233fd95d4f21dce6c (patch)
treeab6f58388501c80ac0aedfef63721b0add1a9e09
parent37e36090d102be2e8f52e5ab43509e40b2e5754e (diff)
downloadradio-gateway-main.tar
radio-gateway-main.tar.zst
radio-gateway-main.zip
Implement LoRa RX to log outputHEADmain
This is the first step towards a minimal viable product. While sending is not possible all received frames are logged.
-rw-r--r--CMakeLists.txt5
-rw-r--r--prj.conf5
-rw-r--r--src/main.c53
3 files changed, 63 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..99d7134
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 3.20.0)
+find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
+project(radio-gateway)
+
+target_sources(app PRIVATE src/main.c)
diff --git a/prj.conf b/prj.conf
new file mode 100644
index 0000000..833146f
--- /dev/null
+++ b/prj.conf
@@ -0,0 +1,5 @@
+CONFIG_LOG=y
+CONFIG_SPI=y
+CONFIG_GPIO=y
+CONFIG_LORA=y
+CONFIG_SHELL=y
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..511f9f4
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,53 @@
+#include <zephyr/device.h>
+#include <zephyr/drivers/lora.h>
+#include <zephyr/kernel.h>
+#include <zephyr/sys/util.h>
+
+#define DEFAULT_RADIO_NODE DT_ALIAS(lora0)
+BUILD_ASSERT(DT_NODE_HAS_STATUS(DEFAULT_RADIO_NODE, okay),
+ "Board has no LoRa modem");
+
+#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
+#include <zephyr/logging/log.h>
+LOG_MODULE_REGISTER(lora);
+
+void lora_rx_cb(const struct device *dev, uint8_t *data, uint16_t size,
+ int16_t rssi, int8_t snr)
+{
+ ARG_UNUSED(dev);
+ ARG_UNUSED(size);
+
+ LOG_INF("rx: %s (RSSI: %d dBm, SNR: %d dBm)", data, rssi, snr);
+}
+
+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 = 433175000;
+ 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 = 14;
+ config.tx = false;
+
+ ret = lora_config(lora_dev, &config);
+ if (ret < 0) {
+ LOG_ERR("LoRa config failed");
+ return 0;
+ }
+
+ lora_recv_async(lora_dev, lora_rx_cb);
+ k_sleep(K_FOREVER);
+ return 0;
+}