-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lora: Initial support for sensor example
Signed-off-by: Alistair Francis <alistair@alistair23.me>
- Loading branch information
1 parent
7f29208
commit 4f7f9ea
Showing
7 changed files
with
199 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
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,25 @@ | ||
LoRa | ||
==== | ||
|
||
LoRa (Long Range) is a radio communication technique that uses | ||
spread spectrum modulation technique derived from chirp spread | ||
spectrum (CSS) technology. | ||
|
||
LoRa provides a number of properties including: | ||
|
||
* long range, can cover tens of kilometres | ||
* low power, devices can run for years | ||
* reasonably secure | ||
* standardised | ||
* relativity cheap | ||
|
||
This directory contains a range of examples using | ||
[RadioLib](https://github.com/jgromes/RadioLib) to | ||
support LoRa on Tock. | ||
|
||
Before the examples will work you first need to build | ||
RadioLib. | ||
|
||
```shell | ||
$ build-RadioLib.sh | ||
``` |
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,22 @@ | ||
#!/bin/bash | ||
|
||
pushd RadioLib/examples/NonArduino/Tock/ | ||
|
||
rm -rf build | ||
|
||
# Change the source to point to the current libtock-c directory | ||
sed -i 's|${CMAKE_CURRENT_SOURCE_DIR}/libtock-c|../../../../../../../|g' CMakeLists.txt | ||
sed -i 's|target_include_directories(${PROJECT_NAME} PUBLIC|target_include_directories(\${PROJECT_NAME}\n PUBLIC ../../../../../../|g' CMakeLists.txt | ||
|
||
mkdir -p build | ||
cd build | ||
|
||
cmake -G "CodeBlocks - Unix Makefiles" .. | ||
|
||
# Build the Tock example application | ||
# This will fail to link, as it can't find the libtock-c libraries | ||
# That's fine for us though, as we just need to build the RadioLib | ||
# library, not the entire example application | ||
make -j4 2> /dev/null | ||
|
||
popd |
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,26 @@ | ||
# Makefile for user application | ||
|
||
# Specify this directory relative to the current application. | ||
TOCK_USERLAND_BASE_DIR = ../../../ | ||
|
||
# Which files to compile. | ||
CXX_SRCS := $(wildcard *.cc) | ||
|
||
# Include the core RadioLib headers | ||
override CPPFLAGS += -I../RadioLib/src | ||
|
||
# Include the Tock specific headers | ||
override CPPFLAGS += -I../RadioLib/examples/NonArduino/Tock | ||
|
||
# Include the base of libtock-c to fix the libtock/ includes from RadioLib | ||
override CPPFLAGS += -I$(TOCK_USERLAND_BASE_DIR)/ | ||
|
||
override LEGACY_LIBS_cortex-m += ../RadioLib/examples/NonArduino/Tock/build/RadioLib/libRadioLib.a | ||
override LEGACY_LIBS_cortex-m0 += ../RadioLib/examples/NonArduino/Tock/build/RadioLib/libRadioLib.a | ||
override LEGACY_LIBS_cortex-m3 += ../RadioLib/examples/NonArduino/Tock/build/RadioLib/libRadioLib.a | ||
override LEGACY_LIBS_cortex-m4 += ../RadioLib/examples/NonArduino/Tock/build/RadioLib/libRadioLib.a | ||
override LEGACY_LIBS_cortex-m7 += ../RadioLib/examples/NonArduino/Tock/build/RadioLib/libRadioLib.a | ||
|
||
# Include userland master makefile. Contains rules and flags for actually | ||
# building the application. | ||
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk |
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,16 @@ | ||
Sensor Transmitter | ||
================== | ||
|
||
This example builds an application that can either transmit sensor data | ||
or receive sensor data, depending on the state of the `SEND` macro in | ||
`main.cc`. | ||
|
||
Before the examples will work you first need to build | ||
RadioLib. | ||
|
||
```shell | ||
cd ../ | ||
$ build-RadioLib.sh | ||
cd sensor-transmit | ||
make | ||
``` |
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,106 @@ | ||
/* | ||
RadioLib Non-Arduino Tock Library test application | ||
Licensed under the MIT or Apache License | ||
Copyright (c) 2023 Alistair Francis <alistair@alistair23.me> | ||
*/ | ||
|
||
// include the library | ||
#include <RadioLib.h> | ||
|
||
// include the hardware abstraction layer | ||
#include "libtockHal.h" | ||
|
||
// Include some libtock-c helpers | ||
#include <temperature.h> | ||
#include <humidity.h> | ||
|
||
#define BUFFER_LEN 64 | ||
|
||
// Define if we should send or receieve data | ||
#define SEND | ||
|
||
// the entry point for the program | ||
int main(void) { | ||
char buffer[BUFFER_LEN]; | ||
|
||
printf("[SX1261] Initialising Radio ... \n"); | ||
|
||
// create a new instance of the HAL class | ||
TockHal* hal = new TockHal(); | ||
|
||
// now we can create the radio module | ||
// pinout corresponds to the SparkFun LoRa Thing Plus - expLoRaBLE | ||
// NSS pin: 0 | ||
// DIO1 pin: 2 | ||
// NRST pin: 4 | ||
// BUSY pin: 1 | ||
Module* tock_module = new Module(hal, RADIO_NSS, RADIO_DIO_1, RADIO_RESET, RADIO_BUSY); | ||
SX1262* radio = new SX1262(tock_module); | ||
|
||
// Setup the radio | ||
// The settings here work for the SparkFun LoRa Thing Plus - expLoRaBLE | ||
radio->XTAL = true; | ||
int state = radio->begin(915.0); | ||
|
||
if (state != RADIOLIB_ERR_NONE) { | ||
printf("failed, code %d\r\n", state); | ||
return 1; | ||
} | ||
printf("success!\r\n"); | ||
|
||
#ifdef SEND | ||
int temp = 0; | ||
unsigned humi = 0; | ||
|
||
// loop forever | ||
for(;;) { | ||
// Ensure there are no pending callbacks | ||
yield_no_wait(); | ||
|
||
// Read some sensor data from the board | ||
temperature_read_sync(&temp); | ||
humidity_read_sync(&humi); | ||
|
||
snprintf(buffer, BUFFER_LEN, "Temp: %d, Hum: %u", temp, humi); | ||
|
||
// send a packet | ||
printf("[SX1261] Transmitting '%s' \r\n", buffer); | ||
|
||
state = radio->transmit(buffer); | ||
|
||
if(state == RADIOLIB_ERR_NONE) { | ||
// the packet was successfully transmitted | ||
printf("success!\r\n"); | ||
|
||
// wait for a second before transmitting again | ||
hal->delay(1000); | ||
} else { | ||
printf("failed, code %d\r\n", state); | ||
} | ||
} | ||
#else /* SEND */ | ||
printf("[SX1261] Receiving...\r\n"); | ||
|
||
// loop forever | ||
for(;;) { | ||
// Ensure there are no pending callbacks | ||
yield_no_wait(); | ||
|
||
state = radio->receive((uint8_t*)buffer, BUFFER_LEN); | ||
|
||
if(state == RADIOLIB_ERR_NONE) { | ||
// the packet was successfully transmitted | ||
printf("success!: %s\r\n", buffer); | ||
|
||
// wait for a second before transmitting again | ||
hal->delay(1000); | ||
} else { | ||
printf("failed, code %d\r\n", state); | ||
} | ||
} | ||
#endif | ||
|
||
return 0; | ||
} |