Library to work with semtech sx127x chips.
There are several similar libraries exist, but this one is much better:
examples/receive_lora_deepsleep/main/main.c
for more info.This library supports all standard LoRa features:
And FSK/OOK features:
Clone this repository somewhere, e.g.:
cd ~/myprojects/esp
git clone https://github.com/dernasherbrezon/sx127x.git
Add path to components:
set(EXTRA_COMPONENT_DIRS /home/user/myprojects/esp/sx127x)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(my-esp-project)
Add the following dependency to platformio.ini:
lib_deps = dernasherbrezon/sx127x
Linux version depends on kernel SPI driver only. Make sure it is enabled. Clone this repository somewhere, e.g.:
cd ~/myprojects/esp
git clone https://github.com/dernasherbrezon/sx127x.git
Add subdirectory:
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sx127x)
target_link_libraries(my_application sx127x)
It is possible to use this library in any other microcontroller architecture. To do this several steps are required.
include/sx127x_spi.h
and put implementation somewhere inside your project.include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sx127x/include)
add_library(sx127x STATIC
"${CMAKE_CURRENT_SOURCE_DIR}/sx127x/src/sx127x.c"
"${CMAKE_CURRENT_SOURCE_DIR}/src/sx127x_custom_spi_implementation.c")
target_link_libraries(my_application sx127x)
All functions follow the same format:
sx127x_(modulation)_(rx or tx or empty)_(set or get)_(parameter)
Where:
examples
folder contains the following examples:
receive_lora
- RX in LoRa mode and explicit header. Uses CAD to quickly detect presence of the message and switch into RX mode.receive_lora_deepsleep
- RX in LoRa mode while in the deep sleepreceive_lora_implicit_header
- RX in LoRa mode and implicit header (without header)receive_lora_raspberrypi
- RX in LoRa mode on RaspberryPI via GPIO pins and onboard SPI. Tested on module RA-02receive_fsk
- RX in FSK mode. Variable packet length, NRZ encoding, CRC, AFC on.receive_fsk_filtered
- RX in FSK mode where only messages with NODE address 0x11 and Broadcast NODE address 0x00 are accepted. Variable packet length, NRZ encoding, CRC, AFC on.receive_fsk_fixed
- RX in FSK mode. Accepted packets with fixed packet length - 2047 bytes (max possible), NRZ encoding, CRC, AFC on.receive_fsk_raspberry
- RX in FSK mode on RaspberryPI via GPIO pins and onboard SPI. Variable packet length, NRZ encoding, CRC, AFC on.receive_ook
- RX in OOK mode. Variable packet length, NRZ encoding, CRC, AFC on.transmit_lora
- TX in LoRa mode and explicit header. Several messages of different sizes and at all supported power levelstransmit_lora_implicit_header
- TX in LoRa mode and implicit header (without header)transmit_lora_raspberrypi
- TX messages using LoRa mode from RaspberryPI. Tested on module RA-02transmit_fsk
- TX in FSK mode. Variable packet length, NRZ encoding, CRC, AFC on. Sending several messages: small 2 byte, messages that can fit into FIFO fully, max messages for variable packet type - 255 bytes and same messages, but for node address 0x11 and 0x00.transmit_fsk_fixed
- TX in FSK mode. Fixed packet length - 2047 bytes, NRZ encoding, CRC, AFC on.transmit_ook
- TX in OOK mode. Variable packet length, NRZ encoding, CRC, AFC on. Sending several messages: small 2 byte, messages that can fit into FIFO fully, max messages for variable packet type - 255 bytes and same messages, but for node address 0x11 and 0x00.There are several unit tests in the test
folder. They can be executed on any host machine using the commands below:
cd test
mkdir build
cd build
cmake ..
make test
Integration tests can verify communication between real devices in different modes. Tests require two LoRa boards connected to the same host. It is possible to test on any other boards by overriding pin mappings in test/test_app/main.c
. By default tests require:
Before running tests from ESP-IDF make sure pytest is installed.
Run the following command to test:
cd test/test_app
idf.py build
pytest --target esp32 --port="/dev/ttyUSB0|/dev/ttyACM0" pytest_*
This command assumes /dev/ttyUSB0
is receiver, /dev/ttyACM0
is transmitter.
Copy to Clipboard
idf.py add-dependency "dernasherbrezon/sx127x^3.0.1"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:receive_fsk"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:receive_fsk_beacon"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:receive_fsk_filtered"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:receive_fsk_fixed"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:receive_lora"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:receive_lora_deepsleep"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:receive_lora_implicit_header"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:receive_ook"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:transmit_fsk"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:transmit_fsk_beacon"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:transmit_fsk_fixed"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:transmit_lora"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:transmit_lora_implicit_header"
To create a project from this example, run:
Copy to Clipboard
idf.py create-project-from-example "dernasherbrezon/sx127x^3.0.1:transmit_ook"
Copy to Clipboard
Copy to Clipboard