Update lib
This commit is contained in:
parent
666b8e1ef8
commit
f5c9cebd61
249 changed files with 18460 additions and 8266 deletions
|
|
@ -8,10 +8,10 @@ assignees: ''
|
|||
---
|
||||
|
||||
**IMPORTANT: Check the wiki**
|
||||
Before submitting new issue, please check the [Wiki](https://github.com/jgromes/RadioLib/wiki) and the [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there.
|
||||
Before submitting new issue, please check the [Troubleshooting Guide](https://github.com/jgromes/RadioLib/wiki/Troubleshooting-Guide) Wiki page and the [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there.
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is. When applicable, please include [debug mode output](https://github.com/jgromes/RadioLib/wiki/Debug-mode).
|
||||
A clear and concise description of what the bug is. When applicable, please include [debug mode output](https://github.com/jgromes/RadioLib/wiki/Debug-mode) **using the appropriate debug mode**.
|
||||
|
||||
**To Reproduce**
|
||||
Minimal Arduino sketch to reproduce the behavior. Please use Markdown to style the code to make it readable (see [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code)).
|
||||
|
|
|
|||
5
lib/RadioLib/.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
5
lib/RadioLib/.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: RadioLib Discussions
|
||||
url: https://github.com/jgromes/RadioLib/discussions
|
||||
about: Please ask generic questions here.
|
||||
|
|
@ -8,7 +8,7 @@ assignees: ''
|
|||
---
|
||||
|
||||
**IMPORTANT: Check the wiki**
|
||||
Before submitting new issue, please check the [Wiki](https://github.com/jgromes/RadioLib/wiki) and the [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there.
|
||||
Before submitting new issue, please check the [Troubleshooting Guide](https://github.com/jgromes/RadioLib/wiki/Troubleshooting-Guide) Wiki page and the [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there.
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ assignees: ''
|
|||
|
||||
**IMPORTANT: Before submitting an issue, please check the following:**
|
||||
1. **Read [CONTRIBUTING.md](https://github.com/jgromes/RadioLib/blob/master/CONTRIBUTING.md)!** Issues that do not follow this document will be closed/locked/deleted/ignored.
|
||||
2. RadioLib has a [Wiki](https://github.com/jgromes/RadioLib/wiki) and an extensive [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there.
|
||||
2. RadioLib has a [Troubleshooting Guide](https://github.com/jgromes/RadioLib/wiki/Troubleshooting-Guide) Wiki page and an extensive [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there.
|
||||
3. Make sure you're using the latest release of the library! Releases can be found [here](https://github.com/jgromes/RadioLib/releases).
|
||||
4. Use [Arduino forums](https://forum.arduino.cc/) to ask generic questions about wireless modules, wiring, usage, etc. Only create issues for problems specific to RadioLib!
|
||||
5. Error codes, their meaning and how to fix them can be found on [this page](https://jgromes.github.io/RadioLib/group__status__codes.html).
|
||||
|
|
@ -24,7 +24,7 @@ paste the sketch here, even if it is an unmodified example code
|
|||
Wiring diagram, schematic, pictures etc.
|
||||
|
||||
**Debug mode output**
|
||||
Enable all [debug levels](https://github.com/jgromes/RadioLib/wiki/Debug-mode) and paste the Serial monitor output here.
|
||||
Enable the appropriate [debug levels](https://github.com/jgromes/RadioLib/wiki/Debug-mode) and paste the Serial monitor output here. For debugging protocols, enable `RADIOLIB_DEBUG_PROTOCOL`. For debugging issues with the radio module itself, enable `RADIOLIB_DEBUG_SPI`.
|
||||
|
||||
**Additional info (please complete):**
|
||||
- MCU: [e.g. Arduino Uno, ESP8266 etc.]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ assignees: ''
|
|||
|
||||
**IMPORTANT: Before submitting an issue, please check the following:**
|
||||
1. **Read [CONTRIBUTING.md](https://github.com/jgromes/RadioLib/blob/master/CONTRIBUTING.md)!** Issues that do not follow this document will be closed/locked/deleted/ignored.
|
||||
2. RadioLib has a [Wiki](https://github.com/jgromes/RadioLib/wiki) and an extensive [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there.
|
||||
2. RadioLib has a [Troubleshooting Guide](https://github.com/jgromes/RadioLib/wiki/Troubleshooting-Guide) Wiki page and an extensive [API documentation](https://jgromes.github.io/RadioLib/). You might find a solution to your issue there.
|
||||
3. Make sure you're using the latest release of the library! Releases can be found [here](https://github.com/jgromes/RadioLib/releases).
|
||||
4. Use [Arduino forums](https://forum.arduino.cc/) to ask generic questions about wireless modules, wiring, usage, etc. Only create issues for problems specific to RadioLib!
|
||||
5. Error codes, their meaning and how to fix them can be found on [this page](https://jgromes.github.io/RadioLib/group__status__codes.html).
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@ on:
|
|||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
|
@ -18,20 +21,11 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
# We must fetch at least the immediate parents so that if this is
|
||||
# a pull request then we can checkout the head.
|
||||
fetch-depth: 2
|
||||
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
|
|
@ -60,7 +54,7 @@ jobs:
|
|||
|
||||
- name: Build example
|
||||
run:
|
||||
arduino-cli compile --libraries /home/runner/work/RadioLib --fqbn arduino:avr:uno $PWD/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino --warnings=all
|
||||
arduino-cli compile --libraries /home/runner/work/RadioLib --fqbn arduino:avr:uno $PWD/examples/SX126x/SX126x_Transmit_Blocking/SX126x_Transmit_Blocking.ino --warnings=all
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
uses: github/codeql-action/analyze@v3
|
||||
|
|
|
|||
27
lib/RadioLib/.github/workflows/cppcheck.yml
vendored
Normal file
27
lib/RadioLib/.github/workflows/cppcheck.yml
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
name: "Cppcheck"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Perform static code check
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install cppcheck
|
||||
run:
|
||||
|
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y cppcheck
|
||||
|
||||
- name: Run cppcheck
|
||||
run:
|
||||
cppcheck src --enable=all --force
|
||||
2
lib/RadioLib/.github/workflows/doxygen.yml
vendored
2
lib/RadioLib/.github/workflows/doxygen.yml
vendored
|
|
@ -13,7 +13,7 @@ jobs:
|
|||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y doxygen
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Generate docs
|
||||
run: doxygen Doxyfile
|
||||
|
|
|
|||
108
lib/RadioLib/.github/workflows/main.yml
vendored
108
lib/RadioLib/.github/workflows/main.yml
vendored
|
|
@ -14,9 +14,9 @@ on:
|
|||
type: choice
|
||||
options:
|
||||
- all
|
||||
- none
|
||||
- arduino:avr:uno
|
||||
- arduino:avr:mega
|
||||
- arduino:avr:leonardo
|
||||
- arduino:mbed:nano33ble
|
||||
- arduino:mbed:envie_m4
|
||||
- arduino:megaavr:uno2018
|
||||
|
|
@ -37,6 +37,7 @@ on:
|
|||
- CubeCell:CubeCell:CubeCell-Board
|
||||
- MegaCore:avr:1281
|
||||
- teensy:avr:teensy41
|
||||
- arduino:renesas_uno:minima
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
|
@ -45,14 +46,15 @@ jobs:
|
|||
# platform-dependent settings - extra board options, board index URLs, skip patterns etc.
|
||||
include:
|
||||
- id: arduino:avr:uno
|
||||
run: echo "skip-pattern=(STM32WL|SSTV)" >> $GITHUB_OUTPUT
|
||||
run: echo "skip-pattern=(STM32WL|SSTV|LoRaWAN)" >> $GITHUB_OUTPUT
|
||||
- id: arduino:avr:mega
|
||||
run: echo "options=':cpu=atmega2560'" >> $GITHUB_OUTPUT
|
||||
- id: arduino:avr:leonardo
|
||||
- id: arduino:mbed:nano33ble
|
||||
- id: arduino:mbed:envie_m4
|
||||
- id: arduino:megaavr:uno2018
|
||||
run: echo "options=':mode=on'" >> $GITHUB_OUTPUT
|
||||
run: |
|
||||
echo "options=':mode=on'" >> $GITHUB_OUTPUT
|
||||
echo "skip-pattern=(STM32WL|LoRaWAN)" >> $GITHUB_OUTPUT
|
||||
- id: arduino:sam:arduino_due_x
|
||||
- id: arduino:samd:arduino_zero_native
|
||||
- id: adafruit:samd:adafruit_feather_m0
|
||||
|
|
@ -69,16 +71,16 @@ jobs:
|
|||
echo "options=':softdevice=s132v6,debug=l0'" >> $GITHUB_OUTPUT
|
||||
echo "index-url=--additional-urls https://adafruit.github.io/arduino-board-index/package_adafruit_index.json" >> $GITHUB_OUTPUT
|
||||
- id: esp32:esp32:esp32
|
||||
run:
|
||||
run: |
|
||||
python -m pip install pyserial
|
||||
echo "index-url=--additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" >> $GITHUB_OUTPUT
|
||||
- id: esp8266:esp8266:generic
|
||||
run: |
|
||||
echo "options=':xtal=80,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=512K'" >> $GITHUB_OUTPUT
|
||||
echo "index-url=--additional-urls http://arduino.esp8266.com/stable/package_esp8266com_index.json" >> $GITHUB_OUTPUT
|
||||
- id: Intel:arc32:arduino_101
|
||||
- id: SparkFun:apollo3:sfe_artemis
|
||||
run: |
|
||||
echo "skip-pattern=(STM32WL|LoRaWAN)" >> $GITHUB_OUTPUT
|
||||
echo "warnings='none'" >> $GITHUB_OUTPUT
|
||||
echo "index-url=--additional-urls https://raw.githubusercontent.com/sparkfun/Arduino_Apollo3/master/package_sparkfun_apollo3_index.json" >> $GITHUB_OUTPUT
|
||||
- id: STMicroelectronics:stm32:GenF3:pnum=BLACKPILL_F303CC
|
||||
|
|
@ -93,7 +95,8 @@ jobs:
|
|||
echo "options=':bootloader_version=original,cpu_speed=speed_72mhz'" >> $GITHUB_OUTPUT
|
||||
echo "index-url=--additional-urls http://dan.drown.org/stm32duino/package_STM32duino_index.json" >> $GITHUB_OUTPUT
|
||||
- id: MegaCoreX:megaavr:4809
|
||||
run: echo "index-url=--additional-urls https://mcudude.github.io/MegaCoreX/package_MCUdude_MegaCoreX_index.json" >> $GITHUB_OUTPUT
|
||||
run: |
|
||||
echo "index-url=--additional-urls https://mcudude.github.io/MegaCoreX/package_MCUdude_MegaCoreX_index.json" >> $GITHUB_OUTPUT
|
||||
- id: arduino:mbed_rp2040:pico
|
||||
- id: rp2040:rp2040:rpipico
|
||||
run: echo "index-url=--additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json" >> $GITHUB_OUTPUT
|
||||
|
|
@ -101,13 +104,14 @@ jobs:
|
|||
run: echo "index-url=--additional-urls https://resource.heltec.cn/download/package_CubeCell_index.json" >> $GITHUB_OUTPUT
|
||||
- id: MegaCore:avr:1281
|
||||
run: echo "index-url=--additional-urls https://mcudude.github.io/MegaCore/package_MCUdude_MegaCore_index.json" >> $GITHUB_OUTPUT
|
||||
- id: teensy:avr:teensy41
|
||||
run: echo "index-url=--additional-urls https://www.pjrc.com/teensy/td_156/package_teensy_index.json" >> $GITHUB_OUTPUT
|
||||
- id: arduino:renesas_uno:minima
|
||||
run: |
|
||||
echo "skip-pattern=(STM32WL|LoRaWAN)" >> $GITHUB_OUTPUT
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
name: ${{ matrix.id }}
|
||||
env:
|
||||
run-build: ${{ (matrix.id == 'arduino:avr:uno') || contains(github.event.head_commit.message, 'CI_BUILD_ALL') || contains(github.event.head_commit.message, 'Bump version to') || contains(github.event.head_commit.message, format('{0}', matrix.id)) || inputs.id == 'all' || inputs.id == matrix.id }}
|
||||
run-build: ${{ (inputs.id != 'none' && matrix.id == 'arduino:avr:uno') || contains(github.event.head_commit.message, 'CI_BUILD_ALL') || contains(github.event.head_commit.message, 'Bump version to') || contains(github.event.head_commit.message, format('{0}', matrix.id)) || inputs.id == 'all' || inputs.id == matrix.id }}
|
||||
|
||||
steps:
|
||||
- name: Install arduino-cli
|
||||
|
|
@ -148,7 +152,7 @@ jobs:
|
|||
|
||||
- name: Checkout repository
|
||||
if: ${{ env.run-build == 'true' }}
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build examples
|
||||
if: ${{ env.run-build == 'true' }}
|
||||
|
|
@ -160,9 +164,14 @@ jobs:
|
|||
# skip sketch
|
||||
echo -e "\n\033[1;33mSkipped ${example##*/} (matched with ${{ steps.prep.outputs.skip-pattern }})\033[0m";
|
||||
else
|
||||
# apply special flags for LoRaWAN
|
||||
if [[ ${example} =~ "LoRaWAN" ]]; then
|
||||
flags="-DRADIOLIB_LORAWAN_DEV_ADDR=0 -DRADIOLIB_LORAWAN_NWKS_KEY=0 -DRADIOLIB_LORAWAN_SNWKSINT_KEY=0 -DRADIOLIB_LORAWAN_NWKSENC_KEY=0 -DRADIOLIB_LORAWAN_APPS_KEY=0 -DRADIOLIB_LORAWAN_APP_KEY=0 -DRADIOLIB_LORAWAN_NWK_KEY=0 -DRADIOLIB_LORAWAN_DEV_EUI=0 -DARDUINO_TTGO_LORA32_V1"
|
||||
fi
|
||||
|
||||
# build sketch
|
||||
echo -e "\n\033[1;33mBuilding ${example##*/} ... \033[0m";
|
||||
arduino-cli compile --libraries /home/runner/work/RadioLib --fqbn ${{ matrix.id }}${{ steps.prep.outputs.options }} $example --warnings=${{ steps.prep.outputs.warnings }}
|
||||
arduino-cli compile --libraries /home/runner/work/RadioLib --fqbn ${{ matrix.id }}${{ steps.prep.outputs.options }} --build-property compiler.cpp.extra_flags="$flags" $example --warnings=${{ steps.prep.outputs.warnings }}
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "\033[1;31m${example##*/} build FAILED\033[0m\n";
|
||||
exit 1;
|
||||
|
|
@ -172,11 +181,60 @@ jobs:
|
|||
fi
|
||||
done
|
||||
|
||||
esp-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
|
||||
|
||||
- name: Clone ESP-IDF
|
||||
run: |
|
||||
mkdir -p ~/esp
|
||||
cd ~/esp
|
||||
git clone --recursive https://github.com/espressif/esp-idf.git
|
||||
|
||||
- name: Install ESP-IDF
|
||||
run: |
|
||||
cd ~/esp/esp-idf
|
||||
./install.sh esp32
|
||||
|
||||
- name: Build the example
|
||||
run: |
|
||||
cd $PWD/examples/NonArduino/ESP-IDF
|
||||
. ~/esp/esp-idf/export.sh
|
||||
idf.py build
|
||||
|
||||
tock-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Setup Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get install -y gcc-arm-none-eabi
|
||||
cargo install elf2tab
|
||||
|
||||
- name: Build the example
|
||||
run: |
|
||||
cd $PWD/examples/NonArduino/Tock
|
||||
./build.sh
|
||||
|
||||
rpi-build:
|
||||
runs-on: [self-hosted, ARM64]
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
|
|
@ -206,3 +264,27 @@ jobs:
|
|||
./clean.sh
|
||||
./build.sh
|
||||
sudo ./build/rpi-sx1261
|
||||
|
||||
rpi-pico-build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install git cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
|
||||
|
||||
- name: Clone the SDK
|
||||
run: |
|
||||
mkdir -p ~/rpi-pico
|
||||
cd ~/rpi-pico
|
||||
git clone https://github.com/raspberrypi/pico-sdk.git
|
||||
cd pico-sdk && git checkout 1.5.1
|
||||
|
||||
- name: Build the example
|
||||
run: |
|
||||
export PICO_SDK_PATH=~/rpi-pico/pico-sdk
|
||||
cd $PWD/examples/NonArduino/Pico
|
||||
./build.sh
|
||||
|
|
|
|||
3
lib/RadioLib/.gitmodules
vendored
Normal file
3
lib/RadioLib/.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "examples/NonArduino/Tock/libtock-c"]
|
||||
path = examples/NonArduino/Tock/libtock-c
|
||||
url = https://github.com/tock/libtock-c.git
|
||||
|
|
@ -1,5 +1,25 @@
|
|||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
if(ESP_PLATFORM)
|
||||
# Build RadioLib as an ESP-IDF component
|
||||
# required because ESP-IDF runs cmake in script mode
|
||||
# and needs idf_component_register()
|
||||
file(GLOB_RECURSE RADIOLIB_ESP_SOURCES
|
||||
"src/*.*"
|
||||
)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${RADIOLIB_ESP_SOURCES}
|
||||
INCLUDE_DIRS . src
|
||||
)
|
||||
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_SCRIPT_MODE_FILE)
|
||||
message(FATAL_ERROR "Attempted to build RadioLib in script mode")
|
||||
endif()
|
||||
|
||||
project(radiolib)
|
||||
|
||||
file(GLOB_RECURSE RADIOLIB_SOURCES
|
||||
|
|
@ -23,4 +43,3 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/
|
|||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/RadioLib
|
||||
FILES_MATCHING PATTERN "*.h"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
# RadioLib  [](https://registry.platformio.org/libraries/jgromes/RadioLib)
|
||||
# RadioLib  [](https://registry.platformio.org/libraries/jgromes/RadioLib) [](https://components.espressif.com/components/jgromes/radiolib)
|
||||
|
||||
### _One radio library to rule them all!_
|
||||
|
||||
## Universal wireless communication library for embedded devices
|
||||
|
||||
## See the [Wiki](https://github.com/jgromes/RadioLib/wiki) for further information. See the [GitHub Pages](https://jgromes.github.io/RadioLib) for detailed and up-to-date API reference.
|
||||
## See the [Wiki](https://github.com/jgromes/RadioLib/wiki) and [FAQ](https://github.com/jgromes/RadioLib/wiki/Frequently-Asked-Questions) for further information. See the [GitHub Pages](https://jgromes.github.io/RadioLib) for detailed and up-to-date API reference.
|
||||
|
||||
RadioLib allows its users to integrate all sorts of different wireless communication modules, protocols and even digital modes into a single consistent system.
|
||||
Want to add a Bluetooth interface to your LoRa network? Sure thing! Do you just want to go really old-school and play around with radio teletype, slow-scan TV, or even Hellschreiber using nothing but a cheap radio module? Why not!
|
||||
|
|
@ -25,7 +25,7 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github
|
|||
* __SX126x__ series LoRa modules (SX1261, SX1262, SX1268)
|
||||
* __SX127x__ series LoRa modules (SX1272, SX1273, SX1276, SX1277, SX1278, SX1279)
|
||||
* __SX128x__ series LoRa/GFSK/BLE/FLRC modules (SX1280, SX1281, SX1282)
|
||||
* __SX1231__ FSK/OOK radio module
|
||||
* __SX123x__ FSK/OOK radio modules (SX1231, SX1233)
|
||||
|
||||
### Supported protocols and digital modes:
|
||||
* [__AX.25__](https://www.sigidwiki.com/wiki/PACKET) using 2-FSK or AFSK for modules:
|
||||
|
|
@ -42,6 +42,9 @@ SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x
|
|||
SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x
|
||||
* [__POCSAG__](https://www.sigidwiki.com/wiki/POCSAG) using 2-FSK for modules:
|
||||
SX127x, RFM9x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x
|
||||
* [__LoRaWAN__](https://lora-alliance.org/) using LoRa for modules:
|
||||
SX127x, RFM9x, SX126x and SX128x
|
||||
* NOTE: LoRaWAN support is currently in beta, feedback via [Issues](https://github.com/jgromes/RadioLib/issues) and [Discussions](https://github.com/jgromes/RadioLib/discussions) is appreciated!
|
||||
|
||||
### Supported Arduino platforms:
|
||||
* __Arduino__
|
||||
|
|
@ -50,6 +53,7 @@ SX127x, RFM9x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x
|
|||
* [__megaAVR__](https://github.com/arduino/ArduinoCore-megaavr) - Arduino Uno WiFi Rev.2 and Nano Every
|
||||
* [__SAM__](https://github.com/arduino/ArduinoCore-sam) - Arduino Due
|
||||
* [__SAMD__](https://github.com/arduino/ArduinoCore-samd) - Arduino Zero, MKR boards, M0 Pro etc.
|
||||
* [__Renesas__](https://github.com/arduino/ArduinoCore-renesas) - Arduino Uno R4
|
||||
|
||||
* __Adafruit__
|
||||
* [__SAMD__](https://github.com/adafruit/ArduinoCore-samd) - Adafruit Feather M0 and M4 boards (Feather, Metro, Gemma, Trinket etc.)
|
||||
|
|
@ -84,23 +88,4 @@ SX127x, RFM9x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x
|
|||
* __PJRC__
|
||||
* [__Teensy__](https://github.com/PaulStoffregen/cores) - Teensy 2.x, 3.x and 4.x boards
|
||||
|
||||
The list above is by no means exhaustive - RadioLib code is independent of the used platform! Compilation of all examples is tested for all platforms officially supported prior to releasing new version. In addition, RadioLib includes an internal hardware abstracton layer, which allows it to be easily ported even to non-Arduino encironments.
|
||||
|
||||
### In development:
|
||||
* __AX5243__ FSK module
|
||||
* __LoRaWAN__ protocol for SX127x, RFM9x and SX126x modules
|
||||
* ___and more!___
|
||||
|
||||
## Frequently Asked Questions
|
||||
|
||||
### Where should I start?
|
||||
First of all, take a look at the [examples](https://github.com/jgromes/RadioLib/tree/master/examples) and the [Wiki](https://github.com/jgromes/RadioLib/wiki) - especially the [Basics](https://github.com/jgromes/RadioLib/wiki/Basics) page. There's a lot of useful information over there. If something isn't working as expected, try searching the [issues](https://github.com/jgromes/RadioLib/issues/).
|
||||
|
||||
### Does RadioLib require Arduino?
|
||||
While RadioLib was originally written with Arduino in mind, it has since evolved and contains its own lightweight hardware abstraction layer. Thanks to this layer, RadioLib can be used on non-Arduino frameworks as well. See [this Wiki page](https://github.com/jgromes/RadioLib/wiki/Porting-to-non-Arduino-Platforms) for details.
|
||||
|
||||
### Help, my module isn't working!
|
||||
The fastest way to get help is by creating an [issue](https://github.com/jgromes/RadioLib/issues/new/choose) using the appropriate template. It is also highly recommended to try running the examples first - their functionality is tested from time to time and they should work. Finally, RadioLib is still under development, which means that sometimes, backwards-incompatible changes might be introduced. Though these are kept at minimum, sometimes it is unavoidable. You can check the [release changelog](https://github.com/jgromes/RadioLib/releases) to find out if there's been such a major change recently.
|
||||
|
||||
### RadioLib doesn't support my module! What should I do?
|
||||
Start by creating new issue (if it doesn't exist yet). If you have some experience with microcontrollers and C/C++ in general, you can try to add the support yourself! Use the template files in `/extras/` folder to get started. This is by far the fastest way to implement new modules into RadioLib, since I can't be working on everything all the time. If you don't trust your programming skills enough to have a go at it yourself, don't worry. I will try to implement all requested modules, but it will take me a while.
|
||||
The list above is by no means exhaustive - RadioLib code is independent of the used platform! Compilation of all examples is tested for all platforms officially supported prior to releasing new version. In addition, RadioLib includes an internal hardware abstraction layer, which allows it to be easily ported even to non-Arduino environments.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
RadioLib APRS Position over LoRa Example
|
||||
|
||||
This example sends APRS position reports
|
||||
using SX1278's LoRa modem.
|
||||
|
||||
Other modules that can be used for APRS:
|
||||
- SX127x/RFM9x
|
||||
- SX126x/LLCC68
|
||||
- SX128x
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
#include <RadioLib.h>
|
||||
|
||||
// SX1278 has the following connections:
|
||||
// NSS pin: 10
|
||||
// DIO0 pin: 2
|
||||
// RESET pin: 9
|
||||
// DIO1 pin: 3
|
||||
SX1278 radio = new Module(10, 2, 9, 3);
|
||||
|
||||
// or using RadioShield
|
||||
// https://github.com/jgromes/RadioShield
|
||||
//SX1278 radio = RadioShield.ModuleA;
|
||||
|
||||
// create APRS client instance using the LoRa radio
|
||||
APRSClient aprs(&radio);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// initialize SX1278 with the settings necessary for LoRa iGates
|
||||
Serial.print(F("[SX1278] Initializing ... "));
|
||||
// frequency: 433.775 MHz
|
||||
// bandwidth: 125 kHz
|
||||
// spreading factor: 12
|
||||
// coding rate: 4/5
|
||||
int state = radio.begin(433.775, 125, 12, 5);
|
||||
|
||||
// when using one of the non-LoRa modules for AX.25
|
||||
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
|
||||
// int state = radio.begin();
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
|
||||
// initialize APRS client
|
||||
Serial.print(F("[APRS] Initializing ... "));
|
||||
// symbol: '>' (car)
|
||||
// callsign "N7LEM"
|
||||
// SSID 1
|
||||
state = aprs.begin('>', "N7LEM", 1);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[APRS] Sending position ... "));
|
||||
|
||||
// send a location with message and timestamp
|
||||
// SSID is set to 1, as APRS over LoRa uses WIDE1-1 path by default
|
||||
int state = aprs.sendPosition("GPS", 1, "4911.67N", "01635.96E", "I'm here!", "093045z");
|
||||
delay(500);
|
||||
|
||||
// you can also send Mic-E encoded messages
|
||||
state |= state = aprs.sendMicE(49.1945, 16.6000, 120, 10, RADIOLIB_APRS_MIC_E_TYPE_EN_ROUTE);
|
||||
delay(500);
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
}
|
||||
|
||||
// wait one minute before transmitting again
|
||||
delay(60000);
|
||||
}
|
||||
|
|
@ -1,19 +1,24 @@
|
|||
/*
|
||||
RadioLib CC1101 Receive Example
|
||||
RadioLib CC1101 Blocking Receive Example
|
||||
|
||||
This example receives packets using CC1101 FSK radio module.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bit rate
|
||||
- frequency deviation
|
||||
- sync word
|
||||
This example receives packets using CC1101 FSK radio module.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bit rate
|
||||
- frequency deviation
|
||||
- sync word
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
|
||||
Using blocking receive is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt receive is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -49,7 +49,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setGdo0Action(setFlag, RISING);
|
||||
radio.setPacketReceivedAction(setFlag);
|
||||
|
||||
// start listening for packets
|
||||
Serial.print(F("[CC1101] Starting to listen ... "));
|
||||
|
|
@ -100,7 +100,8 @@ void loop() {
|
|||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
int numBytes = radio.getPacketLength();
|
||||
int state = radio.readData(byteArr, numBytes);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
/*
|
||||
RadioLib CC1101 Transmit Example
|
||||
RadioLib CC1101 Blocking Transmit Example
|
||||
|
||||
This example transmits packets using CC1101 FSK radio module.
|
||||
Each packet contains up to 64 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits packets using CC1101 FSK radio module.
|
||||
Each packet contains up to 64 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
|
||||
Using blocking transmit is not recommended, as it will lead
|
||||
to inefficient use of processor time!
|
||||
Instead, interrupt transmit is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -43,11 +47,15 @@ void setup() {
|
|||
}
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[CC1101] Transmitting packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to 63 characters long
|
||||
int state = radio.transmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
int state = radio.transmit(str);
|
||||
|
||||
// you can also transmit byte array up to 63 bytes long
|
||||
/*
|
||||
|
|
@ -48,10 +48,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when packet transmission is finished
|
||||
// NOTE: Unlike other modules (such as SX127x),
|
||||
// different GDOx pins are used for
|
||||
// transmit and receive interrupts!
|
||||
radio.setGdo2Action(setFlag, FALLING);
|
||||
radio.setPacketSentAction(setFlag);
|
||||
|
||||
// start transmitting the first packet
|
||||
Serial.print(F("[CC1101] Sending first packet ... "));
|
||||
|
|
@ -83,6 +80,9 @@ void setFlag(void) {
|
|||
transmittedFlag = true;
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
// check if the previous transmission finished
|
||||
if(transmittedFlag) {
|
||||
|
|
@ -116,7 +116,8 @@ void loop() {
|
|||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
transmissionState = radio.startTransmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
transmissionState = radio.startTransmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
|
|
|
|||
71
lib/RadioLib/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino
Normal file
71
lib/RadioLib/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
RadioLib LoRaWAN ABP Example
|
||||
|
||||
ABP = Activation by Personalisation, an alternative
|
||||
to OTAA (Over the Air Activation). OTAA is preferable.
|
||||
|
||||
This example will send uplink packets to a LoRaWAN network.
|
||||
Before you start, you will have to register your device at
|
||||
https://www.thethingsnetwork.org/
|
||||
After your device is registered, you can run this example.
|
||||
The device will join the network and start uploading data.
|
||||
|
||||
LoRaWAN v1.1 requires the use of persistent storage.
|
||||
As this example does not use persistent storage, running this
|
||||
examples REQUIRES you to check "Resets frame counters"
|
||||
on your LoRaWAN dashboard. Refer to the notes or the
|
||||
network's documentation on how to do this.
|
||||
To comply with LoRaWAN v1.1's persistent storage, refer to
|
||||
https://github.com/radiolib-org/radiolib-persistence
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
|
||||
For LoRaWAN details, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/LoRaWAN
|
||||
|
||||
*/
|
||||
|
||||
#include "configABP.h"
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
delay(5000); // Give time to switch to the serial monitor
|
||||
Serial.println(F("\nSetup ... "));
|
||||
|
||||
Serial.println(F("Initalise the radio"));
|
||||
int state = radio.begin();
|
||||
debug(state != RADIOLIB_ERR_NONE, F("Initalise radio failed"), state, true);
|
||||
|
||||
Serial.println(F("Initalise LoRaWAN Network credentials"));
|
||||
state = node.beginABP(devAddr, NwkSEncKey, AppSKey, NwkSKey, SNwkSIntKey, true);
|
||||
debug(state < RADIOLIB_ERR_NONE, F("Session setup failed"), state, true);
|
||||
|
||||
Serial.println(F("Ready!\n"));
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
Serial.println(F("Sending uplink"));
|
||||
|
||||
// Read some inputs
|
||||
uint8_t Digital1 = digitalRead(2);
|
||||
uint16_t Analog1 = analogRead(3);
|
||||
|
||||
// Build payload byte array
|
||||
uint8_t uplinkPayload[3];
|
||||
uplinkPayload[0] = Digital1;
|
||||
uplinkPayload[1] = highByte(Analog1); // See notes for high/lowByte functions
|
||||
uplinkPayload[2] = lowByte(Analog1);
|
||||
|
||||
// Perform an uplink
|
||||
int state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload));
|
||||
debug((state != RADIOLIB_LORAWAN_NO_DOWNLINK) && (state != RADIOLIB_ERR_NONE), F("Error in sendReceive"), state, false);
|
||||
|
||||
// Wait until next uplink - observing legal & TTN FUP constraints
|
||||
delay(uplinkIntervalSeconds * 1000UL);
|
||||
}
|
||||
132
lib/RadioLib/examples/LoRaWAN/LoRaWAN_ABP/configABP.h
Normal file
132
lib/RadioLib/examples/LoRaWAN/LoRaWAN_ABP/configABP.h
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
|
||||
#include <RadioLib.h>
|
||||
|
||||
// how often to send an uplink - consider legal & FUP constraints - see notes
|
||||
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
|
||||
|
||||
// device address - either a development address or one assigned
|
||||
// to the LoRaWAN Service Provider - TTN will generate one for you
|
||||
#ifndef RADIOLIB_LORAWAN_DEV_ADDR // Replace with your DevAddr
|
||||
#define RADIOLIB_LORAWAN_DEV_ADDR 0x------
|
||||
#endif
|
||||
|
||||
#ifndef RADIOLIB_LORAWAN_NWKS_KEY // Replace with your NwkS Key
|
||||
#define RADIOLIB_LORAWAN_NWKS_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
|
||||
#endif
|
||||
#ifndef RADIOLIB_LORAWAN_SNWKSINT_KEY // Replace with your SNwkSInt Key
|
||||
#define RADIOLIB_LORAWAN_SNWKSINT_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
|
||||
#endif
|
||||
#ifndef RADIOLIB_LORAWAN_NWKSENC_KEY // Replace with your NwkSEnc Key
|
||||
#define RADIOLIB_LORAWAN_NWKSENC_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
|
||||
#endif
|
||||
#ifndef RADIOLIB_LORAWAN_APPS_KEY // Replace with your AppS Key
|
||||
#define RADIOLIB_LORAWAN_APPS_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
|
||||
#endif
|
||||
|
||||
// for the curious, the #ifndef blocks allow for automated testing &/or you can
|
||||
// put your EUI & keys in to your platformio.ini - see wiki for more tips
|
||||
|
||||
// regional choices: EU868, US915, AU915, AS923, IN865, KR920, CN780, CN500
|
||||
const LoRaWANBand_t Region = EU868;
|
||||
const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// Below is to support the sketch - only make changes if the notes say so ...
|
||||
|
||||
// Auto select MCU <-> radio connections
|
||||
// If you get an error message when compiling, it may be that the
|
||||
// pinmap could not be determined - see the notes for more info
|
||||
|
||||
// Adafruit
|
||||
#if defined(ARDUINO_SAMD_FEATHER_M0)
|
||||
#pragma message ("Adafruit Feather M0 with RFM95")
|
||||
#pragma message ("Link required on board")
|
||||
SX1276 radio = new Module(8, 3, 4, 6);
|
||||
|
||||
|
||||
// LilyGo
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V1)
|
||||
#pragma message ("TTGO LoRa32 v1 - no Display")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V2)
|
||||
#pragma error ("ARDUINO_TTGO_LORA32_V2 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LoRa32_v21new) // T3_V1.6.1
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1262)
|
||||
#pragma error ("ARDUINO_TBEAM_USE_RADIO_SX1262 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1276)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
SX1276 radio = new Module(18, 26, 23, 33);
|
||||
|
||||
|
||||
// Heltec
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32)
|
||||
#pragma error ("ARDUINO_HELTEC_WIFI_LORA_32 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V2)
|
||||
#pragma message ("ARDUINO_heltec_wifi_kit_32_V2 awaiting pin map")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V3)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v3 - Display + USB-C")
|
||||
SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD_V2)
|
||||
#pragma error ("ARDUINO_CUBECELL_BOARD_V2 awaiting pin map")
|
||||
|
||||
|
||||
#else
|
||||
#pragma message ("Unknown board - no automagic pinmap available")
|
||||
|
||||
// SX1262 pin order: Module(NSS/CS, DIO1, RESET, BUSY);
|
||||
// SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
// SX1278 pin order: Module(NSS/CS, DIO0, RESET, DIO1);
|
||||
// SX1278 radio = new Module(10, 2, 9, 3);
|
||||
|
||||
#endif
|
||||
|
||||
// copy over the keys in to the something that will not compile if incorrectly formatted
|
||||
uint32_t devAddr = RADIOLIB_LORAWAN_DEV_ADDR;
|
||||
uint8_t NwkSKey[] = { RADIOLIB_LORAWAN_NWKS_KEY };
|
||||
uint8_t SNwkSIntKey[] = { RADIOLIB_LORAWAN_SNWKSINT_KEY }; // Previously sNwkSIntKey
|
||||
uint8_t NwkSEncKey[] = { RADIOLIB_LORAWAN_NWKSENC_KEY }; // Previously fNwkSIntKey
|
||||
uint8_t AppSKey[] = { RADIOLIB_LORAWAN_APPS_KEY };
|
||||
|
||||
// create the LoRaWAN node
|
||||
LoRaWANNode node(&radio, &Region, subBand);
|
||||
|
||||
// helper function to display any issues
|
||||
void debug(bool isFail, const __FlashStringHelper* message, int state, bool Freeze) {
|
||||
if (isFail) {
|
||||
Serial.print(message);
|
||||
Serial.print("(");
|
||||
Serial.print(state);
|
||||
Serial.println(")");
|
||||
while (Freeze);
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to display a byte array
|
||||
void arrayDump(uint8_t *buffer, uint16_t len) {
|
||||
for(uint16_t c = 0; c < len; c++) {
|
||||
char b = buffer[c];
|
||||
if(b < 0x10) { Serial.print('0'); }
|
||||
Serial.print(b, HEX);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
RadioLib LoRaWAN End Device Reference Example
|
||||
|
||||
This example joins a LoRaWAN network and will send
|
||||
uplink packets. Before you start, you will have to
|
||||
register your device at https://www.thethingsnetwork.org/
|
||||
After your device is registered, you can run this example.
|
||||
The device will join the network and start uploading data.
|
||||
|
||||
Also, most of the possible and available functions are
|
||||
shown here for reference.
|
||||
|
||||
LoRaWAN v1.1 requires the use of EEPROM (persistent storage).
|
||||
Running this examples REQUIRES you to check "Resets DevNonces"
|
||||
on your LoRaWAN dashboard. Refer to the notes or the
|
||||
network's documentation on how to do this.
|
||||
To comply with LoRaWAN v1.1's persistent storage, refer to
|
||||
https://github.com/radiolib-org/radiolib-persistence
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
|
||||
For LoRaWAN details, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/LoRaWAN
|
||||
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
// include the library
|
||||
#include <RadioLib.h>
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial); // Wait for serial to be initalised
|
||||
delay(5000); // Give time to switch to the serial monitor
|
||||
Serial.println(F("\nSetup"));
|
||||
|
||||
int16_t state = 0; // return value for calls to RadioLib
|
||||
|
||||
Serial.println(F("Initalise the radio"));
|
||||
state = radio.begin();
|
||||
debug(state != RADIOLIB_ERR_NONE, F("Initalise radio failed"), state, true);
|
||||
|
||||
// Override the default join rate
|
||||
// uint8_t joinDR = 3;
|
||||
|
||||
Serial.println(F("Join ('login') to the LoRaWAN Network"));
|
||||
state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, true);
|
||||
debug(state < RADIOLIB_ERR_NONE, F("Join failed"), state, true);
|
||||
|
||||
// Print the DevAddr
|
||||
Serial.print("[LoRaWAN] DevAddr: ");
|
||||
Serial.println((unsigned long)node.getDevAddr(), HEX);
|
||||
|
||||
// Disable the ADR algorithm (on by default which is preferable)
|
||||
node.setADR(false);
|
||||
|
||||
// Set a fixed datarate & make it persistent (not normal)
|
||||
node.setDatarate(4);
|
||||
|
||||
// Enable CSMA which tries to minimize packet loss by searching
|
||||
// for a free channel before actually sending an uplink
|
||||
node.setCSMA(6, 2, true);
|
||||
|
||||
// Manages uplink intervals to the TTN Fair Use Policy
|
||||
node.setDutyCycle(true, 1250);
|
||||
|
||||
// Enable the dwell time limits - 400ms is the limit for the US
|
||||
node.setDwellTime(true, 400);
|
||||
|
||||
Serial.println(F("Ready!\n"));
|
||||
} // setup
|
||||
|
||||
|
||||
void loop() {
|
||||
int state = RADIOLIB_ERR_NONE;
|
||||
|
||||
// set battery fill level - the LoRaWAN network server
|
||||
// may periodically request this information
|
||||
// 0 = external power source
|
||||
// 1 = lowest (empty battery)
|
||||
// 254 = highest (full battery)
|
||||
// 255 = unable to measure
|
||||
uint8_t battLevel = 146;
|
||||
node.setDeviceStatus(battLevel);
|
||||
|
||||
|
||||
// Read some inputs
|
||||
uint8_t Digital1 = digitalRead(2);
|
||||
uint16_t Analog1 = analogRead(3);
|
||||
|
||||
// Build payload byte array
|
||||
uint8_t uplinkPayload[3];
|
||||
uplinkPayload[0] = Digital1;
|
||||
uplinkPayload[1] = highByte(Analog1); // See notes for high/lowByte functions
|
||||
uplinkPayload[2] = lowByte(Analog1);
|
||||
|
||||
uint8_t downlinkPayload[10]; // Make sure this fits your plans!
|
||||
size_t downlinkSize; // To hold the actual payload size rec'd
|
||||
|
||||
// you can also retrieve additional information about an uplink or
|
||||
// downlink by passing a reference to LoRaWANEvent_t structure
|
||||
LoRaWANEvent_t uplinkDetails;
|
||||
LoRaWANEvent_t downlinkDetails;
|
||||
|
||||
uint8_t Port = 10;
|
||||
|
||||
// Retrieve the last uplink frame counter
|
||||
uint32_t fcntUp = node.getFcntUp();
|
||||
// Send a confirmed uplink every 64th frame
|
||||
// and also request the LinkCheck and DeviceTime MAC commands
|
||||
if(fcntUp % 64 == 0) {
|
||||
Serial.println(F("[LoRaWAN] Requesting LinkCheck and DeviceTime"));
|
||||
node.sendMacCommandReq(RADIOLIB_LORAWAN_MAC_LINK_CHECK);
|
||||
node.sendMacCommandReq(RADIOLIB_LORAWAN_MAC_DEVICE_TIME);
|
||||
state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload), Port, downlinkPayload, &downlinkSize, true, &uplinkDetails, &downlinkDetails);
|
||||
} else {
|
||||
state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload), Port, downlinkPayload, &downlinkSize);
|
||||
}
|
||||
debug((state != RADIOLIB_LORAWAN_NO_DOWNLINK) && (state != RADIOLIB_ERR_NONE), F("Error in sendReceive"), state, false);
|
||||
|
||||
// Check if downlink was received
|
||||
if(state != RADIOLIB_LORAWAN_NO_DOWNLINK) {
|
||||
// Did we get a downlink with data for us
|
||||
if (downlinkSize > 0) {
|
||||
Serial.println(F("Downlink data: "));
|
||||
arrayDump(downlinkPayload, downlinkSize);
|
||||
} else {
|
||||
Serial.println(F("<MAC commands only>"));
|
||||
}
|
||||
|
||||
// print RSSI (Received Signal Strength Indicator)
|
||||
Serial.print(F("[LoRaWAN] RSSI:\t\t"));
|
||||
Serial.print(radio.getRSSI());
|
||||
Serial.println(F(" dBm"));
|
||||
|
||||
// print SNR (Signal-to-Noise Ratio)
|
||||
Serial.print(F("[LoRaWAN] SNR:\t\t"));
|
||||
Serial.print(radio.getSNR());
|
||||
Serial.println(F(" dB"));
|
||||
|
||||
// print frequency error
|
||||
Serial.print(F("[LoRaWAN] Frequency error:\t"));
|
||||
Serial.print(radio.getFrequencyError());
|
||||
Serial.println(F(" Hz"));
|
||||
|
||||
// print extra information about the event
|
||||
Serial.println(F("[LoRaWAN] Event information:"));
|
||||
Serial.print(F("[LoRaWAN] Confirmed:\t"));
|
||||
Serial.println(downlinkDetails.confirmed);
|
||||
Serial.print(F("[LoRaWAN] Confirming:\t"));
|
||||
Serial.println(downlinkDetails.confirming);
|
||||
Serial.print(F("[LoRaWAN] Datarate:\t"));
|
||||
Serial.println(downlinkDetails.datarate);
|
||||
Serial.print(F("[LoRaWAN] Frequency:\t"));
|
||||
Serial.print(downlinkDetails.freq, 3);
|
||||
Serial.println(F(" MHz"));
|
||||
Serial.print(F("[LoRaWAN] Output power:\t"));
|
||||
Serial.print(downlinkDetails.power);
|
||||
Serial.println(F(" dBm"));
|
||||
Serial.print(F("[LoRaWAN] Frame count:\t"));
|
||||
Serial.println(downlinkDetails.fcnt);
|
||||
Serial.print(F("[LoRaWAN] Port:\t\t"));
|
||||
Serial.println(downlinkDetails.port);
|
||||
|
||||
uint8_t margin = 0;
|
||||
uint8_t gwCnt = 0;
|
||||
if(node.getMacLinkCheckAns(&margin, &gwCnt) == RADIOLIB_ERR_NONE) {
|
||||
Serial.print(F("[LoRaWAN] LinkCheck margin:\t"));
|
||||
Serial.println(margin);
|
||||
Serial.print(F("[LoRaWAN] LinkCheck count:\t"));
|
||||
Serial.println(gwCnt);
|
||||
}
|
||||
|
||||
uint32_t networkTime = 0;
|
||||
uint8_t fracSecond = 0;
|
||||
if(node.getMacDeviceTimeAns(&networkTime, &fracSecond, true) == RADIOLIB_ERR_NONE) {
|
||||
Serial.print(F("[LoRaWAN] DeviceTime Unix:\t"));
|
||||
Serial.println(networkTime);
|
||||
Serial.print(F("[LoRaWAN] DeviceTime second:\t1/"));
|
||||
Serial.println(fracSecond);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// wait before sending another packet
|
||||
uint32_t minimumDelay = uplinkIntervalSeconds * 1000UL;
|
||||
uint32_t interval = node.timeUntilUplink(); // calculate minimum duty cycle delay (per FUP & law!)
|
||||
uint32_t delayMs = max(interval, minimumDelay); // cannot send faster than duty cycle allows
|
||||
|
||||
Serial.print(F("[LoRaWAN] Next uplink in "));
|
||||
Serial.print(delayMs/1000);
|
||||
Serial.println(F("s"));
|
||||
|
||||
delay(delayMs);
|
||||
|
||||
} // loop
|
||||
126
lib/RadioLib/examples/LoRaWAN/LoRaWAN_Reference/config.h
Normal file
126
lib/RadioLib/examples/LoRaWAN/LoRaWAN_Reference/config.h
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
|
||||
#include <RadioLib.h>
|
||||
|
||||
// how often to send an uplink - consider legal & FUP constraints - see notes
|
||||
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
|
||||
|
||||
// joinEUI - previous versions of LoRaWAN called this AppEUI
|
||||
// for development purposes you can use all zeros - see wiki for details
|
||||
#define RADIOLIB_LORAWAN_JOIN_EUI 0x0000000000000000
|
||||
|
||||
// the Device EUI & two keys can be generated on the TTN console
|
||||
#ifndef RADIOLIB_LORAWAN_DEV_EUI // Replace with your Device EUI
|
||||
#define RADIOLIB_LORAWAN_DEV_EUI 0x---------------
|
||||
#endif
|
||||
#ifndef RADIOLIB_LORAWAN_APP_KEY // Replace with your App Key
|
||||
#define RADIOLIB_LORAWAN_APP_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
|
||||
#endif
|
||||
#ifndef RADIOLIB_LORAWAN_NWK_KEY // Put your Nwk Key here
|
||||
#define RADIOLIB_LORAWAN_NWK_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
|
||||
#endif
|
||||
|
||||
// for the curious, the #ifndef blocks allow for automated testing &/or you can
|
||||
// put your EUI & keys in to your platformio.ini - see wiki for more tips
|
||||
|
||||
// regional choices: EU868, US915, AU915, AS923, IN865, KR920, CN780, CN500
|
||||
const LoRaWANBand_t Region = EU868;
|
||||
const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
|
||||
|
||||
// ============================================================================
|
||||
// Below is to support the sketch - only make changes if the notes say so ...
|
||||
|
||||
// Auto select MCU <-> radio connections
|
||||
// If you get an error message when compiling, it may be that the
|
||||
// pinmap could not be determined - see the notes for more info
|
||||
|
||||
// Adafruit
|
||||
#if defined(ARDUINO_SAMD_FEATHER_M0)
|
||||
#pragma message ("Adafruit Feather M0 with RFM95")
|
||||
#pragma message ("Link required on board")
|
||||
SX1276 radio = new Module(8, 3, 4, 6);
|
||||
|
||||
|
||||
// LilyGo
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V1)
|
||||
#pragma message ("TTGO LoRa32 v1 - no Display")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V2)
|
||||
#pragma error ("ARDUINO_TTGO_LORA32_V2 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LoRa32_v21new) // T3_V1.6.1
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1262)
|
||||
#pragma error ("ARDUINO_TBEAM_USE_RADIO_SX1262 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1276)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
SX1276 radio = new Module(18, 26, 23, 33);
|
||||
|
||||
|
||||
// Heltec
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32)
|
||||
#pragma error ("ARDUINO_HELTEC_WIFI_LORA_32 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V2)
|
||||
#pragma message ("ARDUINO_heltec_wifi_kit_32_V2 awaiting pin map")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V3)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v3 - Display + USB-C")
|
||||
SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD_V2)
|
||||
#pragma error ("ARDUINO_CUBECELL_BOARD_V2 awaiting pin map")
|
||||
|
||||
|
||||
#else
|
||||
#pragma message ("Unknown board - no automagic pinmap available")
|
||||
|
||||
// SX1262 pin order: Module(NSS/CS, DIO1, RESET, BUSY);
|
||||
// SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
// SX1278 pin order: Module(NSS/CS, DIO0, RESET, DIO1);
|
||||
// SX1278 radio = new Module(10, 2, 9, 3);
|
||||
|
||||
#endif
|
||||
|
||||
// copy over the EUI's & keys in to the something that will not compile if incorrectly formatted
|
||||
uint64_t joinEUI = RADIOLIB_LORAWAN_JOIN_EUI;
|
||||
uint64_t devEUI = RADIOLIB_LORAWAN_DEV_EUI;
|
||||
uint8_t appKey[] = { RADIOLIB_LORAWAN_APP_KEY };
|
||||
uint8_t nwkKey[] = { RADIOLIB_LORAWAN_NWK_KEY };
|
||||
|
||||
// create the LoRaWAN node
|
||||
LoRaWANNode node(&radio, &Region, subBand);
|
||||
|
||||
// helper function to display any issues
|
||||
void debug(bool isFail, const __FlashStringHelper* message, int state, bool Freeze) {
|
||||
if (isFail) {
|
||||
Serial.print(message);
|
||||
Serial.print("(");
|
||||
Serial.print(state);
|
||||
Serial.println(")");
|
||||
while (Freeze);
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to display a byte array
|
||||
void arrayDump(uint8_t *buffer, uint16_t len) {
|
||||
for(uint16_t c = 0; c < len; c++) {
|
||||
char b = buffer[c];
|
||||
if(b < 0x10) { Serial.print('0'); }
|
||||
Serial.print(b, HEX);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
RadioLib LoRaWAN Starter Example
|
||||
|
||||
This example joins a LoRaWAN network and will send
|
||||
uplink packets. Before you start, you will have to
|
||||
register your device at https://www.thethingsnetwork.org/
|
||||
After your device is registered, you can run this example.
|
||||
The device will join the network and start uploading data.
|
||||
|
||||
Running this examples REQUIRES you to check "Resets DevNonces"
|
||||
on your LoRaWAN dashboard. Refer to the network's
|
||||
documentation on how to do this.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
|
||||
For LoRaWAN details, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/LoRaWAN
|
||||
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
delay(5000); // Give time to switch to the serial monitor
|
||||
Serial.println(F("\nSetup ... "));
|
||||
|
||||
Serial.println(F("Initalise the radio"));
|
||||
int state = radio.begin();
|
||||
debug(state != RADIOLIB_ERR_NONE, F("Initalise radio failed"), state, true);
|
||||
|
||||
Serial.println(F("Join ('login') to the LoRaWAN Network"));
|
||||
state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, true);
|
||||
debug(state < RADIOLIB_ERR_NONE, F("Join failed"), state, true);
|
||||
|
||||
Serial.println(F("Ready!\n"));
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
Serial.println(F("Sending uplink"));
|
||||
|
||||
// Read some inputs
|
||||
uint8_t Digital1 = digitalRead(2);
|
||||
uint16_t Analog1 = analogRead(3);
|
||||
|
||||
// Build payload byte array
|
||||
uint8_t uplinkPayload[3];
|
||||
uplinkPayload[0] = Digital1;
|
||||
uplinkPayload[1] = highByte(Analog1); // See notes for high/lowByte functions
|
||||
uplinkPayload[2] = lowByte(Analog1);
|
||||
|
||||
// Perform an uplink
|
||||
int state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload));
|
||||
debug((state != RADIOLIB_LORAWAN_NO_DOWNLINK) && (state != RADIOLIB_ERR_NONE), F("Error in sendReceive"), state, false);
|
||||
|
||||
Serial.print(F("Uplink complete, next in "));
|
||||
Serial.print(uplinkIntervalSeconds);
|
||||
Serial.println(F(" seconds"));
|
||||
|
||||
// Wait until next uplink - observing legal & TTN FUP constraints
|
||||
delay(uplinkIntervalSeconds * 1000UL); // delay needs milli-seconds
|
||||
}
|
||||
126
lib/RadioLib/examples/LoRaWAN/LoRaWAN_Starter/config.h
Normal file
126
lib/RadioLib/examples/LoRaWAN/LoRaWAN_Starter/config.h
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
|
||||
#include <RadioLib.h>
|
||||
|
||||
// how often to send an uplink - consider legal & FUP constraints - see notes
|
||||
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
|
||||
|
||||
// joinEUI - previous versions of LoRaWAN called this AppEUI
|
||||
// for development purposes you can use all zeros - see wiki for details
|
||||
#define RADIOLIB_LORAWAN_JOIN_EUI 0x0000000000000000
|
||||
|
||||
// the Device EUI & two keys can be generated on the TTN console
|
||||
#ifndef RADIOLIB_LORAWAN_DEV_EUI // Replace with your Device EUI
|
||||
#define RADIOLIB_LORAWAN_DEV_EUI 0x---------------
|
||||
#endif
|
||||
#ifndef RADIOLIB_LORAWAN_APP_KEY // Replace with your App Key
|
||||
#define RADIOLIB_LORAWAN_APP_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
|
||||
#endif
|
||||
#ifndef RADIOLIB_LORAWAN_NWK_KEY // Put your Nwk Key here
|
||||
#define RADIOLIB_LORAWAN_NWK_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
|
||||
#endif
|
||||
|
||||
// for the curious, the #ifndef blocks allow for automated testing &/or you can
|
||||
// put your EUI & keys in to your platformio.ini - see wiki for more tips
|
||||
|
||||
// regional choices: EU868, US915, AU915, AS923, IN865, KR920, CN780, CN500
|
||||
const LoRaWANBand_t Region = EU868;
|
||||
const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0
|
||||
|
||||
// ============================================================================
|
||||
// Below is to support the sketch - only make changes if the notes say so ...
|
||||
|
||||
// Auto select MCU <-> radio connections
|
||||
// If you get an error message when compiling, it may be that the
|
||||
// pinmap could not be determined - see the notes for more info
|
||||
|
||||
// Adafruit
|
||||
#if defined(ARDUINO_SAMD_FEATHER_M0)
|
||||
#pragma message ("Adafruit Feather M0 with RFM95")
|
||||
#pragma message ("Link required on board")
|
||||
SX1276 radio = new Module(8, 3, 4, 6);
|
||||
|
||||
|
||||
// LilyGo
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V1)
|
||||
#pragma message ("TTGO LoRa32 v1 - no Display")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LORA32_V2)
|
||||
#pragma error ("ARDUINO_TTGO_LORA32_V2 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_TTGO_LoRa32_v21new) // T3_V1.6.1
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
SX1276 radio = new Module(18, 26, 14, 33);
|
||||
|
||||
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1262)
|
||||
#pragma error ("ARDUINO_TBEAM_USE_RADIO_SX1262 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_TBEAM_USE_RADIO_SX1276)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
SX1276 radio = new Module(18, 26, 23, 33);
|
||||
|
||||
|
||||
// Heltec
|
||||
#elif defined(ARDUINO_HELTEC_WIFI_LORA_32)
|
||||
#pragma error ("ARDUINO_HELTEC_WIFI_LORA_32 awaiting pin map")
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V2)
|
||||
#pragma message ("ARDUINO_heltec_wifi_kit_32_V2 awaiting pin map")
|
||||
SX1276 radio = new Module(18, 26, 14, 35);
|
||||
|
||||
#elif defined(ARDUINO_heltec_wifi_kit_32_V3)
|
||||
#pragma message ("Using Heltec WiFi LoRa32 v3 - Display + USB-C")
|
||||
SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD)
|
||||
#pragma message ("Using TTGO LoRa32 v2.1 marked T3_V1.6.1 + Display")
|
||||
SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
|
||||
|
||||
#elif defined(ARDUINO_CUBECELL_BOARD_V2)
|
||||
#pragma error ("ARDUINO_CUBECELL_BOARD_V2 awaiting pin map")
|
||||
|
||||
|
||||
#else
|
||||
#pragma message ("Unknown board - no automagic pinmap available")
|
||||
|
||||
// SX1262 pin order: Module(NSS/CS, DIO1, RESET, BUSY);
|
||||
// SX1262 radio = new Module(8, 14, 12, 13);
|
||||
|
||||
// SX1278 pin order: Module(NSS/CS, DIO0, RESET, DIO1);
|
||||
// SX1278 radio = new Module(10, 2, 9, 3);
|
||||
|
||||
#endif
|
||||
|
||||
// copy over the EUI's & keys in to the something that will not compile if incorrectly formatted
|
||||
uint64_t joinEUI = RADIOLIB_LORAWAN_JOIN_EUI;
|
||||
uint64_t devEUI = RADIOLIB_LORAWAN_DEV_EUI;
|
||||
uint8_t appKey[] = { RADIOLIB_LORAWAN_APP_KEY };
|
||||
uint8_t nwkKey[] = { RADIOLIB_LORAWAN_NWK_KEY };
|
||||
|
||||
// create the LoRaWAN node
|
||||
LoRaWANNode node(&radio, &Region, subBand);
|
||||
|
||||
// helper function to display any issues
|
||||
void debug(bool isFail, const __FlashStringHelper* message, int state, bool Freeze) {
|
||||
if (isFail) {
|
||||
Serial.print(message);
|
||||
Serial.print("(");
|
||||
Serial.print(state);
|
||||
Serial.println(")");
|
||||
while (Freeze);
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to display a byte array
|
||||
void arrayDump(uint8_t *buffer, uint16_t len) {
|
||||
for(uint16_t c = 0; c < len; c++) {
|
||||
char b = buffer[c];
|
||||
if(b < 0x10) { Serial.print('0'); }
|
||||
Serial.print(b, HEX);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
#endif
|
||||
200
lib/RadioLib/examples/LoRaWAN/LoRaWAN_Starter/notes.md
Normal file
200
lib/RadioLib/examples/LoRaWAN/LoRaWAN_Starter/notes.md
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
|
||||
|
||||
# RadioLib LoRaWAN on TTN starter script
|
||||
|
||||
## Welcome
|
||||
|
||||
These notes are for someone who has successfully created a few sketches for their Arduino based device but is starting out with LoRaWAN. You don't have to be a C coding ninja but some familarity with C and procedural programming is assumed. The absolutely simplest way to get started is to buy some known good hardware that's all done for you so you can concentrate on the code & configuration.
|
||||
|
||||
|
||||
## Introduction
|
||||
|
||||
LoRaWAN is an amazing system for small battery powered sensors collecting data for years at a time. With great features comes some more complex elements which means it is not quite as simple as just providing WiFi credentials and pushing data through. It is in the range of setting up & customising the settings for a home router but with no wizards to do the heavy lifting for you. So we strongly recommend spending a couple of hours reviewing the TTN Getting Started section so you are aware of the minimum knowledge to make a successful start: https://www.thethingsnetwork.org/docs/lorawan/. Johan's video is amazing but is also drinking from the firehose. Read the text first and then watch the video on Youtube where there are bookmarks to deliver it in small digestable chunks.
|
||||
|
||||
These notes plus a lot more are available in the wiki: https://github.com/jgromes/RadioLib/wiki/LoRaWAN
|
||||
|
||||
For questions about using RadioLib there is the discussions section (https://github.com/jgromes/RadioLib/discussions) and if you believe you've found an issue (aka bug), the issues section (https://github.com/jgromes/RadioLib/issues). If posting an issue please ensure you tell us what hardware you are using and provide a debug log - make sure you enable `RADIOLIB_DEBUG_PROTOCOL`. If the question is more LoRaWAN or firmware related, then you can use the TTN forum: https://www.thethingsnetwork.org/forum/
|
||||
|
||||
|
||||
## Register & setup on TTN
|
||||
|
||||
This sketch isn't particularly aimed at The Things Stack (TTS) but you can get a free Sandbox account and the following instructions are for that. Helium does not support LoRaWAN v1.1 which is the version implemented by RadioLib. Chirpstack & other LoRaWAN Network Server (LNS) stacks have not yet been tried so YMMV.
|
||||
|
||||
Why no screen shots? TTS is a web based app, one that you will need to become familiar with and we will need to direct you to some of the less obvious parts. So much better that you learn the layouts in concept than slavishly follow screen shots that can & will go stale.
|
||||
|
||||
There will be some instructions that you have to take on face value. You didn't learn to run before you walked and it's so much more encouraging to get started and build on success than get bogged down in endless details. Once you are up & running more of the details start to slot in to place.
|
||||
|
||||
### Register on TTN
|
||||
|
||||
Go to https://www.thethingsnetwork.org/get-started and register - just like any other website. These instructions are for TTS Sandbox.
|
||||
|
||||
Once you have confirmed your email address, you can login to the console here: https://console.cloud.thethings.network/. If you allow your browser to share your location the best console will be selected. For most users the best one is the obvious one, if you have any doubts you can ask on the forum here: https://www.thethingsnetwork.org/forum/ - you login with the exact same details.
|
||||
|
||||
It is simpler to register your gateway first. If you don't have a gateway, then a The Things Indoor Gateway (TTIG) is a very affordable option. A gateway gives you a console to see if your device is being heard and is hugely useful when debugging a DIY device. If you are in range of a community gateway you may be lucky with your first device creation but you will never know if you are in range unless you have access to that gateway's console.
|
||||
|
||||
You can read up on key concepts and troubleshooting here: https://www.thethingsindustries.com/docs/gateways/
|
||||
|
||||
LoRa stands for Long Range - having the gateway & device on the same desk tends to overload both receiver circuits when they hear a transmission so close to hand. The gateway should be 5 - 10m away, preferably with a solid wall in the way as well.
|
||||
|
||||
### Create your application
|
||||
|
||||
An application is like a box to keep some devices in - normally doing the same thing - on larger deployments this may be 1,000's of similar devices. Starting out it is likely to be just a few so there is no need to get concerned about how to divide up your use just yet.
|
||||
|
||||
Onced logged in to the console you can go in to Applications to create your first application. The ID must be all lower case or numbers, no spaces, dashes are OK and it has to be unique to the entire TTN community - so `first-app` will be rejected - you could use `your-username-first-app` as that's likely to be unique. The name and description are for your own use and are optional.
|
||||
|
||||
The main menu for an application is in the left hand panel - nothing is needed there just yet.
|
||||
|
||||
### Create your device
|
||||
|
||||
On the right hand side about half way down on your application's summary is a big blue button `+ Register end device`. Click this to create the settings for your first device.
|
||||
|
||||
You are making your own device using a third party LoRaWAN stack so there will not be an entry in the device repository so choose 'Enter end device specifics manually'.
|
||||
|
||||
Choose the Frequency plan appropriate for your region. Consider that almost all countries have laws relating to what frequencies you use so don't get creative. For Europe please use the recommended option. For other regions use the entry marked 'used by TTN'.
|
||||
|
||||
Choose LoRaWAN 1.1.0 - the last one in the list - the latest specfication. RadioLib uses RP001 Regional Parameters 1.1 revision A.
|
||||
|
||||
At this point you will be asked for your JoinEUI. As this is a DIY device and we are using RadioLib, you can use all zero's as recommended by The LoRa Alliance TR007 Technical Recommendations document. Once you've put in all zeros and clicked confirm you will be asked for a DevEUI, AppKey and NwkKey. It is preferable to have the console generate them so they are properly formatted.
|
||||
|
||||
Your End device ID can be changed to make the device more identifiable. Something related to your hardware helps - like devicename-01. The you can click the blue 'Register device'.
|
||||
|
||||
When many sensors are big deployed, a device is registered, batteries put in, it joins and gets on with sending data for the next few years. For development purposes we need to turn off one of the security settings so that you can join & uplink out of the normal sequence that a device in the field would do.
|
||||
|
||||
Click on General Settings, scroll down to Join settings, click the Expand button, scroll down and click the 'Resets join nonces' option. You will see a warning about replay attacks which is entirely proper & correct. If anyone eavesdropping in your area on your LoRa transmissions could fake a join and send uplinks from their device but only if they happened to find out your AppKey & NwkKey which is kept securely on the TTN servers and is never transmitted over the air, so they'd also have to login to your account, which is protected by your password.
|
||||
|
||||
You then need to copy over the device details in to the config file for RadioLib. There are buttons to copy items to the clipboard so you don't have to hand type them.
|
||||
|
||||
### Copy & Paste made easy
|
||||
|
||||
You can copy the EUIs & keys from the device overview section.
|
||||
|
||||
The EUIs are really straightforward - click the clipboard icon at the right hand end of the EUI display field and it will be copied in the format you need. You can then paste it in to the code - you must leave the 0x in place so the compiler knows that it's a hex value.
|
||||
|
||||
The keys are relatively straightforward. Click the eye icon at the right hand end of the field. Then click the <> icon that will appear to the left. This will format the hex values as an array. Then you can click the clipboard icon to copy the array and then paste it between the { } brackets.
|
||||
|
||||
### Secrets to keep safe.
|
||||
|
||||
The Join & Dev EUI's are transmitted in plain text when the device joins a network. The gateway ID is public. If you have an issue and are asked for details, there are only three things to keep private - your password, the keys which are used for encryption and any API keys you create which are used for accessing your data & configuration.
|
||||
|
||||
|
||||
### Monitoring your device
|
||||
|
||||
If you are on your application summary page you'll see uplinks in the small activity box top right with a link to the full size table. If you click the Live Data menu item on the left it will show activity for all the devices registered on the application in the full window.
|
||||
|
||||
If you just want your devices activity, from the summary page click on the device in the list in the middle of the page.
|
||||
|
||||
The main menu for a device is the horizontal band: Overview, Live Data, Messaging etc. You can click Live Data or the link above the small activity box.
|
||||
|
||||
**The console shows LIVE data - not a history of everything that has ever happened. A LNS is a management & relay service, not a database. When you open the console you may see a summary of recent activity - this is a bonus. You must leave the console open, even in another tab, if you want to see live activity.**
|
||||
|
||||
|
||||
### Explore
|
||||
|
||||
Nothing on the console can be upset unless you confirm a warning message, so you are safe to explore the different menus to orientate yourself. This is very good idea so you have an understanding of the layout of the land and shouldn't take more than 10 or 15 minutes. The documentation & volunteers on GitHub and the TTN forum will make refer to parts of the console without giving blow by blow directions.
|
||||
|
||||
|
||||
|
||||
|
||||
## The config.h
|
||||
|
||||
### The uplinkInterval
|
||||
|
||||
LoRaWAN devices typically send small amounts of data at intervals between 15 minutes through to once per day. This allows a device to run on two AA batteries for 2 to 5 years. Hoping that LoRaWAN can move lots of data and your device can regularly receive commands to do something on demand is trying to bend the LoRaWAN system in ways it is not designed for and usually ends up with far too many issues to unravel.
|
||||
|
||||
The radio frequencies that are used are usually shared with other Industrial, Scientific & Medical, known as ISM, users. The LoRa modulation is particularly resistant to interference due to other simultaneous transmissions on the same frequency but too much local activity will mean that not all uplinks get through. The Things Industries suggest designing a system to a potential packet loss rate of 10%. Typically we see 1 or 2% loss. This is entirely down to shared use of the radio waves, once an uplink is heard by a gateway the system is super reliable through The Things Stack.
|
||||
|
||||
To ensure that the shared ISM bands are fairly used there are limits defined in law on how often you can transmit, called Duty Cycle. The details vary by region or country but typically you can only transmit for 1% of the time. Some frequencies you can only use 0.1% of the time. See https://www.thethingsnetwork.org/docs/lorawan/duty-cycle/ for more information.
|
||||
|
||||
Additionally, as The Things Stack Sandbox aka TTN is an array of servers in three locations around the world paid for by The Things Industries, there is a Fair Use Policy so that those learning LoRaWAN, communities, hobbyists & makers are guided on how much of the resource any one device can use. In short, it's 30 seconds of airtime a day and 10 downlinks. When a gateway is transmitting a downlink it can not hear any uplinks (contributing to the potential uplink loss outlined above). The community consensus is that 1 downlink a fortnight to update or adjust settings is appropriate. See https://www.thethingsnetwork.org/docs/lorawan/duty-cycle/#fair-use-policy for more information.
|
||||
|
||||
You can see what intervals can be used with this interactive calculator: https://avbentem.github.io/airtime-calculator/ttn/. Devices further away from gateways will have to use a higher Spread Factor to be heard - do not assume everything will happen at SF7. An uplink takes a minimum of 6 seconds from start to end, sometimes longer if the device is further away from the gateway, so you will need to be patient for just a short while whilst waiting for feedback after seeing "Sending uplink"
|
||||
|
||||
With all these considerations, trying to use LoRaWAN for command & control isn't appropriate and realtime GPS tracking almost always breaches FUP and usually legal limits, leaving aside the challenges of coverage.
|
||||
|
||||
See the hints & tips section on testing your device.
|
||||
|
||||
|
||||
### EUI's & Keys
|
||||
|
||||
In the `config.h` towards the top there are four lines thus:
|
||||
|
||||
// replace-with-your-device-id
|
||||
uint64_t joinEUI = 0x0000000000000000;
|
||||
uint64_t devEUI = 0x0000000000000000;
|
||||
uint8_t appKey[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
uint8_t nwkKey[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
On the TTN console on the device summary page, click the clipboard icon next to the DevEUI, highlight the 16 0's in the third line after the x and paste.
|
||||
|
||||
The devEUI must start with 0x and will end up looking something like 0x70B3D57ED006544E
|
||||
|
||||
For the appKey we need TTN to format it correctly. Click the eye icon and an extra icon will appear <> - click this and the key will be formatted for you. Click the clipboard icon and then paste over the 32 0x00's in the config file. Then do the same for nwkKey.
|
||||
|
||||
A key will end up something like 0x31, 0x16, 0x6A, 0x22, 0x97, 0x52, 0xB6, 0x34, 0x57, 0x45, 0x1B, 0xC3, 0xC9, 0xD8, 0x83, 0xE8
|
||||
|
||||
|
||||
### Region
|
||||
|
||||
The region value you use MUST match the one you selected on the console.
|
||||
|
||||
If you are using US915 or AU915 then you should change the subBand const to 2.
|
||||
|
||||
### The pinmap
|
||||
|
||||
This is the connection between the MCU (ESP32/ATmega/SAMD) and the LoRa radio (SX1276/SX1262).
|
||||
|
||||
Prebuilt modules are easy - we can detect the board and setup the pinmap for you. These boards are:
|
||||
|
||||
* TTGO_LoRa32
|
||||
* TTGO_LoRa32_V1
|
||||
* TTGO_LORA32_V2
|
||||
* TTGO_LORA32_v21NEW
|
||||
* HELTEC_WIFI_LORA_32
|
||||
* HELTEC_WIFI_LORA_32_V2
|
||||
* HELTEC_WIFI_LORA_32_V3
|
||||
|
||||
If you have a TTGO T-Beam, you must choose the correct radio from the Board Revision sub-menu found under the main Tools menu.
|
||||
|
||||
* TBEAM_USE_RADIO_SX1262
|
||||
* TBEAM_USE_RADIO_SX1276
|
||||
|
||||
Auto-setup for the Adafruit Feather M0 with RFM95 is included but you must solder a wire or use a jumper to link from pin 6 to io1: https://learn.adafruit.com/the-things-network-for-feather/arduino-wiring
|
||||
|
||||
If you have a module that's not on this list, please go to the "Pinmap How-To" below.
|
||||
|
||||
|
||||
|
||||
## Observations on the main sketch
|
||||
|
||||
Most of the sketch has comments that tell you what the various parts are doing. This should add a little more info:
|
||||
|
||||
### The Join
|
||||
|
||||
When a device is first started, it needs to register with the LoRaWAN Network Server (LNS) and setup it's session. With the settings from the console copied over and a gateway an appropriate distance away, most of the time the join will 'just work'.
|
||||
|
||||
If it doesn't, then there is no point trying repeatedly without going through the troubleshootng sequence. So this starter sketch will try once only to save the airwaves & TTN Community servers from repeated misfires.
|
||||
|
||||
|
||||
### The payload
|
||||
|
||||
You may see other starter sketches sending text. Apart from being massively inefficient, the text isn't easily displayed on the TTN console which makes it rather pointless and pro embedded engineers don't send strings. So this sketch sends the data as a sequence of bytes as recommended.
|
||||
|
||||
Further reading on this can be found here, just ignore the pink message about v2, it's all still valid: https://www.thethingsnetwork.org/docs/devices/bytes/
|
||||
|
||||
We've not assumed anything about any sensors you have, so we are just reading a digital & an analog pin. An analog reading is typically a two byte value - an integer - this is split using the Arduino highByte & lowByte function. You'll see how we put it back together in the TTN console below.
|
||||
|
||||
|
||||
## TTN Console Payload Decoder
|
||||
|
||||
Coming soon
|
||||
|
||||
## Hints & Tips
|
||||
|
||||
### Device testing
|
||||
|
||||
The LoRaWAN code base works to a specification and once you are happy your device is able to join & send a few dozen uplinks, continuing to sit around waiting for an uplink to test your sensor code & payload format is a waste of your time. The solution is to write everything else in a different sketch, output the array to the serial console and then you can copy & paste the hex array in to the TTN console Payload Formatters section to test the decoding.
|
||||
|
||||
|
||||
## Pinmap How-To
|
||||
|
||||
Coming soon
|
||||
18
lib/RadioLib/examples/LoRaWAN/README.md
Normal file
18
lib/RadioLib/examples/LoRaWAN/README.md
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# LoRaWAN examples
|
||||
RadioLib LoRaWAN v1.1 examples.
|
||||
|
||||
* [LoRaWAN_Starter](https://github.com/jgromes/RadioLib/tree/master/examples/LoRaWAN/LoRaWAN_Starter): this is the recommended entry point for new users. Please read the `notes` that come with this example to learn more about LoRaWAN and how to use it in RadioLib!
|
||||
* [LoRaWAN_Reference](https://github.com/jgromes/RadioLib/tree/master/examples/LoRaWAN/LoRaWAN_Reference): this sketch showcases most of the available API for LoRaWAN in RadioLib. Be frightened by the possibilities! It is recommended you have read all the `notes` for the Starter sketch first, as well as the [Learn section on The Things Network](https://www.thethingsnetwork.org/docs/lorawan/)!
|
||||
* [LoRaWAN_ABP](https://github.com/jgromes/RadioLib/tree/master/examples/LoRaWAN/LoRaWAN_ABP): if you wish to use ABP instead of OTAA (but why?), this example shows how you can do this using RadioLib.
|
||||
|
||||
---
|
||||
|
||||
All three of these examples do not fully comply with LoRaWAN v1.1: for that, persistent storage is necessary. As the implementation of persistent storage differs between different platforms, these are not given here, but in a separate repository, see below:
|
||||
|
||||
## RadioLib persistence
|
||||
In [this repository](https://github.com/radiolib-org/radiolib-persistence), examples are provided that do comply with the required persistence of certain parameters for LoRaWAN v1.1. Examples are (or will become) available for some of the most popular platforms. **These examples assume you have successfully used the Starter sketch and understood (most of) the accompanying notes!**
|
||||
Currently, examples are available for the following platforms:
|
||||
|
||||
* [LoRaWAN for ESP32](https://github.com/radiolib-org/radiolib-persistence/tree/main/examples/LoRaWAN_ESP32)
|
||||
|
||||
_This list is last updated for RadioLib 6.5.0_
|
||||
7
lib/RadioLib/examples/NonArduino/ESP-IDF/CMakeLists.txt
Normal file
7
lib/RadioLib/examples/NonArduino/ESP-IDF/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# include the top-level cmake
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
# name the project something nice
|
||||
project(esp-sx1261)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# register the component and set "RadioLib", "esp_timer" and "driver" as required
|
||||
idf_component_register(SRCS "main.cpp"
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES RadioLib esp_timer driver)
|
||||
322
lib/RadioLib/examples/NonArduino/ESP-IDF/main/EspHal.h
Normal file
322
lib/RadioLib/examples/NonArduino/ESP-IDF/main/EspHal.h
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
#ifndef ESP_HAL_H
|
||||
#define ESP_HAL_H
|
||||
|
||||
// include RadioLib
|
||||
#include <RadioLib.h>
|
||||
|
||||
// this example only works on ESP32 and is unlikely to work on ESP32S2/S3 etc.
|
||||
// if you need high portability, you should probably use Arduino anyway ...
|
||||
#if CONFIG_IDF_TARGET_ESP32 == 0
|
||||
#error Target is not ESP32!
|
||||
#endif
|
||||
|
||||
// include all the dependencies
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp32/rom/gpio.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/dport_reg.h"
|
||||
#include "soc/spi_reg.h"
|
||||
#include "soc/spi_struct.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "hal/gpio_hal.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
// define Arduino-style macros
|
||||
#define LOW (0x0)
|
||||
#define HIGH (0x1)
|
||||
#define INPUT (0x01)
|
||||
#define OUTPUT (0x03)
|
||||
#define RISING (0x01)
|
||||
#define FALLING (0x02)
|
||||
#define NOP() asm volatile ("nop")
|
||||
|
||||
#define MATRIX_DETACH_OUT_SIG (0x100)
|
||||
#define MATRIX_DETACH_IN_LOW_PIN (0x30)
|
||||
|
||||
// all of the following is needed to calculate SPI clock divider
|
||||
#define ClkRegToFreq(reg) (apb_freq / (((reg)->clkdiv_pre + 1) * ((reg)->clkcnt_n + 1)))
|
||||
|
||||
typedef union {
|
||||
uint32_t value;
|
||||
struct {
|
||||
uint32_t clkcnt_l: 6;
|
||||
uint32_t clkcnt_h: 6;
|
||||
uint32_t clkcnt_n: 6;
|
||||
uint32_t clkdiv_pre: 13;
|
||||
uint32_t clk_equ_sysclk: 1;
|
||||
};
|
||||
} spiClk_t;
|
||||
|
||||
uint32_t getApbFrequency() {
|
||||
rtc_cpu_freq_config_t conf;
|
||||
rtc_clk_cpu_freq_get_config(&conf);
|
||||
|
||||
if(conf.freq_mhz >= 80) {
|
||||
return(80 * MHZ);
|
||||
}
|
||||
|
||||
return((conf.source_freq_mhz * MHZ) / conf.div);
|
||||
}
|
||||
|
||||
uint32_t spiFrequencyToClockDiv(uint32_t freq) {
|
||||
uint32_t apb_freq = getApbFrequency();
|
||||
if(freq >= apb_freq) {
|
||||
return SPI_CLK_EQU_SYSCLK;
|
||||
}
|
||||
|
||||
const spiClk_t minFreqReg = { 0x7FFFF000 };
|
||||
uint32_t minFreq = ClkRegToFreq((spiClk_t*) &minFreqReg);
|
||||
if(freq < minFreq) {
|
||||
return minFreqReg.value;
|
||||
}
|
||||
|
||||
uint8_t calN = 1;
|
||||
spiClk_t bestReg = { 0 };
|
||||
int32_t bestFreq = 0;
|
||||
while(calN <= 0x3F) {
|
||||
spiClk_t reg = { 0 };
|
||||
int32_t calFreq;
|
||||
int32_t calPre;
|
||||
int8_t calPreVari = -2;
|
||||
|
||||
reg.clkcnt_n = calN;
|
||||
|
||||
while(calPreVari++ <= 1) {
|
||||
calPre = (((apb_freq / (reg.clkcnt_n + 1)) / freq) - 1) + calPreVari;
|
||||
if(calPre > 0x1FFF) {
|
||||
reg.clkdiv_pre = 0x1FFF;
|
||||
} else if(calPre <= 0) {
|
||||
reg.clkdiv_pre = 0;
|
||||
} else {
|
||||
reg.clkdiv_pre = calPre;
|
||||
}
|
||||
reg.clkcnt_l = ((reg.clkcnt_n + 1) / 2);
|
||||
calFreq = ClkRegToFreq(®);
|
||||
if(calFreq == (int32_t) freq) {
|
||||
memcpy(&bestReg, ®, sizeof(bestReg));
|
||||
break;
|
||||
} else if(calFreq < (int32_t) freq) {
|
||||
if(RADIOLIB_ABS(freq - calFreq) < RADIOLIB_ABS(freq - bestFreq)) {
|
||||
bestFreq = calFreq;
|
||||
memcpy(&bestReg, ®, sizeof(bestReg));
|
||||
}
|
||||
}
|
||||
}
|
||||
if(calFreq == (int32_t) freq) {
|
||||
break;
|
||||
}
|
||||
calN++;
|
||||
}
|
||||
return(bestReg.value);
|
||||
}
|
||||
|
||||
// create a new ESP-IDF hardware abstraction layer
|
||||
// the HAL must inherit from the base RadioLibHal class
|
||||
// and implement all of its virtual methods
|
||||
// this is pretty much just copied from Arduino ESP32 core
|
||||
class EspHal : public RadioLibHal {
|
||||
public:
|
||||
// default constructor - initializes the base HAL and any needed private members
|
||||
EspHal(int8_t sck, int8_t miso, int8_t mosi)
|
||||
: RadioLibHal(INPUT, OUTPUT, LOW, HIGH, RISING, FALLING),
|
||||
spiSCK(sck), spiMISO(miso), spiMOSI(mosi) {
|
||||
}
|
||||
|
||||
void init() override {
|
||||
// we only need to init the SPI here
|
||||
spiBegin();
|
||||
}
|
||||
|
||||
void term() override {
|
||||
// we only need to stop the SPI here
|
||||
spiEnd();
|
||||
}
|
||||
|
||||
// GPIO-related methods (pinMode, digitalWrite etc.) should check
|
||||
// RADIOLIB_NC as an alias for non-connected pins
|
||||
void pinMode(uint32_t pin, uint32_t mode) override {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_hal_context_t gpiohal;
|
||||
gpiohal.dev = GPIO_LL_GET_HW(GPIO_PORT_0);
|
||||
|
||||
gpio_config_t conf = {
|
||||
.pin_bit_mask = (1ULL<<pin),
|
||||
.mode = (gpio_mode_t)mode,
|
||||
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||
.intr_type = (gpio_int_type_t)gpiohal.dev->pin[pin].int_type,
|
||||
};
|
||||
gpio_config(&conf);
|
||||
}
|
||||
|
||||
void digitalWrite(uint32_t pin, uint32_t value) override {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_set_level((gpio_num_t)pin, value);
|
||||
}
|
||||
|
||||
uint32_t digitalRead(uint32_t pin) override {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(gpio_get_level((gpio_num_t)pin));
|
||||
}
|
||||
|
||||
void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override {
|
||||
if(interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_install_isr_service((int)ESP_INTR_FLAG_IRAM);
|
||||
gpio_set_intr_type((gpio_num_t)interruptNum, (gpio_int_type_t)(mode & 0x7));
|
||||
|
||||
// this uses function typecasting, which is not defined when the functions have different signatures
|
||||
// untested and might not work
|
||||
gpio_isr_handler_add((gpio_num_t)interruptNum, (void (*)(void*))interruptCb, NULL);
|
||||
}
|
||||
|
||||
void detachInterrupt(uint32_t interruptNum) override {
|
||||
if(interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_isr_handler_remove((gpio_num_t)interruptNum);
|
||||
gpio_wakeup_disable((gpio_num_t)interruptNum);
|
||||
gpio_set_intr_type((gpio_num_t)interruptNum, GPIO_INTR_DISABLE);
|
||||
}
|
||||
|
||||
void delay(unsigned long ms) override {
|
||||
vTaskDelay(ms / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
void delayMicroseconds(unsigned long us) override {
|
||||
uint64_t m = (uint64_t)esp_timer_get_time();
|
||||
if(us) {
|
||||
uint64_t e = (m + us);
|
||||
if(m > e) { // overflow
|
||||
while((uint64_t)esp_timer_get_time() > e) {
|
||||
NOP();
|
||||
}
|
||||
}
|
||||
while((uint64_t)esp_timer_get_time() < e) {
|
||||
NOP();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long millis() override {
|
||||
return((unsigned long)(esp_timer_get_time() / 1000ULL));
|
||||
}
|
||||
|
||||
unsigned long micros() override {
|
||||
return((unsigned long)(esp_timer_get_time()));
|
||||
}
|
||||
|
||||
long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) override {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
this->pinMode(pin, INPUT);
|
||||
uint32_t start = this->micros();
|
||||
uint32_t curtick = this->micros();
|
||||
|
||||
while(this->digitalRead(pin) == state) {
|
||||
if((this->micros() - curtick) > timeout) {
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
return(this->micros() - start);
|
||||
}
|
||||
|
||||
void spiBegin() {
|
||||
// enable peripheral
|
||||
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_SPI2_CLK_EN);
|
||||
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI2_RST);
|
||||
|
||||
// reset the control struct
|
||||
this->spi->slave.trans_done = 0;
|
||||
this->spi->slave.val = 0;
|
||||
this->spi->pin.val = 0;
|
||||
this->spi->user.val = 0;
|
||||
this->spi->user1.val = 0;
|
||||
this->spi->ctrl.val = 0;
|
||||
this->spi->ctrl1.val = 0;
|
||||
this->spi->ctrl2.val = 0;
|
||||
this->spi->clock.val = 0;
|
||||
this->spi->user.usr_mosi = 1;
|
||||
this->spi->user.usr_miso = 1;
|
||||
this->spi->user.doutdin = 1;
|
||||
for(uint8_t i = 0; i < 16; i++) {
|
||||
this->spi->data_buf[i] = 0x00000000;
|
||||
}
|
||||
|
||||
// set SPI mode 0
|
||||
this->spi->pin.ck_idle_edge = 0;
|
||||
this->spi->user.ck_out_edge = 0;
|
||||
|
||||
// set bit order to MSB first
|
||||
this->spi->ctrl.wr_bit_order = 0;
|
||||
this->spi->ctrl.rd_bit_order = 0;
|
||||
|
||||
// set the clock
|
||||
this->spi->clock.val = spiFrequencyToClockDiv(2000000);
|
||||
|
||||
// initialize pins
|
||||
this->pinMode(this->spiSCK, OUTPUT);
|
||||
this->pinMode(this->spiMISO, INPUT);
|
||||
this->pinMode(this->spiMOSI, OUTPUT);
|
||||
gpio_matrix_out(this->spiSCK, HSPICLK_OUT_IDX, false, false);
|
||||
gpio_matrix_in(this->spiMISO, HSPIQ_OUT_IDX, false);
|
||||
gpio_matrix_out(this->spiMOSI, HSPID_IN_IDX, false, false);
|
||||
}
|
||||
|
||||
void spiBeginTransaction() {
|
||||
// not needed - in ESP32 Arduino core, this function
|
||||
// repeats clock div, mode and bit order configuration
|
||||
}
|
||||
|
||||
uint8_t spiTransferByte(uint8_t b) {
|
||||
this->spi->mosi_dlen.usr_mosi_dbitlen = 7;
|
||||
this->spi->miso_dlen.usr_miso_dbitlen = 7;
|
||||
this->spi->data_buf[0] = b;
|
||||
this->spi->cmd.usr = 1;
|
||||
while(this->spi->cmd.usr);
|
||||
return(this->spi->data_buf[0] & 0xFF);
|
||||
}
|
||||
|
||||
void spiTransfer(uint8_t* out, size_t len, uint8_t* in) {
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
in[i] = this->spiTransferByte(out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void spiEndTransaction() {
|
||||
// nothing needs to be done here
|
||||
}
|
||||
|
||||
void spiEnd() {
|
||||
// detach pins
|
||||
gpio_matrix_out(this->spiSCK, MATRIX_DETACH_OUT_SIG, false, false);
|
||||
gpio_matrix_in(this->spiMISO, MATRIX_DETACH_IN_LOW_PIN, false);
|
||||
gpio_matrix_out(this->spiMOSI, MATRIX_DETACH_OUT_SIG, false, false);
|
||||
}
|
||||
|
||||
private:
|
||||
// the HAL can contain any additional private members
|
||||
int8_t spiSCK;
|
||||
int8_t spiMISO;
|
||||
int8_t spiMOSI;
|
||||
spi_dev_t * spi = (volatile spi_dev_t *)(DR_REG_SPI2_BASE);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
dependencies:
|
||||
RadioLib:
|
||||
# referenced locally because the example is a part of the repository itself
|
||||
# under normal circumstances, it's preferrable to reference the repository instead
|
||||
# for other options, see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html
|
||||
path: ../../../../../RadioLib
|
||||
#git: https://github.com/jgromes/RadioLib.git
|
||||
67
lib/RadioLib/examples/NonArduino/ESP-IDF/main/main.cpp
Normal file
67
lib/RadioLib/examples/NonArduino/ESP-IDF/main/main.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
RadioLib Non-Arduino ESP-IDF Example
|
||||
|
||||
This example shows how to use RadioLib without Arduino.
|
||||
In this case, a Liligo T-BEAM (ESP32 and SX1276)
|
||||
is used.
|
||||
|
||||
Can be used as a starting point to port RadioLib to any platform!
|
||||
See this API reference page for details on the RadioLib hardware abstraction
|
||||
https://jgromes.github.io/RadioLib/class_hal.html
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
#include <RadioLib.h>
|
||||
|
||||
// include the hardware abstraction layer
|
||||
#include "EspHal.h"
|
||||
|
||||
// create a new instance of the HAL class
|
||||
EspHal* hal = new EspHal(5, 19, 27);
|
||||
|
||||
// now we can create the radio module
|
||||
// NSS pin: 18
|
||||
// DIO0 pin: 26
|
||||
// NRST pin: 14
|
||||
// DIO1 pin: 33
|
||||
SX1276 radio = new Module(hal, 18, 26, 14, 33);
|
||||
|
||||
static const char *TAG = "main";
|
||||
|
||||
// the entry point for the program
|
||||
// it must be declared as "extern C" because the compiler assumes this will be a C function
|
||||
extern "C" void app_main(void) {
|
||||
// initialize just like with Arduino
|
||||
ESP_LOGI(TAG, "[SX1276] Initializing ... ");
|
||||
int state = radio.begin();
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
ESP_LOGI(TAG, "failed, code %d\n", state);
|
||||
while(true) {
|
||||
hal->delay(1000);
|
||||
}
|
||||
}
|
||||
ESP_LOGI(TAG, "success!\n");
|
||||
|
||||
// loop forever
|
||||
for(;;) {
|
||||
// send a packet
|
||||
ESP_LOGI(TAG, "[SX1276] Transmitting packet ... ");
|
||||
state = radio.transmit("Hello World!");
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
// the packet was successfully transmitted
|
||||
ESP_LOGI(TAG, "success!");
|
||||
|
||||
} else {
|
||||
ESP_LOGI(TAG, "failed, code %d\n", state);
|
||||
|
||||
}
|
||||
|
||||
// wait for a second before transmitting again
|
||||
hal->delay(1000);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
1669
lib/RadioLib/examples/NonArduino/ESP-IDF/sdkconfig
Normal file
1669
lib/RadioLib/examples/NonArduino/ESP-IDF/sdkconfig
Normal file
File diff suppressed because it is too large
Load diff
33
lib/RadioLib/examples/NonArduino/Pico/CMakeLists.txt
Normal file
33
lib/RadioLib/examples/NonArduino/Pico/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
cmake_minimum_required(VERSION 3.18)
|
||||
|
||||
# Pull in SDK (must be before project)
|
||||
include(pico_sdk_import.cmake)
|
||||
|
||||
project(pico-sx1276 C CXX ASM)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Initialize the SDK
|
||||
pico_sdk_init()
|
||||
|
||||
add_compile_options(
|
||||
-Wall
|
||||
-Wno-format
|
||||
-Wno-unused-function
|
||||
)
|
||||
|
||||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../../../RadioLib" "${CMAKE_CURRENT_BINARY_DIR}/RadioLib")
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
main.cpp
|
||||
)
|
||||
|
||||
# Pull in common dependencies
|
||||
target_link_libraries(${PROJECT_NAME} pico_stdlib hardware_spi hardware_gpio hardware_timer RadioLib)
|
||||
|
||||
|
||||
pico_enable_stdio_usb(${PROJECT_NAME} 1)
|
||||
pico_enable_stdio_uart(${PROJECT_NAME} 0)
|
||||
|
||||
# Create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(${PROJECT_NAME})
|
||||
143
lib/RadioLib/examples/NonArduino/Pico/PicoHal.h
Normal file
143
lib/RadioLib/examples/NonArduino/Pico/PicoHal.h
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
#ifndef PICO_HAL_H
|
||||
#define PICO_HAL_H
|
||||
|
||||
// include RadioLib
|
||||
#include <RadioLib.h>
|
||||
|
||||
// include the necessary Pico libraries
|
||||
#include <pico/stdlib.h>
|
||||
#include "hardware/spi.h"
|
||||
#include "hardware/timer.h"
|
||||
|
||||
// create a new Raspberry Pi Pico hardware abstraction
|
||||
// layer using the Pico SDK
|
||||
// the HAL must inherit from the base RadioLibHal class
|
||||
// and implement all of its virtual methods
|
||||
class PicoHal : public RadioLibHal {
|
||||
public:
|
||||
PicoHal(spi_inst_t *spiChannel, uint32_t misoPin, uint32_t mosiPin, uint32_t sckPin, uint32_t spiSpeed = 500 * 1000)
|
||||
: RadioLibHal(GPIO_IN, GPIO_OUT, 0, 1, GPIO_IRQ_EDGE_RISE, GPIO_IRQ_EDGE_FALL),
|
||||
_spiChannel(spiChannel),
|
||||
_spiSpeed(spiSpeed),
|
||||
_misoPin(misoPin),
|
||||
_mosiPin(mosiPin),
|
||||
_sckPin(sckPin) {
|
||||
}
|
||||
|
||||
void init() override {
|
||||
stdio_init_all();
|
||||
spiBegin();
|
||||
}
|
||||
|
||||
void term() override {
|
||||
spiEnd();
|
||||
}
|
||||
|
||||
// GPIO-related methods (pinMode, digitalWrite etc.) should check
|
||||
// RADIOLIB_NC as an alias for non-connected pins
|
||||
void pinMode(uint32_t pin, uint32_t mode) override {
|
||||
if (pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_init(pin);
|
||||
gpio_set_dir(pin, mode);
|
||||
}
|
||||
|
||||
void digitalWrite(uint32_t pin, uint32_t value) override {
|
||||
if (pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_put(pin, (bool)value);
|
||||
}
|
||||
|
||||
uint32_t digitalRead(uint32_t pin) override {
|
||||
if (pin == RADIOLIB_NC) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return gpio_get(pin);
|
||||
}
|
||||
|
||||
void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override {
|
||||
if (interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_set_irq_enabled_with_callback(interruptNum, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true, (gpio_irq_callback_t)interruptCb);
|
||||
}
|
||||
|
||||
void detachInterrupt(uint32_t interruptNum) override {
|
||||
if (interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_set_irq_enabled_with_callback(interruptNum, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, false, NULL);
|
||||
}
|
||||
|
||||
void delay(unsigned long ms) override {
|
||||
sleep_ms(ms);
|
||||
}
|
||||
|
||||
void delayMicroseconds(unsigned long us) override {
|
||||
sleep_us(us);
|
||||
}
|
||||
|
||||
unsigned long millis() override {
|
||||
return to_ms_since_boot(get_absolute_time());
|
||||
}
|
||||
|
||||
unsigned long micros() override {
|
||||
return to_us_since_boot(get_absolute_time());
|
||||
}
|
||||
|
||||
long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) override {
|
||||
if (pin == RADIOLIB_NC) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->pinMode(pin, GPIO_IN);
|
||||
uint32_t start = this->micros();
|
||||
uint32_t curtick = this->micros();
|
||||
|
||||
while (this->digitalRead(pin) == state) {
|
||||
if ((this->micros() - curtick) > timeout) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return (this->micros() - start);
|
||||
}
|
||||
|
||||
void spiBegin() {
|
||||
spi_init(_spiChannel, _spiSpeed);
|
||||
spi_set_format(_spiChannel, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
|
||||
|
||||
gpio_set_function(_sckPin, GPIO_FUNC_SPI);
|
||||
gpio_set_function(_mosiPin, GPIO_FUNC_SPI);
|
||||
gpio_set_function(_misoPin, GPIO_FUNC_SPI);
|
||||
}
|
||||
|
||||
void spiBeginTransaction() {}
|
||||
|
||||
void spiTransfer(uint8_t *out, size_t len, uint8_t *in) {
|
||||
spi_write_read_blocking(_spiChannel, out, in, len);
|
||||
}
|
||||
|
||||
void spiEndTransaction() {}
|
||||
|
||||
void spiEnd() {
|
||||
spi_deinit(_spiChannel);
|
||||
}
|
||||
|
||||
private:
|
||||
// the HAL can contain any additional private members
|
||||
spi_inst_t *_spiChannel;
|
||||
uint32_t _spiSpeed;
|
||||
uint32_t _misoPin;
|
||||
uint32_t _mosiPin;
|
||||
uint32_t _sckPin;
|
||||
};
|
||||
|
||||
#endif
|
||||
8
lib/RadioLib/examples/NonArduino/Pico/build.sh
Normal file
8
lib/RadioLib/examples/NonArduino/Pico/build.sh
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
cd ..
|
||||
3
lib/RadioLib/examples/NonArduino/Pico/clean.sh
Normal file
3
lib/RadioLib/examples/NonArduino/Pico/clean.sh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
rm -rf ./build
|
||||
86
lib/RadioLib/examples/NonArduino/Pico/main.cpp
Normal file
86
lib/RadioLib/examples/NonArduino/Pico/main.cpp
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
RadioLib Non-Arduino Raspberry Pi Pico library example
|
||||
|
||||
Licensed under the MIT License
|
||||
|
||||
Copyright (c) 2024 Cameron Goddard
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// define pins to be used
|
||||
#define SPI_PORT spi0
|
||||
#define SPI_MISO 4
|
||||
#define SPI_MOSI 3
|
||||
#define SPI_SCK 2
|
||||
|
||||
#define RFM_NSS 26
|
||||
#define RFM_RST 22
|
||||
#define RFM_DIO0 14
|
||||
#define RFM_DIO1 15
|
||||
|
||||
#include <pico/stdlib.h>
|
||||
|
||||
// include the library
|
||||
#include <RadioLib.h>
|
||||
|
||||
// include the hardware abstraction layer
|
||||
#include "PicoHal.h"
|
||||
|
||||
// create a new instance of the HAL class
|
||||
PicoHal* hal = new PicoHal(SPI_PORT, SPI_MISO, SPI_MOSI, SPI_SCK);
|
||||
|
||||
// now we can create the radio module
|
||||
// NSS pin: 26
|
||||
// DIO0 pin: 14
|
||||
// RESET pin: 22
|
||||
// DIO1 pin: 15
|
||||
SX1276 radio = new Module(hal, RFM_NSS, RFM_DIO0, RFM_RST, RFM_DIO1);
|
||||
|
||||
int main() {
|
||||
// initialize just like with Arduino
|
||||
printf("[SX1276] Initializing ... ");
|
||||
int state = radio.begin();
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
printf("failed, code %d\n", state);
|
||||
return(1);
|
||||
}
|
||||
printf("success!\n");
|
||||
|
||||
// loop forever
|
||||
for(;;) {
|
||||
// send a packet
|
||||
printf("[SX1276] Transmitting packet ... ");
|
||||
state = radio.transmit("Hello World!");
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
// the packet was successfully transmitted
|
||||
printf("success!\n");
|
||||
|
||||
// wait for a second before transmitting again
|
||||
hal->delay(1000);
|
||||
|
||||
} else {
|
||||
printf("failed, code %d\n", state);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
73
lib/RadioLib/examples/NonArduino/Pico/pico_sdk_import.cmake
Normal file
73
lib/RadioLib/examples/NonArduino/Pico/pico_sdk_import.cmake
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate this SDK
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
|
||||
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||
|
||||
if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT)
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
|
||||
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
# GIT_SUBMODULES_RECURSE was added in 3.17
|
||||
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
GIT_SUBMODULES_RECURSE FALSE
|
||||
)
|
||||
else ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (NOT pico_sdk)
|
||||
message("Downloading Raspberry Pi Pico SDK")
|
||||
FetchContent_Populate(pico_sdk)
|
||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS ${PICO_SDK_PATH})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
|
||||
|
||||
include(${PICO_SDK_INIT_CMAKE_FILE})
|
||||
|
|
@ -6,10 +6,10 @@ project(rpi-sx1261)
|
|||
# when using debuggers such as gdb, the following line can be used
|
||||
#set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
# if you did not build RadioLib as shared library (see README),
|
||||
# if you did not build RadioLib as shared library (see wiki),
|
||||
# you will have to add it as source directory
|
||||
# the following is just an example, yours will likely be different
|
||||
#add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../../../RadioLib" "${CMAKE_CURRENT_BINARY_DIR}/RadioLib")
|
||||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../../../RadioLib" "${CMAKE_CURRENT_BINARY_DIR}/RadioLib")
|
||||
|
||||
# add the executable
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define PI_HAL_H
|
||||
|
||||
// include RadioLib
|
||||
#include <RadioLib/RadioLib.h>
|
||||
#include <RadioLib.h>
|
||||
|
||||
// include the library for Raspberry GPIO pins
|
||||
#include "pigpio.h"
|
||||
|
|
@ -107,17 +107,17 @@ class PiHal : public RadioLibHal {
|
|||
return(0);
|
||||
}
|
||||
|
||||
gpioSetMode(pin, PI_INPUT);
|
||||
uint32_t start = gpioTick();
|
||||
uint32_t curtick = gpioTick();
|
||||
this->pinMode(pin, PI_INPUT);
|
||||
uint32_t start = this->micros();
|
||||
uint32_t curtick = this->micros();
|
||||
|
||||
while(gpioRead(pin) == state) {
|
||||
if((gpioTick() - curtick) > timeout) {
|
||||
while(this->digitalRead(pin) == state) {
|
||||
if((this->micros() - curtick) > timeout) {
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
return(gpioTick() - start);
|
||||
return(this->micros() - start);
|
||||
}
|
||||
|
||||
void spiBegin() {
|
||||
|
|
@ -128,10 +128,8 @@ class PiHal : public RadioLibHal {
|
|||
|
||||
void spiBeginTransaction() {}
|
||||
|
||||
uint8_t spiTransfer(uint8_t b) {
|
||||
char ret;
|
||||
spiXfer(_spiHandle, (char*)&b, &ret, 1);
|
||||
return(ret);
|
||||
void spiTransfer(uint8_t* out, size_t len, uint8_t* in) {
|
||||
spiXfer(_spiHandle, (char*)out, (char*)in, len);
|
||||
}
|
||||
|
||||
void spiEndTransaction() {}
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@ set -e
|
|||
mkdir -p build
|
||||
cd build
|
||||
cmake -G "CodeBlocks - Unix Makefiles" ..
|
||||
make -j4
|
||||
make
|
||||
cd ..
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
// include the library
|
||||
#include <RadioLib/RadioLib.h>
|
||||
#include <RadioLib.h>
|
||||
|
||||
// include the hardware abstraction layer
|
||||
#include "PiHal.h"
|
||||
|
|
@ -29,8 +29,8 @@ PiHal* hal = new PiHal(1);
|
|||
// NSS pin: 7
|
||||
// DIO1 pin: 17
|
||||
// NRST pin: 22
|
||||
// BUSY pin: 4
|
||||
SX1261 radio = new Module(hal, 7, 17, 22, 4);
|
||||
// BUSY pin: not connected
|
||||
SX1261 radio = new Module(hal, 7, 17, 22, RADIOLIB_NC);
|
||||
|
||||
// the entry point for the program
|
||||
int main(int argc, char** argv) {
|
||||
|
|
@ -50,7 +50,7 @@ int main(int argc, char** argv) {
|
|||
state = radio.transmit("Hello World!");
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
// the packet was successfully transmitted
|
||||
printf("success!");
|
||||
printf("success!\n");
|
||||
|
||||
// wait for a second before transmitting again
|
||||
hal->delay(1000);
|
||||
|
|
|
|||
61
lib/RadioLib/examples/NonArduino/Tock/CMakeLists.txt
Normal file
61
lib/RadioLib/examples/NonArduino/Tock/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# RadioLib Non-Arduino Tock Library CMake script
|
||||
#
|
||||
# Licensed under the MIT License
|
||||
#
|
||||
# Copyright (c) 2023 Alistair Francis <alistair@alistair23.me>
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
|
||||
# create the project
|
||||
project(tock-sx1261)
|
||||
|
||||
set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/userland_generic.ld)
|
||||
|
||||
include("tock.cmake")
|
||||
|
||||
# when using debuggers such as gdb, the following line can be used
|
||||
#set(CMAKE_BUILD_TYPE Debug)
|
||||
|
||||
# if you did not build RadioLib as shared library (see wiki),
|
||||
# you will have to add it as source directory
|
||||
# the following is just an example, yours will likely be different
|
||||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../../../RadioLib" "${CMAKE_CURRENT_BINARY_DIR}/RadioLib")
|
||||
|
||||
# add the executable
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
|
||||
# link with RadioLib and libtock-c
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC
|
||||
RadioLib
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/libtock/build/cortex-m4/libtock.a
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/libc++/cortex-m/libgcc.a
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/libc++/cortex-m/libstdc++.a
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/newlib/cortex-m/v7-m/libc.a
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c/newlib/cortex-m/v7-m/libm.a
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libtock-c
|
||||
)
|
||||
|
||||
# you can also specify RadioLib compile-time flags here
|
||||
#target_compile_definitions(${PROJECT_NAME} PUBLIC RADIOLIB_DEBUG RADIOLIB_VERBOSE)
|
||||
28
lib/RadioLib/examples/NonArduino/Tock/README.md
Normal file
28
lib/RadioLib/examples/NonArduino/Tock/README.md
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# RadioLib as Tock application
|
||||
|
||||
[Tock](https://github.com/tock/tock) is an embedded operating system designed
|
||||
for running multiple concurrent, mutually distrustful applications on Cortex-M
|
||||
and RISC-V based embedded platforms.
|
||||
|
||||
RadioLib can be built as a Tock application using
|
||||
[libtock-c](https://github.com/tock/libtock-c). This is an example of running
|
||||
RadioLib as a Tock application.
|
||||
|
||||
This has been tested on the
|
||||
[SparkFun LoRa Thing Plus - expLoRaBLE board] (https://github.com/tock/tock/tree/master/boards/apollo3/lora_things_plus)
|
||||
but will work on any LoRa compatible Tock board (currently only the
|
||||
expLoRaBLE board).
|
||||
|
||||
The RadioLib example can be built with:
|
||||
|
||||
```shell
|
||||
$ git clone https://github.com/jgromes/RadioLib.git
|
||||
$ cd RadioLib/examples/NonArduino/Tock/
|
||||
$ ./build.sh
|
||||
```
|
||||
|
||||
Then in the Tock repo you can flash the kernel and app with:
|
||||
|
||||
```shell
|
||||
$ make flash; APP=RadioLib/examples/NonArduino/Tock/build/tock-sx1261.tbf make flash-app
|
||||
```
|
||||
20
lib/RadioLib/examples/NonArduino/Tock/build.sh
Normal file
20
lib/RadioLib/examples/NonArduino/Tock/build.sh
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
rm -rf ./build
|
||||
|
||||
cd libtock-c/libtock
|
||||
make -j4
|
||||
cd ../../
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
|
||||
cmake -G "CodeBlocks - Unix Makefiles" ..
|
||||
make -j4
|
||||
|
||||
cd ..
|
||||
|
||||
elf2tab -n radio-lib --stack 4096 --app-heap 2048 --kernel-heap 2048 \
|
||||
--kernel-major 2 --kernel-minor 1 \
|
||||
-v ./build/tock-sx1261
|
||||
200
lib/RadioLib/examples/NonArduino/Tock/libtockHal.h
Normal file
200
lib/RadioLib/examples/NonArduino/Tock/libtockHal.h
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
RadioLib Non-Arduino Tock Library helper functions
|
||||
|
||||
Licensed under the MIT License
|
||||
|
||||
Copyright (c) 2023 Alistair Francis <alistair@alistair23.me>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef TOCK_HAL_H
|
||||
#define TOCK_HAL_H
|
||||
|
||||
// include RadioLib
|
||||
#include <RadioLib.h>
|
||||
|
||||
// include all the dependencies
|
||||
#include "libtock/lora_phy.h"
|
||||
#include "libtock/gpio.h"
|
||||
#include "libtock/timer.h"
|
||||
#include "libtock/read_only_state.h"
|
||||
|
||||
#define RADIO_BUSY 1
|
||||
#define RADIO_DIO_1 2
|
||||
#define RADIO_DIO_3 3
|
||||
#define RADIO_RESET 4
|
||||
// Skip the chips select as Tock handles this for us
|
||||
#define RADIO_NSS RADIOLIB_NC
|
||||
|
||||
// define Arduino-style macros
|
||||
#define PIN_LOW (0x0)
|
||||
#define PIN_HIGH (0x1)
|
||||
#define PIN_INPUT (0x01)
|
||||
#define PIN_OUTPUT (0x03)
|
||||
#define PIN_RISING (0x01)
|
||||
#define PIN_FALLING (0x02)
|
||||
|
||||
typedef void (*gpioIrqFn)(void);
|
||||
|
||||
/*
|
||||
* Get the the timer frequency in Hz.
|
||||
*/
|
||||
int alarm_internal_frequency(uint32_t* frequency) {
|
||||
syscall_return_t rval = command(0x0, 1, 0, 0);
|
||||
return tock_command_return_u32_to_returncode(rval, frequency);
|
||||
}
|
||||
|
||||
int alarm_internal_read(uint32_t* time) {
|
||||
syscall_return_t rval = command(0x0, 2, 0, 0);
|
||||
return tock_command_return_u32_to_returncode(rval, time);
|
||||
}
|
||||
|
||||
static void lora_phy_gpio_Callback (int gpioPin,
|
||||
__attribute__ ((unused)) int arg2,
|
||||
__attribute__ ((unused)) int arg3,
|
||||
void* userdata)
|
||||
{
|
||||
gpioIrqFn fn = *(gpioIrqFn*)(&userdata);
|
||||
|
||||
if (fn != NULL ) {
|
||||
fn();
|
||||
}
|
||||
}
|
||||
|
||||
class TockHal : public RadioLibHal {
|
||||
public:
|
||||
// default constructor - initializes the base HAL and any needed private members
|
||||
TockHal()
|
||||
: RadioLibHal(PIN_INPUT, PIN_OUTPUT, PIN_LOW, PIN_HIGH, PIN_RISING, PIN_FALLING) {
|
||||
}
|
||||
|
||||
void init() override {
|
||||
}
|
||||
|
||||
void term() override {
|
||||
}
|
||||
|
||||
// GPIO-related methods (pinMode, digitalWrite etc.) should check
|
||||
// RADIOLIB_NC as an alias for non-connected pins
|
||||
void pinMode(uint32_t pin, uint32_t mode) override {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == PIN_OUTPUT) {
|
||||
lora_phy_gpio_enable_output(pin);
|
||||
} else if (mode == PIN_INPUT) {
|
||||
lora_phy_gpio_enable_input(pin, PullDown);
|
||||
}
|
||||
}
|
||||
|
||||
void digitalWrite(uint32_t pin, uint32_t value) override {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
lora_phy_gpio_set(pin);
|
||||
} else {
|
||||
lora_phy_gpio_clear(pin);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t digitalRead(uint32_t pin) override {
|
||||
int value;
|
||||
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
lora_phy_gpio_read(pin, &value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void attachInterrupt(uint32_t interruptNum, gpioIrqFn interruptCb, uint32_t mode) override {
|
||||
if(interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
lora_phy_gpio_interrupt_callback(lora_phy_gpio_Callback, &interruptCb);
|
||||
|
||||
// set GPIO as input and enable interrupts on it
|
||||
lora_phy_gpio_enable_input(interruptNum, PullDown);
|
||||
lora_phy_gpio_enable_interrupt(interruptNum, Change);
|
||||
}
|
||||
|
||||
void detachInterrupt(uint32_t interruptNum) override {
|
||||
if(interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
|
||||
lora_phy_gpio_disable_interrupt(interruptNum);
|
||||
}
|
||||
|
||||
void delay(unsigned long ms) override {
|
||||
delay_ms( ms );
|
||||
}
|
||||
|
||||
void delayMicroseconds(unsigned long us) override {
|
||||
delay_ms( us / 1000 );
|
||||
}
|
||||
|
||||
unsigned long millis() override {
|
||||
uint32_t frequency, now;
|
||||
|
||||
alarm_internal_frequency(&frequency);
|
||||
alarm_internal_read(&now);
|
||||
|
||||
return (now / frequency) / 1000;
|
||||
}
|
||||
|
||||
unsigned long micros() override {
|
||||
return millis() / 1000;
|
||||
}
|
||||
|
||||
long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void spiBegin() {
|
||||
}
|
||||
|
||||
void spiBeginTransaction() {
|
||||
}
|
||||
|
||||
void spiTransfer(uint8_t* out, size_t len, uint8_t* in) {
|
||||
lora_phy_read_write_sync((const char*) out, (char*) in, len);
|
||||
}
|
||||
|
||||
void spiEndTransaction() {
|
||||
}
|
||||
|
||||
void spiEnd() {
|
||||
}
|
||||
|
||||
void yield() {
|
||||
::yield_no_wait();
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
81
lib/RadioLib/examples/NonArduino/Tock/main.cpp
Normal file
81
lib/RadioLib/examples/NonArduino/Tock/main.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
RadioLib Non-Arduino Tock Library test application
|
||||
|
||||
Licensed under the MIT License
|
||||
|
||||
Copyright (c) 2023 Alistair Francis <alistair@alistair23.me>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// include the library
|
||||
#include <RadioLib.h>
|
||||
|
||||
// include the hardware abstraction layer
|
||||
#include "libtockHal.h"
|
||||
|
||||
// the entry point for the program
|
||||
int main(void) {
|
||||
printf("[SX1261] Initialising Radio ... \r\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");
|
||||
|
||||
// loop forever
|
||||
for(;;) {
|
||||
yield_no_wait();
|
||||
// send a packet
|
||||
printf("[SX1261] Transmitting\r\n");
|
||||
|
||||
state = radio->transmit("Hello World!");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
51
lib/RadioLib/examples/NonArduino/Tock/tock.cmake
Normal file
51
lib/RadioLib/examples/NonArduino/Tock/tock.cmake
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# Tock target specific CMake file
|
||||
#
|
||||
# Licensed under the MIT License
|
||||
#
|
||||
# Copyright (c) 2023 Alistair Francis <alistair@alistair23.me>
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
# This is copied from https://github.com/Lora-net/LoRaMac-node/pull/1390
|
||||
# and has been relicensed by the original author
|
||||
|
||||
include("toolchain-arm-none-eabi.cmake")
|
||||
|
||||
if(NOT DEFINED LINKER_SCRIPT)
|
||||
message(FATAL_ERROR "No linker script defined")
|
||||
endif(NOT DEFINED LINKER_SCRIPT)
|
||||
message("Linker script: ${LINKER_SCRIPT}")
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Set compiler/linker flags
|
||||
#---------------------------------------------------------------------------------------
|
||||
|
||||
set(STACK_SIZE 4096)
|
||||
set(APP_HEAP_SIZE 2048)
|
||||
set(KERNEL_HEAP_SIZE 2048)
|
||||
|
||||
# Object build options
|
||||
set(OBJECT_GEN_FLAGS "-mthumb -g2 -fno-builtin -mcpu=cortex-m4 -Wall -Wextra -pedantic -Wno-unused-parameter -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize -frecord-gcc-switches -gdwarf-2 -Os -fdata-sections -ffunction-sections -fstack-usage -Wl,--emit-relocs -fPIC -mthumb -mfloat-abi=soft -msingle-pic-base -mpic-register=r9 -mno-pic-data-is-text-relative -D__TOCK__ -DSVCALL_AS_NORMAL_FUNCTION -DSOFTDEVICE_s130")
|
||||
|
||||
set(CMAKE_C_FLAGS "${OBJECT_GEN_FLAGS} -std=gnu99 " CACHE INTERNAL "C Compiler options")
|
||||
set(CMAKE_CXX_FLAGS "${OBJECT_GEN_FLAGS} -std=c++20 " CACHE INTERNAL "C++ Compiler options")
|
||||
set(CMAKE_ASM_FLAGS "${OBJECT_GEN_FLAGS} -x assembler-with-cpp " CACHE INTERNAL "ASM Compiler options")
|
||||
|
||||
# Linker flags
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections --specs=nano.specs --specs=nosys.specs -mthumb -g2 -mcpu=cortex-m4 -mabi=aapcs -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Xlinker --defsym=STACK_SIZE=${STACK_SIZE} -Xlinker --defsym=APP_HEAP_SIZE=${APP_HEAP_SIZE} -Xlinker --defsym=KERNEL_HEAP_SIZE=${KERNEL_HEAP_SIZE} -nostdlib -Wl,--start-group" CACHE INTERNAL "Linker options")
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
# Arm specific CMake file
|
||||
#
|
||||
# This is copied from:
|
||||
# https://github.com/Lora-net/LoRaMac-node/blob/2bf36bde72f68257eb96b5c00900619546bedca8/cmake/toolchain-arm-none-eabi.cmake
|
||||
#
|
||||
# The below file is licensed as Revised BSD License
|
||||
# See https://github.com/Lora-net/LoRaMac-node/blob/master/LICENSE for details
|
||||
|
||||
##
|
||||
## ______ _
|
||||
## / _____) _ | |
|
||||
## ( (____ _____ ____ _| |_ _____ ____| |__
|
||||
## \____ \| ___ | (_ _) ___ |/ ___) _ \
|
||||
## _____) ) ____| | | || |_| ____( (___| | | |
|
||||
## (______/|_____)_|_|_| \__)_____)\____)_| |_|
|
||||
## (C)2013-2017 Semtech
|
||||
## ___ _____ _ ___ _ _____ ___ ___ ___ ___
|
||||
## / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
|
||||
## \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
|
||||
## |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
|
||||
## embedded.connectivity.solutions.==============
|
||||
##
|
||||
## License: Revised BSD License, see LICENSE.TXT file included in the project
|
||||
## Authors: Johannes Bruder ( STACKFORCE ), Miguel Luis ( Semtech )
|
||||
##
|
||||
##
|
||||
## CMake arm-none-eabi toolchain file
|
||||
##
|
||||
|
||||
# Append current directory to CMAKE_MODULE_PATH for making device specific cmake modules visible
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Target definition
|
||||
set(CMAKE_SYSTEM_NAME Generic)
|
||||
set(CMAKE_SYSTEM_PROCESSOR ARM)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Set toolchain paths
|
||||
#---------------------------------------------------------------------------------------
|
||||
set(TOOLCHAIN arm-none-eabi)
|
||||
|
||||
find_program(TOOLCHAIN_PREFIX ${TOOLCHAIN}-gcc NO_CACHE)
|
||||
get_filename_component(TOOLCHAIN_PREFIX ${TOOLCHAIN_PREFIX} DIRECTORY)
|
||||
|
||||
set(TOOLCHAIN_BIN_DIR ${TOOLCHAIN_PREFIX}/../bin)
|
||||
set(TOOLCHAIN_INC_DIR ${TOOLCHAIN_PREFIX}/../${TOOLCHAIN}/include)
|
||||
set(TOOLCHAIN_LIB_DIR ${TOOLCHAIN_PREFIX}/../${TOOLCHAIN}/lib)
|
||||
|
||||
# Set system depended extensions
|
||||
if(WIN32)
|
||||
set(TOOLCHAIN_EXT ".exe" )
|
||||
else()
|
||||
set(TOOLCHAIN_EXT "" )
|
||||
endif()
|
||||
|
||||
# Perform compiler test with static library
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Preset some general GCC Options
|
||||
#---------------------------------------------------------------------------------------
|
||||
|
||||
# Options for DEBUG build
|
||||
# -Og enables optimizations that do not interfere with debugging
|
||||
# -g produce debugging information in the operating system's native format
|
||||
set(CMAKE_C_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C Compiler options for debug build type")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DDEBUG" CACHE INTERNAL "C++ Compiler options for debug build type")
|
||||
set(CMAKE_ASM_FLAGS_DEBUG "-g" CACHE INTERNAL "ASM Compiler options for debug build type")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE INTERNAL "Linker options for debug build type")
|
||||
|
||||
# Options for RELEASE build
|
||||
# -Os Optimize for size. -Os enables all -O2 optimizations
|
||||
set(CMAKE_C_FLAGS_RELEASE "-Os" CACHE INTERNAL "C Compiler options for release build type")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-Os" CACHE INTERNAL "C++ Compiler options for release build type")
|
||||
set(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "ASM Compiler options for release build type")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE INTERNAL "Linker options for release build type")
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Set compilers
|
||||
#---------------------------------------------------------------------------------------
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "C Compiler")
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-g++${TOOLCHAIN_EXT} CACHE INTERNAL "C++ Compiler")
|
||||
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN}-gcc${TOOLCHAIN_EXT} CACHE INTERNAL "ASM Compiler")
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_PREFIX}/${${TOOLCHAIN}} ${CMAKE_PREFIX_PATH})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
RadioLib PhysicalLayer Interface Example
|
||||
|
||||
This example shows how to use the common PhysicalLayer
|
||||
to interface with different radio modules using the same
|
||||
methods.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
#include <RadioLib.h>
|
||||
|
||||
// select which radio to use
|
||||
// this can be any radio supported by RadioLib!
|
||||
#define RADIO_TYPE SX1278
|
||||
|
||||
// set the pinout depending on the wiring and module type
|
||||
// SPI NSS pin: 10
|
||||
// interrupt pin: 2
|
||||
// reset pin: 9 (unused on some modules)
|
||||
// extra GPIO/interrupt pin: 3 (unused on some modules)
|
||||
RADIO_TYPE radio = new Module(10, 2, 9, 3);
|
||||
|
||||
// get pointer to the common layer
|
||||
PhysicalLayer* phy = (PhysicalLayer*)&radio;
|
||||
|
||||
void dummyISR(void) {
|
||||
// nothing here, this example is just a showcase
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// now we can use "radio" to access the features
|
||||
// specific to that radio type, such as the begin() method
|
||||
Serial.print(F("[Radio] Initializing ... "));
|
||||
int state = radio.begin();
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
|
||||
// or we can use the "phy" pointer to access the common layer
|
||||
// PhysicalLayer has some common configuration
|
||||
Serial.print(F("[PHY] Changing frequency ... "));
|
||||
state = phy->setFrequency(433.5);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
|
||||
// PhysicalLayer also contains basic functionality
|
||||
// like transmitting and receiving packets
|
||||
Serial.print(F("[PHY] Sending packet ... "));
|
||||
state = phy->transmit("Hello World!");
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
|
||||
// try to receive now - this will almost certainly timeout
|
||||
// unless by chance there is a transmitter nearby,
|
||||
// but the point of this example is to showcase the interface
|
||||
String str;
|
||||
Serial.print(F("[PHY] Listening for packets ... "));
|
||||
state = phy->receive(str);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else if(state == RADIOLIB_ERR_RX_TIMEOUT) {
|
||||
Serial.println(F("timeout!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
|
||||
// interrupt-driven versions of Rx/Tx are supported as well
|
||||
// for these to work, you have to configure the interrupt actions
|
||||
phy->setPacketReceivedAction(dummyISR);
|
||||
phy->setPacketSentAction(dummyISR);
|
||||
|
||||
// now you can use methods like startTransmit(), startReceive(),
|
||||
// readData() etc.
|
||||
|
||||
// interrupt actions can be cleared as well
|
||||
phy->clearPacketReceivedAction();
|
||||
phy->clearPacketSentAction();
|
||||
|
||||
// PhysicalLayer supports basic mode changes like sleep ...
|
||||
Serial.print(F("[PHY] Going to sleep ... "));
|
||||
state = phy->sleep();
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
|
||||
// ... or standby
|
||||
Serial.print(F("[PHY] Going to standby ... "));
|
||||
state = phy->standby();
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while(true);
|
||||
}
|
||||
|
||||
// there are also common SNR/RSSI measurement functions
|
||||
Serial.print(F("[PHY] Measured SNR = "));
|
||||
Serial.print(phy->getSNR());
|
||||
Serial.println(F(" dB"));
|
||||
Serial.print(F("[PHY] Measured RSSI = "));
|
||||
Serial.print(phy->getRSSI());
|
||||
Serial.println(F(" dBm"));
|
||||
|
||||
// and also a true random number generator
|
||||
Serial.print(F("[PHY] Random number between 0 and 100 = "));
|
||||
Serial.println(phy->random(100));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// nothing here, the example is just a showcase
|
||||
}
|
||||
|
|
@ -1,19 +1,24 @@
|
|||
/*
|
||||
RadioLib RF69 Receive Example
|
||||
RadioLib RF69 Blocking Receive Example
|
||||
|
||||
This example receives packets using RF69 FSK radio module.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bit rate
|
||||
- frequency deviation
|
||||
- sync word
|
||||
This example receives packets using RF69 FSK radio module.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bit rate
|
||||
- frequency deviation
|
||||
- sync word
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
|
||||
Using blocking receive is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can miss some packets!
|
||||
Instead, interrupt receive is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -41,7 +41,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setDio0Action(setFlag);
|
||||
radio.setPacketReceivedAction(setFlag);
|
||||
|
||||
// start listening for packets
|
||||
Serial.print(F("[RF69] Starting to listen ... "));
|
||||
|
|
@ -92,7 +92,8 @@ void loop() {
|
|||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
int numBytes = radio.getPacketLength();
|
||||
int state = radio.readData(byteArr, numBytes);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
/*
|
||||
RadioLib RF69 Transmit Example
|
||||
RadioLib RF69 Blocking Transmit Example
|
||||
|
||||
This example transmits packets using RF69 FSK radio module.
|
||||
Each packet contains up to 64 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits packets using RF69 FSK radio module.
|
||||
Each packet contains up to 64 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
|
||||
Using blocking transmit is not recommended, as it will lead
|
||||
to inefficient use of processor time!
|
||||
Instead, interrupt transmit is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -59,11 +63,15 @@ void setup() {
|
|||
*/
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[RF69] Transmitting packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to 64 characters long
|
||||
int state = radio.transmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
int state = radio.transmit(str);
|
||||
|
||||
// you can also transmit byte array up to 64 bytes long
|
||||
/*
|
||||
|
|
@ -47,7 +47,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when packet transmission is finished
|
||||
radio.setDio0Action(setFlag);
|
||||
radio.setPacketSentAction(setFlag);
|
||||
|
||||
// NOTE: some RF69 modules use high power output,
|
||||
// those are usually marked RF69H(C/CW).
|
||||
|
|
@ -96,6 +96,9 @@ void setFlag(void) {
|
|||
transmittedFlag = true;
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
// check if the previous transmission finished
|
||||
if(transmittedFlag) {
|
||||
|
|
@ -128,14 +131,15 @@ void loop() {
|
|||
Serial.print(F("[RF69] Sending another packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
transmissionState = radio.startTransmit("Hello World!");
|
||||
// 64 characters long
|
||||
String str = "Hello World! #" + String(count++);
|
||||
transmissionState = radio.startTransmit(str);
|
||||
|
||||
// you can also transmit byte array up to 64 bytes long
|
||||
/*
|
||||
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
|
||||
0x89, 0xAB, 0xCD, 0xEF};
|
||||
int state = radio.startTransmit(byteArr, 8);
|
||||
transmissionState = radio.startTransmit(byteArr, 8);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,28 @@
|
|||
// no need to configure pins, signals are routed to the radio internally
|
||||
STM32WLx radio = new STM32WLx_Module();
|
||||
|
||||
// set RF switch configuration for Nucleo WL55JC1
|
||||
// NOTE: other boards may be different!
|
||||
// Some boards may not have either LP or HP.
|
||||
// For those, do not set the LP/HP entry in the table.
|
||||
static const uint32_t rfswitch_pins[] =
|
||||
{PC3, PC4, PC5};
|
||||
static const Module::RfSwitchMode_t rfswitch_table[] = {
|
||||
{STM32WLx::MODE_IDLE, {LOW, LOW, LOW}},
|
||||
{STM32WLx::MODE_RX, {HIGH, HIGH, LOW}},
|
||||
{STM32WLx::MODE_TX_LP, {HIGH, HIGH, HIGH}},
|
||||
{STM32WLx::MODE_TX_HP, {HIGH, LOW, HIGH}},
|
||||
END_OF_MODE_TABLE,
|
||||
};
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// initialize STM32WLx with default settings
|
||||
// set RF switch control configuration
|
||||
// this has to be done prior to calling begin()
|
||||
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
|
||||
|
||||
// initialize STM32WLx with default settings, except frequency
|
||||
Serial.print(F("[STM32WLx] Initializing ... "));
|
||||
int state = radio.begin(868.0);
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -19,11 +19,28 @@
|
|||
// no need to configure pins, signals are routed to the radio internally
|
||||
STM32WLx radio = new STM32WLx_Module();
|
||||
|
||||
// set RF switch configuration for Nucleo WL55JC1
|
||||
// NOTE: other boards may be different!
|
||||
// Some boards may not have either LP or HP.
|
||||
// For those, do not set the LP/HP entry in the table.
|
||||
static const uint32_t rfswitch_pins[] =
|
||||
{PC3, PC4, PC5};
|
||||
static const Module::RfSwitchMode_t rfswitch_table[] = {
|
||||
{STM32WLx::MODE_IDLE, {LOW, LOW, LOW}},
|
||||
{STM32WLx::MODE_RX, {HIGH, HIGH, LOW}},
|
||||
{STM32WLx::MODE_TX_LP, {HIGH, HIGH, HIGH}},
|
||||
{STM32WLx::MODE_TX_HP, {HIGH, LOW, HIGH}},
|
||||
END_OF_MODE_TABLE,
|
||||
};
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// initialize STM32WLx with default settings
|
||||
// set RF switch control configuration
|
||||
// this has to be done prior to calling begin()
|
||||
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
|
||||
|
||||
// initialize STM32WLx with default settings, except frequency
|
||||
Serial.print(F("[STM32WLx] Initializing ... "));
|
||||
int state = radio.begin(868.0);
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -1,27 +1,32 @@
|
|||
/*
|
||||
RadioLib STM32WLx Receive Example
|
||||
RadioLib STM32WLx Blocking Receive Example
|
||||
|
||||
This example listens for LoRa transmissions using STM32WL MCU with
|
||||
integrated (SX126x) LoRa radio.
|
||||
This example listens for LoRa transmissions using STM32WL MCU with
|
||||
integrated (SX126x) LoRa radio.
|
||||
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bandwidth
|
||||
- spreading factor
|
||||
- coding rate
|
||||
- sync word
|
||||
- preamble length
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bandwidth
|
||||
- spreading factor
|
||||
- coding rate
|
||||
- sync word
|
||||
- preamble length
|
||||
|
||||
This example assumes Nucleo WL55JC1 is used. For other Nucleo boards
|
||||
or standalone STM32WL, some configuration such as TCXO voltage and
|
||||
RF switch control may have to be adjusted.
|
||||
This example assumes Nucleo WL55JC1 is used. For other Nucleo boards
|
||||
or standalone STM32WL, some configuration such as TCXO voltage and
|
||||
RF switch control may have to be adjusted.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
Using blocking receive is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt receive is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -32,6 +37,8 @@ STM32WLx radio = new STM32WLx_Module();
|
|||
|
||||
// set RF switch configuration for Nucleo WL55JC1
|
||||
// NOTE: other boards may be different!
|
||||
// Some boards may not have either LP or HP.
|
||||
// For those, do not set the LP/HP entry in the table.
|
||||
static const uint32_t rfswitch_pins[] =
|
||||
{PC3, PC4, PC5};
|
||||
static const Module::RfSwitchMode_t rfswitch_table[] = {
|
||||
|
|
@ -75,9 +82,6 @@ void loop() {
|
|||
Serial.print(F("[STM32WL] Waiting for incoming transmission ... "));
|
||||
|
||||
// you can receive data as an Arduino String
|
||||
// NOTE: receive() is a blocking method!
|
||||
// See example ReceiveInterrupt for details
|
||||
// on non-blocking reception method.
|
||||
String str;
|
||||
int state = radio.receive(str);
|
||||
|
||||
|
|
@ -31,6 +31,8 @@ STM32WLx radio = new STM32WLx_Module();
|
|||
|
||||
// set RF switch configuration for Nucleo WL55JC1
|
||||
// NOTE: other boards may be different!
|
||||
// Some boards may not have either LP or HP.
|
||||
// For those, do not set the LP/HP entry in the table.
|
||||
static const uint32_t rfswitch_pins[] =
|
||||
{PC3, PC4, PC5};
|
||||
static const Module::RfSwitchMode_t rfswitch_table[] = {
|
||||
|
|
@ -120,7 +122,8 @@ void loop() {
|
|||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
int numBytes = radio.getPacketLength();
|
||||
int state = radio.readData(byteArr, numBytes);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -1,23 +1,27 @@
|
|||
/*
|
||||
RadioLib STM32WLx Transmit Example
|
||||
RadioLib STM32WLx Blocking Transmit Example
|
||||
|
||||
This example transmits packets using STM32WL MCU with integrated
|
||||
(SX126x) LoRa radio.
|
||||
This example transmits packets using STM32WL MCU with integrated
|
||||
(SX126x) LoRa radio.
|
||||
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
This example assumes Nucleo WL55JC1 is used. For other Nucleo boards
|
||||
or standalone STM32WL, some configuration such as TCXO voltage and
|
||||
RF switch control may have to be adjusted.
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
This example assumes Nucleo WL55JC1 is used. For other Nucleo boards
|
||||
or standalone STM32WL, some configuration such as TCXO voltage and
|
||||
RF switch control may have to be adjusted.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
Using blocking transmit is not recommended, as it will lead
|
||||
to inefficient use of processor time!
|
||||
Instead, interrupt transmit is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -28,6 +32,8 @@ STM32WLx radio = new STM32WLx_Module();
|
|||
|
||||
// set RF switch configuration for Nucleo WL55JC1
|
||||
// NOTE: other boards may be different!
|
||||
// Some boards may not have either LP or HP.
|
||||
// For those, do not set the LP/HP entry in the table.
|
||||
static const uint32_t rfswitch_pins[] =
|
||||
{PC3, PC4, PC5};
|
||||
static const Module::RfSwitchMode_t rfswitch_table[] = {
|
||||
|
|
@ -67,15 +73,16 @@ void setup() {
|
|||
}
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[STM32WL] Transmitting packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
// NOTE: transmit() is a blocking method!
|
||||
// See example STM32WLx_Transmit_Interrupt for details
|
||||
// on non-blocking transmission method.
|
||||
int state = radio.transmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
int state = radio.transmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
/*
|
||||
RadioLib STM32WLx Transmit with Interrupts Example
|
||||
RadioLib STM32WLx Transmit with Interrupts Example
|
||||
|
||||
This example transmits LoRa packets with one second delays
|
||||
between them. Each packet contains up to 256 bytes
|
||||
of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits LoRa packets with one second delays
|
||||
between them. Each packet contains up to 256 bytes
|
||||
of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -23,6 +23,8 @@ STM32WLx radio = new STM32WLx_Module();
|
|||
|
||||
// set RF switch configuration for Nucleo WL55JC1
|
||||
// NOTE: other boards may be different!
|
||||
// Some boards may not have either LP or HP.
|
||||
// For those, do not set the LP/HP entry in the table.
|
||||
static const uint32_t rfswitch_pins[] =
|
||||
{PC3, PC4, PC5};
|
||||
static const Module::RfSwitchMode_t rfswitch_table[] = {
|
||||
|
|
@ -95,6 +97,9 @@ void setFlag(void) {
|
|||
transmittedFlag = true;
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
// check if the previous transmission finished
|
||||
if(transmittedFlag) {
|
||||
|
|
@ -128,13 +133,14 @@ void loop() {
|
|||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
transmissionState = radio.startTransmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
transmissionState = radio.startTransmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
|
||||
0x89, 0xAB, 0xCD, 0xEF};
|
||||
int state = radio.startTransmit(byteArr, 8);
|
||||
transmissionState = radio.startTransmit(byteArr, 8);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,23 @@
|
|||
/*
|
||||
RadioLib SX1231 Receive Example
|
||||
RadioLib SX123x Blocking Receive Example
|
||||
|
||||
This example receives packets using SX1231 FSK radio module.
|
||||
This example receives packets using SX1231 FSK radio module.
|
||||
Other modules from SX123x family can also be used.
|
||||
|
||||
NOTE: SX1231 offers the same features as RF69 and has the same
|
||||
interface. Please see RF69 examples for examples on AES,
|
||||
address filtering, interrupts and settings.
|
||||
NOTE: SX123x modules offer the same features as RF69 and have the same
|
||||
interface. Please see RF69 examples for examples on AES,
|
||||
address filtering, interrupts and settings.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
|
||||
Using blocking receive is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt receive is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -1,17 +1,22 @@
|
|||
/*
|
||||
RadioLib SX1231 Transmit Example
|
||||
RadioLib SX123x Blocking Transmit Example
|
||||
|
||||
This example transmits packets using SX1231 FSK radio module.
|
||||
This example transmits packets using SX1231 FSK radio module.
|
||||
Other modules from SX123x family can also be used.
|
||||
|
||||
NOTE: SX1231 offers the same features as RF69 and has the same
|
||||
interface. Please see RF69 examples for examples on AES,
|
||||
address filtering, interrupts and settings.
|
||||
NOTE: SX123x modules offer the same features as RF69 and have the same
|
||||
interface. Please see RF69 examples for examples on AES,
|
||||
address filtering, interrupts and settings.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
|
||||
Using blocking transmit is not recommended, as it will lead
|
||||
to inefficient use of processor time!
|
||||
Instead, interrupt transmit is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -42,11 +47,15 @@ void setup() {
|
|||
}
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[SX1231] Transmitting packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to 256 characters long
|
||||
int state = radio.transmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
int state = radio.transmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
|
|
@ -1,18 +1,23 @@
|
|||
/*
|
||||
RadioLib SX126x Channel Activity Detection Example
|
||||
RadioLib SX126x Blocking Channel Activity Detection Example
|
||||
|
||||
This example uses SX1262 to scan the current LoRa
|
||||
channel and detect ongoing LoRa transmissions.
|
||||
Unlike SX127x CAD, SX126x can detect any part
|
||||
of LoRa transmission, not just the preamble.
|
||||
This example uses SX1262 to scan the current LoRa
|
||||
channel and detect ongoing LoRa transmissions.
|
||||
Unlike SX127x CAD, SX126x can detect any part
|
||||
of LoRa transmission, not just the preamble.
|
||||
|
||||
Other modules from SX126x family can also be used.
|
||||
Other modules from SX126x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
Using blocking CAD is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt CAD is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
RadioLib SX126x Receive after Channel Activity Detection Example
|
||||
|
||||
This example uses SX1262 to scan the current LoRa
|
||||
channel and detect ongoing LoRa transmissions.
|
||||
Unlike SX127x CAD, SX126x can detect any part
|
||||
of LoRa transmission, not just the preamble.
|
||||
If a packet is detected, the module will switch
|
||||
to receive mode and receive the packet.
|
||||
|
||||
Other modules from SX126x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
#include <RadioLib.h>
|
||||
|
||||
// SX1262 has the following connections:
|
||||
// NSS pin: 10
|
||||
// DIO1 pin: 2
|
||||
// NRST pin: 3
|
||||
// BUSY pin: 9
|
||||
SX1262 radio = new Module(10, 2, 3, 9);
|
||||
|
||||
// or using RadioShield
|
||||
// https://github.com/jgromes/RadioShield
|
||||
//SX1262 radio = RadioShield.ModuleA;
|
||||
|
||||
// or using CubeCell
|
||||
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// initialize SX1262 with default settings
|
||||
Serial.print(F("[SX1262] Initializing ... "));
|
||||
int state = radio.begin();
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
}
|
||||
|
||||
// set the function that will be called
|
||||
// when LoRa packet or timeout is detected
|
||||
radio.setDio1Action(setFlag);
|
||||
|
||||
// start scanning the channel
|
||||
Serial.print(F("[SX1262] Starting scan for LoRa preamble ... "));
|
||||
state = radio.startChannelScan();
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
}
|
||||
}
|
||||
|
||||
// flag to indicate that a packet was detected or CAD timed out
|
||||
volatile bool scanFlag = false;
|
||||
|
||||
bool receiving = false;
|
||||
|
||||
// this function is called when a complete packet
|
||||
// is received by the module
|
||||
// IMPORTANT: this function MUST be 'void' type
|
||||
// and MUST NOT have any arguments!
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
ICACHE_RAM_ATTR
|
||||
#endif
|
||||
void setFlag(void) {
|
||||
// something happened, set the flag
|
||||
scanFlag = true;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check if the flag is set
|
||||
if(scanFlag) {
|
||||
int state = RADIOLIB_ERR_NONE;
|
||||
|
||||
// reset flag
|
||||
scanFlag = false;
|
||||
|
||||
// check ongoing reception
|
||||
if(receiving) {
|
||||
// DIO triggered while reception is ongoing
|
||||
// that means we got a packet
|
||||
|
||||
// you can read received data as an Arduino String
|
||||
String str;
|
||||
state = radio.readData(str);
|
||||
|
||||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
state = radio.readData(byteArr, 8);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
// packet was successfully received
|
||||
Serial.println(F("[SX1262] Received packet!"));
|
||||
|
||||
// print data of the packet
|
||||
Serial.print(F("[SX1262] Data:\t\t"));
|
||||
Serial.println(str);
|
||||
|
||||
// print RSSI (Received Signal Strength Indicator)
|
||||
Serial.print(F("[SX1262] RSSI:\t\t"));
|
||||
Serial.print(radio.getRSSI());
|
||||
Serial.println(F(" dBm"));
|
||||
|
||||
// print SNR (Signal-to-Noise Ratio)
|
||||
Serial.print(F("[SX1262] SNR:\t\t"));
|
||||
Serial.print(radio.getSNR());
|
||||
Serial.println(F(" dB"));
|
||||
|
||||
// print frequency error
|
||||
Serial.print(F("[SX1262] Frequency error:\t"));
|
||||
Serial.print(radio.getFrequencyError());
|
||||
Serial.println(F(" Hz"));
|
||||
|
||||
} else {
|
||||
// some other error occurred
|
||||
Serial.print(F("[SX1262] Failed, code "));
|
||||
Serial.println(state);
|
||||
|
||||
}
|
||||
|
||||
// reception is done now
|
||||
receiving = false;
|
||||
|
||||
} else {
|
||||
// check CAD result
|
||||
state = radio.getChannelScanResult();
|
||||
|
||||
if (state == RADIOLIB_LORA_DETECTED) {
|
||||
// LoRa packet was detected
|
||||
Serial.print(F("[SX1262] Packet detected, starting reception ... "));
|
||||
state = radio.startReceive();
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
}
|
||||
|
||||
// set the flag for ongoing reception
|
||||
receiving = true;
|
||||
|
||||
} else if (state == RADIOLIB_CHANNEL_FREE) {
|
||||
// channel is free
|
||||
Serial.println(F("[SX1262] Channel is free!"));
|
||||
|
||||
} else {
|
||||
// some other error occurred
|
||||
Serial.print(F("[SX1262] Failed, code "));
|
||||
Serial.println(state);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if we're not receiving, start scanning again
|
||||
if(!receiving) {
|
||||
Serial.print(F("[SX1262] Starting scan for LoRa preamble ... "));
|
||||
state = radio.startChannelScan();
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -42,6 +42,9 @@ volatile bool operationDone = false;
|
|||
// is transmitted or received by the module
|
||||
// IMPORTANT: this function MUST be 'void' type
|
||||
// and MUST NOT have any arguments!
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
ICACHE_RAM_ATTR
|
||||
#endif
|
||||
void setFlag(void) {
|
||||
// we sent or received a packet, set the flag
|
||||
operationDone = true;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
RadioLib SX126x Receive Example
|
||||
RadioLib SX126x Blocking Receive Example
|
||||
|
||||
This example listens for LoRa transmissions using SX126x Lora modules.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
|
|
@ -13,6 +13,11 @@
|
|||
|
||||
Other modules from SX126x family can also be used.
|
||||
|
||||
Using blocking receive is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt receive is recommended.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
|
||||
|
|
@ -56,9 +61,6 @@ void loop() {
|
|||
Serial.print(F("[SX1262] Waiting for incoming transmission ... "));
|
||||
|
||||
// you can receive data as an Arduino String
|
||||
// NOTE: receive() is a blocking method!
|
||||
// See example ReceiveInterrupt for details
|
||||
// on non-blocking reception method.
|
||||
String str;
|
||||
int state = radio.receive(str);
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setDio1Action(setFlag);
|
||||
radio.setPacketReceivedAction(setFlag);
|
||||
|
||||
// start listening for LoRa packets
|
||||
Serial.print(F("[SX1262] Starting to listen ... "));
|
||||
|
|
@ -105,7 +105,8 @@ void loop() {
|
|||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
int numBytes = radio.getPacketLength();
|
||||
int state = radio.readData(byteArr, numBytes);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,23 @@
|
|||
/*
|
||||
RadioLib SX126x Transmit Example
|
||||
RadioLib SX126x Blocking Transmit Example
|
||||
|
||||
This example transmits packets using SX1262 LoRa radio module.
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits packets using SX1262 LoRa radio module.
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from SX126x family can also be used.
|
||||
Other modules from SX126x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
Using blocking transmit is not recommended, as it will lead
|
||||
to inefficient use of processor time!
|
||||
Instead, interrupt transmit is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -58,15 +62,16 @@ void setup() {
|
|||
*/
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[SX1262] Transmitting packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
// NOTE: transmit() is a blocking method!
|
||||
// See example SX126x_Transmit_Interrupt for details
|
||||
// on non-blocking transmission method.
|
||||
int state = radio.transmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
int state = radio.transmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
/*
|
||||
RadioLib SX126x Transmit with Interrupts Example
|
||||
RadioLib SX126x Transmit with Interrupts Example
|
||||
|
||||
This example transmits LoRa packets with one second delays
|
||||
between them. Each packet contains up to 256 bytes
|
||||
of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits LoRa packets with one second delays
|
||||
between them. Each packet contains up to 256 bytes
|
||||
of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from SX126x family can also be used.
|
||||
Other modules from SX126x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -53,7 +53,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when packet transmission is finished
|
||||
radio.setDio1Action(setFlag);
|
||||
radio.setPacketSentAction(setFlag);
|
||||
|
||||
// start transmitting the first packet
|
||||
Serial.print(F("[SX1262] Sending first packet ... "));
|
||||
|
|
@ -85,6 +85,9 @@ void setFlag(void) {
|
|||
transmittedFlag = true;
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
// check if the previous transmission finished
|
||||
if(transmittedFlag) {
|
||||
|
|
@ -118,13 +121,14 @@ void loop() {
|
|||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
transmissionState = radio.startTransmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
transmissionState = radio.startTransmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
|
||||
0x89, 0xAB, 0xCD, 0xEF};
|
||||
int state = radio.startTransmit(byteArr, 8);
|
||||
transmissionState = radio.startTransmit(byteArr, 8);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,24 @@
|
|||
/*
|
||||
RadioLib SX127x Channel Activity Detection Example
|
||||
RadioLib SX127x Blocking Channel Activity Detection Example
|
||||
|
||||
This example scans the current LoRa channel and detects
|
||||
valid LoRa preambles. Preamble is the first part of
|
||||
LoRa transmission, so this can be used to check
|
||||
if the LoRa channel is free, or if you should start
|
||||
receiving a message.
|
||||
This example scans the current LoRa channel and detects
|
||||
valid LoRa preambles. Preamble is the first part of
|
||||
LoRa transmission, so this can be used to check
|
||||
if the LoRa channel is free, or if you should start
|
||||
receiving a message.
|
||||
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
Using blocking CAD is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt CAD is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -39,6 +39,9 @@ volatile bool operationDone = false;
|
|||
// is transmitted or received by the module
|
||||
// IMPORTANT: this function MUST be 'void' type
|
||||
// and MUST NOT have any arguments!
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
ICACHE_RAM_ATTR
|
||||
#endif
|
||||
void setFlag(void) {
|
||||
// we sent or received packet, set the flag
|
||||
operationDone = true;
|
||||
|
|
|
|||
|
|
@ -1,23 +1,28 @@
|
|||
/*
|
||||
RadioLib SX127x Receive Example
|
||||
RadioLib SX127x Blocking Receive Example
|
||||
|
||||
This example listens for LoRa transmissions using SX127x Lora modules.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bandwidth
|
||||
- spreading factor
|
||||
- coding rate
|
||||
- sync word
|
||||
- preamble length
|
||||
This example listens for LoRa transmissions using SX127x Lora modules.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bandwidth
|
||||
- spreading factor
|
||||
- coding rate
|
||||
- sync word
|
||||
- preamble length
|
||||
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
Using blocking receive is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt receive is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -53,9 +58,6 @@ void loop() {
|
|||
Serial.print(F("[SX1278] Waiting for incoming transmission ... "));
|
||||
|
||||
// you can receive data as an Arduino String
|
||||
// NOTE: receive() is a blocking method!
|
||||
// See example ReceiveInterrupt for details
|
||||
// on non-blocking reception method.
|
||||
String str;
|
||||
int state = radio.receive(str);
|
||||
|
||||
|
|
@ -123,7 +123,8 @@ void loop() {
|
|||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
int numBytes = radio.getPacketLength();
|
||||
int state = radio.readData(byteArr, numBytes);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setDio0Action(setFlag, RISING);
|
||||
radio.setPacketReceivedAction(setFlag);
|
||||
|
||||
// start listening for LoRa packets
|
||||
Serial.print(F("[SX1278] Starting to listen ... "));
|
||||
|
|
@ -102,7 +102,8 @@ void loop() {
|
|||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
int numBytes = radio.getPacketLength();
|
||||
int state = radio.readData(byteArr, numBytes);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,23 @@
|
|||
/*
|
||||
RadioLib SX127x Transmit Example
|
||||
RadioLib SX127x Blocking Transmit Example
|
||||
|
||||
This example transmits packets using SX1278 LoRa radio module.
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits packets using SX1278 LoRa radio module.
|
||||
Each packet contains up to 255 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
Using blocking transmit is not recommended, as it will lead
|
||||
to inefficient use of processor time!
|
||||
Instead, interrupt transmit is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -55,15 +59,16 @@ void setup() {
|
|||
*/
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[SX1278] Transmitting packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
// NOTE: transmit() is a blocking method!
|
||||
// See example SX127x_Transmit_Interrupt for details
|
||||
// on non-blocking transmission method.
|
||||
int state = radio.transmit("Hello World!");
|
||||
// 255 characters long
|
||||
String str = "Hello World! #" + String(count++);
|
||||
int state = radio.transmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
RadioLib SX127x Transmit with Frequency Hopping Example
|
||||
|
||||
This example transmits packets using SX1278 LoRa radio module.
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
Each packet contains up to 255 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
|
@ -56,7 +56,7 @@ int transmissionState = RADIOLIB_ERR_NONE;
|
|||
|
||||
// this is the packet that will be sent
|
||||
String longPacket = "Let's create a really long packet to trigger \
|
||||
lots of hop interrupts. A packet can be up to 256 bytes long. \
|
||||
lots of hop interrupts. A packet can be up to 255 bytes long. \
|
||||
This packet is 222 bytes so using sf = 9, bw = 125, timeOnAir is \
|
||||
1488ms. 1488ms / (9*4.10ms) = 40 hops. Counter: ";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
/*
|
||||
RadioLib SX127x Transmit with Interrupts Example
|
||||
RadioLib SX127x Transmit with Interrupts Example
|
||||
|
||||
This example transmits LoRa packets with one second delays
|
||||
between them. Each packet contains up to 256 bytes
|
||||
of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits LoRa packets with one second delays
|
||||
between them. Each packet contains up to 255 bytes
|
||||
of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
Other modules from SX127x/RFM9x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -50,20 +50,20 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when packet transmission is finished
|
||||
radio.setDio0Action(setFlag, RISING);
|
||||
radio.setPacketSentAction(setFlag);
|
||||
|
||||
// start transmitting the first packet
|
||||
Serial.print(F("[SX1278] Sending first packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
// 255 characters long
|
||||
transmissionState = radio.startTransmit("Hello World!");
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
// you can also transmit byte array up to 255 bytes long
|
||||
/*
|
||||
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
|
||||
0x89, 0xAB, 0xCD, 0xEF};
|
||||
state = radio.startTransmit(byteArr, 8);
|
||||
transmissionState = radio.startTransmit(byteArr, 8);
|
||||
*/
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +82,9 @@ void setFlag(void) {
|
|||
transmittedFlag = true;
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
// check if the previous transmission finished
|
||||
if(transmittedFlag) {
|
||||
|
|
@ -114,14 +117,15 @@ void loop() {
|
|||
Serial.print(F("[SX1278] Sending another packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
transmissionState = radio.startTransmit("Hello World!");
|
||||
// 255 characters long
|
||||
String str = "Hello World! #" + String(count++);
|
||||
transmissionState = radio.startTransmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
// you can also transmit byte array up to 255 bytes long
|
||||
/*
|
||||
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
|
||||
0x89, 0xAB, 0xCD, 0xEF};
|
||||
int state = radio.startTransmit(byteArr, 8);
|
||||
transmissionState = radio.startTransmit(byteArr, 8);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,21 @@
|
|||
/*
|
||||
RadioLib SX128x Channel Activity Detection Example
|
||||
RadioLib SX128x Blocking Channel Activity Detection Example
|
||||
|
||||
This example uses SX1280 to scan the current LoRa
|
||||
channel and detect ongoing LoRa transmissions.
|
||||
This example uses SX1280 to scan the current LoRa
|
||||
channel and detect ongoing LoRa transmissions.
|
||||
|
||||
Other modules from SX128x family can also be used.
|
||||
Other modules from SX128x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
|
||||
Using blocking CAD is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt CAD is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -1,23 +1,28 @@
|
|||
/*
|
||||
RadioLib SX128x Receive Example
|
||||
RadioLib SX128x Blocking Receive Example
|
||||
|
||||
This example listens for LoRa transmissions using SX126x Lora modules.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bandwidth
|
||||
- spreading factor
|
||||
- coding rate
|
||||
- sync word
|
||||
- preamble length
|
||||
This example listens for LoRa transmissions using SX126x Lora modules.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bandwidth
|
||||
- spreading factor
|
||||
- coding rate
|
||||
- sync word
|
||||
- preamble length
|
||||
|
||||
Other modules from SX128x family can also be used.
|
||||
Other modules from SX128x family can also be used.
|
||||
|
||||
Using blocking receive is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt receive is recommended.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -53,9 +58,6 @@ void loop() {
|
|||
Serial.print(F("[SX1280] Waiting for incoming transmission ... "));
|
||||
|
||||
// you can receive data as an Arduino String
|
||||
// NOTE: receive() is a blocking method!
|
||||
// See example ReceiveInterrupt for details
|
||||
// on non-blocking reception method.
|
||||
String str;
|
||||
int state = radio.receive(str);
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setDio1Action(setFlag);
|
||||
radio.setPacketReceivedAction(setFlag);
|
||||
|
||||
// start listening for LoRa packets
|
||||
Serial.print(F("[SX1280] Starting to listen ... "));
|
||||
|
|
@ -103,7 +103,8 @@ void loop() {
|
|||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
int numBytes = radio.getPacketLength();
|
||||
int state = radio.readData(byteArr, numBytes);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,23 @@
|
|||
/*
|
||||
RadioLib SX128x Transmit Example
|
||||
RadioLib SX128x Blocking Transmit Example
|
||||
|
||||
This example transmits packets using SX1280 LoRa radio module.
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits packets using SX1280 LoRa radio module.
|
||||
Each packet contains up to 256 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from SX128x family can also be used.
|
||||
Other modules from SX128x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
|
||||
Using blocking transmit is not recommended, as it will lead
|
||||
to inefficient use of processor time!
|
||||
Instead, interrupt transmit is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -62,15 +66,16 @@ void setup() {
|
|||
*/
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[SX1280] Transmitting packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
// NOTE: transmit() is a blocking method!
|
||||
// See example SX128x_Transmit_Interrupt for details
|
||||
// on non-blocking transmission method.
|
||||
int state = radio.transmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
int state = radio.transmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
/*
|
||||
RadioLib SX128x Transmit with Interrupts Example
|
||||
RadioLib SX128x Transmit with Interrupts Example
|
||||
|
||||
This example transmits LoRa packets with one second delays
|
||||
between them. Each packet contains up to 256 bytes
|
||||
of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits LoRa packets with one second delays
|
||||
between them. Each packet contains up to 256 bytes
|
||||
of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from SX128x family can also be used.
|
||||
Other modules from SX128x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -50,7 +50,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when packet transmission is finished
|
||||
radio.setDio1Action(setFlag);
|
||||
radio.setPacketSentAction(setFlag);
|
||||
|
||||
// start transmitting the first packet
|
||||
Serial.print(F("[SX1280] Sending first packet ... "));
|
||||
|
|
@ -82,6 +82,9 @@ void setFlag(void) {
|
|||
transmittedFlag = true;
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
// check if the previous transmission finished
|
||||
if(transmittedFlag) {
|
||||
|
|
@ -111,13 +114,14 @@ void loop() {
|
|||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
transmissionState = radio.startTransmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
transmissionState = radio.startTransmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
|
||||
0x89, 0xAB, 0xCD, 0xEF};
|
||||
int state = radio.startTransmit(byteArr, 8);
|
||||
transmissionState = radio.startTransmit(byteArr, 8);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,26 @@
|
|||
/*
|
||||
RadioLib Si443x Receive Example
|
||||
RadioLib Si443x Blocking Receive Example
|
||||
|
||||
This example receives packets using Si443x FSK radio module.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bit rate
|
||||
- frequency deviation
|
||||
- sync word
|
||||
This example receives packets using Si443x FSK radio module.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- bit rate
|
||||
- frequency deviation
|
||||
- sync word
|
||||
|
||||
Other modules from Si443x/RFM2x family can also be used.
|
||||
Using blocking receive is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt receive is recommended.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
|
||||
Other modules from Si443x/RFM2x family can also be used.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -43,7 +43,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setIrqAction(setFlag);
|
||||
radio.setPacketReceivedAction(setFlag);
|
||||
|
||||
// start listening for packets
|
||||
Serial.print(F("[Si4432] Starting to listen ... "));
|
||||
|
|
@ -94,7 +94,8 @@ void loop() {
|
|||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
int numBytes = radio.getPacketLength();
|
||||
int state = radio.readData(byteArr, numBytes);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,23 @@
|
|||
/*
|
||||
RadioLib Si443x Transmit Example
|
||||
RadioLib Si443x Blocking Transmit Example
|
||||
|
||||
This example transmits packets using Si4432 FSK radio module.
|
||||
Each packet contains up to 64 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits packets using Si4432 FSK radio module.
|
||||
Each packet contains up to 64 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from Si443x/RFM2x family can also be used.
|
||||
Other modules from Si443x/RFM2x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
|
||||
Using blocking transmit is not recommended, as it will lead
|
||||
to inefficient use of processor time!
|
||||
Instead, interrupt transmit is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -44,15 +48,16 @@ void setup() {
|
|||
}
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[Si4432] Transmitting packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 64 characters long
|
||||
// NOTE: transmit() is a blocking method!
|
||||
// See example Si443x_Transmit_Interrupt for details
|
||||
// on non-blocking transmission method.
|
||||
int state = radio.transmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
int state = radio.transmit(str);
|
||||
|
||||
// you can also transmit byte array up to 64 bytes long
|
||||
/*
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
/*
|
||||
RadioLib Si443x Transmit with Interrupts Example
|
||||
RadioLib Si443x Transmit with Interrupts Example
|
||||
|
||||
This example transmits packets using Si4432 FSK radio module.
|
||||
Each packet contains up to 64 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
This example transmits packets using Si4432 FSK radio module.
|
||||
Each packet contains up to 64 bytes of data, in the form of:
|
||||
- Arduino String
|
||||
- null-terminated char array (C-string)
|
||||
- arbitrary binary data (byte array)
|
||||
|
||||
Other modules from Si443x/RFM2x family can also be used.
|
||||
Other modules from Si443x/RFM2x family can also be used.
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -48,7 +48,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when packet transmission is finished
|
||||
radio.setIrqAction(setFlag);
|
||||
radio.setPacketSentAction(setFlag);
|
||||
|
||||
// start transmitting the first packet
|
||||
Serial.print(F("[Si4432] Sending first packet ... "));
|
||||
|
|
@ -80,6 +80,9 @@ void setFlag(void) {
|
|||
transmittedFlag = true;
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
// check if the previous transmission finished
|
||||
if(transmittedFlag) {
|
||||
|
|
@ -109,13 +112,14 @@ void loop() {
|
|||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
transmissionState = radio.startTransmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
transmissionState = radio.startTransmit(str);
|
||||
|
||||
// you can also transmit byte array up to 64 bytes long
|
||||
/*
|
||||
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
|
||||
0x89, 0xAB, 0xCD, 0xEF};
|
||||
int state = radio.startTransmit(byteArr, 8);
|
||||
transmissionState = radio.startTransmit(byteArr, 8);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,23 @@
|
|||
/*
|
||||
RadioLib nRF24 Receive Example
|
||||
RadioLib nRF24 Blocking Receive Example
|
||||
|
||||
This example listens for FSK transmissions using nRF24 2.4 GHz radio module.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- data rate
|
||||
- transmit pipe on transmitter must match receive pipe
|
||||
on receiver
|
||||
This example listens for FSK transmissions using nRF24 2.4 GHz radio module.
|
||||
To successfully receive data, the following settings have to be the same
|
||||
on both transmitter and receiver:
|
||||
- carrier frequency
|
||||
- data rate
|
||||
- transmit pipe on transmitter must match receive pipe on receiver
|
||||
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24
|
||||
Using blocking receive is not recommended, as it will lead
|
||||
to significant amount of timeouts, inefficient use of processor
|
||||
time and can some miss packets!
|
||||
Instead, interrupt receive is recommended.
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
For default module settings, see the wiki page
|
||||
https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24
|
||||
|
||||
For full API reference, see the GitHub Pages
|
||||
https://jgromes.github.io/RadioLib/
|
||||
*/
|
||||
|
||||
// include the library
|
||||
|
|
@ -61,7 +61,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when new packet is received
|
||||
radio.setIrqAction(setFlag);
|
||||
radio.setPacketReceivedAction(setFlag);
|
||||
|
||||
// start listening
|
||||
Serial.print(F("[nRF24] Starting to listen ... "));
|
||||
|
|
@ -112,7 +112,8 @@ void loop() {
|
|||
// you can also read received data as byte array
|
||||
/*
|
||||
byte byteArr[8];
|
||||
int state = radio.readData(byteArr, 8);
|
||||
int numBytes = radio.getPacketLength();
|
||||
int state = radio.readData(byteArr, numBytes);
|
||||
*/
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
|
|
|
|||
|
|
@ -59,12 +59,16 @@ void setup() {
|
|||
}
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("[nRF24] Transmitting packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 32 characters long
|
||||
int state = radio.transmit("Hello World!");
|
||||
String str = "Hello World! #" + String(count++);
|
||||
int state = radio.transmit(str);
|
||||
|
||||
if (state == RADIOLIB_ERR_NONE) {
|
||||
// the packet was successfully transmitted
|
||||
|
|
@ -63,7 +63,7 @@ void setup() {
|
|||
|
||||
// set the function that will be called
|
||||
// when packet transmission is finished
|
||||
radio.setIrqAction(setFlag);
|
||||
radio.setPacketSentAction(setFlag);
|
||||
|
||||
// start transmitting the first packet
|
||||
Serial.print(F("[nRF24] Sending first packet ... "));
|
||||
|
|
@ -95,6 +95,9 @@ void setFlag(void) {
|
|||
transmittedFlag = true;
|
||||
}
|
||||
|
||||
// counter to keep track of transmitted packets
|
||||
int count = 0;
|
||||
|
||||
void loop() {
|
||||
// check if the previous transmission finished
|
||||
if(transmittedFlag) {
|
||||
|
|
@ -127,8 +130,9 @@ void loop() {
|
|||
Serial.print(F("[nRF24] Sending another packet ... "));
|
||||
|
||||
// you can transmit C-string or Arduino string up to
|
||||
// 256 characters long
|
||||
transmissionState = radio.startTransmit("Hello World!");
|
||||
// 32 characters long
|
||||
String str = "Hello World! #" + String(count++);
|
||||
transmissionState = radio.startTransmit(str);
|
||||
|
||||
// you can also transmit byte array up to 256 bytes long
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -1,176 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import serial
|
||||
import sys
|
||||
import numpy as np
|
||||
import matplotlib as mpl
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from datetime import datetime
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
||||
# number of samples in each scanline
|
||||
SCAN_WIDTH = 33
|
||||
|
||||
# scanline Serial start/end markers
|
||||
SCAN_MARK_START = 'SCAN '
|
||||
SCAN_MARK_FREQ = 'FREQ '
|
||||
SCAN_MARK_END = ' END'
|
||||
|
||||
# output path
|
||||
OUT_PATH = 'out'
|
||||
|
||||
# default settings
|
||||
DEFAULT_BAUDRATE = 115200
|
||||
DEFAULT_COLOR_MAP = 'viridis'
|
||||
DEFAULT_SCAN_LEN = 200
|
||||
DEFAULT_RSSI_OFFSET = -11
|
||||
|
||||
# Print iterations progress
|
||||
# from https://stackoverflow.com/questions/3173320/text-progress-bar-in-terminal-with-block-characters
|
||||
def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 50, fill = '█', printEnd = "\r"):
|
||||
"""
|
||||
Call in a loop to create terminal progress bar
|
||||
@params:
|
||||
iteration - Required : current iteration (Int)
|
||||
total - Required : total iterations (Int)
|
||||
prefix - Optional : prefix string (Str)
|
||||
suffix - Optional : suffix string (Str)
|
||||
decimals - Optional : positive number of decimals in percent complete (Int)
|
||||
length - Optional : character length of bar (Int)
|
||||
fill - Optional : bar fill character (Str)
|
||||
printEnd - Optional : end character (e.g. "\r", "\r\n") (Str)
|
||||
"""
|
||||
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
|
||||
filledLength = int(length * iteration // total)
|
||||
bar = fill * filledLength + '-' * (length - filledLength)
|
||||
print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd)
|
||||
if iteration == total:
|
||||
print()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description='''
|
||||
RadioLib SX126x_Spectrum_Scan plotter script. Displays output from SX126x_Spectrum_Scan example
|
||||
as grayscale and
|
||||
|
||||
Depends on pyserial and matplotlib, install by:
|
||||
'python3 -m pip install pyserial matplotlib'
|
||||
|
||||
Step-by-step guide on how to use the script:
|
||||
1. Upload the SX126x_Spectrum_Scan example to your Arduino board with SX1262 connected.
|
||||
2. Run the script with appropriate arguments.
|
||||
3. Once the scan is complete, output files will be saved to out/
|
||||
''')
|
||||
parser.add_argument('port',
|
||||
type=str,
|
||||
help='COM port to connect to the device')
|
||||
parser.add_argument('--speed',
|
||||
default=DEFAULT_BAUDRATE,
|
||||
type=int,
|
||||
help=f'COM port baudrate (defaults to {DEFAULT_BAUDRATE})')
|
||||
parser.add_argument('--map',
|
||||
default=DEFAULT_COLOR_MAP,
|
||||
type=str,
|
||||
help=f'Matplotlib color map to use for the output (defaults to "{DEFAULT_COLOR_MAP}")')
|
||||
parser.add_argument('--len',
|
||||
default=DEFAULT_SCAN_LEN,
|
||||
type=int,
|
||||
help=f'Number of scanlines to record (defaults to {DEFAULT_SCAN_LEN})')
|
||||
parser.add_argument('--offset',
|
||||
default=DEFAULT_RSSI_OFFSET,
|
||||
type=int,
|
||||
help=f'Default RSSI offset in dBm (defaults to {DEFAULT_RSSI_OFFSET})')
|
||||
parser.add_argument('--freq',
|
||||
default=-1,
|
||||
type=float,
|
||||
help=f'Default starting frequency in MHz')
|
||||
args = parser.parse_args()
|
||||
|
||||
freq_mode = False
|
||||
scan_len = args.len
|
||||
if (args.freq != -1):
|
||||
freq_mode = True
|
||||
scan_len = 1000
|
||||
|
||||
# create the color map and the result array
|
||||
arr = np.zeros((SCAN_WIDTH, scan_len))
|
||||
|
||||
# scanline counter
|
||||
row = 0
|
||||
|
||||
# list of frequencies in frequency mode
|
||||
freq_list = []
|
||||
|
||||
# open the COM port
|
||||
with serial.Serial(args.port, args.speed, timeout=None) as com:
|
||||
while(True):
|
||||
# update the progress bar
|
||||
if not freq_mode:
|
||||
printProgressBar(row, scan_len)
|
||||
|
||||
# read a single line
|
||||
try:
|
||||
line = com.readline().decode('utf-8')
|
||||
except:
|
||||
continue
|
||||
|
||||
if SCAN_MARK_FREQ in line:
|
||||
new_freq = float(line.split(' ')[1])
|
||||
if (len(freq_list) > 1) and (new_freq < freq_list[-1]):
|
||||
break
|
||||
|
||||
freq_list.append(new_freq)
|
||||
print('{:.3f}'.format(new_freq), end = '\r')
|
||||
continue
|
||||
|
||||
# check the markers
|
||||
if (SCAN_MARK_START in line) and (SCAN_MARK_END in line):
|
||||
# get the values
|
||||
scanline = line[len(SCAN_MARK_START):-len(SCAN_MARK_END)].split(',')
|
||||
for col in range(SCAN_WIDTH):
|
||||
arr[col][row] = int(scanline[col])
|
||||
|
||||
# increment the row counter
|
||||
row = row + 1
|
||||
|
||||
# check if we're done
|
||||
if (not freq_mode) and (row >= scan_len):
|
||||
break
|
||||
|
||||
# scale to the number of scans (sum of any given scanline)
|
||||
num_samples = arr.sum(axis=0)[0]
|
||||
arr *= (num_samples/arr.max())
|
||||
|
||||
if freq_mode:
|
||||
scan_len = len(freq_list)
|
||||
|
||||
# create the figure
|
||||
fig, ax = plt.subplots()
|
||||
|
||||
# display the result as heatmap
|
||||
extent = [0, scan_len, -4*(SCAN_WIDTH + 1), args.offset]
|
||||
if freq_mode:
|
||||
extent[0] = freq_list[0]
|
||||
extent[1] = freq_list[-1]
|
||||
im = ax.imshow(arr[:,:scan_len], cmap=args.map, extent=extent)
|
||||
fig.colorbar(im)
|
||||
|
||||
# set some properites and show
|
||||
timestamp = datetime.now().strftime('%y-%m-%d %H-%M-%S')
|
||||
title = f'RadioLib SX126x Spectral Scan {timestamp}'
|
||||
if freq_mode:
|
||||
plt.xlabel("Frequency [Hz]")
|
||||
else:
|
||||
plt.xlabel("Time [sample]")
|
||||
plt.ylabel("RSSI [dBm]")
|
||||
ax.set_aspect('auto')
|
||||
fig.suptitle(title)
|
||||
fig.canvas.manager.set_window_title(title)
|
||||
plt.savefig(f'{OUT_PATH}/{title.replace(" ", "_")}.png', dpi=300)
|
||||
plt.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
import re, sys, argparse
|
||||
from pathlib import Path
|
||||
from argparse import RawTextHelpFormatter
|
||||
|
||||
|
||||
'''
|
||||
TODO list:
|
||||
1. Parse macro values (the names of bits in all registers in header file)
|
||||
2. Failed SPI write handling
|
||||
3. SX126x/SX128x handling
|
||||
'''
|
||||
|
||||
|
||||
def get_macro_name(value, macros):
|
||||
for macro in macros:
|
||||
if macro[1] == value:
|
||||
return macro[0]
|
||||
return 'UNKNOWN_VALUE'
|
||||
|
||||
|
||||
def get_macro_value(value):
|
||||
return ' 0x{0:02X}\n'.format(int(value, 16))
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description='''
|
||||
RadioLib debug output decoder script. Turns RadioLib Serial dumps into readable text.
|
||||
|
||||
Step-by-step guid on how to use the decoder:
|
||||
1. Uncomment lines 312 (#define RADIOLIB_DEBUG) and 313 (#define RADIOLIB_VERBOSE) in RadioLib/src/BuildOpt.h
|
||||
2. Recompile and upload the failing Arduino sketch
|
||||
3. Open Arduino IDE Serial Monitor and enable timestamps
|
||||
4. Copy the Serial output and save it into a .txt file
|
||||
5. Run this script
|
||||
|
||||
Output will be saved in the file specified by --out and printed to the terminal
|
||||
''')
|
||||
parser.add_argument('file', metavar='file', type=str, help='Text file of the debug output')
|
||||
parser.add_argument('--out', metavar='out', default='./out.txt', type=str, help='Where to save the decoded file (defaults to ./out.txt)')
|
||||
args = parser.parse_args()
|
||||
|
||||
# open the log file
|
||||
log = open(args.file, 'r').readlines()
|
||||
|
||||
# find modules that are in use
|
||||
used_modules = []
|
||||
pattern_module = re.compile('(([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?.[0-9]{3} -> )?M\t')
|
||||
for entry in log:
|
||||
m = pattern_module.search(entry)
|
||||
if m != None:
|
||||
used_modules.append(entry[m.end():].rstrip())
|
||||
|
||||
# get paths to all relevant header files
|
||||
header_files = []
|
||||
for path in Path('../../src').rglob('*.h'):
|
||||
for module in used_modules:
|
||||
if module in path.name:
|
||||
header_files.append(path)
|
||||
|
||||
# extract names of address macros from the header files
|
||||
macro_addresses = []
|
||||
pattern_define = re.compile('#define \w* +\w*(\n| +\/\/){1}')
|
||||
for path in header_files:
|
||||
file = open(path, 'r').readlines()
|
||||
for line in file:
|
||||
m = pattern_define.search(line)
|
||||
if m != None:
|
||||
s = re.split(' +', m.group().rstrip())
|
||||
if (s.__len__() > 1) and ('_REG' in s[1]):
|
||||
macro_addresses.append([s[1], int(s[2], 0)])
|
||||
|
||||
'''
|
||||
# extract names of value macros for each adddress macro
|
||||
macro_values = []
|
||||
for path in header_files:
|
||||
file = open(path, 'r').readlines()
|
||||
for line in file:
|
||||
for module in used_modules:
|
||||
pattern_addr_macro = re.compile('\/\/ SI443X_REG_\w+'.format(module.capitalize()))
|
||||
'''
|
||||
|
||||
# parse every line in the log file
|
||||
out = []
|
||||
pattern_debug = re.compile('(([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?.[0-9]{3} -> )?[RWM]\t.+')
|
||||
for entry in log:
|
||||
m = pattern_debug.search(entry)
|
||||
if m != None:
|
||||
s = re.split('( |\t)+', entry.rstrip())
|
||||
cmd_len = int((s.__len__() - 7)/2)
|
||||
new_entry = s[0] + s[1] + s[2] + s[3]
|
||||
if s[4] == 'W':
|
||||
macro_address = int(s[6], 16)
|
||||
new_entry += 'write {0:>2} 0x{1:02X} {2}\n'.format(cmd_len, macro_address, get_macro_name(macro_address, macro_addresses))
|
||||
for i in range(cmd_len):
|
||||
new_entry += get_macro_value(s[8 + 2*i]);
|
||||
elif s[4] == 'R':
|
||||
macro_address = int(s[6], 16)
|
||||
new_entry += 'read {0:>2} 0x{1:02X} {2}\n'.format(cmd_len, macro_address, get_macro_name(macro_address, macro_addresses))
|
||||
for i in range(cmd_len):
|
||||
new_entry += get_macro_value(s[8 + 2*i]);
|
||||
elif s[4] == 'M':
|
||||
new_entry += 'module {}\n'.format(s[6])
|
||||
out.append(new_entry)
|
||||
else:
|
||||
out.append(entry)
|
||||
|
||||
# write the output file
|
||||
out_file = open(args.out, 'w')
|
||||
for line in out:
|
||||
print(line, end='')
|
||||
out_file.write(line)
|
||||
out_file.close()
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#include "<module_name>.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_<module_name>)
|
||||
|
||||
<module_name>::<module_name>(Module* mod) {
|
||||
/*
|
||||
Constructor implementation MUST assign the provided "mod" pointer to the private "_mod" pointer.
|
||||
*/
|
||||
_mod = mod;
|
||||
}
|
||||
|
||||
int16_t <module_name>::begin() {
|
||||
/*
|
||||
"begin" method implementation MUST call the "init" method with appropriate settings.
|
||||
*/
|
||||
_mod->init();
|
||||
|
||||
/*
|
||||
"begin" method SHOULD implement some sort of mechanism to verify the connection between Arduino and the module.
|
||||
|
||||
For example, reading a version register
|
||||
*/
|
||||
}
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
RadioLib Module Template header file
|
||||
|
||||
Before opening pull request, please make sure that:
|
||||
1. All files MUST be compiled without errors using default Arduino IDE settings.
|
||||
2. All files SHOULD be compiled without warnings with compiler warnings set to "All".
|
||||
3. Example sketches MUST be working correctly and MUST be stable enough to run for prolonged periods of time.
|
||||
4. Writing style SHOULD be consistent.
|
||||
5. Comments SHOULD be in place for the most important chunks of code and SHOULD be free of typos.
|
||||
6. To indent, 2 spaces MUST be used.
|
||||
|
||||
If at any point you are unsure about the required style, please refer to the rest of the modules.
|
||||
*/
|
||||
|
||||
#if !defined(_RADIOLIB_<module_name>_H) && !defined(RADIOLIB_EXCLUDE_<module_name>)
|
||||
#if !defined(_RADIOLIB_<module_name>_H)
|
||||
#define _RADIOLIB_<module_name>_H
|
||||
|
||||
/*
|
||||
Header file for each module MUST include Module.h and TypeDef.h in the src folder.
|
||||
The header file MAY include additional header files.
|
||||
*/
|
||||
#include "../../Module.h"
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
/*
|
||||
Only use the following include if the module implements methods for OSI physical layer control.
|
||||
This concerns only modules similar to SX127x/RF69/CC1101 etc.
|
||||
|
||||
In this case, your class MUST implement all virtual methods of PhysicalLayer class.
|
||||
*/
|
||||
//#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
||||
|
||||
/*
|
||||
Register map
|
||||
Definition of SPI register map SHOULD be placed here. The register map SHOULD have two parts:
|
||||
|
||||
1 - Address map: only defines register names and addresses. Register names MUST match names in
|
||||
official documentation (datasheets etc.).
|
||||
2 - Variable map: defines variables inside register. This functions as a bit range map for a specific register.
|
||||
Bit range (MSB and LSB) as well as short description for each variable MUST be provided in a comment.
|
||||
|
||||
See RF69 and SX127x header files for examples of register maps.
|
||||
*/
|
||||
// <module_name> register map | spaces up to this point
|
||||
#define RADIOLIB_<module_name>_REG_<register_name> 0x00
|
||||
|
||||
// <module_name>_REG_<register_name> MSB LSB DESCRIPTION
|
||||
#define RADIOLIB_<module_name>_<register_variable> 0b00000000 // 7 0 <description>
|
||||
|
||||
|
||||
/*
|
||||
Module class definition
|
||||
|
||||
The module class MAY inherit from the following classes:
|
||||
|
||||
1 - PhysicalLayer: In case the module implements methods for OSI physical layer control (e.g. SX127x).
|
||||
2 - Common class: In case the module further specifies some more generic class (e.g. SX127x/SX1278)
|
||||
*/
|
||||
class <module_name> {
|
||||
public:
|
||||
/*
|
||||
Constructor MUST have only one parameter "Module* mod".
|
||||
The class MAY implement additional overloaded constructors.
|
||||
*/
|
||||
// constructor
|
||||
<module_name>(Module* mod);
|
||||
|
||||
/*
|
||||
The class MUST implement at least one basic method called "begin".
|
||||
The "begin" method MUST initialize the module and return the status as int16_t type.
|
||||
*/
|
||||
// basic methods
|
||||
int16_t begin();
|
||||
|
||||
/*
|
||||
The class MAY implement additional methods.
|
||||
All implemented methods SHOULD return the status as int16_t type.
|
||||
*/
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
private:
|
||||
#endif
|
||||
/*
|
||||
The class MUST contain private member "Module* _mod"
|
||||
*/
|
||||
Module* _mod;
|
||||
|
||||
/*
|
||||
The class MAY contain additional private variables and/or methods.
|
||||
Private member variables MUST have a name prefixed with "_" (underscore, ASCII 0x5F)
|
||||
|
||||
Usually, these are variables for saving module configuration, or methods that do not have to be exposed to the end user.
|
||||
*/
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
11
lib/RadioLib/idf_component.yml
Normal file
11
lib/RadioLib/idf_component.yml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
version: "6.5.0"
|
||||
description: "Universal wireless communication library. User-friendly library for sub-GHz radio modules (SX1278, RF69, CC1101, SX1268, and many others), as well as ham radio digital modes (RTTY, SSTV, AX.25 etc.) and other protocols (Pagers, LoRaWAN)."
|
||||
tags: "radio, communication, morse, cc1101, aprs, sx1276, sx1278, sx1272, rtty, ax25, afsk, nrf24, rfm96, sx1231, rfm96, rfm98, sstv, sx1278, sx1272, sx1276, sx1280, sx1281, sx1282, sx1261, sx1262, sx1268, si4432, rfm22, llcc68, pager, pocsag, lorawan"
|
||||
url: "https://github.com/jgromes/RadioLib"
|
||||
repository: "https://github.com/jgromes/RadioLib.git"
|
||||
license: "MIT"
|
||||
dependencies:
|
||||
# Required IDF version
|
||||
idf: ">=4.1"
|
||||
maintainers:
|
||||
"Jan Gromeš <gromes.jan@gmail.com>"
|
||||
|
|
@ -28,6 +28,7 @@ Si4431 KEYWORD1
|
|||
Si4432 KEYWORD1
|
||||
SIM800 KEYWORD1
|
||||
SX1231 KEYWORD1
|
||||
SX1233 KEYWORD1
|
||||
SX1261 KEYWORD1
|
||||
SX1262 KEYWORD1
|
||||
SX1268 KEYWORD1
|
||||
|
|
@ -56,6 +57,9 @@ APRSClient KEYWORD1
|
|||
PagerClient KEYWORD1
|
||||
ExternalRadio KEYWORD1
|
||||
BellClient KEYWORD1
|
||||
LoRaWANNode KEYWORD1
|
||||
LoRaWANBand_t KEYWORD1
|
||||
LoRaWANEvent_t KEYWORD1
|
||||
|
||||
# SSTV modes
|
||||
Scottie1 KEYWORD1
|
||||
|
|
@ -73,6 +77,17 @@ Bell101 KEYWORD1
|
|||
Bell103 KEYWORD1
|
||||
Bell202 KEYWORD1
|
||||
|
||||
# LoRaWAN bands
|
||||
EU868 KEYWORD1
|
||||
US915 KEYWORD1
|
||||
CN780 KEYWORD1
|
||||
EU433 KEYWORD1
|
||||
AU915 KEYWORD1
|
||||
CN500 KEYWORD1
|
||||
AS923 KEYWORD1
|
||||
KR920 KEYWORD1
|
||||
IN865 KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
|
@ -132,10 +147,10 @@ setDataShapingOOK KEYWORD2
|
|||
setCRC KEYWORD2
|
||||
variablePacketLengthMode KEYWORD2
|
||||
fixedPacketLengthMode KEYWORD2
|
||||
setCrcFiltering KEYWORD2
|
||||
enableSyncWordFiltering KEYWORD2
|
||||
disableSyncWordFiltering KEYWORD2
|
||||
setPromiscuous KEYWORD2
|
||||
setCrcFiltering KEYWORD2
|
||||
enableSyncWordFiltering KEYWORD2
|
||||
disableSyncWordFiltering KEYWORD2
|
||||
setPromiscuous KEYWORD2
|
||||
setRSSIConfig KEYWORD2
|
||||
setEncoding KEYWORD2
|
||||
getIRQFlags KEYWORD2
|
||||
|
|
@ -145,11 +160,11 @@ setRfSwitchPins KEYWORD2
|
|||
forceLDRO KEYWORD2
|
||||
autoLDRO KEYWORD2
|
||||
getChipVersion KEYWORD2
|
||||
invertIQ KEYWORD2
|
||||
invertIQ KEYWORD2
|
||||
setOokThresholdType KEYWORD2
|
||||
setOokPeakThresholdDecrement KEYWORD2
|
||||
setOokFixedOrFloorThreshold KEYWORD2
|
||||
setOokPeakThresholdStep KEYWORD2
|
||||
setOokPeakThresholdStep KEYWORD2
|
||||
setDirectSyncWord KEYWORD2
|
||||
setDirectAction KEYWORD2
|
||||
readBit KEYWORD2
|
||||
|
|
@ -167,6 +182,7 @@ setFifoFullAction KEYWORD2
|
|||
clearFifoFullAction KEYWORD2
|
||||
fifoAdd KEYWORD2
|
||||
fifoGet KEYWORD2
|
||||
setLowBatteryThreshold KEYWORD2
|
||||
|
||||
# RF69-specific
|
||||
setAESKey KEYWORD2
|
||||
|
|
@ -265,10 +281,49 @@ sendTone KEYWORD2
|
|||
dropSync KEYWORD2
|
||||
setTimerFlag KEYWORD2
|
||||
setInterruptSetup KEYWORD2
|
||||
setPacketReceivedAction KEYWORD2
|
||||
clearPacketReceivedAction KEYWORD2
|
||||
setPacketSentAction KEYWORD2
|
||||
clearPacketSentAction KEYWORD2
|
||||
setDataRate KEYWORD2
|
||||
checkDataRate KEYWORD2
|
||||
|
||||
# BellModem
|
||||
setModem KEYWORD2
|
||||
|
||||
# LoRaWAN
|
||||
wipe KEYWORD2
|
||||
getBufferNonces KEYWORD2
|
||||
setBufferNonces KEYWORD2
|
||||
getBufferSession KEYWORD2
|
||||
setBufferSession KEYWORD2
|
||||
restore KEYWORD2
|
||||
beginOTAA KEYWORD2
|
||||
beginABP KEYWORD2
|
||||
isJoined KEYWORD2
|
||||
saveSession KEYWORD2
|
||||
sendMacCommandReq KEYWORD2
|
||||
uplink KEYWORD2
|
||||
downlink KEYWORD2
|
||||
sendReceive KEYWORD2
|
||||
setDeviceStatus KEYWORD2
|
||||
getFcntUp KEYWORD2
|
||||
getNFcntDown KEYWORD2
|
||||
getAFcntDown KEYWORD2
|
||||
resetFcntDown KEYWORD2
|
||||
setDatarate KEYWORD2
|
||||
setADR KEYWORD2
|
||||
setDutyCycle KEYWORD2
|
||||
dutyCycleInterval KEYWORD2
|
||||
timeUntilUplink KEYWORD2
|
||||
setDwellTime KEYWORD2
|
||||
maxPayloadDwellTime KEYWORD2
|
||||
setTxPower KEYWORD2
|
||||
setCSMA KEYWORD2
|
||||
getMacLinkCheckAns KEYWORD2
|
||||
getMacDeviceTimeAns KEYWORD2
|
||||
getDevAddr KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
|
@ -364,3 +419,22 @@ RADIOLIB_ERR_RANGING_TIMEOUT LITERAL1
|
|||
|
||||
RADIOLIB_ERR_INVALID_PAYLOAD LITERAL1
|
||||
RADIOLIB_ERR_ADDRESS_NOT_FOUND LITERAL1
|
||||
RADIOLIB_ERR_INVALID_FUNCTION LITERAL1
|
||||
|
||||
RADIOLIB_ERR_NETWORK_NOT_JOINED LITERAL1
|
||||
RADIOLIB_ERR_DOWNLINK_MALFORMED LITERAL1
|
||||
RADIOLIB_ERR_INVALID_REVISION LITERAL1
|
||||
RADIOLIB_ERR_INVALID_PORT LITERAL1
|
||||
RADIOLIB_ERR_NO_RX_WINDOW LITERAL1
|
||||
RADIOLIB_ERR_INVALID_CHANNEL LITERAL1
|
||||
RADIOLIB_ERR_INVALID_CID LITERAL1
|
||||
RADIOLIB_ERR_UPLINK_UNAVAILABLE LITERAL1
|
||||
RADIOLIB_ERR_COMMAND_QUEUE_FULL LITERAL1
|
||||
RADIOLIB_ERR_COMMAND_QUEUE_ITEM_NOT_FOUND LITERAL1
|
||||
RADIOLIB_ERR_JOIN_NONCE_INVALID LITERAL1
|
||||
RADIOLIB_ERR_N_FCNT_DOWN_INVALID LITERAL1
|
||||
RADIOLIB_ERR_A_FCNT_DOWN_INVALID LITERAL1
|
||||
RADIOLIB_ERR_DATA_RATE_INVALID LITERAL1
|
||||
RADIOLIB_ERR_DWELL_TIME_EXCEEDED LITERAL1
|
||||
RADIOLIB_ERR_CHECKSUM_MISMATCH LITERAL1
|
||||
RADIOLIB_LORAWAN_NO_DOWNLINK LITERAL1
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"name": "RadioLib",
|
||||
"version": "6.0.0",
|
||||
"description": "Universal wireless communication library. User-friendly library for sub-GHz radio modules (SX1278, RF69, CC1101, SX1268, and many others), as well as ham radio digital modes (RTTY, SSTV, AX.25 etc.).",
|
||||
"keywords": "radio, communication, morse, cc1101, aprs, sx1276, sx1278, sx1272, rtty, ax25, afsk, nrf24, rfm96, sx1231, rfm96, rfm98, sstv, sx1278, sx1272, sx1276, sx1280, sx1281, sx1282, sx1261, sx1262, sx1268, si4432, rfm22, llcc68, pager, pocsag",
|
||||
"version": "6.5.0",
|
||||
"description": "Universal wireless communication library. User-friendly library for sub-GHz radio modules (SX1278, RF69, CC1101, SX1268, and many others), as well as ham radio digital modes (RTTY, SSTV, AX.25 etc.) and other protocols (Pagers, LoRaWAN).",
|
||||
"keywords": "radio, communication, morse, cc1101, aprs, sx1276, sx1278, sx1272, rtty, ax25, afsk, nrf24, rfm96, sx1231, rfm96, rfm98, sstv, sx1278, sx1272, sx1276, sx1280, sx1281, sx1282, sx1261, sx1262, sx1268, si4432, rfm22, llcc68, pager, pocsag, lorawan",
|
||||
"homepage": "https://github.com/jgromes/RadioLib",
|
||||
"repository":
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
name=RadioLib
|
||||
version=6.0.0
|
||||
version=6.5.0
|
||||
author=Jan Gromes <gromes.jan@gmail.com>
|
||||
maintainer=Jan Gromes <gromes.jan@gmail.com>
|
||||
sentence=Universal wireless communication library
|
||||
paragraph=User-friendly library for sub-GHz radio modules (SX1278, RF69, CC1101, SX1268, and many others), as well as ham radio digital modes (RTTY, SSTV, AX.25 etc.).
|
||||
paragraph=User-friendly library for sub-GHz radio modules (SX1278, RF69, CC1101, SX1268, and many others), as well as ham radio digital modes (RTTY, SSTV, AX.25 etc.) and other protocols (Pagers, LoRaWAN).
|
||||
category=Communication
|
||||
url=https://github.com/jgromes/RadioLib
|
||||
architectures=*
|
||||
|
|
|
|||
|
|
@ -54,19 +54,35 @@ void inline ArduinoHal::detachInterrupt(uint32_t interruptNum) {
|
|||
}
|
||||
|
||||
void inline ArduinoHal::delay(unsigned long ms) {
|
||||
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
|
||||
::delay(ms);
|
||||
#else
|
||||
::delay(ms * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS));
|
||||
#endif
|
||||
}
|
||||
|
||||
void inline ArduinoHal::delayMicroseconds(unsigned long us) {
|
||||
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
|
||||
::delayMicroseconds(us);
|
||||
#else
|
||||
::delayMicroseconds(us * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS));
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned long inline ArduinoHal::millis() {
|
||||
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
|
||||
return(::millis());
|
||||
#else
|
||||
return(::millis() * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS));
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned long inline ArduinoHal::micros() {
|
||||
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
|
||||
return(::micros());
|
||||
#else
|
||||
return(::micros() * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS));
|
||||
#endif
|
||||
}
|
||||
|
||||
long inline ArduinoHal::pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) {
|
||||
|
|
@ -84,8 +100,10 @@ void inline ArduinoHal::spiBeginTransaction() {
|
|||
spi->beginTransaction(spiSettings);
|
||||
}
|
||||
|
||||
uint8_t inline ArduinoHal::spiTransfer(uint8_t b) {
|
||||
return(spi->transfer(b));
|
||||
void ArduinoHal::spiTransfer(uint8_t* out, size_t len, uint8_t* in) {
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
in[i] = spi->transfer(out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void inline ArduinoHal::spiEndTransaction() {
|
||||
|
|
@ -102,14 +120,20 @@ void inline ArduinoHal::tone(uint32_t pin, unsigned int frequency, unsigned long
|
|||
return;
|
||||
}
|
||||
::tone(pin, frequency, duration);
|
||||
#elif defined(ESP32)
|
||||
#elif defined(RADIOLIB_ESP32)
|
||||
// ESP32 tone() emulation
|
||||
(void)duration;
|
||||
if(prev == -1) {
|
||||
#if !defined(ESP_IDF_VERSION) || (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0))
|
||||
ledcAttachPin(pin, RADIOLIB_TONE_ESP32_CHANNEL);
|
||||
#endif
|
||||
}
|
||||
if(prev != frequency) {
|
||||
#if !defined(ESP_IDF_VERSION) || (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0))
|
||||
ledcWriteTone(RADIOLIB_TONE_ESP32_CHANNEL, frequency);
|
||||
#else
|
||||
ledcWriteTone(pin, frequency);
|
||||
#endif
|
||||
}
|
||||
prev = frequency;
|
||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
|
|
@ -120,6 +144,10 @@ void inline ArduinoHal::tone(uint32_t pin, unsigned int frequency, unsigned long
|
|||
}
|
||||
pwmPin->period(1.0 / frequency);
|
||||
pwmPin->write(0.5);
|
||||
#else
|
||||
(void)pin;
|
||||
(void)frequency;
|
||||
(void)duration;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -134,13 +162,18 @@ void inline ArduinoHal::noTone(uint32_t pin) {
|
|||
return;
|
||||
}
|
||||
::noTone(pin);
|
||||
#elif defined(ESP32)
|
||||
#elif defined(RADIOLIB_ESP32)
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
// ESP32 tone() emulation
|
||||
#if !defined(ESP_IDF_VERSION) || (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0))
|
||||
ledcDetachPin(pin);
|
||||
ledcWrite(RADIOLIB_TONE_ESP32_CHANNEL, 0);
|
||||
#else
|
||||
ledcDetach(pin);
|
||||
ledcWrite(pin, 0);
|
||||
#endif
|
||||
prev = -1;
|
||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
if(pin == RADIOLIB_NC) {
|
||||
|
|
@ -149,6 +182,8 @@ void inline ArduinoHal::noTone(uint32_t pin) {
|
|||
// better tone for mbed OS boards
|
||||
(void)pin;
|
||||
pwmPin->suspend();
|
||||
#else
|
||||
(void)pin;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class ArduinoHal : public RadioLibHal {
|
|||
long pulseIn(uint32_t pin, uint32_t state, unsigned long timeout) override;
|
||||
void spiBegin() override;
|
||||
void spiBeginTransaction() override;
|
||||
uint8_t spiTransfer(uint8_t b) override;
|
||||
void spiTransfer(uint8_t* out, size_t len, uint8_t* in) override;
|
||||
void spiEndTransaction() override;
|
||||
void spiEnd() override;
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ class ArduinoHal : public RadioLibHal {
|
|||
void yield() override;
|
||||
uint32_t pinToInterrupt(uint32_t pin) override;
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
SPIClass* spi = NULL;
|
||||
|
|
@ -70,7 +70,7 @@ class ArduinoHal : public RadioLibHal {
|
|||
mbed::PwmOut *pwmPin = NULL;
|
||||
#endif
|
||||
|
||||
#if defined(ESP32)
|
||||
#if defined(RADIOLIB_ESP32)
|
||||
int32_t prev = -1;
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,121 @@
|
|||
#if !defined(_RADIOLIB_BUILD_OPTIONS_H)
|
||||
#define _RADIOLIB_BUILD_OPTIONS_H
|
||||
|
||||
/* RadioLib build configuration options */
|
||||
|
||||
/*
|
||||
* Debug output enable.
|
||||
* Warning: Debug output will slow down the whole system significantly.
|
||||
* Also, it will result in larger compiled binary.
|
||||
* Levels: basic - only main info
|
||||
* protocol - mainly LoRaWAN stuff, but other protocols as well
|
||||
* SPI - full transcript of all SPI communication
|
||||
*/
|
||||
#if !defined(RADIOLIB_DEBUG_BASIC)
|
||||
#define RADIOLIB_DEBUG_BASIC (0)
|
||||
#endif
|
||||
#if !defined(RADIOLIB_DEBUG_PROTOCOL)
|
||||
#define RADIOLIB_DEBUG_PROTOCOL (0)
|
||||
#endif
|
||||
#if !defined(RADIOLIB_DEBUG_SPI)
|
||||
#define RADIOLIB_DEBUG_SPI (0)
|
||||
#endif
|
||||
|
||||
// set which output port should be used for debug output
|
||||
// may be Serial port (on Arduino) or file like stdout or stderr (on generic platforms)
|
||||
#if !defined(RADIOLIB_DEBUG_PORT)
|
||||
#define RADIOLIB_DEBUG_PORT Serial
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Comment to disable "paranoid" SPI mode, or set RADIOLIB_SPI_PARANOID to 0
|
||||
* Every write to an SPI register using SPI set function will be verified by a subsequent read operation.
|
||||
* This improves reliability, but slightly slows down communication.
|
||||
* Note: Enabled by default.
|
||||
*/
|
||||
#if !defined(RADIOLIB_SPI_PARANOID)
|
||||
#define RADIOLIB_SPI_PARANOID (1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Comment to disable parameter range checking
|
||||
* RadioLib will check provided parameters (such as frequency) against limits determined by the device manufacturer.
|
||||
* It is highly advised to keep this macro defined, removing it will allow invalid values to be set,
|
||||
* possibly leading to bricked module and/or program crashing.
|
||||
* Note: Enabled by default.
|
||||
*/
|
||||
#if !defined(RADIOLIB_CHECK_PARAMS)
|
||||
#define RADIOLIB_CHECK_PARAMS (1)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SX127x errata fix enable
|
||||
* Warning: SX127x errata fix has been reported to cause issues with LoRa bandwidths lower than 62.5 kHz.
|
||||
* It should only be enabled if you really are observing some errata-related issue.
|
||||
* Note: Disabled by default.
|
||||
*/
|
||||
#if !defined(RADIOLIB_FIX_ERRATA_SX127X)
|
||||
#define RADIOLIB_FIX_ERRATA_SX127X (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* God mode enable - all methods and member variables in all classes will be made public, thus making them accessible from Arduino code.
|
||||
* Warning: Come on, it's called GOD mode - obviously only use this if you know what you're doing.
|
||||
* Failure to heed the above warning may result in bricked module.
|
||||
*/
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#define RADIOLIB_GODMODE (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Low-level hardware access enable
|
||||
* This will make some hardware methods like SPI get/set accessible from the user sketch - think of it as "god mode lite"
|
||||
* Warning: RadioLib won't stop you from writing invalid stuff into your device, so it's quite easy to brick your module with this.
|
||||
*/
|
||||
#if !defined(RADIOLIB_LOW_LEVEL)
|
||||
#define RADIOLIB_LOW_LEVEL (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enable pre-defined modules when using RadioShield, disabled by default.
|
||||
*/
|
||||
#if !defined(RADIOLIB_RADIOSHIELD)
|
||||
#define RADIOLIB_RADIOSHIELD (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enable interrupt-based timing control
|
||||
* For details, see https://github.com/jgromes/RadioLib/wiki/Interrupt-Based-Timing
|
||||
*/
|
||||
#if !defined(RADIOLIB_INTERRUPT_TIMING)
|
||||
#define RADIOLIB_INTERRUPT_TIMING (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enable static-only memory management: no dynamic allocation will be performed.
|
||||
* Warning: Large static arrays will be created in some methods. It is not advised to send large packets in this mode.
|
||||
*/
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#define RADIOLIB_STATIC_ONLY (0)
|
||||
#endif
|
||||
|
||||
// set the size of static arrays to use
|
||||
#if !defined(RADIOLIB_STATIC_ARRAY_SIZE)
|
||||
#define RADIOLIB_STATIC_ARRAY_SIZE (256)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment on boards whose clock runs too slow or too fast
|
||||
* Set the value according to the following scheme:
|
||||
* Enable timestamps on your terminal
|
||||
* Print something to terminal, wait 1000 milliseconds, print something again
|
||||
* If the difference is e.g. 1014 milliseconds between the prints, set this value to 14
|
||||
* Or, for more accuracy, wait for 100,000 milliseconds and divide the total drift by 100
|
||||
*/
|
||||
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
|
||||
//#define RADIOLIB_CLOCK_DRIFT_MS (0)
|
||||
#endif
|
||||
|
||||
#if ARDUINO >= 100
|
||||
// Arduino build
|
||||
#include "Arduino.h"
|
||||
|
|
@ -61,34 +176,39 @@
|
|||
// NOTE: Some of the exclusion macros are dependent on each other. For example, it is not possible to exclude RF69
|
||||
// while keeping SX1231 (because RF69 is the base class for SX1231). The dependency is always uni-directional,
|
||||
// so excluding SX1231 and keeping RF69 is valid.
|
||||
//#define RADIOLIB_EXCLUDE_CC1101
|
||||
//#define RADIOLIB_EXCLUDE_NRF24
|
||||
//#define RADIOLIB_EXCLUDE_RF69
|
||||
//#define RADIOLIB_EXCLUDE_SX1231 // dependent on RADIOLIB_EXCLUDE_RF69
|
||||
//#define RADIOLIB_EXCLUDE_SI443X
|
||||
//#define RADIOLIB_EXCLUDE_RFM2X // dependent on RADIOLIB_EXCLUDE_SI443X
|
||||
//#define RADIOLIB_EXCLUDE_SX127X
|
||||
//#define RADIOLIB_EXCLUDE_RFM9X // dependent on RADIOLIB_EXCLUDE_SX127X
|
||||
//#define RADIOLIB_EXCLUDE_SX126X
|
||||
//#define RADIOLIB_EXCLUDE_STM32WLX // dependent on RADIOLIB_EXCLUDE_SX126X
|
||||
//#define RADIOLIB_EXCLUDE_SX128X
|
||||
//#define RADIOLIB_EXCLUDE_AFSK
|
||||
//#define RADIOLIB_EXCLUDE_AX25
|
||||
//#define RADIOLIB_EXCLUDE_HELLSCHREIBER
|
||||
//#define RADIOLIB_EXCLUDE_MORSE
|
||||
//#define RADIOLIB_EXCLUDE_RTTY
|
||||
//#define RADIOLIB_EXCLUDE_SSTV
|
||||
//#define RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
//#define RADIOLIB_EXCLUDE_CC1101 (1)
|
||||
//#define RADIOLIB_EXCLUDE_NRF24 (1)
|
||||
//#define RADIOLIB_EXCLUDE_RF69 (1)
|
||||
//#define RADIOLIB_EXCLUDE_SX1231 (1) // dependent on RADIOLIB_EXCLUDE_RF69
|
||||
//#define RADIOLIB_EXCLUDE_SI443X (1)
|
||||
//#define RADIOLIB_EXCLUDE_RFM2X (1) // dependent on RADIOLIB_EXCLUDE_SI443X
|
||||
//#define RADIOLIB_EXCLUDE_SX127X (1)
|
||||
//#define RADIOLIB_EXCLUDE_SX126X (1)
|
||||
//#define RADIOLIB_EXCLUDE_STM32WLX (1) // dependent on RADIOLIB_EXCLUDE_SX126X
|
||||
//#define RADIOLIB_EXCLUDE_SX128X (1)
|
||||
//#define RADIOLIB_EXCLUDE_AFSK (1)
|
||||
//#define RADIOLIB_EXCLUDE_AX25 (1)
|
||||
//#define RADIOLIB_EXCLUDE_HELLSCHREIBER (1)
|
||||
//#define RADIOLIB_EXCLUDE_MORSE (1)
|
||||
//#define RADIOLIB_EXCLUDE_RTTY (1)
|
||||
//#define RADIOLIB_EXCLUDE_SSTV (1)
|
||||
//#define RADIOLIB_EXCLUDE_DIRECT_RECEIVE (1)
|
||||
|
||||
#elif defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) || defined(ARDUINO_ARCH_MEGAAVR))
|
||||
// Arduino AVR boards (except for megaAVR) - Uno, Mega etc.
|
||||
#define RADIOLIB_PLATFORM "Arduino AVR"
|
||||
|
||||
#if !(defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
|
||||
#define RADIOLIB_LOWEND_PLATFORM
|
||||
#endif
|
||||
|
||||
#elif defined(ESP8266)
|
||||
// ESP8266 boards
|
||||
#define RADIOLIB_PLATFORM "ESP8266"
|
||||
|
||||
#elif defined(ESP32)
|
||||
#elif defined(ESP32) || defined(ARDUINO_ARCH_ESP32)
|
||||
#define RADIOLIB_ESP32
|
||||
|
||||
// ESP32 boards
|
||||
#define RADIOLIB_PLATFORM "ESP32"
|
||||
|
||||
|
|
@ -242,6 +362,13 @@
|
|||
// Teensy
|
||||
#define RADIOLIB_PLATFORM "Teensy"
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RENESAS)
|
||||
// Arduino Renesas (UNO R4)
|
||||
#define RADIOLIB_PLATFORM "Arduino Renesas (UNO R4)"
|
||||
#define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
|
||||
#define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
|
||||
#define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
|
||||
|
||||
#else
|
||||
// other Arduino platforms not covered by the above list - this may or may not work
|
||||
#define RADIOLIB_PLATFORM "Unknown Arduino"
|
||||
|
|
@ -314,168 +441,126 @@
|
|||
#define OCT 8
|
||||
#define BIN 2
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdint.h>
|
||||
|
||||
using std::max;
|
||||
using std::min;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment to enable debug output.
|
||||
* Warning: Debug output will slow down the whole system significantly.
|
||||
* Also, it will result in larger compiled binary.
|
||||
* Levels: debug - only main info
|
||||
* verbose - full transcript of all SPI communication
|
||||
*/
|
||||
#if !defined(RADIOLIB_DEBUG)
|
||||
//#define RADIOLIB_DEBUG
|
||||
#endif
|
||||
#if !defined(RADIOLIB_VERBOSE)
|
||||
//#define RADIOLIB_VERBOSE
|
||||
#endif
|
||||
|
||||
// set which output port should be used for debug output
|
||||
// may be Serial port (on Arduino) or file like stdout or stderr (on generic platforms)
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO) && !defined(RADIOLIB_DEBUG_PORT)
|
||||
#define RADIOLIB_DEBUG_PORT Serial
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment to enable "paranoid" SPI mode
|
||||
* Every write to an SPI register using SPI set function will be verified by a subsequent read operation.
|
||||
* This improves reliablility, but slightly slows down communication.
|
||||
* Note: Enabled by default.
|
||||
*/
|
||||
#if !defined(RADIOLIB_SPI_PARANOID)
|
||||
#define RADIOLIB_SPI_PARANOID
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment to enable parameter range checking
|
||||
* RadioLib will check provided parameters (such as frequency) against limits determined by the device manufacturer.
|
||||
* It is highly advised to keep this macro defined, removing it will allow invalid values to be set,
|
||||
* possibly leading to bricked module and/or program crashing.
|
||||
* Note: Enabled by default.
|
||||
*/
|
||||
#if !defined(RADIOLIB_CHECK_PARAMS)
|
||||
#define RADIOLIB_CHECK_PARAMS
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment to enable SX127x errata fix
|
||||
* Warning: SX127x errata fix has been reported to cause issues with LoRa bandwidths lower than 62.5 kHz.
|
||||
* It should only be enabled if you really are observing some errata-related issue.
|
||||
* Note: Disabled by default.
|
||||
*/
|
||||
#if !defined(RADIOLIB_FIX_ERRATA_SX127X)
|
||||
//#define RADIOLIB_FIX_ERRATA_SX127X
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment to enable god mode - all methods and member variables in all classes will be made public, thus making them accessible from Arduino code.
|
||||
* Warning: Come on, it's called GOD mode - obviously only use this if you know what you're doing.
|
||||
* Failure to heed the above warning may result in bricked module.
|
||||
*/
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
//#define RADIOLIB_GODMODE
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment to enable low-level hardware access
|
||||
* This will make some hardware methods like SPI get/set accessible from the user sketch - think of it as "god mode lite"
|
||||
* Warning: RadioLib won't stop you from writing invalid stuff into your device, so it's quite easy to brick your module with this.
|
||||
*/
|
||||
#if !defined(RADIOLIB_LOW_LEVEL)
|
||||
//#define RADIOLIB_LOW_LEVEL
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment to enable pre-defined modules when using RadioShield.
|
||||
*/
|
||||
#if !defined(RADIOLIB_RADIOSHIELD)
|
||||
//#define RADIOLIB_RADIOSHIELD
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment to enable interrupt-based timing control
|
||||
* For details, see https://github.com/jgromes/RadioLib/wiki/Interrupt-Based-Timing
|
||||
*/
|
||||
#if !defined(RADIOLIB_INTERRUPT_TIMING)
|
||||
//#define RADIOLIB_INTERRUPT_TIMING
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Uncomment to enable static-only memory management: no dynamic allocation will be performed.
|
||||
* Warning: Large static arrays will be created in some methods. It is not advised to send large packets in this mode.
|
||||
*/
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
//#define RADIOLIB_STATIC_ONLY
|
||||
#endif
|
||||
|
||||
// set the size of static arrays to use
|
||||
#if !defined(RADIOLIB_STATIC_ARRAY_SIZE)
|
||||
#define RADIOLIB_STATIC_ARRAY_SIZE (256)
|
||||
#endif
|
||||
|
||||
// This only compiles on STM32 boards with SUBGHZ module, but also
|
||||
// include when generating docs
|
||||
#if (!defined(ARDUINO_ARCH_STM32) || !defined(SUBGHZSPI_BASE)) && !defined(DOXYGEN)
|
||||
#define RADIOLIB_EXCLUDE_STM32WLX
|
||||
#define RADIOLIB_EXCLUDE_STM32WLX (1)
|
||||
#endif
|
||||
|
||||
#if defined(RADIOLIB_DEBUG)
|
||||
// set the global debug mode flag
|
||||
#if RADIOLIB_DEBUG_BASIC || RADIOLIB_DEBUG_PROTOCOL || RADIOLIB_DEBUG_SPI
|
||||
#define RADIOLIB_DEBUG (1)
|
||||
#else
|
||||
#define RADIOLIB_DEBUG (0)
|
||||
#endif
|
||||
|
||||
#if RADIOLIB_DEBUG
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
#define RADIOLIB_DEBUG_PRINT(...) Module::serialPrintf(__VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_PRINTLN(M, ...) Module::serialPrintf(M "\n", ##__VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_PRINT_LVL(LEVEL, M, ...) Module::serialPrintf(LEVEL "" M, ##__VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) Module::serialPrintf(LEVEL "" M "\n", ##__VA_ARGS__)
|
||||
|
||||
// some platforms do not support printf("%f"), so it has to be done this way
|
||||
#define RADIOLIB_DEBUG_PRINT_FLOAT(LEVEL, VAL, DECIMALS) RADIOLIB_DEBUG_PRINT(LEVEL); RADIOLIB_DEBUG_PORT.print(VAL, DECIMALS)
|
||||
#else
|
||||
#if !defined(RADIOLIB_DEBUG_PRINT)
|
||||
#define RADIOLIB_DEBUG_PRINT(...) fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_PRINT_LVL(LEVEL, M, ...) fprintf(RADIOLIB_DEBUG_PORT, LEVEL "" M, ##__VA_ARGS__)
|
||||
#endif
|
||||
#if !defined(RADIOLIB_DEBUG_PRINTLN)
|
||||
#define RADIOLIB_DEBUG_PRINTLN(M, ...) fprintf(RADIOLIB_DEBUG_PORT, M "\n", ##__VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) fprintf(RADIOLIB_DEBUG_PORT, LEVEL "" M "\n", ##__VA_ARGS__)
|
||||
#endif
|
||||
#define RADIOLIB_DEBUG_PRINT_FLOAT(LEVEL, VAL, DECIMALS) RADIOLIB_DEBUG_PRINT(LEVEL "%.3f", VAL)
|
||||
#endif
|
||||
|
||||
#define RADIOLIB_DEBUG_HEXDUMP(LEVEL, ...) Module::hexdump(LEVEL, __VA_ARGS__)
|
||||
#else
|
||||
#define RADIOLIB_DEBUG_PRINT(...) {}
|
||||
#define RADIOLIB_DEBUG_PRINTLN(...) {}
|
||||
#define RADIOLIB_DEBUG_PRINT_FLOAT(VAL, DECIMALS) {}
|
||||
#define RADIOLIB_DEBUG_HEXDUMP(...) {}
|
||||
#endif
|
||||
|
||||
#if defined(RADIOLIB_VERBOSE)
|
||||
#define RADIOLIB_VERBOSE_PRINT(...) RADIOLIB_DEBUG_PRINT(__VA_ARGS__)
|
||||
#define RADIOLIB_VERBOSE_PRINTLN(...) RADIOLIB_DEBUG_PRINTLN(__VA_ARGS__)
|
||||
#if RADIOLIB_DEBUG_BASIC
|
||||
#define RADIOLIB_DEBUG_BASIC_PRINT(...) RADIOLIB_DEBUG_PRINT_LVL("RLB_DBG: ", __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_BASIC_PRINT_NOTAG(...) RADIOLIB_DEBUG_PRINT_LVL("", __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_BASIC_PRINTLN(...) RADIOLIB_DEBUG_PRINTLN_LVL("RLB_DBG: ", __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_BASIC_PRINT_FLOAT(...) RADIOLIB_DEBUG_PRINT_FLOAT("RLB_DBG: ", __VA_ARGS__);
|
||||
#define RADIOLIB_DEBUG_BASIC_HEXDUMP(...) RADIOLIB_DEBUG_HEXDUMP("RLB_DBG: ", __VA_ARGS__);
|
||||
#else
|
||||
#define RADIOLIB_VERBOSE_PRINT(...) {}
|
||||
#define RADIOLIB_VERBOSE_PRINTLN(...) {}
|
||||
#define RADIOLIB_DEBUG_BASIC_PRINT(...) {}
|
||||
#define RADIOLIB_DEBUG_BASIC_PRINT_NOTAG(...) {}
|
||||
#define RADIOLIB_DEBUG_BASIC_PRINTLN(...) {}
|
||||
#define RADIOLIB_DEBUG_BASIC_PRINT_FLOAT(...) {}
|
||||
#define RADIOLIB_DEBUG_BASIC_HEXDUMP(...) {}
|
||||
#endif
|
||||
|
||||
#if RADIOLIB_DEBUG_PROTOCOL
|
||||
#define RADIOLIB_DEBUG_PROTOCOL_PRINT(...) RADIOLIB_DEBUG_PRINT_LVL("RLB_PRO: ", __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_PROTOCOL_PRINTLN(...) RADIOLIB_DEBUG_PRINTLN_LVL("RLB_PRO: ", __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_PROTOCOL_PRINT_FLOAT(...) RADIOLIB_DEBUG_PRINT_FLOAT("RLB_PRO: ", __VA_ARGS__);
|
||||
#define RADIOLIB_DEBUG_PROTOCOL_HEXDUMP(...) RADIOLIB_DEBUG_HEXDUMP("RLB_PRO: ", __VA_ARGS__);
|
||||
#else
|
||||
#define RADIOLIB_DEBUG_PROTOCOL_PRINT(...) {}
|
||||
#define RADIOLIB_DEBUG_PROTOCOL_PRINTLN(...) {}
|
||||
#define RADIOLIB_DEBUG_PROTOCOL_PRINT_FLOAT(...) {}
|
||||
#define RADIOLIB_DEBUG_PROTOCOL_HEXDUMP(...) {}
|
||||
#endif
|
||||
|
||||
#if RADIOLIB_DEBUG_SPI
|
||||
#define RADIOLIB_DEBUG_SPI_PRINT(...) RADIOLIB_DEBUG_PRINT_LVL("RLB_SPI: ", __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_SPI_PRINT_NOTAG(...) RADIOLIB_DEBUG_PRINT_LVL("", __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_SPI_PRINTLN(...) RADIOLIB_DEBUG_PRINTLN_LVL("RLB_SPI: ", __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_SPI_PRINTLN_NOTAG(...) RADIOLIB_DEBUG_PRINTLN_LVL("", __VA_ARGS__)
|
||||
#define RADIOLIB_DEBUG_SPI_PRINT_FLOAT(...) RADIOLIB_DEBUG_PRINT_FLOAT("RLB_SPI: ", __VA_ARGS__);
|
||||
#define RADIOLIB_DEBUG_SPI_HEXDUMP(...) RADIOLIB_DEBUG_HEXDUMP("RLB_SPI: ", __VA_ARGS__);
|
||||
#else
|
||||
#define RADIOLIB_DEBUG_SPI_PRINT(...) {}
|
||||
#define RADIOLIB_DEBUG_SPI_PRINT_NOTAG(...) {}
|
||||
#define RADIOLIB_DEBUG_SPI_PRINTLN(...) {}
|
||||
#define RADIOLIB_DEBUG_SPI_PRINTLN_NOTAG(...) {}
|
||||
#define RADIOLIB_DEBUG_SPI_PRINT_FLOAT(...) {}
|
||||
#define RADIOLIB_DEBUG_SPI_HEXDUMP(...) {}
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
\brief A simple assert macro, will return on error.
|
||||
*/
|
||||
#define RADIOLIB_ASSERT(STATEVAR) { if((STATEVAR) != RADIOLIB_ERR_NONE) { return(STATEVAR); } }
|
||||
|
||||
|
||||
/*!
|
||||
\brief Macro to check variable is within constraints - this is commonly used to check parameter ranges. Requires RADIOLIB_CHECK_RANGE to be enabled
|
||||
*/
|
||||
#if defined(RADIOLIB_CHECK_PARAMS)
|
||||
#if RADIOLIB_CHECK_PARAMS
|
||||
#define RADIOLIB_CHECK_RANGE(VAR, MIN, MAX, ERR) { if(!(((VAR) >= (MIN)) && ((VAR) <= (MAX)))) { return(ERR); } }
|
||||
#else
|
||||
#define RADIOLIB_CHECK_RANGE(VAR, MIN, MAX, ERR) {}
|
||||
#endif
|
||||
|
||||
#if defined(RADIOLIB_FIX_ERRATA_SX127X)
|
||||
#if RADIOLIB_FIX_ERRATA_SX127X
|
||||
#define RADIOLIB_ERRATA_SX127X(...) { errataFix(__VA_ARGS__); }
|
||||
#else
|
||||
#define RADIOLIB_ERRATA_SX127X(...) {}
|
||||
#endif
|
||||
|
||||
// these macros are usually defined by Arduino, but some platforms undef them, so its safer to use our own
|
||||
#define RADIOLIB_MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#define RADIOLIB_MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#define RADIOLIB_ABS(x) ((x)>0?(x):-(x))
|
||||
|
||||
// version definitions
|
||||
#define RADIOLIB_VERSION_MAJOR (0x06)
|
||||
#define RADIOLIB_VERSION_MINOR (0x00)
|
||||
#define RADIOLIB_VERSION_PATCH (0x00)
|
||||
#define RADIOLIB_VERSION_EXTRA (0x00)
|
||||
#define RADIOLIB_VERSION_MAJOR 6
|
||||
#define RADIOLIB_VERSION_MINOR 5
|
||||
#define RADIOLIB_VERSION_PATCH 0
|
||||
#define RADIOLIB_VERSION_EXTRA 0
|
||||
|
||||
#define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA))
|
||||
#define RADIOLIB_VERSION (((RADIOLIB_VERSION_MAJOR) << 24) | ((RADIOLIB_VERSION_MINOR) << 16) | ((RADIOLIB_VERSION_PATCH) << 8) | (RADIOLIB_VERSION_EXTRA))
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue