├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ ├── module-not-working.md │ └── regular-issue.md └── workflows │ ├── codeql-analysis.yml │ ├── doxygen.yml │ └── main.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Doxyfile ├── README.md ├── SECURITY.md ├── examples ├── AFSK │ ├── AFSK_Imperial_March │ │ ├── AFSK_Imperial_March.ino │ │ └── melody.h │ ├── AFSK_Tone │ │ └── AFSK_Tone.ino │ └── AFSK_Tone_AM │ │ └── AFSK_Tone_AM.ino ├── AX25 │ ├── AX25_Frames │ │ └── AX25_Frames.ino │ ├── AX25_Transmit │ │ └── AX25_Transmit.ino │ └── AX25_Transmit_AFSK │ │ └── AX25_Transmit_AFSK.ino ├── CC1101 │ ├── CC1101_Receive │ │ └── CC1101_Receive.ino │ ├── CC1101_Receive_Address │ │ └── CC1101_Receive_Address.ino │ ├── CC1101_Receive_Interrupt │ │ └── CC1101_Receive_Interrupt.ino │ ├── CC1101_Settings │ │ └── CC1101_Settings.ino │ ├── CC1101_Transmit │ │ └── CC1101_Transmit.ino │ ├── CC1101_Transmit_Address │ │ └── CC1101_Transmit_Address.ino │ └── CC1101_Transmit_Interrupt │ │ └── CC1101_Transmit_Interrupt.ino ├── FSK4 │ ├── FSK4_Transmit │ │ └── FSK4_Transmit.ino │ └── FSK4_Transmit_AFSK │ │ └── FSK4_Transmit_AFSK.ino ├── HC05 │ └── HC05_Basic │ │ └── HC05_Basic.ino ├── HTTP │ ├── HTTP_Get │ │ └── HTTP_Get.ino │ └── HTTP_Post │ │ └── HTTP_Post.ino ├── Hellschreiber │ ├── Hellschreiber_Transmit │ │ └── Hellschreiber_Transmit.ino │ └── Hellschreiber_Transmit_AFSK │ │ └── Hellschreiber_Transmit_AFSK.ino ├── JDY08 │ └── JDY08_Basic │ │ └── JDY08_Basic.ino ├── MQTT │ ├── MQTT_Publish │ │ └── MQTT_Publish.ino │ └── MQTT_Subscribe │ │ └── MQTT_Subscribe.ino ├── Morse │ ├── Morse_Transmit │ │ └── Morse_Transmit.ino │ └── Morse_Transmit_AFSK │ │ └── Morse_Transmit_AFSK.ino ├── RF69 │ ├── RF69_Receive │ │ └── RF69_Receive.ino │ ├── RF69_Receive_AES │ │ └── RF69_Receive_AES.ino │ ├── RF69_Receive_Address │ │ └── RF69_Receive_Address.ino │ ├── RF69_Receive_Interrupt │ │ └── RF69_Receive_Interrupt.ino │ ├── RF69_Settings │ │ └── RF69_Settings.ino │ ├── RF69_Transmit │ │ └── RF69_Transmit.ino │ ├── RF69_Transmit_AES │ │ └── RF69_Transmit_AES.ino │ ├── RF69_Transmit_Address │ │ └── RF69_Transmit_Address.ino │ └── RF69_Transmit_Interrupt │ │ └── RF69_Transmit_Interrupt.ino ├── RTTY │ ├── RTTY_Transmit │ │ └── RTTY_Transmit.ino │ └── RTTY_Transmit_AFSK │ │ └── RTTY_Transmit_AFSK.ino ├── SSTV │ ├── SSTV_Transmit │ │ └── SSTV_Transmit.ino │ └── SSTV_Transmit_AFSK │ │ └── SSTV_Transmit_AFSK.ino ├── SX1231 │ ├── SX1231_Receive │ │ └── SX1231_Receive.ino │ └── SX1231_Transmit │ │ └── SX1231_Transmit.ino ├── SX126x │ ├── SX126x_Channel_Activity_Detection │ │ └── SX126x_Channel_Activity_Detection.ino │ ├── SX126x_FSK_Modem │ │ └── SX126x_FSK_Modem.ino │ ├── SX126x_PingPong │ │ └── SX126x_PingPong.ino │ ├── SX126x_Receive │ │ └── SX126x_Receive.ino │ ├── SX126x_Receive_Interrupt │ │ └── SX126x_Receive_Interrupt.ino │ ├── SX126x_Settings │ │ └── SX126x_Settings.ino │ ├── SX126x_Transmit │ │ └── SX126x_Transmit.ino │ └── SX126x_Transmit_Interrupt │ │ └── SX126x_Transmit_Interrupt.ino ├── SX127x │ ├── SX127x_Channel_Activity_Detection │ │ └── SX127x_Channel_Activity_Detection.ino │ ├── SX127x_FSK_Modem │ │ └── SX127x_FSK_Modem.ino │ ├── SX127x_Receive │ │ └── SX127x_Receive.ino │ ├── SX127x_Receive_Direct │ │ └── SX127x_Receive_Direct.ino │ ├── SX127x_Receive_Interrupt │ │ └── SX127x_Receive_Interrupt.ino │ ├── SX127x_Settings │ │ └── SX127x_Settings.ino │ ├── SX127x_Transmit │ │ └── SX127x_Transmit.ino │ └── SX127x_Transmit_Interrupt │ │ └── SX127x_Transmit_Interrupt.ino ├── SX128x │ ├── SX128x_BLE_Modem │ │ └── SX128x_BLE_Modem.ino │ ├── SX128x_Channel_Activity_Detection │ │ └── SX128x_Channel_Activity_Detection.ino │ ├── SX128x_FLRC_Modem │ │ └── SX128x_FLRC_Modem.ino │ ├── SX128x_GFSK_Modem │ │ └── SX128x_GFSK_Modem.ino │ ├── SX128x_Ranging │ │ └── SX128x_Ranging.ino │ ├── SX128x_Receive │ │ └── SX128x_Receive.ino │ ├── SX128x_Receive_Interrupt │ │ └── SX128x_Receive_Interrupt.ino │ ├── SX128x_Settings │ │ └── SX128x_Settings.ino │ ├── SX128x_Transmit │ │ └── SX128x_Transmit.ino │ └── SX128x_Transmit_Interrupt │ │ └── SX128x_Transmit_Interrupt.ino ├── Si443x │ ├── Si443x_Receive │ │ └── Si443x_Receive.ino │ ├── Si443x_Receive_Interrupt │ │ └── Si443x_Receive_Interrupt.ino │ ├── Si443x_Settings │ │ └── Si443x_Settings.ino │ ├── Si443x_Transmit │ │ └── Si443x_Transmit.ino │ └── Si443x_Transmit_Interrupt │ │ └── Si443x_Transmit_Interrupt.ino ├── XBee │ ├── XBee_Receive │ │ └── XBee_Receive.ino │ ├── XBee_Transmit │ │ └── XBee_Transmit.ino │ └── XBee_Transparent │ │ └── XBee_Transparent.ino └── nRF24 │ ├── nRF24_Receive │ └── nRF24_Receive.ino │ ├── nRF24_Receive_Interrupt │ └── nRF24_Receive_Interrupt.ino │ ├── nRF24_Transmit │ └── nRF24_Transmit.ino │ └── nRF24_Transmit_Interrupt │ └── nRF24_Transmit_Interrupt.ino ├── extras ├── bin │ ├── AiThinker_ESP8266_DIO_32M_32M_20160615_V1.5.4.bin │ └── AiThinker_ESP8266_DIO_8M_8M_20160615_V1.5.4.bin ├── decoder │ └── DebugDecoder.py └── template │ ├── ModuleTemplate.cpp │ └── ModuleTemplate.h ├── keywords.txt ├── library.properties ├── license.txt └── src ├── BuildOpt.h ├── ISerial.cpp ├── ISerial.h ├── Module.cpp ├── Module.h ├── RadioLib.h ├── TypeDef.h ├── modules ├── CC1101 │ ├── CC1101.cpp │ └── CC1101.h ├── ESP8266 │ ├── ESP8266.cpp │ └── ESP8266.h ├── HC05 │ ├── HC05.cpp │ └── HC05.h ├── JDY08 │ ├── JDY08.cpp │ └── JDY08.h ├── LLCC68 │ ├── LLCC68.cpp │ └── LLCC68.h ├── RF69 │ ├── RF69.cpp │ └── RF69.h ├── RFM2x │ ├── RFM22.h │ └── RFM23.h ├── RFM9x │ ├── RFM95.cpp │ ├── RFM95.h │ ├── RFM96.cpp │ ├── RFM96.h │ ├── RFM97.cpp │ └── RFM97.h ├── SX1231 │ ├── SX1231.cpp │ └── SX1231.h ├── SX126x │ ├── SX1261.cpp │ ├── SX1261.h │ ├── SX1262.cpp │ ├── SX1262.h │ ├── SX1268.cpp │ ├── SX1268.h │ ├── SX126x.cpp │ └── SX126x.h ├── SX127x │ ├── SX1272.cpp │ ├── SX1272.h │ ├── SX1273.cpp │ ├── SX1273.h │ ├── SX1276.cpp │ ├── SX1276.h │ ├── SX1277.cpp │ ├── SX1277.h │ ├── SX1278.cpp │ ├── SX1278.h │ ├── SX1279.cpp │ ├── SX1279.h │ ├── SX127x.cpp │ └── SX127x.h ├── SX128x │ ├── SX1280.cpp │ ├── SX1280.h │ ├── SX1281.cpp │ ├── SX1281.h │ ├── SX1282.cpp │ ├── SX1282.h │ ├── SX128x.cpp │ └── SX128x.h ├── Si443x │ ├── Si4430.cpp │ ├── Si4430.h │ ├── Si4431.cpp │ ├── Si4431.h │ ├── Si4432.cpp │ ├── Si4432.h │ ├── Si443x.cpp │ └── Si443x.h ├── XBee │ ├── XBee.cpp │ └── XBee.h └── nRF24 │ ├── nRF24.cpp │ └── nRF24.h └── protocols ├── AFSK ├── AFSK.cpp └── AFSK.h ├── AX25 ├── AX25.cpp └── AX25.h ├── FSK4 ├── FSK4.cpp └── FSK4.h ├── HTTP ├── HTTP.cpp └── HTTP.h ├── Hellschreiber ├── Hellschreiber.cpp └── Hellschreiber.h ├── MQTT ├── MQTT.cpp └── MQTT.h ├── Morse ├── Morse.cpp └── Morse.h ├── PhysicalLayer ├── PhysicalLayer.cpp └── PhysicalLayer.h ├── RTTY ├── RTTY.cpp └── RTTY.h ├── SSTV ├── SSTV.cpp └── SSTV.h └── TransportLayer └── TransportLayer.h /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **IMPORTANT: Check the wiki** 11 | 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. 12 | 13 | **Describe the bug** 14 | 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). 15 | 16 | **To Reproduce** 17 | Minimal Arduino sketch to reproduce the behavior. Please user Markdown to style the code to make it readable (see [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code)). 18 | 19 | **Expected behavior** 20 | A clear and concise description of what you expected to happen. 21 | 22 | **Screenshots** 23 | If applicable, add screenshots to help explain your problem. 24 | 25 | **Additional info (please complete):** 26 | - MCU: [e.g. Arduino Uno, ESP8266 etc.] 27 | - Link to Arduino core: [e.g. https://github.com/stm32duino/Arduino_Core_STM32 when using official STM32 core. See readme for links to all supported cores] 28 | - Wireless module type [e.g. CC1101, SX1268, etc.] 29 | - Arduino IDE version [e.g. 1.8.5] 30 | - Library version [e.g. 3.0.0] 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **IMPORTANT: Check the wiki** 11 | 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. 12 | 13 | **Is your feature request related to a problem? Please describe.** 14 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 15 | 16 | **Describe the solution you'd like** 17 | A clear and concise description of what you want to happen. 18 | 19 | **Describe alternatives you've considered** 20 | A clear and concise description of any alternative solutions or features you've considered. 21 | 22 | **Additional context** 23 | Add any other context or screenshots about the feature request here. 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/module-not-working.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Module not working 3 | about: Template to use when your module isn't working 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **IMPORTANT: Before submitting an issue, please check the following:** 11 | 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. 12 | 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. 13 | 3. Make sure you're using the latest release of the library! Releases can be found [here](https://github.com/jgromes/RadioLib/releases). 14 | 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! 15 | 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). 16 | 17 | **Sketch that is causing the module fail** 18 | 19 | ```c++ 20 | paste the sketch here, even if it is an unmodified example code 21 | ``` 22 | 23 | **Hardware setup** 24 | Wiring diagram, schematic, pictures etc. 25 | 26 | **Debug mode output** 27 | Enable all [debug levels](https://github.com/jgromes/RadioLib/wiki/Debug-mode) and paste the Serial monitor output here. 28 | 29 | **Additional info (please complete):** 30 | - MCU: [e.g. Arduino Uno, ESP8266 etc.] 31 | - Link to Arduino core: [e.g. https://github.com/stm32duino/Arduino_Core_STM32 when using official STM32 core. See readme for links to all supported cores] 32 | - Wireless module type [e.g. CC1101, SX1268, etc.] 33 | - Arduino IDE version [e.g. 1.8.5] 34 | - Library version [e.g. 3.0.0] 35 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/regular-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Regular issue 3 | about: Use this template for any other issue 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **IMPORTANT: Before submitting an issue, please check the following:** 11 | 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. 12 | 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. 13 | 3. Make sure you're using the latest release of the library! Releases can be found [here](https://github.com/jgromes/RadioLib/releases). 14 | 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! 15 | 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). 16 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: 7 | branches: [master] 8 | 9 | jobs: 10 | analyze: 11 | name: Analyze 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | language: ['cpp'] 18 | 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@v2 22 | with: 23 | # We must fetch at least the immediate parents so that if this is 24 | # a pull request then we can checkout the head. 25 | fetch-depth: 2 26 | 27 | # If this run was triggered by a pull request event, then checkout 28 | # the head of the pull request instead of the merge commit. 29 | - run: git checkout HEAD^2 30 | if: ${{ github.event_name == 'pull_request' }} 31 | 32 | # Initializes the CodeQL tools for scanning. 33 | - name: Initialize CodeQL 34 | uses: github/codeql-action/init@v1 35 | with: 36 | languages: ${{ matrix.language }} 37 | 38 | - name: Install arduino-cli 39 | run: 40 | | 41 | mkdir -p ~/.local/bin 42 | echo "~/.local/bin" >> $GITHUB_PATH 43 | curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=~/.local/bin sh 44 | 45 | - name: Install platform 46 | run: 47 | | 48 | arduino-cli core update-index 49 | arduino-cli core install arduino:avr 50 | 51 | - name: Static link 52 | run: 53 | | 54 | # static link fix from https://github.com/github/securitylab/discussions/171 55 | for i in ~/.arduino*/packages/arduino/tools/avr-gcc/*/bin/*; do 56 | mv "$i" "$i.real"; 57 | printf '#!/bin/bash\nexec "'"$i"'.real" ${1+"$@"}\n' > "$i"; 58 | chmod +x "$i"; 59 | done 60 | 61 | - name: Build example 62 | run: 63 | arduino-cli compile --libraries /home/runner/work/RadioLib --fqbn arduino:avr:uno $PWD/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino --warnings=all 64 | 65 | - name: Perform CodeQL Analysis 66 | uses: github/codeql-action/analyze@v1 67 | -------------------------------------------------------------------------------- /.github/workflows/doxygen.yml: -------------------------------------------------------------------------------- 1 | name: Doxygen 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | doxygen: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Install Doxygen 13 | run: | 14 | sudo apt-get update 15 | sudo apt-get install -y doxygen 16 | - uses: actions/checkout@v2 17 | 18 | - name: Generate docs 19 | run: doxygen Doxyfile 20 | 21 | - name: Deploy to GitHub Pages 22 | uses: JamesIves/github-pages-deploy-action@releases/v3 23 | with: 24 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 25 | BRANCH: gh-pages 26 | FOLDER: docs/html 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Arduino Library Development file 2 | .development 3 | 4 | # Atom 5 | *.tags 6 | *.tags1 7 | 8 | # Jetbrain IDEs 9 | .idea 10 | 11 | # Debug decoder 12 | extras/decoder/log.txt 13 | extras/decoder/out.txt 14 | 15 | # PlatformIO 16 | .pio* 17 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | Don't be an a*shole. 4 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | RadioLib is provided as-is without any warranty, and is not intended to be used in security-critical applications. However, if you discover a vulnerability within the library code, please report it to gromes.jan@gmail.com. 6 | -------------------------------------------------------------------------------- /examples/AFSK/AFSK_Imperial_March/AFSK_Imperial_March.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib AFSK Imperial March Example 3 | 4 | This example shows how to EXECUTE ORDER 66 5 | 6 | Other modules that can be used for AFSK: 7 | - SX127x/RFM9x 8 | - RF69 9 | - SX1231 10 | - CC1101 11 | - Si443x/RFM2x 12 | 13 | For default module settings, see the wiki page 14 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 15 | 16 | For full API reference, see the GitHub Pages 17 | https://jgromes.github.io/RadioLib/ 18 | */ 19 | 20 | // include the library 21 | #include 22 | 23 | // include the melody 24 | #include "melody.h" 25 | 26 | // SX1278 has the following connections: 27 | // NSS pin: 10 28 | // DIO0 pin: 2 29 | // RESET pin: 9 30 | // DIO1 pin: 3 31 | SX1278 radio = new Module(10, 2, 9, 3); 32 | 33 | // create AFSK client instance using the FSK module 34 | // this requires connection to the module direct 35 | // input pin, here connected to Arduino pin 5 36 | // SX127x/RFM9x: DIO2 37 | // RF69: DIO2 38 | // SX1231: DIO2 39 | // CC1101: GDO2 40 | // Si443x/RFM2x: GPIO 41 | AFSKClient audio(&radio, 5); 42 | 43 | void setup() { 44 | Serial.begin(9600); 45 | 46 | // initialize SX1278 with default settings 47 | Serial.print(F("[SX1278] Initializing ... ")); 48 | int state = radio.beginFSK(); 49 | 50 | // when using one of the non-LoRa modules for AFSK 51 | // (RF69, CC1101,, Si4432 etc.), use the basic begin() method 52 | // int state = radio.begin(); 53 | 54 | if(state == ERR_NONE) { 55 | Serial.println(F("success!")); 56 | } else { 57 | Serial.print(F("failed, code ")); 58 | Serial.println(state); 59 | while(true); 60 | } 61 | 62 | // initialize AFSK client 63 | Serial.print(F("[AFSK] Initializing ... ")); 64 | state = audio.begin(); 65 | if(state == ERR_NONE) { 66 | Serial.println(F("success!")); 67 | } else { 68 | Serial.print(F("failed, code ")); 69 | Serial.println(state); 70 | while(true); 71 | } 72 | } 73 | 74 | void loop() { 75 | Serial.print(F("[AFSK] Executing Order 66 ... ")); 76 | 77 | // calculate whole note duration 78 | int wholenote = (60000 * 4) / 120; 79 | 80 | // iterate over the melody 81 | for(unsigned int note = 0; note < sizeof(melody) / sizeof(melody[0]); note += 2) { 82 | // calculate the duration of each note 83 | int noteDuration = 0; 84 | int divider = melody[note + 1]; 85 | if(divider > 0) { 86 | // regular note, just proceed 87 | noteDuration = wholenote / divider; 88 | } else if(divider < 0) { 89 | // dotted notes are represented with negative durations!! 90 | noteDuration = wholenote / abs(divider); 91 | noteDuration *= 1.5; // increases the duration in half for dotted notes 92 | } 93 | 94 | // we only play the note for 90% of the duration, leaving 10% as a pause 95 | audio.tone(melody[note]); 96 | delay(noteDuration*0.9); 97 | audio.noTone(); 98 | delay(noteDuration*0.1); 99 | } 100 | 101 | Serial.println(F("done!")); 102 | 103 | // wait for a second 104 | delay(1000); 105 | } 106 | -------------------------------------------------------------------------------- /examples/AFSK/AFSK_Tone/AFSK_Tone.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib AFSK Example 3 | 4 | This example shows hot to send audio FSK tones 5 | using SX1278's FSK modem. 6 | 7 | Other modules that can be used for AFSK: 8 | - SX127x/RFM9x 9 | - RF69 10 | - SX1231 11 | - CC1101 12 | - Si443x/RFM2x 13 | 14 | For default module settings, see the wiki page 15 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 16 | 17 | For full API reference, see the GitHub Pages 18 | https://jgromes.github.io/RadioLib/ 19 | */ 20 | 21 | // include the library 22 | #include 23 | 24 | // SX1278 has the following connections: 25 | // NSS pin: 10 26 | // DIO0 pin: 2 27 | // RESET pin: 9 28 | // DIO1 pin: 3 29 | SX1278 radio = new Module(10, 2, 9, 3); 30 | 31 | // create AFSK client instance using the FSK module 32 | // this requires connection to the module direct 33 | // input pin, here connected to Arduino pin 5 34 | // SX127x/RFM9x: DIO2 35 | // RF69: DIO2 36 | // SX1231: DIO2 37 | // CC1101: GDO2 38 | // Si443x/RFM2x: GPIO 39 | AFSKClient audio(&radio, 5); 40 | 41 | void setup() { 42 | Serial.begin(9600); 43 | 44 | // initialize SX1278 with default settings 45 | Serial.print(F("[SX1278] Initializing ... ")); 46 | int state = radio.beginFSK(); 47 | 48 | // when using one of the non-LoRa modules for AFSK 49 | // (RF69, CC1101, Si4432 etc.), use the basic begin() method 50 | // int state = radio.begin(); 51 | 52 | if(state == ERR_NONE) { 53 | Serial.println(F("success!")); 54 | } else { 55 | Serial.print(F("failed, code ")); 56 | Serial.println(state); 57 | while(true); 58 | } 59 | 60 | // initialize AFSK client 61 | Serial.print(F("[AFSK] Initializing ... ")); 62 | state = audio.begin(); 63 | if(state == ERR_NONE) { 64 | Serial.println(F("success!")); 65 | } else { 66 | Serial.print(F("failed, code ")); 67 | Serial.println(state); 68 | while(true); 69 | } 70 | } 71 | 72 | void loop() { 73 | // AFSKClient can be used to transmit tones, 74 | // same as Arduino tone() function 75 | 76 | // 400 Hz tone 77 | Serial.print(F("[AFSK] 400 Hz tone ... ")); 78 | audio.tone(400); 79 | delay(1000); 80 | 81 | // silence 82 | Serial.println(F("done!")); 83 | audio.noTone(); 84 | delay(1000); 85 | 86 | // AFSKClient can also be used to transmit HAM-friendly 87 | // RTTY, Morse code, Hellschreiber, SSTV and AX.25. 88 | // Details on how to use AFSK are in the example 89 | // folders for each of the above modes. 90 | } 91 | -------------------------------------------------------------------------------- /examples/AFSK/AFSK_Tone_AM/AFSK_Tone_AM.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib AM-modulated AFSK Example 3 | 4 | This example shows hot to send AM-modulated 5 | audio FSK tones using SX1278's OOK modem. 6 | 7 | Other modules that can be used for AFSK: 8 | - SX127x/RFM9x 9 | - RF69 10 | - SX1231 11 | - CC1101 12 | 13 | For default module settings, see the wiki page 14 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 15 | 16 | For full API reference, see the GitHub Pages 17 | https://jgromes.github.io/RadioLib/ 18 | */ 19 | 20 | // include the library 21 | #include 22 | 23 | // SX1278 has the following connections: 24 | // NSS pin: 10 25 | // DIO0 pin: 2 26 | // RESET pin: 9 27 | SX1278 radio = new Module(10, 2, 9); 28 | 29 | // create AFSK client instance using the FSK module 30 | // this requires connection to the module direct 31 | // input pin, here connected to Arduino pin 5 32 | // SX127x/RFM9x: DIO2 33 | // RF69: DIO2 34 | // SX1231: DIO2 35 | // CC1101: GDO2 36 | AFSKClient audio(&radio, 5); 37 | 38 | void setup() { 39 | Serial.begin(9600); 40 | 41 | // initialize SX1278 with default settings 42 | Serial.print(F("[SX1278] Initializing ... ")); 43 | int state = radio.beginFSK(); 44 | 45 | // when using one of the non-LoRa modules for AFSK 46 | // (RF69, CC1101, Si4432 etc.), use the basic begin() method 47 | // int state = radio.begin(); 48 | 49 | if(state == ERR_NONE) { 50 | Serial.println(F("success!")); 51 | } else { 52 | Serial.print(F("failed, code ")); 53 | Serial.println(state); 54 | while(true); 55 | } 56 | 57 | // initialize AFSK client 58 | Serial.print(F("[AFSK] Initializing ... ")); 59 | state = audio.begin(); 60 | if(state == ERR_NONE) { 61 | Serial.println(F("success!")); 62 | } else { 63 | Serial.print(F("failed, code ")); 64 | Serial.println(state); 65 | while(true); 66 | } 67 | 68 | // after that, set mode to OOK 69 | Serial.print(F("[SX1278] Switching to OOK ... ")); 70 | state = radio.setOOK(true); 71 | if(state == ERR_NONE) { 72 | Serial.println(F("success!")); 73 | } else { 74 | Serial.print(F("failed, code ")); 75 | Serial.println(state); 76 | while(true); 77 | } 78 | } 79 | 80 | void loop() { 81 | // AFSKClient can be used to transmit tones, 82 | // same as Arduino tone() function 83 | 84 | // 400 Hz tone 85 | Serial.print(F("[AFSK] 400 Hz tone ... ")); 86 | audio.tone(400); 87 | delay(1000); 88 | 89 | // silence 90 | Serial.println(F("done!")); 91 | audio.noTone(); 92 | delay(1000); 93 | 94 | // AFSKClient can also be used to transmit HAM-friendly 95 | // RTTY, Morse code, Hellschreiber, SSTV and AX.25. 96 | // Details on how to use AFSK are in the example 97 | // folders for each of the above modes. 98 | 99 | // CAUTION: Unlike standard AFSK, the result when using OOK 100 | // must be demodulated as AM! 101 | } 102 | -------------------------------------------------------------------------------- /examples/AX25/AX25_Transmit/AX25_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib AX.25 Transmit Example 3 | 4 | This example sends AX.25 messages using 5 | SX1278's FSK modem. 6 | 7 | Other modules that can be used for AX.25: 8 | - SX127x/RFM9x 9 | - RF69 10 | - SX1231 11 | - CC1101 12 | - SX126x 13 | - nRF24 14 | - Si443x/RFM2x 15 | 16 | For default module settings, see the wiki page 17 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 18 | 19 | For full API reference, see the GitHub Pages 20 | https://jgromes.github.io/RadioLib/ 21 | */ 22 | 23 | // include the library 24 | #include 25 | 26 | // SX1278 has the following connections: 27 | // NSS pin: 10 28 | // DIO0 pin: 2 29 | // RESET pin: 9 30 | // DIO1 pin: 3 31 | SX1278 radio = new Module(10, 2, 9, 3); 32 | 33 | // or using RadioShield 34 | // https://github.com/jgromes/RadioShield 35 | //SX1278 radio = RadioShield.ModuleA; 36 | 37 | // create AX.25 client instance using the FSK module 38 | AX25Client ax25(&radio); 39 | 40 | void setup() { 41 | Serial.begin(9600); 42 | 43 | // initialize SX1278 44 | Serial.print(F("[SX1278] Initializing ... ")); 45 | // carrier frequency: 434.0 MHz 46 | // bit rate: 1.2 kbps (1200 baud 2-FSK AX.25) 47 | int state = radio.beginFSK(434.0, 1.2); 48 | 49 | // when using one of the non-LoRa modules for AX.25 50 | // (RF69, CC1101,, Si4432 etc.), use the basic begin() method 51 | // int state = radio.begin(); 52 | 53 | if(state == ERR_NONE) { 54 | Serial.println(F("success!")); 55 | } else { 56 | Serial.print(F("failed, code ")); 57 | Serial.println(state); 58 | while(true); 59 | } 60 | 61 | // initialize AX.25 client 62 | Serial.print(F("[AX.25] Initializing ... ")); 63 | // source station callsign: "N7LEM" 64 | // source station SSID: 0 65 | // preamble length: 8 bytes 66 | state = ax25.begin("N7LEM"); 67 | if(state == ERR_NONE) { 68 | Serial.println(F("success!")); 69 | } else { 70 | Serial.print(F("failed, code ")); 71 | Serial.println(state); 72 | while(true); 73 | } 74 | } 75 | 76 | void loop() { 77 | // send AX.25 unnumbered information frame 78 | Serial.print(F("[AX.25] Sending UI frame ... ")); 79 | // destination station callsign: "NJ7P" 80 | // destination station SSID: 0 81 | int state = ax25.transmit("Hello World!", "NJ7P"); 82 | if (state == ERR_NONE) { 83 | // the packet was successfully transmitted 84 | Serial.println(F("success!")); 85 | 86 | } else { 87 | // some error occurred 88 | Serial.print(F("failed, code ")); 89 | Serial.println(state); 90 | 91 | } 92 | 93 | delay(1000); 94 | } 95 | -------------------------------------------------------------------------------- /examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib AX.25 Transmit AFSK Example 3 | 4 | This example sends AX.25 messages using 5 | SX1278's FSK modem. The data is modulated 6 | as AFSK at 1200 baud using Bell 202 tones. 7 | 8 | Other modules that can be used for AX.25 9 | with AFSK modulation: 10 | - SX127x/RFM9x 11 | - RF69 12 | - SX1231 13 | - CC1101 14 | - nRF24 15 | - Si443x/RFM2x 16 | 17 | For default module settings, see the wiki page 18 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 19 | 20 | For full API reference, see the GitHub Pages 21 | https://jgromes.github.io/RadioLib/ 22 | */ 23 | 24 | // include the library 25 | #include 26 | 27 | // SX1278 has the following connections: 28 | // NSS pin: 10 29 | // DIO0 pin: 2 30 | // RESET pin: 9 31 | // DIO1 pin: 3 32 | SX1278 radio = new Module(10, 2, 9, 3); 33 | 34 | // or using RadioShield 35 | // https://github.com/jgromes/RadioShield 36 | //SX1278 radio = RadioShield.ModuleA; 37 | 38 | // create AFSK client instance using the FSK module 39 | // pin 5 is connected to SX1278 DIO2 40 | AFSKClient audio(&radio, 5); 41 | 42 | // create AX.25 client instance using the AFSK instance 43 | AX25Client ax25(&audio); 44 | 45 | void setup() { 46 | Serial.begin(9600); 47 | 48 | // initialize SX1278 with default settings 49 | Serial.print(F("[SX1278] Initializing ... ")); 50 | int state = radio.beginFSK(); 51 | 52 | // when using one of the non-LoRa modules for AX.25 53 | // (RF69, CC1101,, Si4432 etc.), use the basic begin() method 54 | // int state = radio.begin(); 55 | 56 | if(state == ERR_NONE) { 57 | Serial.println(F("success!")); 58 | } else { 59 | Serial.print(F("failed, code ")); 60 | Serial.println(state); 61 | while(true); 62 | } 63 | 64 | // initialize AX.25 client 65 | Serial.print(F("[AX.25] Initializing ... ")); 66 | // source station callsign: "N7LEM" 67 | // source station SSID: 0 68 | // preamble length: 8 bytes 69 | state = ax25.begin("N7LEM"); 70 | if(state == ERR_NONE) { 71 | Serial.println(F("success!")); 72 | } else { 73 | Serial.print(F("failed, code ")); 74 | Serial.println(state); 75 | while(true); 76 | } 77 | 78 | // Sometimes, it may be required to adjust audio 79 | // frequencies to match the expected 1200/2200 Hz tones. 80 | // The following method will offset mark frequency by 81 | // 100 Hz up and space frequency by 100 Hz down 82 | /* 83 | Serial.print(F("[AX.25] Setting correction ... ")); 84 | state = ax25.setCorrection(100, -100); 85 | if(state == ERR_NONE) { 86 | Serial.println(F("success!")); 87 | } else { 88 | Serial.print(F("failed, code ")); 89 | Serial.println(state); 90 | while(true); 91 | } 92 | */ 93 | } 94 | 95 | void loop() { 96 | // send AX.25 unnumbered information frame 97 | Serial.print(F("[AX.25] Sending UI frame ... ")); 98 | // destination station callsign: "NJ7P" 99 | // destination station SSID: 0 100 | int state = ax25.transmit("Hello World!", "NJ7P"); 101 | if (state == ERR_NONE) { 102 | // the packet was successfully transmitted 103 | Serial.println(F("success!")); 104 | 105 | } else { 106 | // some error occurred 107 | Serial.print(F("failed, code ")); 108 | Serial.println(state); 109 | 110 | } 111 | 112 | delay(1000); 113 | } 114 | -------------------------------------------------------------------------------- /examples/CC1101/CC1101_Receive/CC1101_Receive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib CC1101 Receive Example 3 | 4 | This example receives packets using CC1101 FSK radio module. 5 | To successfully receive data, the following settings have to be the same 6 | on both transmitter and receiver: 7 | - carrier frequency 8 | - bit rate 9 | - frequency deviation 10 | - sync word 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // CC1101 has the following connections: 23 | // CS pin: 10 24 | // GDO0 pin: 2 25 | // RST pin: unused 26 | // GDO2 pin: 3 (optional) 27 | CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); 28 | 29 | // or using RadioShield 30 | // https://github.com/jgromes/RadioShield 31 | //CC1101 radio = RadioShield.ModuleA; 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | 36 | // initialize CC1101 with default settings 37 | Serial.print(F("[CC1101] Initializing ... ")); 38 | int state = radio.begin(); 39 | if (state == ERR_NONE) { 40 | Serial.println(F("success!")); 41 | } else { 42 | Serial.print(F("failed, code ")); 43 | Serial.println(state); 44 | while (true); 45 | } 46 | } 47 | 48 | void loop() { 49 | Serial.print(F("[CC1101] Waiting for incoming transmission ... ")); 50 | 51 | // you can receive data as an Arduino String 52 | String str; 53 | int state = radio.receive(str); 54 | 55 | // you can also receive data as byte array 56 | /* 57 | byte byteArr[8]; 58 | int state = radio.receive(byteArr, 8); 59 | */ 60 | 61 | if (state == ERR_NONE) { 62 | // packet was successfully received 63 | Serial.println(F("success!")); 64 | 65 | // print the data of the packet 66 | Serial.print(F("[CC1101] Data:\t\t")); 67 | Serial.println(str); 68 | 69 | // print RSSI (Received Signal Strength Indicator) 70 | // of the last received packet 71 | Serial.print(F("[CC1101] RSSI:\t\t")); 72 | Serial.print(radio.getRSSI()); 73 | Serial.println(F(" dBm")); 74 | 75 | // print LQI (Link Quality Indicator) 76 | // of the last received packet, lower is better 77 | Serial.print(F("[CC1101] LQI:\t\t")); 78 | Serial.println(radio.getLQI()); 79 | 80 | } else if (state == ERR_RX_TIMEOUT) { 81 | // timeout occurred while waiting for a packet 82 | Serial.println(F("timeout!")); 83 | 84 | } else if (state == ERR_CRC_MISMATCH) { 85 | // packet was received, but is malformed 86 | Serial.println(F("CRC error!")); 87 | 88 | } else { 89 | // some other error occurred 90 | Serial.print(F("failed, code ")); 91 | Serial.println(state); 92 | 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib CC1101 Transmit Example 3 | 4 | This example transmits packets using CC1101 FSK radio module. 5 | Each packet contains up to 64 bytes of data, in the form of: 6 | - Arduino String 7 | - null-terminated char array (C-string) 8 | - arbitrary binary data (byte array) 9 | 10 | For default module settings, see the wiki page 11 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 12 | 13 | For full API reference, see the GitHub Pages 14 | https://jgromes.github.io/RadioLib/ 15 | */ 16 | 17 | // include the library 18 | #include 19 | 20 | // CC1101 has the following connections: 21 | // CS pin: 10 22 | // GDO0 pin: 2 23 | // RST pin: unused 24 | // GDO2 pin: 3 (optional) 25 | CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); 26 | 27 | // or using RadioShield 28 | // https://github.com/jgromes/RadioShield 29 | //CC1101 radio = RadioShield.ModuleA; 30 | 31 | void setup() { 32 | Serial.begin(9600); 33 | 34 | // initialize CC1101 with default settings 35 | Serial.print(F("[CC1101] Initializing ... ")); 36 | int state = radio.begin(); 37 | if (state == ERR_NONE) { 38 | Serial.println(F("success!")); 39 | } else { 40 | Serial.print(F("failed, code ")); 41 | Serial.println(state); 42 | while (true); 43 | } 44 | } 45 | 46 | void loop() { 47 | Serial.print(F("[CC1101] Transmitting packet ... ")); 48 | 49 | // you can transmit C-string or Arduino string up to 63 characters long 50 | int state = radio.transmit("Hello World!"); 51 | 52 | // you can also transmit byte array up to 63 bytes long 53 | /* 54 | byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; 55 | int state = radio.transmit(byteArr, 8); 56 | */ 57 | 58 | if (state == ERR_NONE) { 59 | // the packet was successfully transmitted 60 | Serial.println(F("success!")); 61 | 62 | } else if (state == ERR_PACKET_TOO_LONG) { 63 | // the supplied packet was longer than 64 bytes 64 | Serial.println(F("too long!")); 65 | 66 | } else { 67 | // some other error occurred 68 | Serial.print(F("failed, code ")); 69 | Serial.println(state); 70 | 71 | } 72 | 73 | // wait for a second before transmitting again 74 | delay(1000); 75 | } 76 | -------------------------------------------------------------------------------- /examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib CC1101 Transmit to Address Example 3 | 4 | This example transmits packets using CC1101 FSK radio 5 | module. Packets can have 1-byte address of the 6 | destination node. After setting node address, this node 7 | will automatically filter out any packets that do not 8 | contain either node address or broadcast addresses. 9 | 10 | For default module settings, see the wiki page 11 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101 12 | 13 | For full API reference, see the GitHub Pages 14 | https://jgromes.github.io/RadioLib/ 15 | */ 16 | 17 | // include the library 18 | #include 19 | 20 | // CC1101 has the following connections: 21 | // CS pin: 10 22 | // GDO0 pin: 2 23 | // RST pin: unused 24 | // GDO2 pin: 3 (optional) 25 | CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3); 26 | 27 | // or using RadioShield 28 | // https://github.com/jgromes/RadioShield 29 | //CC1101 radio = RadioShield.ModuleA; 30 | 31 | void setup() { 32 | Serial.begin(9600); 33 | 34 | // initialize CC1101 with default settings 35 | Serial.print(F("[CC1101] Initializing ... ")); 36 | int state = radio.begin(); 37 | if (state == ERR_NONE) { 38 | Serial.println(F("success!")); 39 | } else { 40 | Serial.print(F("failed, code ")); 41 | Serial.println(state); 42 | while (true); 43 | } 44 | 45 | // set node address 46 | // NOTE: Calling this method will automatically enable 47 | // address filtering. CC1101 also allows to set 48 | // number of broadcast address (0/1/2). 49 | // The following sets one broadcast address 0x00. 50 | // When setting two broadcast addresses, 0x00 and 51 | // 0xFF will be used. 52 | Serial.print(F("[CC1101] Setting node address ... ")); 53 | state = radio.setNodeAddress(0x01, 1); 54 | if (state == ERR_NONE) { 55 | Serial.println(F("success!")); 56 | } else { 57 | Serial.print(F("failed, code ")); 58 | Serial.println(state); 59 | while (true); 60 | } 61 | 62 | // address filtering can also be disabled 63 | // NOTE: Calling this method will also erase previously 64 | // set node address 65 | /* 66 | Serial.print(F("[CC1101] Disabling address filtering ... ")); 67 | state == radio.disableAddressFiltering(); 68 | if(state == ERR_NONE) { 69 | Serial.println(F("success!")); 70 | } else { 71 | Serial.print(F("failed, code ")); 72 | Serial.println(state); 73 | while(true); 74 | } 75 | */ 76 | } 77 | 78 | void loop() { 79 | Serial.print(F("[CC1101] Transmitting packet ... ")); 80 | 81 | // you can transmit C-string or Arduino string up to 63 characters long 82 | int state = radio.transmit("Hello World!"); 83 | 84 | // you can also transmit byte array up to 63 bytes long 85 | /* 86 | byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; 87 | int state = radio.transmit(byteArr, 8); 88 | */ 89 | 90 | if (state == ERR_NONE) { 91 | // the packet was successfully transmitted 92 | Serial.println(F("success!")); 93 | 94 | } else if (state == ERR_PACKET_TOO_LONG) { 95 | // the supplied packet was longer than 255 bytes 96 | Serial.println(F("too long!")); 97 | 98 | } else { 99 | // some other error occurred 100 | Serial.print(F("failed, code ")); 101 | Serial.println(state); 102 | 103 | } 104 | 105 | // wait for a second before transmitting again 106 | delay(1000); 107 | } 108 | -------------------------------------------------------------------------------- /examples/HC05/HC05_Basic/HC05_Basic.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib HC05 Example 3 | 4 | This example sends data using HC05 Bluetooth module. 5 | HC05 works exactly like a Serial line, data are sent to the paired device. 6 | The default pairing code for HC05 is 1234 or 1111. 7 | 8 | For full API reference, see the GitHub Pages 9 | https://jgromes.github.io/RadioLib/ 10 | */ 11 | 12 | // include the library 13 | #include 14 | 15 | // HC05 has the following connections: 16 | // TX pin: 9 17 | // RX pin: 8 18 | HC05 bluetooth = new SerialModule(9, 8); 19 | 20 | // or using RadioShield 21 | // https://github.com/jgromes/RadioShield 22 | //HC05 bluetooth = RadioShield.ModuleA; 23 | 24 | void setup() { 25 | Serial.begin(9600); 26 | 27 | // initialize HC05 28 | // baudrate: 9600 baud 29 | bluetooth.begin(9600); 30 | } 31 | 32 | void loop() { 33 | // HC05 supports all methods of the Serial class 34 | // read data incoming from Serial port and write them to Bluetooth 35 | while (Serial.available() > 0) { 36 | bluetooth.write(Serial.read()); 37 | } 38 | 39 | // read data incoming from Bluetooth and write them to Serial port 40 | while (bluetooth.available() > 0) { 41 | Serial.write(bluetooth.read()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/HTTP/HTTP_Get/HTTP_Get.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib HTTP GET Example 3 | 4 | This example sends HTTP GET request using ESP8266 WiFi module. 5 | 6 | Please note that the response will be saved including header. HTTP header size 7 | can easily exceed Arduino resources and cause the program to behave erratically. 8 | 9 | IMPORTANT: Before uploading this example, make sure that the ESP8266 module is running 10 | AT firmware (can be found in the /extras folder of the library)! 11 | 12 | For full API reference, see the GitHub Pages 13 | https://jgromes.github.io/RadioLib/ 14 | */ 15 | 16 | // include the library 17 | #include 18 | 19 | // ESP8266 has the following connections: 20 | // TX pin: 9 21 | // RX pin: 8 22 | ESP8266 wifi = new SerialModule(9, 8); 23 | 24 | // or using RadioShield 25 | // https://github.com/jgromes/RadioShield 26 | //ESP8266 wifi = RadioShield.ModuleA; 27 | 28 | // create HTTP client instance using the wifi module 29 | // the default port used for HTTP is 80 30 | HTTPClient http(&wifi, 80); 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | 35 | // initialize ESP8266 36 | Serial.print(F("[ESP8266] Initializing ... ")); 37 | // baudrate: 9600 baud 38 | int state = wifi.begin(9600); 39 | if (state == ERR_NONE) { 40 | Serial.println(F("success!")); 41 | } else { 42 | Serial.print(F("failed, code ")); 43 | Serial.println(state); 44 | while (true); 45 | } 46 | 47 | // join access point 48 | Serial.print(F("[ESP8266] Joining AP ... ")); 49 | // name: SSID 50 | // password: password 51 | state = wifi.join("SSID", "password"); 52 | if (state == ERR_NONE) { 53 | Serial.println(F("success!")); 54 | } else { 55 | Serial.print(F("failed, code ")); 56 | Serial.println(state); 57 | while (true); 58 | } 59 | 60 | } 61 | 62 | void loop() { 63 | // send HTTP GET request to www.httpbin.org/ip 64 | // the response will contain origin IP address of the request 65 | String response; 66 | Serial.print(F("[ESP8266] Sending HTTP GET request ... ")); 67 | // URL: www.httpbin.org/ip 68 | int http_code = http.get("www.httpbin.org/ip", response); 69 | if (http_code > 0) { 70 | Serial.print(F("HTTP code ")); 71 | Serial.println(http_code); 72 | Serial.print(F("[ESP8266] Response is ")); 73 | Serial.print(response.length()); 74 | Serial.println(F(" bytes long.")); 75 | Serial.println(response); 76 | } else { 77 | Serial.print(F("failed, code ")); 78 | Serial.println(http_code); 79 | } 80 | 81 | // wait for a second before sending new request 82 | delay(1000); 83 | } 84 | -------------------------------------------------------------------------------- /examples/HTTP/HTTP_Post/HTTP_Post.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib HTTP POST Example 3 | 4 | This example sends HTTP POST request using ESP8266 WiFi module. 5 | 6 | Please note that the response will be saved including header. HTTP header size 7 | can easily exceed Arduino resources and cause the program to behave erratically. 8 | 9 | IMPORTANT: Before uploading this example, make sure that the ESP8266 module is running 10 | AT firmware (can be found in the /extras folder of the library)! 11 | 12 | For full API reference, see the GitHub Pages 13 | https://jgromes.github.io/RadioLib/ 14 | */ 15 | 16 | // include the library 17 | #include 18 | 19 | // ESP8266 has the following connections: 20 | // TX pin: 9 21 | // RX pin: 8 22 | ESP8266 wifi = new SerialModule(9, 8); 23 | 24 | // or using RadioShield 25 | // https://github.com/jgromes/RadioShield 26 | //ESP8266 wifi = RadioShield.ModuleA; 27 | 28 | // create HTTP client instance using the wifi module 29 | // the default port used for HTTP is 80 30 | HTTPClient http(&wifi, 80); 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | 35 | // initialize ESP8266 36 | Serial.print(F("[ESP8266] Initializing ... ")); 37 | // baudrate: 9600 baud 38 | int state = wifi.begin(9600); 39 | if(state == ERR_NONE) { 40 | Serial.println(F("success!")); 41 | } else { 42 | Serial.print(F("failed, code ")); 43 | Serial.println(state); 44 | while(true); 45 | } 46 | 47 | // join access point 48 | Serial.print(F("[ESP8266] Joining AP ... ")); 49 | // name: SSID 50 | // password: password 51 | state = wifi.join("SSID", "password"); 52 | if(state == ERR_NONE) { 53 | Serial.println(F("success!")); 54 | } else { 55 | Serial.print(F("failed, code ")); 56 | Serial.println(state); 57 | while(true); 58 | } 59 | 60 | } 61 | 62 | void loop() { 63 | // send HTTP POST request to www.httpbin.org/status/404 64 | // the server doesn't process the posted data, it just returns 65 | // response with the status code 404 66 | String response; 67 | Serial.print(F("[ESP8266] Sending HTTP POST request ... ")); 68 | // URL: www.httpbin.org/status/404 69 | // content: str 70 | // content type: text/plain 71 | int http_code = http.post("www.httpbin.org/status/404", "str", response); 72 | if(http_code > 0) { 73 | Serial.print(F("HTTP code ")); 74 | Serial.println(http_code); 75 | Serial.print(F("[ESP8266] Response is ")); 76 | Serial.print(response.length()); 77 | Serial.println(F(" bytes long.")); 78 | Serial.println(response); 79 | } else { 80 | Serial.print(F("failed, code ")); 81 | Serial.println(http_code); 82 | } 83 | 84 | // wait for a second before sending new request 85 | delay(1000); 86 | } 87 | -------------------------------------------------------------------------------- /examples/Hellschreiber/Hellschreiber_Transmit/Hellschreiber_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib Hellschreiber Transmit Example 3 | 4 | This example sends Hellschreiber message using 5 | SX1278's FSK modem. 6 | 7 | Other modules that can be used for Hellschreiber: 8 | - SX127x/RFM9x 9 | - RF69 10 | - SX1231 11 | - CC1101 12 | - SX126x 13 | - nRF24 14 | - Si443x/RFM2x 15 | - SX128x 16 | 17 | For default module settings, see the wiki page 18 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 19 | 20 | For full API reference, see the GitHub Pages 21 | https://jgromes.github.io/RadioLib/ 22 | */ 23 | 24 | // include the library 25 | #include 26 | 27 | // SX1278 has the following connections: 28 | // NSS pin: 10 29 | // DIO0 pin: 2 30 | // RESET pin: 9 31 | // DIO1 pin: 3 32 | SX1278 radio = new Module(10, 2, 9, 3); 33 | 34 | // or using RadioShield 35 | // https://github.com/jgromes/RadioShield 36 | //SX1278 radio = RadioShield.ModuleA; 37 | 38 | // create Hellschreiber client instance using the FSK module 39 | HellClient hell(&radio); 40 | 41 | void setup() { 42 | Serial.begin(9600); 43 | 44 | // initialize SX1278 with default settings 45 | Serial.print(F("[SX1278] Initializing ... ")); 46 | int state = radio.beginFSK(); 47 | 48 | // when using one of the non-LoRa modules for Morse code 49 | // (RF69, CC1101, Si4432 etc.), use the basic begin() method 50 | // int state = radio.begin(); 51 | 52 | if(state == ERR_NONE) { 53 | Serial.println(F("success!")); 54 | } else { 55 | Serial.print(F("failed, code ")); 56 | Serial.println(state); 57 | while(true); 58 | } 59 | 60 | // initialize Hellschreiber client 61 | Serial.print(F("[Hell] Initializing ... ")); 62 | // base frequency: 434.0 MHz 63 | // speed: 122.5 Baud ("Feld Hell") 64 | state = hell.begin(434.0); 65 | if(state == ERR_NONE) { 66 | Serial.println(F("success!")); 67 | } else { 68 | Serial.print(F("failed, code ")); 69 | Serial.println(state); 70 | while(true); 71 | } 72 | } 73 | 74 | void loop() { 75 | Serial.print(F("[Hell] Sending Hellschreiber data ... ")); 76 | 77 | // HellClient supports all methods of the Serial class 78 | // NOTE: Lower case letter will be capitalized. 79 | 80 | // Arduino String class 81 | String aStr = "Arduino String"; 82 | hell.print(aStr); 83 | 84 | // character array (C-String) 85 | hell.print("C-String"); 86 | 87 | // string saved in flash 88 | hell.print(F("Flash String")); 89 | 90 | // character 91 | hell.print('c'); 92 | 93 | // byte 94 | // formatting DEC/HEX/OCT/BIN is supported for 95 | // any integer type (byte/int/long) 96 | hell.print(255, HEX); 97 | 98 | // integer number 99 | int i = 1000; 100 | hell.print(i); 101 | 102 | // floating point number 103 | // NOTE: println() has no effect on the transmission, 104 | // and is only kept for compatibility reasons. 105 | float f = -3.1415; 106 | hell.println(f, 3); 107 | 108 | // custom glyph - must be a 7 byte array of rows 7 pixels long 109 | uint8_t customGlyph[] = { 0b0000000, 0b0010100, 0b0010100, 0b0000000, 0b0100010, 0b0011100, 0b0000000 }; 110 | hell.printGlyph(customGlyph); 111 | 112 | Serial.println(F("done!")); 113 | 114 | // wait for a second before transmitting again 115 | delay(1000); 116 | } 117 | -------------------------------------------------------------------------------- /examples/Hellschreiber/Hellschreiber_Transmit_AFSK/Hellschreiber_Transmit_AFSK.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib Hellschreiber Transmit AFSK Example 3 | 4 | This example sends Hellschreiber message using 5 | SX1278's FSK modem. The data is modulated 6 | as AFSK. 7 | 8 | Other modules that can be used for Hellschreiber 9 | with AFSK modulation: 10 | - SX127x/RFM9x 11 | - RF69 12 | - SX1231 13 | - CC1101 14 | - Si443x/RFM2x 15 | 16 | For default module settings, see the wiki page 17 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 18 | 19 | For full API reference, see the GitHub Pages 20 | https://jgromes.github.io/RadioLib/ 21 | */ 22 | 23 | // include the library 24 | #include 25 | 26 | // SX1278 has the following connections: 27 | // NSS pin: 10 28 | // DIO0 pin: 2 29 | // RESET pin: 9 30 | // DIO1 pin: 3 31 | SX1278 radio = new Module(10, 2, 9, 3); 32 | 33 | // or using RadioShield 34 | // https://github.com/jgromes/RadioShield 35 | //SX1278 radio = RadioShield.ModuleA; 36 | 37 | // create AFSK client instance using the FSK module 38 | // pin 5 is connected to SX1278 DIO2 39 | AFSKClient audio(&radio, 5); 40 | 41 | // create Hellschreiber client instance using the AFSK instance 42 | HellClient hell(&audio); 43 | 44 | void setup() { 45 | Serial.begin(9600); 46 | 47 | // initialize SX1278 with default settings 48 | Serial.print(F("[SX1278] Initializing ... ")); 49 | int state = radio.beginFSK(); 50 | 51 | // when using one of the non-LoRa modules for Morse code 52 | // (RF69, CC1101, Si4432 etc.), use the basic begin() method 53 | // int state = radio.begin(); 54 | 55 | if(state == ERR_NONE) { 56 | Serial.println(F("success!")); 57 | } else { 58 | Serial.print(F("failed, code ")); 59 | Serial.println(state); 60 | while(true); 61 | } 62 | 63 | // initialize Hellschreiber client 64 | Serial.print(F("[Hell] Initializing ... ")); 65 | // AFSK tone frequency: 400 Hz 66 | // speed: 122.5 Baud ("Feld Hell") 67 | state = hell.begin(400); 68 | if(state == ERR_NONE) { 69 | Serial.println(F("success!")); 70 | } else { 71 | Serial.print(F("failed, code ")); 72 | Serial.println(state); 73 | while(true); 74 | } 75 | } 76 | 77 | void loop() { 78 | Serial.print(F("[Hell] Sending Hellschreiber data ... ")); 79 | 80 | // HellClient supports all methods of the Serial class 81 | // NOTE: Lower case letter will be capitalized. 82 | 83 | // Arduino String class 84 | String aStr = "Arduino String"; 85 | hell.print(aStr); 86 | 87 | // character array (C-String) 88 | hell.print("C-String"); 89 | 90 | // string saved in flash 91 | hell.print(F("Flash String")); 92 | 93 | // character 94 | hell.print('c'); 95 | 96 | // byte 97 | // formatting DEC/HEX/OCT/BIN is supported for 98 | // any integer type (byte/int/long) 99 | hell.print(255, HEX); 100 | 101 | // integer number 102 | int i = 1000; 103 | hell.print(i); 104 | 105 | // floating point number 106 | // NOTE: println() has no effect on the transmission, 107 | // and is only kept for compatibility reasons. 108 | float f = -3.1415; 109 | hell.println(f, 3); 110 | 111 | // custom glyph - must be a 7 byte array of rows 7 pixels long 112 | uint8_t customGlyph[] = { 0b0000000, 0b0010100, 0b0010100, 0b0000000, 0b0100010, 0b0011100, 0b0000000 }; 113 | hell.printGlyph(customGlyph); 114 | 115 | Serial.println(F("done!")); 116 | 117 | // wait for a second before transmitting again 118 | delay(1000); 119 | } 120 | -------------------------------------------------------------------------------- /examples/JDY08/JDY08_Basic/JDY08_Basic.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib JDY08 Example 3 | 4 | This example sends data using JDY08 Bluetooth module. 5 | JDY08 works exactly like a Serial line, data are sent to the paired device. 6 | 7 | For full API reference, see the GitHub Pages 8 | https://jgromes.github.io/RadioLib/ 9 | */ 10 | 11 | // include the library 12 | #include 13 | 14 | // JDY08 has the following connections: 15 | // TX pin: 9 16 | // RX pin: 8 17 | JDY08 ble = new SerialModule(9, 8); 18 | 19 | // or using RadioShield 20 | // https://github.com/jgromes/RadioShield 21 | //JDY08 ble = RadioShield.ModuleA; 22 | 23 | void setup() { 24 | Serial.begin(9600); 25 | 26 | // initialize JDY08 27 | // baudrate: 9600 baud 28 | ble.begin(9600); 29 | } 30 | 31 | void loop() { 32 | // JDY08 supports all methods of the Serial class 33 | // read data incoming from Serial port and write them to Bluetooth 34 | while (Serial.available() > 0) { 35 | ble.write(Serial.read()); 36 | } 37 | 38 | // read data incoming from Bluetooth and write them to Serial port 39 | while (ble.available() > 0) { 40 | Serial.write(ble.read()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /examples/MQTT/MQTT_Publish/MQTT_Publish.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib MQTT Publish Example 3 | 4 | This example publishes MQTT messages using ESP8266 WiFi module. 5 | 6 | The messages are published to https://shiftr.io/try. You can use this namespace 7 | for testing purposes, but remember that it is publicly accessible! 8 | 9 | IMPORTANT: Before uploading this example, make sure that the ESP8266 module is running 10 | AT firmware (can be found in the /extras folder of the library)! 11 | 12 | For full API reference, see the GitHub Pages 13 | https://jgromes.github.io/RadioLib/ 14 | */ 15 | 16 | // include the library 17 | #include 18 | 19 | // ESP8266 has the following connections: 20 | // TX pin: 9 21 | // RX pin: 8 22 | ESP8266 wifi = new SerialModule(9, 8); 23 | 24 | // or using RadioShield 25 | // https://github.com/jgromes/RadioShield 26 | //ESP8266 wifi = RadioShield.ModuleA; 27 | 28 | // create MQTT client instance using the wifi module 29 | // the default port used for MQTT is 1883 30 | MQTTClient mqtt(&wifi, 1883); 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | 35 | // initialize ESP8266 36 | Serial.print(F("[ESP8266] Initializing ... ")); 37 | // baudrate: 9600 baud 38 | int state = wifi.begin(9600); 39 | if (state == ERR_NONE) { 40 | Serial.println(F("success!")); 41 | } else { 42 | Serial.print(F("failed, code ")); 43 | Serial.println(state); 44 | while (true); 45 | } 46 | 47 | // join access point 48 | Serial.print(F("[ESP8266] Joining AP ... ")); 49 | // name: SSID 50 | // password: password 51 | state = wifi.join("SSID", "password"); 52 | if (state == ERR_NONE) { 53 | Serial.println(F("success!")); 54 | } else { 55 | Serial.print(F("failed, code ")); 56 | Serial.println(state); 57 | while (true); 58 | } 59 | 60 | // connect to MQTT server 61 | Serial.print(F("[ESP8266] Connecting to MQTT server ... ")); 62 | // server URL: broker.shiftr.io 63 | // client ID: arduino 64 | // username: try 65 | // password: try 66 | state = mqtt.connect("broker.shiftr.io", "arduino", "try", "try"); 67 | if (state == ERR_NONE) { 68 | Serial.println(F("success!")); 69 | } else { 70 | Serial.print(F("failed, code ")); 71 | Serial.println(state); 72 | while (true); 73 | } 74 | } 75 | 76 | void loop() { 77 | // publish MQTT message 78 | Serial.print(F("[ESP8266] Publishing MQTT message ... ")); 79 | // topic name: hello 80 | // application message: world 81 | int state = mqtt.publish("hello", "world"); 82 | if (state == ERR_NONE) { 83 | Serial.println(F("success!")); 84 | } else { 85 | Serial.print(F("failed, code ")); 86 | Serial.println(state); 87 | } 88 | 89 | // wait for a second before publishing again 90 | delay(1000); 91 | } 92 | -------------------------------------------------------------------------------- /examples/Morse/Morse_Transmit/Morse_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib Morse Transmit Example 3 | 4 | This example sends Morse code message using 5 | SX1278's FSK modem. 6 | 7 | Other modules that can be used for Morse Code: 8 | - SX127x/RFM9x 9 | - RF69 10 | - SX1231 11 | - CC1101 12 | - SX126x 13 | - nRF24 14 | - Si443x/RFM2x 15 | - SX128x 16 | 17 | For default module settings, see the wiki page 18 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 19 | 20 | For full API reference, see the GitHub Pages 21 | https://jgromes.github.io/RadioLib/ 22 | */ 23 | 24 | // include the library 25 | #include 26 | 27 | // SX1278 has the following connections: 28 | // NSS pin: 10 29 | // DIO0 pin: 2 30 | // RESET pin: 9 31 | // DIO1 pin: 3 32 | SX1278 radio = new Module(10, 2, 9, 3); 33 | 34 | // or using RadioShield 35 | // https://github.com/jgromes/RadioShield 36 | //SX1278 radio = RadioShield.ModuleA; 37 | 38 | // create Morse client instance using the FSK module 39 | MorseClient morse(&radio); 40 | 41 | void setup() { 42 | Serial.begin(9600); 43 | 44 | // initialize SX1278 with default settings 45 | Serial.print(F("[SX1278] Initializing ... ")); 46 | int state = radio.beginFSK(); 47 | 48 | // when using one of the non-LoRa modules for Morse code 49 | // (RF69, CC1101, Si4432 etc.), use the basic begin() method 50 | // int state = radio.begin(); 51 | 52 | if(state == ERR_NONE) { 53 | Serial.println(F("success!")); 54 | } else { 55 | Serial.print(F("failed, code ")); 56 | Serial.println(state); 57 | while(true); 58 | } 59 | 60 | // initialize Morse client 61 | Serial.print(F("[Morse] Initializing ... ")); 62 | // base frequency: 434.0 MHz 63 | // speed: 20 words per minute 64 | state = morse.begin(434.0); 65 | if(state == ERR_NONE) { 66 | Serial.println(F("success!")); 67 | } else { 68 | Serial.print(F("failed, code ")); 69 | Serial.println(state); 70 | while(true); 71 | } 72 | } 73 | 74 | void loop() { 75 | Serial.print(F("[Morse] Sending Morse data ... ")); 76 | 77 | // MorseClient supports all methods of the Serial class 78 | // NOTE: Characters that do not have ITU-R M.1677-1 79 | // representation will not be sent! Lower case 80 | // letters will be capitalized. 81 | 82 | // send start signal first 83 | morse.startSignal(); 84 | 85 | // Arduino String class 86 | String aStr = "Arduino String"; 87 | morse.print(aStr); 88 | 89 | // character array (C-String) 90 | morse.print("C-String"); 91 | 92 | // string saved in flash 93 | morse.print(F("Flash String")); 94 | 95 | // character 96 | morse.print('c'); 97 | 98 | // byte 99 | // formatting DEC/HEX/OCT/BIN is supported for 100 | // any integer type (byte/int/long) 101 | morse.print(255, HEX); 102 | 103 | // integer number 104 | int i = 1000; 105 | morse.print(i); 106 | 107 | // floating point number 108 | // NOTE: When using println(), the transmission will be 109 | // terminated with end-of-work signal (...-.-). 110 | float f = -3.1415; 111 | morse.println(f, 3); 112 | 113 | Serial.println(F("done!")); 114 | 115 | // wait for a second before transmitting again 116 | delay(1000); 117 | } 118 | -------------------------------------------------------------------------------- /examples/Morse/Morse_Transmit_AFSK/Morse_Transmit_AFSK.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib Morse Transmit AFSK Example 3 | 4 | This example sends Morse code message using 5 | SX1278's FSK modem. The data is modulated 6 | as AFSK. 7 | 8 | Other modules that can be used for Morse Code 9 | with AFSK modulation: 10 | - SX127x/RFM9x 11 | - RF69 12 | - SX1231 13 | - CC1101 14 | - Si443x/RFM2x 15 | 16 | For default module settings, see the wiki page 17 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 18 | 19 | For full API reference, see the GitHub Pages 20 | https://jgromes.github.io/RadioLib/ 21 | */ 22 | 23 | // include the library 24 | #include 25 | 26 | // SX1278 has the following connections: 27 | // NSS pin: 10 28 | // DIO0 pin: 2 29 | // RESET pin: 9 30 | // DIO1 pin: 3 31 | SX1278 radio = new Module(10, 2, 9, 3); 32 | 33 | // or using RadioShield 34 | // https://github.com/jgromes/RadioShield 35 | //SX1278 radio = RadioShield.ModuleA; 36 | 37 | // create AFSK client instance using the FSK module 38 | // pin 5 is connected to SX1278 DIO2 39 | AFSKClient audio(&radio, 5); 40 | 41 | // create Morse client instance using the AFSK instance 42 | MorseClient morse(&audio); 43 | 44 | void setup() { 45 | Serial.begin(9600); 46 | 47 | // initialize SX1278 with default settings 48 | Serial.print(F("[SX1278] Initializing ... ")); 49 | int state = radio.beginFSK(); 50 | 51 | // when using one of the non-LoRa modules for Morse code 52 | // (RF69, CC1101, Si4432 etc.), use the basic begin() method 53 | // int state = radio.begin(); 54 | 55 | if(state == ERR_NONE) { 56 | Serial.println(F("success!")); 57 | } else { 58 | Serial.print(F("failed, code ")); 59 | Serial.println(state); 60 | while(true); 61 | } 62 | 63 | // initialize Morse client 64 | Serial.print(F("[Morse] Initializing ... ")); 65 | // AFSK tone frequency: 400 MHz 66 | // speed: 20 words per minute 67 | state = morse.begin(400); 68 | if(state == ERR_NONE) { 69 | Serial.println(F("success!")); 70 | } else { 71 | Serial.print(F("failed, code ")); 72 | Serial.println(state); 73 | while(true); 74 | } 75 | } 76 | 77 | void loop() { 78 | Serial.print(F("[Morse] Sending Morse data ... ")); 79 | 80 | // MorseClient supports all methods of the Serial class 81 | // NOTE: Characters that do not have ITU-R M.1677-1 82 | // representation will not be sent! Lower case 83 | // letters will be capitalized. 84 | 85 | // send start signal first 86 | morse.startSignal(); 87 | 88 | // Arduino String class 89 | String aStr = "Arduino String"; 90 | morse.print(aStr); 91 | 92 | // character array (C-String) 93 | morse.print("C-String"); 94 | 95 | // string saved in flash 96 | morse.print(F("Flash String")); 97 | 98 | // character 99 | morse.print('c'); 100 | 101 | // byte 102 | // formatting DEC/HEX/OCT/BIN is supported for 103 | // any integer type (byte/int/long) 104 | morse.print(255, HEX); 105 | 106 | // integer number 107 | int i = 1000; 108 | morse.print(i); 109 | 110 | // floating point number 111 | // NOTE: When using println(), the transmission will be 112 | // terminated with end-of-work signal (...-.-). 113 | float f = -3.1415; 114 | morse.println(f, 3); 115 | 116 | Serial.println(F("done!")); 117 | 118 | // wait for a second before transmitting again 119 | delay(1000); 120 | } 121 | -------------------------------------------------------------------------------- /examples/RF69/RF69_Receive/RF69_Receive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib RF69 Receive Example 3 | 4 | This example receives packets using RF69 FSK radio module. 5 | To successfully receive data, the following settings have to be the same 6 | on both transmitter and receiver: 7 | - carrier frequency 8 | - bit rate 9 | - frequency deviation 10 | - sync word 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // RF69 has the following connections: 23 | // CS pin: 10 24 | // DIO0 pin: 2 25 | // RESET pin: 3 26 | RF69 radio = new Module(10, 2, 3); 27 | 28 | // or using RadioShield 29 | // https://github.com/jgromes/RadioShield 30 | //RF69 radio = RadioShield.ModuleA; 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | 35 | // initialize RF69 with default settings 36 | Serial.print(F("[RF69] Initializing ... ")); 37 | int state = radio.begin(); 38 | if (state == ERR_NONE) { 39 | Serial.println(F("success!")); 40 | } else { 41 | Serial.print(F("failed, code ")); 42 | Serial.println(state); 43 | while (true); 44 | } 45 | } 46 | 47 | void loop() { 48 | Serial.print(F("[RF69] Waiting for incoming transmission ... ")); 49 | 50 | // you can receive data as an Arduino String 51 | String str; 52 | int state = radio.receive(str); 53 | 54 | // you can also receive data as byte array 55 | /* 56 | byte byteArr[8]; 57 | int state = radio.receive(byteArr, 8); 58 | */ 59 | 60 | if (state == ERR_NONE) { 61 | // packet was successfully received 62 | Serial.println(F("success!")); 63 | 64 | // print the data of the packet 65 | Serial.print(F("[RF69] Data:\t\t")); 66 | Serial.println(str); 67 | 68 | // print RSSI (Received Signal Strength Indicator) 69 | // of the last received packet 70 | Serial.print(F("[RF69] RSSI:\t\t")); 71 | Serial.print(radio.getRSSI()); 72 | Serial.println(F(" dBm")); 73 | 74 | } else if (state == ERR_RX_TIMEOUT) { 75 | // timeout occurred while waiting for a packet 76 | Serial.println(F("timeout!")); 77 | 78 | } else if (state == ERR_CRC_MISMATCH) { 79 | // packet was received, but is malformed 80 | Serial.println(F("CRC error!")); 81 | 82 | } else { 83 | // some other error occurred 84 | Serial.print(F("failed, code ")); 85 | Serial.println(state); 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /examples/RF69/RF69_Receive_AES/RF69_Receive_AES.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib RF69 Receive with AES Example 3 | 4 | This example receives packets using RF69 FSK radio module. 5 | Packets are decrypted using hardware AES. 6 | NOTE: When using address filtering, the address byte is NOT encrypted! 7 | 8 | For default module settings, see the wiki page 9 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 10 | 11 | For full API reference, see the GitHub Pages 12 | https://jgromes.github.io/RadioLib/ 13 | */ 14 | 15 | // include the library 16 | #include 17 | 18 | // RF69 has the following connections: 19 | // CS pin: 10 20 | // DIO0 pin: 2 21 | // RESET pin: 3 22 | RF69 radio = new Module(10, 2, 3); 23 | 24 | // or using RadioShield 25 | // https://github.com/jgromes/RadioShield 26 | //RF69 radio = RadioShield.ModuleA; 27 | 28 | void setup() { 29 | Serial.begin(9600); 30 | 31 | // initialize RF69 with default settings 32 | Serial.print(F("[RF69] Initializing ... ")); 33 | int state = radio.begin(); 34 | if (state == ERR_NONE) { 35 | Serial.println(F("success!")); 36 | } else { 37 | Serial.print(F("failed, code ")); 38 | Serial.println(state); 39 | while (true); 40 | } 41 | 42 | // set AES key that will be used to decrypt the packet 43 | // NOTE: the key must be exactly 16 bytes long! 44 | uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 45 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; 46 | radio.setAESKey(key); 47 | 48 | // enable AES encryption 49 | radio.enableAES(); 50 | 51 | // AES encryption can also be disabled 52 | /* 53 | radio.disableAES(); 54 | */ 55 | } 56 | 57 | void loop() { 58 | Serial.print(F("[RF69] Waiting for incoming transmission ... ")); 59 | 60 | // you can receive data as an Arduino String 61 | String str; 62 | int state = radio.receive(str); 63 | 64 | // you can also receive data as byte array 65 | /* 66 | byte byteArr[8]; 67 | int state = radio.receive(byteArr, 8); 68 | */ 69 | 70 | if (state == ERR_NONE) { 71 | // packet was successfully received 72 | Serial.println(F("success!")); 73 | 74 | // print the data of the packet 75 | Serial.print(F("[RF69] Data:\t\t")); 76 | Serial.println(str); 77 | 78 | } else if (state == ERR_RX_TIMEOUT) { 79 | // timeout occurred while waiting for a packet 80 | Serial.println(F("timeout!")); 81 | 82 | } else if (state == ERR_CRC_MISMATCH) { 83 | // packet was received, but is malformed 84 | Serial.println(F("CRC error!")); 85 | 86 | } else { 87 | // some other error occurred 88 | Serial.print(F("failed, code ")); 89 | Serial.println(state); 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /examples/RF69/RF69_Receive_Address/RF69_Receive_Address.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib RF69 Receive with Address Example 3 | 4 | This example receives packets using RF69 FSK radio module. 5 | Packets can have 1-byte address of the destination node. 6 | After setting node (or broadcast) address, this node will 7 | automatically filter out any packets that do not contain 8 | either node address or broadcast address. 9 | 10 | For default module settings, see the wiki page 11 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 12 | 13 | For full API reference, see the GitHub Pages 14 | https://jgromes.github.io/RadioLib/ 15 | */ 16 | 17 | // include the library 18 | #include 19 | 20 | // RF69 has the following connections: 21 | // CS pin: 10 22 | // DIO0 pin: 2 23 | // RESET pin: 3 24 | RF69 radio = new Module(10, 2, 3); 25 | 26 | // or using RadioShield 27 | // https://github.com/jgromes/RadioShield 28 | //RF69 radio = RadioShield.ModuleA; 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | 33 | // initialize RF69 with default settings 34 | Serial.print(F("[RF69] Initializing ... ")); 35 | int state = radio.begin(); 36 | if (state == ERR_NONE) { 37 | Serial.println(F("success!")); 38 | } else { 39 | Serial.print(F("failed, code ")); 40 | Serial.println(state); 41 | while (true); 42 | } 43 | 44 | // set node address 45 | // NOTE: calling this method will automatically enable 46 | // address filtering (node address only) 47 | Serial.print(F("[RF69] Setting node address ... ")); 48 | state = radio.setNodeAddress(0x02); 49 | if (state == ERR_NONE) { 50 | Serial.println(F("success!")); 51 | } else { 52 | Serial.print(F("failed, code ")); 53 | Serial.println(state); 54 | while (true); 55 | } 56 | 57 | // set broadcast address 58 | // NOTE: calling this method will automatically enable 59 | // address filtering (node or broadcast address) 60 | Serial.print(F("[RF69] Setting broadcast address ... ")); 61 | state = radio.setBroadcastAddress(0xFF); 62 | if (state == ERR_NONE) { 63 | Serial.println(F("success!")); 64 | } else { 65 | Serial.print(F("failed, code ")); 66 | Serial.println(state); 67 | while (true); 68 | } 69 | 70 | // address filtering can also be disabled 71 | // NOTE: calling this method will also erase previously set 72 | // node and broadcast address 73 | /* 74 | Serial.print(F("[RF69] Disabling address filtering ... ")); 75 | state == radio.disableAddressFiltering(); 76 | if(state == ERR_NONE) { 77 | Serial.println(F("success!")); 78 | } else { 79 | Serial.print(F("failed, code ")); 80 | Serial.println(state); 81 | while(true); 82 | } 83 | */ 84 | } 85 | 86 | void loop() { 87 | Serial.print(F("[RF69] Waiting for incoming transmission ... ")); 88 | 89 | // you can receive data as an Arduino String 90 | String str; 91 | int state = radio.receive(str); 92 | 93 | // you can also receive data as byte array 94 | /* 95 | byte byteArr[8]; 96 | int state = radio.receive(byteArr, 8); 97 | */ 98 | 99 | if (state == ERR_NONE) { 100 | // packet was successfully received 101 | Serial.println(F("success!")); 102 | 103 | // print the data of the packet 104 | Serial.print(F("[RF69] Data:\t\t")); 105 | Serial.println(str); 106 | 107 | } else if (state == ERR_RX_TIMEOUT) { 108 | // timeout occurred while waiting for a packet 109 | Serial.println(F("timeout!")); 110 | 111 | } else if (state == ERR_CRC_MISMATCH) { 112 | // packet was received, but is malformed 113 | Serial.println(F("CRC error!")); 114 | 115 | } else { 116 | // some other error occurred 117 | Serial.print(F("failed, code ")); 118 | Serial.println(state); 119 | 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /examples/RF69/RF69_Transmit/RF69_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib RF69 Transmit Example 3 | 4 | This example transmits packets using RF69 FSK radio module. 5 | Each packet contains up to 64 bytes of data, in the form of: 6 | - Arduino String 7 | - null-terminated char array (C-string) 8 | - arbitrary binary data (byte array) 9 | 10 | For default module settings, see the wiki page 11 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 12 | 13 | For full API reference, see the GitHub Pages 14 | https://jgromes.github.io/RadioLib/ 15 | */ 16 | 17 | // include the library 18 | #include 19 | 20 | // RF69 has the following connections: 21 | // CS pin: 10 22 | // DIO0 pin: 2 23 | // RESET pin: 3 24 | RF69 radio = new Module(10, 2, 3); 25 | 26 | // or using RadioShield 27 | // https://github.com/jgromes/RadioShield 28 | //RF69 radio = RadioShield.ModuleA; 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | 33 | // initialize RF69 with default settings 34 | Serial.print(F("[RF69] Initializing ... ")); 35 | int state = radio.begin(); 36 | if (state == ERR_NONE) { 37 | Serial.println(F("success!")); 38 | } else { 39 | Serial.print(F("failed, code ")); 40 | Serial.println(state); 41 | while (true); 42 | } 43 | 44 | // NOTE: some RF69 modules use high power output, 45 | // those are usually marked RF69H(C/CW). 46 | // To configure RadioLib for these modules, 47 | // you must call setOutputPower() with 48 | // second argument set to true. 49 | /* 50 | Serial.print(F("[RF69] Setting high power module ... ")); 51 | state = radio.setOutputPower(20, true); 52 | if (state == ERR_NONE) { 53 | Serial.println(F("success!")); 54 | } else { 55 | Serial.print(F("failed, code ")); 56 | Serial.println(state); 57 | while (true); 58 | } 59 | */ 60 | } 61 | 62 | void loop() { 63 | Serial.print(F("[RF69] Transmitting packet ... ")); 64 | 65 | // you can transmit C-string or Arduino string up to 64 characters long 66 | int state = radio.transmit("Hello World!"); 67 | 68 | // you can also transmit byte array up to 64 bytes long 69 | /* 70 | byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; 71 | int state = radio.transmit(byteArr, 8); 72 | */ 73 | 74 | if (state == ERR_NONE) { 75 | // the packet was successfully transmitted 76 | Serial.println(F("success!")); 77 | 78 | } else if (state == ERR_PACKET_TOO_LONG) { 79 | // the supplied packet was longer than 64 bytes 80 | Serial.println(F("too long!")); 81 | 82 | } else { 83 | // some other error occurred 84 | Serial.print(F("failed, code ")); 85 | Serial.println(state); 86 | 87 | } 88 | 89 | // wait for a second before transmitting again 90 | delay(1000); 91 | } 92 | -------------------------------------------------------------------------------- /examples/RF69/RF69_Transmit_AES/RF69_Transmit_AES.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib RF69 Transmit with AES Example 3 | 4 | This example transmits packets using RF69 FSK radio module. 5 | Packets are encrypted using hardware AES. 6 | NOTE: When using address filtering, the address byte is NOT encrypted! 7 | 8 | For default module settings, see the wiki page 9 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 10 | 11 | For full API reference, see the GitHub Pages 12 | https://jgromes.github.io/RadioLib/ 13 | */ 14 | 15 | // include the library 16 | #include 17 | 18 | // RF69 has the following connections: 19 | // CS pin: 10 20 | // DIO0 pin: 2 21 | // RESET pin: 3 22 | RF69 radio = new Module(10, 2, 3); 23 | 24 | // or using RadioShield 25 | // https://github.com/jgromes/RadioShield 26 | //RF69 radio = RadioShield.ModuleA; 27 | 28 | void setup() { 29 | Serial.begin(9600); 30 | 31 | // initialize RF69 with default settings 32 | Serial.print(F("[RF69] Initializing ... ")); 33 | int state = radio.begin(); 34 | if (state == ERR_NONE) { 35 | Serial.println(F("success!")); 36 | } else { 37 | Serial.print(F("failed, code ")); 38 | Serial.println(state); 39 | while (true); 40 | } 41 | 42 | // set AES key to encrypt the packet 43 | // NOTE: the key must be exactly 16 bytes long! 44 | uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 45 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; 46 | radio.setAESKey(key); 47 | 48 | // enable AES encryption 49 | radio.enableAES(); 50 | 51 | // AES encryption can also be disabled 52 | /* 53 | radio.disableAES(); 54 | */ 55 | } 56 | 57 | void loop() { 58 | Serial.print(F("[RF69] Transmitting packet ... ")); 59 | 60 | // you can transmit C-string or Arduino string up to 64 characters long 61 | int state = radio.transmit("Hello World!"); 62 | 63 | // you can also transmit byte array up to 64 bytes long 64 | /* 65 | byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; 66 | int state = radio.transmit(byteArr, 8); 67 | */ 68 | 69 | if (state == ERR_NONE) { 70 | // the packet was successfully transmitted 71 | Serial.println(F("success!")); 72 | 73 | } else if (state == ERR_PACKET_TOO_LONG) { 74 | // the supplied packet was longer than 64 bytes 75 | Serial.println(F("too long!")); 76 | 77 | } else { 78 | // some other error occurred 79 | Serial.print(F("failed, code ")); 80 | Serial.println(state); 81 | 82 | } 83 | 84 | // wait for a second before transmitting again 85 | delay(1000); 86 | } 87 | -------------------------------------------------------------------------------- /examples/RTTY/RTTY_Transmit_AFSK/RTTY_Transmit_AFSK.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib RTTY Transmit AFSK Example 3 | 4 | This example sends RTTY message using SX1278's 5 | FSK modem. The data is modulated as AFSK. 6 | 7 | Other modules that can be used for RTTY: 8 | - SX127x/RFM9x 9 | - RF69 10 | - SX1231 11 | - CC1101 12 | - Si443x/RFM2x 13 | 14 | For default module settings, see the wiki page 15 | https://github.com/jgromes/RadioLib/wiki/Default-configuration 16 | 17 | For full API reference, see the GitHub Pages 18 | https://jgromes.github.io/RadioLib/ 19 | */ 20 | 21 | // include the library 22 | #include 23 | 24 | // SX1278 has the following connections: 25 | // NSS pin: 10 26 | // DIO0 pin: 2 27 | // RESET pin: 9 28 | // DIO1 pin: 3 29 | SX1278 radio = new Module(10, 2, 9, 3); 30 | 31 | // or using RadioShield 32 | // https://github.com/jgromes/RadioShield 33 | //SX1278 radio = RadioShield.ModuleA; 34 | 35 | // create AFSK client instance using the FSK module 36 | // pin 5 is connected to SX1278 DIO2 37 | AFSKClient audio(&radio, 5); 38 | 39 | // create RTTY client instance using the AFSK instance 40 | RTTYClient rtty(&audio); 41 | 42 | void setup() { 43 | Serial.begin(9600); 44 | 45 | // initialize SX1278 with default settings 46 | Serial.print(F("[SX1278] Initializing ... ")); 47 | int state = radio.beginFSK(); 48 | 49 | // when using one of the non-LoRa modules for RTTY 50 | // (RF69, CC1101, Si4432 etc.), use the basic begin() method 51 | // int state = radio.begin(); 52 | 53 | if(state == ERR_NONE) { 54 | Serial.println(F("success!")); 55 | } else { 56 | Serial.print(F("failed, code ")); 57 | Serial.println(state); 58 | while(true); 59 | } 60 | 61 | // initialize RTTY client 62 | // NOTE: Unlike FSK RTTY, AFSK requires no rounding of 63 | // the frequency shift. 64 | Serial.print(F("[RTTY] Initializing ... ")); 65 | // space frequency: 400 Hz 66 | // frequency shift: 170 Hz 67 | // baud rate: 45 baud 68 | // encoding: ASCII (7-bit) 69 | // stop bits: 1 70 | state = rtty.begin(400, 170, 45); 71 | if(state == ERR_NONE) { 72 | Serial.println(F("success!")); 73 | } else { 74 | Serial.print(F("failed, code ")); 75 | Serial.println(state); 76 | while(true); 77 | } 78 | 79 | /* 80 | // RadioLib also provides ITA2 ("Baudot") support 81 | rtty.begin(400, 170, 45, ITA2); 82 | 83 | // All transmissions in loop() (strings and numbers) 84 | // will now be encoded using ITA2 code 85 | 86 | // ASCII characters that do not have ITA2 equivalent 87 | // will be sent as NUL (including lower case letters!) 88 | */ 89 | } 90 | 91 | void loop() { 92 | Serial.print(F("[RTTY] Sending RTTY data ... ")); 93 | 94 | // send out idle condition for 500 ms 95 | rtty.idle(); 96 | delay(500); 97 | 98 | // RTTYClient supports all methods of the Serial class 99 | 100 | // Arduino String class 101 | String aStr = "Arduino String"; 102 | rtty.println(aStr); 103 | 104 | // character array (C-String) 105 | rtty.println("C-String"); 106 | 107 | // string saved in flash 108 | rtty.println(F("Flash String")); 109 | 110 | // character 111 | rtty.println('c'); 112 | 113 | // byte 114 | // formatting DEC/HEX/OCT/BIN is supported for 115 | // any integer type (byte/int/long) 116 | rtty.println(255, HEX); 117 | 118 | // integer number 119 | int i = 1000; 120 | rtty.println(i); 121 | 122 | // floating point number 123 | float f = -3.1415; 124 | rtty.println(f, 3); 125 | 126 | // turn the transmitter off 127 | rtty.standby(); 128 | 129 | Serial.println(F("done!")); 130 | 131 | // wait for a second before transmitting again 132 | delay(1000); 133 | } 134 | -------------------------------------------------------------------------------- /examples/SX1231/SX1231_Receive/SX1231_Receive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX1231 Receive Example 3 | 4 | This example receives packets using SX1231 FSK radio module. 5 | 6 | NOTE: SX1231 offers the same features as RF69 and has the same 7 | interface. Please see RF69 examples for examples on AES, 8 | address filtering, interrupts and settings. 9 | 10 | For default module settings, see the wiki page 11 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 12 | 13 | For full API reference, see the GitHub Pages 14 | https://jgromes.github.io/RadioLib/ 15 | */ 16 | 17 | // include the library 18 | #include 19 | 20 | // SX1231 has the following connections: 21 | // CS pin: 10 22 | // DIO0 pin: 2 23 | // RESET pin: 3 24 | SX1231 radio = new Module(10, 2, 3); 25 | 26 | // or using RadioShield 27 | // https://github.com/jgromes/RadioShield 28 | //SX1231 radio = RadioShield.ModuleA; 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | 33 | // initialize SX1231 with default settings 34 | Serial.print(F("[SX1231] Initializing ... ")); 35 | int state = radio.begin(); 36 | if (state == ERR_NONE) { 37 | Serial.println(F("success!")); 38 | } else { 39 | Serial.print(F("failed, code ")); 40 | Serial.println(state); 41 | while (true); 42 | } 43 | } 44 | 45 | void loop() { 46 | Serial.print(F("[SX1231] Waiting for incoming transmission ... ")); 47 | 48 | // you can receive data as an Arduino String 49 | String str; 50 | int state = radio.receive(str); 51 | 52 | // you can also receive data as byte array 53 | /* 54 | byte byteArr[8]; 55 | int state = radio.receive(byteArr, 8); 56 | */ 57 | 58 | if (state == ERR_NONE) { 59 | // packet was successfully received 60 | Serial.println(F("success!")); 61 | 62 | // print the data of the packet 63 | Serial.print(F("[SX1231] Data:\t\t")); 64 | Serial.println(str); 65 | 66 | } else if (state == ERR_RX_TIMEOUT) { 67 | // timeout occurred while waiting for a packet 68 | Serial.println(F("timeout!")); 69 | 70 | } else if (state == ERR_CRC_MISMATCH) { 71 | // packet was received, but is malformed 72 | Serial.println(F("CRC error!")); 73 | 74 | } else { 75 | // some other error occurred 76 | Serial.print(F("failed, code ")); 77 | Serial.println(state); 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /examples/SX1231/SX1231_Transmit/SX1231_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX1231 Transmit Example 3 | 4 | This example transmits packets using SX1231 FSK radio module. 5 | 6 | NOTE: SX1231 offers the same features as RF69 and has the same 7 | interface. Please see RF69 examples for examples on AES, 8 | address filtering, interrupts and settings. 9 | 10 | For default module settings, see the wiki page 11 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231 12 | 13 | For full API reference, see the GitHub Pages 14 | https://jgromes.github.io/RadioLib/ 15 | */ 16 | 17 | // include the library 18 | #include 19 | 20 | // SX1231 has the following connections: 21 | // CS pin: 10 22 | // DIO0 pin: 2 23 | // RESET pin: 3 24 | SX1231 radio = new Module(10, 2, 3); 25 | 26 | // or using RadioShield 27 | // https://github.com/jgromes/RadioShield 28 | //SX1231 radio = RadioShield.ModuleA; 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | 33 | // initialize SX1231 with default settings 34 | Serial.print(F("[SX1231] Initializing ... ")); 35 | int state = radio.begin(); 36 | if (state == ERR_NONE) { 37 | Serial.println(F("success!")); 38 | } else { 39 | Serial.print(F("failed, code ")); 40 | Serial.println(state); 41 | while (true); 42 | } 43 | } 44 | 45 | void loop() { 46 | Serial.print(F("[SX1231] Transmitting packet ... ")); 47 | 48 | // you can transmit C-string or Arduino string up to 256 characters long 49 | int state = radio.transmit("Hello World!"); 50 | 51 | // you can also transmit byte array up to 256 bytes long 52 | /* 53 | byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; 54 | int state = radio.transmit(byteArr, 8); 55 | */ 56 | 57 | if (state == ERR_NONE) { 58 | // the packet was successfully transmitted 59 | Serial.println(F("success!")); 60 | 61 | } else if (state == ERR_PACKET_TOO_LONG) { 62 | // the supplied packet was longer than 256 bytes 63 | Serial.println(F("too long!")); 64 | 65 | } 66 | 67 | // wait for a second before transmitting again 68 | delay(1000); 69 | } 70 | -------------------------------------------------------------------------------- /examples/SX126x/SX126x_Channel_Activity_Detection/SX126x_Channel_Activity_Detection.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX126x Channel Activity Detection Example 3 | 4 | This example uses SX1262 to scan the current LoRa 5 | channel and detect ongoing LoRa transmissions. 6 | Unlike SX127x CAD, SX126x can detect any part 7 | of LoRa transmission, not just the preamble. 8 | 9 | Other modules from SX126x family can also be used. 10 | 11 | For default module settings, see the wiki page 12 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem 13 | 14 | For full API reference, see the GitHub Pages 15 | https://jgromes.github.io/RadioLib/ 16 | */ 17 | 18 | // include the library 19 | #include 20 | 21 | // SX1262 has the following connections: 22 | // NSS pin: 10 23 | // DIO1 pin: 2 24 | // NRST pin: 3 25 | // BUSY pin: 9 26 | SX1262 radio = new Module(10, 2, 3, 9); 27 | 28 | // or using RadioShield 29 | // https://github.com/jgromes/RadioShield 30 | //SX1262 radio = RadioShield.ModuleA; 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | 35 | // initialize SX1262 with default settings 36 | Serial.print(F("[SX1262] Initializing ... ")); 37 | int state = radio.begin(); 38 | if (state == ERR_NONE) { 39 | Serial.println(F("success!")); 40 | } else { 41 | Serial.print(F("failed, code ")); 42 | Serial.println(state); 43 | while (true); 44 | } 45 | } 46 | 47 | void loop() { 48 | Serial.print(F("[SX1262] Scanning channel for LoRa transmission ... ")); 49 | 50 | // start scanning current channel 51 | int state = radio.scanChannel(); 52 | 53 | if (state == LORA_DETECTED) { 54 | // LoRa preamble was detected 55 | Serial.println(F("detected!")); 56 | 57 | } else if (state == CHANNEL_FREE) { 58 | // no preamble was detected, channel is free 59 | Serial.println(F("channel is free!")); 60 | 61 | } else { 62 | // some other error occurred 63 | Serial.print(F("failed, code ")); 64 | Serial.println(state); 65 | 66 | } 67 | 68 | // wait 100 ms before new scan 69 | delay(100); 70 | } 71 | -------------------------------------------------------------------------------- /examples/SX126x/SX126x_Receive/SX126x_Receive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX126x Receive Example 3 | 4 | This example listens for LoRa transmissions using SX126x Lora modules. 5 | To successfully receive data, the following settings have to be the same 6 | on both transmitter and receiver: 7 | - carrier frequency 8 | - bandwidth 9 | - spreading factor 10 | - coding rate 11 | - sync word 12 | - preamble length 13 | 14 | Other modules from SX126x family can also be used. 15 | 16 | For default module settings, see the wiki page 17 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem 18 | 19 | For full API reference, see the GitHub Pages 20 | https://jgromes.github.io/RadioLib/ 21 | */ 22 | 23 | // include the library 24 | #include 25 | 26 | // SX1262 has the following connections: 27 | // NSS pin: 10 28 | // DIO1 pin: 2 29 | // NRST pin: 3 30 | // BUSY pin: 9 31 | SX1262 radio = new Module(10, 2, 3, 9); 32 | 33 | // or using RadioShield 34 | // https://github.com/jgromes/RadioShield 35 | //SX1262 radio = RadioShield.ModuleA; 36 | 37 | void setup() { 38 | Serial.begin(9600); 39 | 40 | // initialize SX1262 with default settings 41 | Serial.print(F("[SX1262] Initializing ... ")); 42 | int state = radio.begin(); 43 | if (state == ERR_NONE) { 44 | Serial.println(F("success!")); 45 | } else { 46 | Serial.print(F("failed, code ")); 47 | Serial.println(state); 48 | while (true); 49 | } 50 | } 51 | 52 | void loop() { 53 | Serial.print(F("[SX1262] Waiting for incoming transmission ... ")); 54 | 55 | // you can receive data as an Arduino String 56 | // NOTE: receive() is a blocking method! 57 | // See example ReceiveInterrupt for details 58 | // on non-blocking reception method. 59 | String str; 60 | int state = radio.receive(str); 61 | 62 | // you can also receive data as byte array 63 | /* 64 | byte byteArr[8]; 65 | int state = radio.receive(byteArr, 8); 66 | */ 67 | 68 | if (state == ERR_NONE) { 69 | // packet was successfully received 70 | Serial.println(F("success!")); 71 | 72 | // print the data of the packet 73 | Serial.print(F("[SX1262] Data:\t\t")); 74 | Serial.println(str); 75 | 76 | // print the RSSI (Received Signal Strength Indicator) 77 | // of the last received packet 78 | Serial.print(F("[SX1262] RSSI:\t\t")); 79 | Serial.print(radio.getRSSI()); 80 | Serial.println(F(" dBm")); 81 | 82 | // print the SNR (Signal-to-Noise Ratio) 83 | // of the last received packet 84 | Serial.print(F("[SX1262] SNR:\t\t")); 85 | Serial.print(radio.getSNR()); 86 | Serial.println(F(" dB")); 87 | 88 | } else if (state == ERR_RX_TIMEOUT) { 89 | // timeout occurred while waiting for a packet 90 | Serial.println(F("timeout!")); 91 | 92 | } else if (state == ERR_CRC_MISMATCH) { 93 | // packet was received, but is malformed 94 | Serial.println(F("CRC error!")); 95 | 96 | } else { 97 | // some other error occurred 98 | Serial.print(F("failed, code ")); 99 | Serial.println(state); 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX126x Transmit Example 3 | 4 | This example transmits packets using SX1262 LoRa radio module. 5 | Each packet contains up to 256 bytes of data, in the form of: 6 | - Arduino String 7 | - null-terminated char array (C-string) 8 | - arbitrary binary data (byte array) 9 | 10 | Other modules from SX126x family can also be used. 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // SX1262 has the following connections: 23 | // NSS pin: 10 24 | // DIO1 pin: 2 25 | // NRST pin: 3 26 | // BUSY pin: 9 27 | SX1262 radio = new Module(10, 2, 3, 9); 28 | 29 | // or using RadioShield 30 | // https://github.com/jgromes/RadioShield 31 | //SX1262 radio = RadioShield.ModuleA; 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | 36 | // initialize SX1262 with default settings 37 | Serial.print(F("[SX1262] Initializing ... ")); 38 | int state = radio.begin(); 39 | if (state == ERR_NONE) { 40 | Serial.println(F("success!")); 41 | } else { 42 | Serial.print(F("failed, code ")); 43 | Serial.println(state); 44 | while (true); 45 | } 46 | 47 | // some modules have an external RF switch 48 | // controlled via two pins (RX enable, TX enable) 49 | // to enable automatic control of the switch, 50 | // call the following method 51 | // RX enable: 4 52 | // TX enable: 5 53 | /* 54 | radio.setRfSwitchPins(4, 5); 55 | */ 56 | } 57 | 58 | void loop() { 59 | Serial.print(F("[SX1262] Transmitting packet ... ")); 60 | 61 | // you can transmit C-string or Arduino string up to 62 | // 256 characters long 63 | // NOTE: transmit() is a blocking method! 64 | // See example SX126x_Transmit_Interrupt for details 65 | // on non-blocking transmission method. 66 | int state = radio.transmit("Hello World!"); 67 | 68 | // you can also transmit byte array up to 256 bytes long 69 | /* 70 | byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; 71 | int state = radio.transmit(byteArr, 8); 72 | */ 73 | 74 | if (state == ERR_NONE) { 75 | // the packet was successfully transmitted 76 | Serial.println(F("success!")); 77 | 78 | // print measured data rate 79 | Serial.print(F("[SX1262] Datarate:\t")); 80 | Serial.print(radio.getDataRate()); 81 | Serial.println(F(" bps")); 82 | 83 | } else if (state == ERR_PACKET_TOO_LONG) { 84 | // the supplied packet was longer than 256 bytes 85 | Serial.println(F("too long!")); 86 | 87 | } else if (state == ERR_TX_TIMEOUT) { 88 | // timeout occured while transmitting packet 89 | Serial.println(F("timeout!")); 90 | 91 | } else { 92 | // some other error occurred 93 | Serial.print(F("failed, code ")); 94 | Serial.println(state); 95 | 96 | } 97 | 98 | // wait for a second before transmitting again 99 | delay(1000); 100 | } 101 | -------------------------------------------------------------------------------- /examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX127x Channel Activity Detection Example 3 | 4 | This example scans the current LoRa channel and detects 5 | valid LoRa preambles. Preamble is the first part of 6 | LoRa transmission, so this can be used to check 7 | if the LoRa channel is free, or if you should start 8 | receiving a message. 9 | 10 | Other modules from SX127x/RFM9x family can also be used. 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // SX1278 has the following connections: 23 | // NSS pin: 10 24 | // DIO0 pin: 2 25 | // RESET pin: 9 26 | // DIO1 pin: 3 27 | SX1278 radio = new Module(10, 2, 9, 3); 28 | 29 | // or using RadioShield 30 | // https://github.com/jgromes/RadioShield 31 | //SX1278 radio = RadioShield.ModuleA; 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | 36 | // initialize SX1278 with default settings 37 | Serial.print(F("[SX1278] Initializing ... ")); 38 | int state = radio.begin(); 39 | if (state == ERR_NONE) { 40 | Serial.println(F("success!")); 41 | } else { 42 | Serial.print(F("failed, code ")); 43 | Serial.println(state); 44 | while (true); 45 | } 46 | } 47 | 48 | void loop() { 49 | Serial.print(F("[SX1278] Scanning channel for LoRa preamble ... ")); 50 | 51 | // start scanning current channel 52 | int state = radio.scanChannel(); 53 | 54 | if (state == PREAMBLE_DETECTED) { 55 | // LoRa preamble was detected 56 | Serial.println(F("detected preamble!")); 57 | 58 | } else if (state == CHANNEL_FREE) { 59 | // no preamble was detected, channel is free 60 | Serial.println(F("channel is free!")); 61 | 62 | } 63 | 64 | // wait 100 ms before new scan 65 | delay(100); 66 | } 67 | -------------------------------------------------------------------------------- /examples/SX127x/SX127x_Receive/SX127x_Receive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX127x Receive Example 3 | 4 | This example listens for LoRa transmissions using SX127x Lora modules. 5 | To successfully receive data, the following settings have to be the same 6 | on both transmitter and receiver: 7 | - carrier frequency 8 | - bandwidth 9 | - spreading factor 10 | - coding rate 11 | - sync word 12 | - preamble length 13 | 14 | Other modules from SX127x/RFM9x family can also be used. 15 | 16 | For default module settings, see the wiki page 17 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem 18 | 19 | For full API reference, see the GitHub Pages 20 | https://jgromes.github.io/RadioLib/ 21 | */ 22 | 23 | // include the library 24 | #include 25 | 26 | // SX1278 has the following connections: 27 | // NSS pin: 10 28 | // DIO0 pin: 2 29 | // RESET pin: 9 30 | // DIO1 pin: 3 31 | SX1278 radio = new Module(10, 2, 9, 3); 32 | 33 | // or using RadioShield 34 | // https://github.com/jgromes/RadioShield 35 | //SX1278 radio = RadioShield.ModuleA; 36 | 37 | void setup() { 38 | Serial.begin(9600); 39 | 40 | // initialize SX1278 with default settings 41 | Serial.print(F("[SX1278] Initializing ... ")); 42 | int state = radio.begin(); 43 | if (state == ERR_NONE) { 44 | Serial.println(F("success!")); 45 | } else { 46 | Serial.print(F("failed, code ")); 47 | Serial.println(state); 48 | while (true); 49 | } 50 | } 51 | 52 | void loop() { 53 | Serial.print(F("[SX1278] Waiting for incoming transmission ... ")); 54 | 55 | // you can receive data as an Arduino String 56 | // NOTE: receive() is a blocking method! 57 | // See example ReceiveInterrupt for details 58 | // on non-blocking reception method. 59 | String str; 60 | int state = radio.receive(str); 61 | 62 | // you can also receive data as byte array 63 | /* 64 | byte byteArr[8]; 65 | int state = radio.receive(byteArr, 8); 66 | */ 67 | 68 | if (state == ERR_NONE) { 69 | // packet was successfully received 70 | Serial.println(F("success!")); 71 | 72 | // print the data of the packet 73 | Serial.print(F("[SX1278] Data:\t\t\t")); 74 | Serial.println(str); 75 | 76 | // print the RSSI (Received Signal Strength Indicator) 77 | // of the last received packet 78 | Serial.print(F("[SX1278] RSSI:\t\t\t")); 79 | Serial.print(radio.getRSSI()); 80 | Serial.println(F(" dBm")); 81 | 82 | // print the SNR (Signal-to-Noise Ratio) 83 | // of the last received packet 84 | Serial.print(F("[SX1278] SNR:\t\t\t")); 85 | Serial.print(radio.getSNR()); 86 | Serial.println(F(" dB")); 87 | 88 | // print frequency error 89 | // of the last received packet 90 | Serial.print(F("[SX1278] Frequency error:\t")); 91 | Serial.print(radio.getFrequencyError()); 92 | Serial.println(F(" Hz")); 93 | 94 | } else if (state == ERR_RX_TIMEOUT) { 95 | // timeout occurred while waiting for a packet 96 | Serial.println(F("timeout!")); 97 | 98 | } else if (state == ERR_CRC_MISMATCH) { 99 | // packet was received, but is malformed 100 | Serial.println(F("CRC error!")); 101 | 102 | } else { 103 | // some other error occurred 104 | Serial.print(F("failed, code ")); 105 | Serial.println(state); 106 | 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /examples/SX127x/SX127x_Receive_Direct/SX127x_Receive_Direct.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX127x Direct Receive Example 3 | 4 | This example shows how to receive FSK packets without using 5 | SX127x packet engine. 6 | 7 | For default module settings, see the wiki page 8 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem 9 | 10 | For full API reference, see the GitHub Pages 11 | https://jgromes.github.io/RadioLib/ 12 | */ 13 | 14 | // include the library 15 | #include 16 | 17 | // SX1278 has the following connections: 18 | // NSS pin: 10 19 | // DIO0 pin: 2 20 | // RESET pin: 9 21 | // DIO1 pin: 3 22 | SX1278 radio = new Module(10, 2, 9, 3); 23 | 24 | // DIO2 pin: 5 25 | const int pin = 5; 26 | 27 | // or using RadioShield 28 | // https://github.com/jgromes/RadioShield 29 | //SX1278 radio = RadioShield.ModuleA; 30 | 31 | void setup() { 32 | Serial.begin(9600); 33 | 34 | // initialize SX1278 with FSK modem at 9600 bps 35 | Serial.print(F("[SX1278] Initializing ... ")); 36 | int state = radio.beginFSK(434.0, 9.6, 20.0); 37 | if (state == ERR_NONE) { 38 | Serial.println(F("success!")); 39 | } else { 40 | Serial.print(F("failed, code ")); 41 | Serial.println(state); 42 | while (true); 43 | } 44 | 45 | // set the direct mode sync word 46 | // the default RadioLib FSK sync word is 0x12AD 47 | // we can add in some preamble bits, to lower the chance 48 | // of false detection 49 | radio.setDirectSyncWord(0x555512AD, 32); 50 | 51 | // set function that will be called each time a bit is received 52 | radio.setDirectAction(readBit); 53 | 54 | // start direct mode reception 55 | radio.receiveDirect(); 56 | } 57 | 58 | // this function is called when a new bit is received 59 | void readBit(void) { 60 | // read the data bit 61 | radio.readBit(pin); 62 | } 63 | 64 | void loop() { 65 | // we expect the packet to contain the string "Hello World!", 66 | // a length byte and 2 CRC bytes, that's 15 bytes in total 67 | if(radio.available() >= 15) { 68 | Serial.println("[SX1278] Received packet in direct mode!"); 69 | while(radio.available()) { 70 | // read a byte 71 | byte b = radio.read(); 72 | 73 | // print it 74 | Serial.print(b, HEX); 75 | Serial.print('\t'); 76 | Serial.write(b); 77 | Serial.println(); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX127x Transmit Example 3 | 4 | This example transmits packets using SX1278 LoRa radio module. 5 | Each packet contains up to 256 bytes of data, in the form of: 6 | - Arduino String 7 | - null-terminated char array (C-string) 8 | - arbitrary binary data (byte array) 9 | 10 | Other modules from SX127x/RFM9x family can also be used. 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // SX1278 has the following connections: 23 | // NSS pin: 10 24 | // DIO0 pin: 2 25 | // RESET pin: 9 26 | // DIO1 pin: 3 27 | SX1278 radio = new Module(10, 2, 9, 3); 28 | 29 | // or using RadioShield 30 | // https://github.com/jgromes/RadioShield 31 | //SX1278 radio = RadioShield.ModuleA; 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | 36 | // initialize SX1278 with default settings 37 | Serial.print(F("[SX1278] Initializing ... ")); 38 | int state = radio.begin(); 39 | if (state == ERR_NONE) { 40 | Serial.println(F("success!")); 41 | } else { 42 | Serial.print(F("failed, code ")); 43 | Serial.println(state); 44 | while (true); 45 | } 46 | 47 | // some modules have an external RF switch 48 | // controlled via two pins (RX enable, TX enable) 49 | // to enable automatic control of the switch, 50 | // call the following method 51 | // RX enable: 4 52 | // TX enable: 5 53 | /* 54 | radio.setRfSwitchPins(4, 5); 55 | */ 56 | } 57 | 58 | void loop() { 59 | Serial.print(F("[SX1278] Transmitting packet ... ")); 60 | 61 | // you can transmit C-string or Arduino string up to 62 | // 256 characters long 63 | // NOTE: transmit() is a blocking method! 64 | // See example SX127x_Transmit_Interrupt for details 65 | // on non-blocking transmission method. 66 | int state = radio.transmit("Hello World!"); 67 | 68 | // you can also transmit byte array up to 256 bytes long 69 | /* 70 | byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}; 71 | int state = radio.transmit(byteArr, 8); 72 | */ 73 | 74 | if (state == ERR_NONE) { 75 | // the packet was successfully transmitted 76 | Serial.println(F(" success!")); 77 | 78 | // print measured data rate 79 | Serial.print(F("[SX1278] Datarate:\t")); 80 | Serial.print(radio.getDataRate()); 81 | Serial.println(F(" bps")); 82 | 83 | } else if (state == ERR_PACKET_TOO_LONG) { 84 | // the supplied packet was longer than 256 bytes 85 | Serial.println(F("too long!")); 86 | 87 | } else if (state == ERR_TX_TIMEOUT) { 88 | // timeout occurred while transmitting packet 89 | Serial.println(F("timeout!")); 90 | 91 | } else { 92 | // some other error occurred 93 | Serial.print(F("failed, code ")); 94 | Serial.println(state); 95 | 96 | } 97 | 98 | // wait for a second before transmitting again 99 | delay(1000); 100 | } 101 | -------------------------------------------------------------------------------- /examples/SX128x/SX128x_BLE_Modem/SX128x_BLE_Modem.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX128x BLE Modem Example 3 | 4 | This example shows how to use BLE modem in SX128x chips. 5 | RadioLib does not provide BLE protocol support (yet), 6 | only compatibility with the physical layer. 7 | 8 | NOTE: The sketch below is just a guide on how to use 9 | BLE modem, so this code should not be run directly! 10 | Instead, modify the other examples to use BLE 11 | modem and use the appropriate configuration 12 | methods. 13 | 14 | For default module settings, see the wiki page 15 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---ble-modem 16 | 17 | For full API reference, see the GitHub Pages 18 | https://jgromes.github.io/RadioLib/ 19 | */ 20 | 21 | // include the library 22 | #include 23 | 24 | // SX1280 has the following connections: 25 | // NSS pin: 10 26 | // DIO1 pin: 2 27 | // NRST pin: 3 28 | // BUSY pin: 9 29 | SX1280 radio = new Module(10, 2, 3, 9); 30 | 31 | // or using RadioShield 32 | // https://github.com/jgromes/RadioShield 33 | //SX1280 radio = RadioShield.ModuleA; 34 | 35 | void setup() { 36 | Serial.begin(9600); 37 | 38 | // initialize SX1280 with default settings 39 | Serial.print(F("[SX1280] Initializing ... ")); 40 | int state = radio.beginBLE(); 41 | if (state == ERR_NONE) { 42 | Serial.println(F("success!")); 43 | } else { 44 | Serial.print(F("failed, code ")); 45 | Serial.println(state); 46 | while (true); 47 | } 48 | 49 | // if needed, you can switch between any of the modems 50 | // 51 | // radio.begin() start LoRa modem (and disable BLE) 52 | // radio.beginBLE() start BLE modem (and disable LoRa) 53 | 54 | // the following settings can also 55 | // be modified at run-time 56 | state = radio.setFrequency(2410.5); 57 | state = radio.setBitRate(250); 58 | state = radio.setFrequencyDeviation(100.0); 59 | state = radio.setOutputPower(5); 60 | state = radio.setDataShaping(1.0); 61 | state = radio.setAccessAddress(0x12345678); 62 | if (state != ERR_NONE) { 63 | Serial.print(F("Unable to set configuration, code ")); 64 | Serial.println(state); 65 | while (true); 66 | } 67 | 68 | #warning "This sketch is just an API guide! Read the note at line 6." 69 | } 70 | 71 | void loop() { 72 | // BLE modem can use the same transmit/receive methods 73 | // as the LoRa modem, even their interrupt-driven versions 74 | 75 | // transmit BLE packet 76 | int state = radio.transmit("Hello World!"); 77 | /* 78 | byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 79 | 0x89, 0xAB, 0xCD, 0xEF}; 80 | int state = radio.transmit(byteArr, 8); 81 | */ 82 | if (state == ERR_NONE) { 83 | Serial.println(F("[SX1280] Packet transmitted successfully!")); 84 | } else if (state == ERR_PACKET_TOO_LONG) { 85 | Serial.println(F("[SX1280] Packet too long!")); 86 | } else if (state == ERR_TX_TIMEOUT) { 87 | Serial.println(F("[SX1280] Timed out while transmitting!")); 88 | } else { 89 | Serial.print(F("[SX1280] Failed to transmit packet, code ")); 90 | Serial.println(state); 91 | } 92 | 93 | // receive BLE packet 94 | String str; 95 | state = radio.receive(str); 96 | /* 97 | byte byteArr[8]; 98 | int state = radio.receive(byteArr, 8); 99 | */ 100 | if (state == ERR_NONE) { 101 | Serial.println(F("[SX1280] Received packet!")); 102 | Serial.print(F("[SX1280] Data:\t")); 103 | Serial.println(str); 104 | } else if (state == ERR_RX_TIMEOUT) { 105 | Serial.println(F("[SX1280] Timed out while waiting for packet!")); 106 | } else { 107 | Serial.print(F("[SX1280] Failed to receive packet, code ")); 108 | Serial.println(state); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /examples/SX128x/SX128x_Channel_Activity_Detection/SX128x_Channel_Activity_Detection.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX128x Channel Activity Detection Example 3 | 4 | This example uses SX1280 to scan the current LoRa 5 | channel and detect ongoing LoRa transmissions. 6 | 7 | Other modules from SX128x family can also be used. 8 | 9 | For default module settings, see the wiki page 10 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem 11 | 12 | For full API reference, see the GitHub Pages 13 | https://jgromes.github.io/RadioLib/ 14 | */ 15 | 16 | // include the library 17 | #include 18 | 19 | // SX1280 has the following connections: 20 | // NSS pin: 10 21 | // DIO1 pin: 2 22 | // NRST pin: 3 23 | // BUSY pin: 9 24 | SX1280 radio = new Module(10, 2, 3, 9); 25 | 26 | // or using RadioShield 27 | // https://github.com/jgromes/RadioShield 28 | //SX1280 radio = RadioShield.ModuleA; 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | 33 | // initialize SX1280 with default settings 34 | Serial.print(F("[SX1280] Initializing ... ")); 35 | int state = radio.begin(); 36 | if (state == ERR_NONE) { 37 | Serial.println(F("success!")); 38 | } else { 39 | Serial.print(F("failed, code ")); 40 | Serial.println(state); 41 | while (true); 42 | } 43 | } 44 | 45 | void loop() { 46 | Serial.print(F("[SX1280] Scanning channel for LoRa transmission ... ")); 47 | 48 | // start scanning current channel 49 | int state = radio.scanChannel(); 50 | 51 | if (state == LORA_DETECTED) { 52 | // LoRa preamble was detected 53 | Serial.println(F("detected!")); 54 | 55 | } else if (state == CHANNEL_FREE) { 56 | // no preamble was detected, channel is free 57 | Serial.println(F("channel is free!")); 58 | 59 | } else { 60 | // some other error occurred 61 | Serial.print(F("failed, code ")); 62 | Serial.println(state); 63 | 64 | } 65 | 66 | // wait 100 ms before new scan 67 | delay(100); 68 | } 69 | -------------------------------------------------------------------------------- /examples/SX128x/SX128x_FLRC_Modem/SX128x_FLRC_Modem.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX128x FLRC Modem Example 3 | 4 | This example shows how to use FLRC modem in SX128x chips. 5 | 6 | NOTE: The sketch below is just a guide on how to use 7 | FLRC modem, so this code should not be run directly! 8 | Instead, modify the other examples to use FLRC 9 | modem and use the appropriate configuration 10 | methods. 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---flrc-modem 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // SX1280 has the following connections: 23 | // NSS pin: 10 24 | // DIO1 pin: 2 25 | // NRST pin: 3 26 | // BUSY pin: 9 27 | SX1280 radio = new Module(10, 2, 3, 9); 28 | 29 | // or using RadioShield 30 | // https://github.com/jgromes/RadioShield 31 | //SX1280 radio = RadioShield.ModuleA; 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | 36 | // initialize SX1280 with default settings 37 | Serial.print(F("[SX1280] Initializing ... ")); 38 | int state = radio.beginFLRC(); 39 | if (state == ERR_NONE) { 40 | Serial.println(F("success!")); 41 | } else { 42 | Serial.print(F("failed, code ")); 43 | Serial.println(state); 44 | while (true); 45 | } 46 | 47 | // if needed, you can switch between any of the modems 48 | // 49 | // radio.begin() start LoRa modem (and disable FLRC) 50 | // radio.beginFLRC() start FLRC modem (and disable LoRa) 51 | 52 | // the following settings can also 53 | // be modified at run-time 54 | state = radio.setFrequency(2410.5); 55 | state = radio.setBitRate(520); 56 | state = radio.setCodingRate(2); 57 | state = radio.setOutputPower(5); 58 | state = radio.setDataShaping(1.0); 59 | uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67}; 60 | state = radio.setSyncWord(syncWord, 4); 61 | if (state != ERR_NONE) { 62 | Serial.print(F("Unable to set configuration, code ")); 63 | Serial.println(state); 64 | while (true); 65 | } 66 | 67 | #warning "This sketch is just an API guide! Read the note at line 6." 68 | } 69 | 70 | void loop() { 71 | // FLRC modem can use the same transmit/receive methods 72 | // as the LoRa modem, even their interrupt-driven versions 73 | 74 | // transmit FLRC packet 75 | int state = radio.transmit("Hello World!"); 76 | /* 77 | byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 78 | 0x89, 0xAB, 0xCD, 0xEF}; 79 | int state = radio.transmit(byteArr, 8); 80 | */ 81 | if (state == ERR_NONE) { 82 | Serial.println(F("[SX1280] Packet transmitted successfully!")); 83 | } else if (state == ERR_PACKET_TOO_LONG) { 84 | Serial.println(F("[SX1280] Packet too long!")); 85 | } else if (state == ERR_TX_TIMEOUT) { 86 | Serial.println(F("[SX1280] Timed out while transmitting!")); 87 | } else { 88 | Serial.println(F("[SX1280] Failed to transmit packet, code ")); 89 | Serial.println(state); 90 | } 91 | 92 | // receive FLRC packet 93 | String str; 94 | state = radio.receive(str); 95 | /* 96 | byte byteArr[8]; 97 | int state = radio.receive(byteArr, 8); 98 | */ 99 | if (state == ERR_NONE) { 100 | Serial.println(F("[SX1280] Received packet!")); 101 | Serial.print(F("[SX1280] Data:\t")); 102 | Serial.println(str); 103 | } else if (state == ERR_RX_TIMEOUT) { 104 | Serial.println(F("[SX1280] Timed out while waiting for packet!")); 105 | } else { 106 | Serial.print(F("[SX1280] Failed to receive packet, code ")); 107 | Serial.println(state); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /examples/SX128x/SX128x_GFSK_Modem/SX128x_GFSK_Modem.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX128x GFSK Modem Example 3 | 4 | This example shows how to use GFSK modem in SX128x chips. 5 | 6 | NOTE: The sketch below is just a guide on how to use 7 | GFSK modem, so this code should not be run directly! 8 | Instead, modify the other examples to use GFSK 9 | modem and use the appropriate configuration 10 | methods. 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---gfsk-modem 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // SX1280 has the following connections: 23 | // NSS pin: 10 24 | // DIO1 pin: 2 25 | // NRST pin: 3 26 | // BUSY pin: 9 27 | SX1280 radio = new Module(10, 2, 3, 9); 28 | 29 | // or using RadioShield 30 | // https://github.com/jgromes/RadioShield 31 | //SX1280 radio = RadioShield.ModuleA; 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | 36 | // initialize SX1280 with default settings 37 | Serial.print(F("[SX1280] Initializing ... ")); 38 | int state = radio.beginGFSK(); 39 | if (state == ERR_NONE) { 40 | Serial.println(F("success!")); 41 | } else { 42 | Serial.print(F("failed, code ")); 43 | Serial.println(state); 44 | while (true); 45 | } 46 | 47 | // if needed, you can switch between any of the modems 48 | // 49 | // radio.begin() start LoRa modem (and disable GFSK) 50 | // radio.beginGFSK() start GFSK modem (and disable LoRa) 51 | 52 | // the following settings can also 53 | // be modified at run-time 54 | state = radio.setFrequency(2410.5); 55 | state = radio.setBitRate(200); 56 | state = radio.setFrequencyDeviation(100.0); 57 | state = radio.setOutputPower(5); 58 | state = radio.setDataShaping(RADIOLIB_SHAPING_1_0); 59 | uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89}; 60 | state = radio.setSyncWord(syncWord, 5); 61 | if (state != ERR_NONE) { 62 | Serial.print(F("Unable to set configuration, code ")); 63 | Serial.println(state); 64 | while (true); 65 | } 66 | 67 | #warning "This sketch is just an API guide! Read the note at line 6." 68 | } 69 | 70 | void loop() { 71 | // GFSK modem can use the same transmit/receive methods 72 | // as the LoRa modem, even their interrupt-driven versions 73 | 74 | // transmit GFSK packet 75 | int state = radio.transmit("Hello World!"); 76 | /* 77 | byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 78 | 0x89, 0xAB, 0xCD, 0xEF}; 79 | int state = radio.transmit(byteArr, 8); 80 | */ 81 | if (state == ERR_NONE) { 82 | Serial.println(F("[SX1280] Packet transmitted successfully!")); 83 | } else if (state == ERR_PACKET_TOO_LONG) { 84 | Serial.println(F("[SX1280] Packet too long!")); 85 | } else if (state == ERR_TX_TIMEOUT) { 86 | Serial.println(F("[SX1280] Timed out while transmitting!")); 87 | } else { 88 | Serial.println(F("[SX1280] Failed to transmit packet, code ")); 89 | Serial.println(state); 90 | } 91 | 92 | // receive GFSK packet 93 | String str; 94 | state = radio.receive(str); 95 | /* 96 | byte byteArr[8]; 97 | int state = radio.receive(byteArr, 8); 98 | */ 99 | if (state == ERR_NONE) { 100 | Serial.println(F("[SX1280] Received packet!")); 101 | Serial.print(F("[SX1280] Data:\t")); 102 | Serial.println(str); 103 | } else if (state == ERR_RX_TIMEOUT) { 104 | Serial.println(F("[SX1280] Timed out while waiting for packet!")); 105 | } else { 106 | Serial.print(F("[SX1280] Failed to receive packet, code ")); 107 | Serial.println(state); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /examples/SX128x/SX128x_Ranging/SX128x_Ranging.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX128x Ranging Example 3 | 4 | This example performs ranging exchange between two 5 | SX1280 LoRa radio modules. Ranging allows to measure 6 | distance between the modules using time-of-flight 7 | measurement. 8 | 9 | Only SX1280 and SX1282 support ranging! 10 | 11 | For default module settings, see the wiki page 12 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem 13 | 14 | For full API reference, see the GitHub Pages 15 | https://jgromes.github.io/RadioLib/ 16 | */ 17 | 18 | // include the library 19 | #include 20 | 21 | // SX1280 has the following connections: 22 | // NSS pin: 10 23 | // DIO1 pin: 2 24 | // NRST pin: 3 25 | // BUSY pin: 9 26 | SX1280 radio = new Module(10, 2, 3, 9); 27 | 28 | // or using RadioShield 29 | // https://github.com/jgromes/RadioShield 30 | //SX1280 radio = RadioShield.ModuleA; 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | 35 | // initialize SX1280 with default settings 36 | Serial.print(F("[SX1280] Initializing ... ")); 37 | int state = radio.begin(); 38 | if (state == ERR_NONE) { 39 | Serial.println(F("success!")); 40 | } else { 41 | Serial.print(F("failed, code ")); 42 | Serial.println(state); 43 | while (true); 44 | } 45 | } 46 | 47 | void loop() { 48 | Serial.print(F("[SX1280] Ranging ... ")); 49 | 50 | // start ranging exchange 51 | // range as master: true 52 | // slave address: 0x12345678 53 | int state = radio.range(true, 0x12345678); 54 | 55 | // the other module must be configured as slave with the same address 56 | /* 57 | int state = radio.range(false, 0x12345678); 58 | */ 59 | 60 | if (state == ERR_NONE) { 61 | // ranging finished successfully 62 | Serial.println(F("success!")); 63 | Serial.print(F("[SX1280] Distance:\t\t\t")); 64 | Serial.print(radio.getRangingResult()); 65 | Serial.println(F(" meters")); 66 | 67 | } else if (state == ERR_RANGING_TIMEOUT) { 68 | // timed out waiting for ranging packet 69 | Serial.println(F("timed out!")); 70 | 71 | } else { 72 | // some other error occurred 73 | Serial.print(F("failed, code ")); 74 | Serial.println(state); 75 | 76 | } 77 | 78 | // wait for a second before ranging again 79 | delay(1000); 80 | } 81 | -------------------------------------------------------------------------------- /examples/SX128x/SX128x_Receive/SX128x_Receive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX128x Receive Example 3 | 4 | This example listens for LoRa transmissions using SX126x Lora modules. 5 | To successfully receive data, the following settings have to be the same 6 | on both transmitter and receiver: 7 | - carrier frequency 8 | - bandwidth 9 | - spreading factor 10 | - coding rate 11 | - sync word 12 | - preamble length 13 | 14 | Other modules from SX128x family can also be used. 15 | 16 | For default module settings, see the wiki page 17 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem 18 | 19 | For full API reference, see the GitHub Pages 20 | https://jgromes.github.io/RadioLib/ 21 | */ 22 | 23 | // include the library 24 | #include 25 | 26 | // SX1280 has the following connections: 27 | // NSS pin: 10 28 | // DIO1 pin: 2 29 | // NRST pin: 3 30 | // BUSY pin: 9 31 | SX1280 radio = new Module(10, 2, 3, 9); 32 | 33 | // or using RadioShield 34 | // https://github.com/jgromes/RadioShield 35 | //SX1280 radio = RadioShield.ModuleA; 36 | 37 | void setup() { 38 | Serial.begin(9600); 39 | 40 | // initialize SX1280 with default settings 41 | Serial.print(F("[SX1280] Initializing ... ")); 42 | int state = radio.begin(); 43 | if (state == ERR_NONE) { 44 | Serial.println(F("success!")); 45 | } else { 46 | Serial.print(F("failed, code ")); 47 | Serial.println(state); 48 | while (true); 49 | } 50 | } 51 | 52 | void loop() { 53 | Serial.print(F("[SX1280] Waiting for incoming transmission ... ")); 54 | 55 | // you can receive data as an Arduino String 56 | // NOTE: receive() is a blocking method! 57 | // See example ReceiveInterrupt for details 58 | // on non-blocking reception method. 59 | String str; 60 | int state = radio.receive(str); 61 | 62 | // you can also receive data as byte array 63 | /* 64 | byte byteArr[8]; 65 | int state = radio.receive(byteArr, 8); 66 | */ 67 | 68 | if (state == ERR_NONE) { 69 | // packet was successfully received 70 | Serial.println(F("success!")); 71 | 72 | // print the data of the packet 73 | Serial.print(F("[SX1280] Data:\t\t")); 74 | Serial.println(str); 75 | 76 | // print the RSSI (Received Signal Strength Indicator) 77 | // of the last received packet 78 | Serial.print(F("[SX1280] RSSI:\t\t")); 79 | Serial.print(radio.getRSSI()); 80 | Serial.println(F(" dBm")); 81 | 82 | // print the SNR (Signal-to-Noise Ratio) 83 | // of the last received packet 84 | Serial.print(F("[SX1280] SNR:\t\t")); 85 | Serial.print(radio.getSNR()); 86 | Serial.println(F(" dB")); 87 | 88 | } else if (state == ERR_RX_TIMEOUT) { 89 | // timeout occurred while waiting for a packet 90 | Serial.println(F("timeout!")); 91 | 92 | } else if (state == ERR_CRC_MISMATCH) { 93 | // packet was received, but is malformed 94 | Serial.println(F("CRC error!")); 95 | 96 | } else { 97 | // some other error occurred 98 | Serial.print(F("failed, code ")); 99 | Serial.println(state); 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /examples/SX128x/SX128x_Transmit/SX128x_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib SX128x Transmit Example 3 | 4 | This example transmits packets using SX1280 LoRa radio module. 5 | Each packet contains up to 256 bytes of data, in the form of: 6 | - Arduino String 7 | - null-terminated char array (C-string) 8 | - arbitrary binary data (byte array) 9 | 10 | Other modules from SX128x family can also be used. 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // SX1280 has the following connections: 23 | // NSS pin: 10 24 | // DIO1 pin: 2 25 | // NRST pin: 3 26 | // BUSY pin: 9 27 | SX1280 radio = new Module(10, 2, 3, 9); 28 | 29 | // or using RadioShield 30 | // https://github.com/jgromes/RadioShield 31 | //SX1280 radio = RadioShield.ModuleA; 32 | 33 | void setup() { 34 | Serial.begin(9600); 35 | 36 | // initialize SX1280 with default settings 37 | Serial.print(F("[SX1280] Initializing ... ")); 38 | // carrier frequency: 2400.0 MHz 39 | // bandwidth: 812.5 kHz 40 | // spreading factor: 9 41 | // coding rate: 7 42 | // output power: 10 dBm 43 | // preamble length: 12 symbols 44 | // CRC: enabled 45 | int state = radio.begin(); 46 | if (state == ERR_NONE) { 47 | Serial.println(F("success!")); 48 | } else { 49 | Serial.print(F("failed, code ")); 50 | Serial.println(state); 51 | while (true); 52 | } 53 | 54 | // some modules have an external RF switch 55 | // controlled via two pins (RX enable, TX enable) 56 | // to enable automatic control of the switch, 57 | // call the following method 58 | // RX enable: 4 59 | // TX enable: 5 60 | /* 61 | radio.setRfSwitchPins(4, 5); 62 | */ 63 | } 64 | 65 | void loop() { 66 | Serial.print(F("[SX1280] Transmitting packet ... ")); 67 | 68 | // you can transmit C-string or Arduino string up to 69 | // 256 characters long 70 | // NOTE: transmit() is a blocking method! 71 | // See example SX128x_Transmit_Interrupt for details 72 | // on non-blocking transmission method. 73 | int state = radio.transmit("Hello World!"); 74 | 75 | // you can also transmit byte array up to 256 bytes long 76 | /* 77 | byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; 78 | int state = radio.transmit(byteArr, 8); 79 | */ 80 | 81 | if (state == ERR_NONE) { 82 | // the packet was successfully transmitted 83 | Serial.println(F("success!")); 84 | 85 | } else if (state == ERR_PACKET_TOO_LONG) { 86 | // the supplied packet was longer than 256 bytes 87 | Serial.println(F("too long!")); 88 | 89 | } else { 90 | // some other error occurred 91 | Serial.print(F("failed, code ")); 92 | Serial.println(state); 93 | 94 | } 95 | 96 | // wait for a second before transmitting again 97 | delay(1000); 98 | } 99 | -------------------------------------------------------------------------------- /examples/Si443x/Si443x_Receive/Si443x_Receive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib Si443x Receive Example 3 | 4 | This example receives packets using Si443x FSK radio module. 5 | To successfully receive data, the following settings have to be the same 6 | on both transmitter and receiver: 7 | - carrier frequency 8 | - bit rate 9 | - frequency deviation 10 | - sync word 11 | 12 | Other modules from Si443x/RFM2x family can also be used. 13 | 14 | For default module settings, see the wiki page 15 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x 16 | 17 | For full API reference, see the GitHub Pages 18 | https://jgromes.github.io/RadioLib/ 19 | */ 20 | 21 | // include the library 22 | #include 23 | 24 | // Si4432 has the following connections: 25 | // nSEL pin: 10 26 | // nIRQ pin: 2 27 | // SDN pin: 9 28 | Si4432 radio = new Module(10, 2, 9); 29 | 30 | // or using RadioShield 31 | // https://github.com/jgromes/RadioShield 32 | //Si4432 radio = RadioShield.ModuleA; 33 | 34 | void setup() { 35 | Serial.begin(9600); 36 | 37 | // initialize Si4432 with default settings 38 | Serial.print(F("[Si4432] Initializing ... ")); 39 | int state = radio.begin(); 40 | if (state == ERR_NONE) { 41 | Serial.println(F("success!")); 42 | } else { 43 | Serial.print(F("failed, code ")); 44 | Serial.println(state); 45 | while (true); 46 | } 47 | } 48 | 49 | void loop() { 50 | Serial.print(F("[Si4432] Waiting for incoming transmission ... ")); 51 | 52 | // you can receive data as an Arduino String 53 | String str; 54 | int state = radio.receive(str); 55 | 56 | // you can also receive data as byte array 57 | /* 58 | byte byteArr[8]; 59 | int state = radio.receive(byteArr, 8); 60 | */ 61 | 62 | if (state == ERR_NONE) { 63 | // packet was successfully received 64 | Serial.println(F("success!")); 65 | 66 | // print the data of the packet 67 | Serial.print(F("[Si4432] Data:\t\t")); 68 | Serial.println(str); 69 | 70 | } else if (state == ERR_RX_TIMEOUT) { 71 | // timeout occurred while waiting for a packet 72 | Serial.println(F("timeout!")); 73 | 74 | } else if (state == ERR_CRC_MISMATCH) { 75 | // packet was received, but is malformed 76 | Serial.println(F("CRC error!")); 77 | 78 | } else { 79 | // some other error occurred 80 | Serial.print(F("failed, code ")); 81 | Serial.println(state); 82 | 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /examples/Si443x/Si443x_Transmit/Si443x_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib Si443x Transmit Example 3 | 4 | This example transmits packets using Si4432 FSK radio module. 5 | Each packet contains up to 64 bytes of data, in the form of: 6 | - Arduino String 7 | - null-terminated char array (C-string) 8 | - arbitrary binary data (byte array) 9 | 10 | Other modules from Si443x/RFM2x family can also be used. 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // Si4432 has the following connections: 23 | // nSEL pin: 10 24 | // nIRQ pin: 2 25 | // SDN pin: 9 26 | Si4432 radio = new Module(10, 2, 9); 27 | 28 | // or using RadioShield 29 | // https://github.com/jgromes/RadioShield 30 | //Si4432 radio = RadioShield.ModuleA; 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | 35 | // initialize Si4432 with default settings 36 | Serial.print(F("[Si4432] Initializing ... ")); 37 | int state = radio.begin(); 38 | if (state == ERR_NONE) { 39 | Serial.println(F("success!")); 40 | } else { 41 | Serial.print(F("failed, code ")); 42 | Serial.println(state); 43 | while (true); 44 | } 45 | } 46 | 47 | void loop() { 48 | Serial.print(F("[Si4432] Transmitting packet ... ")); 49 | 50 | // you can transmit C-string or Arduino string up to 51 | // 64 characters long 52 | // NOTE: transmit() is a blocking method! 53 | // See example Si443x_Transmit_Interrupt for details 54 | // on non-blocking transmission method. 55 | int state = radio.transmit("Hello World!"); 56 | 57 | // you can also transmit byte array up to 64 bytes long 58 | /* 59 | byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; 60 | int state = radio.transmit(byteArr, 8); 61 | */ 62 | 63 | if (state == ERR_NONE) { 64 | // the packet was successfully transmitted 65 | Serial.println(F(" success!")); 66 | 67 | } else if (state == ERR_PACKET_TOO_LONG) { 68 | // the supplied packet was longer than 256 bytes 69 | Serial.println(F(" too long!")); 70 | 71 | } else if (state == ERR_TX_TIMEOUT) { 72 | // timeout occured while transmitting packet 73 | Serial.println(F(" timeout!")); 74 | 75 | } else { 76 | // some other error occurred 77 | Serial.print(F("failed, code ")); 78 | Serial.println(state); 79 | 80 | } 81 | 82 | // wait for a second before transmitting again 83 | delay(1000); 84 | } 85 | -------------------------------------------------------------------------------- /examples/XBee/XBee_Receive/XBee_Receive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib XBee API Receive Example 3 | 4 | This example receives packets using XBee API mode. 5 | In API mode, many XBee modules can form a mesh network. 6 | 7 | IMPORTANT: Before uploading this example, make sure that the XBee module 8 | is running API ROUTER/ENDPOINT firmware! 9 | 10 | For full API reference, see the GitHub Pages 11 | https://jgromes.github.io/RadioLib/ 12 | */ 13 | 14 | // include the library 15 | #include 16 | 17 | // XBee has the following connections: 18 | // TX pin: 9 19 | // RX pin: 8 20 | // RESET pin: 3 21 | XBee bee = new SerialModule(9, 8, 3); 22 | 23 | // or using RadioShield 24 | // https://github.com/jgromes/RadioShield 25 | //XBee bee = RadioShield.ModuleA; 26 | 27 | void setup() { 28 | Serial.begin(9600); 29 | 30 | // initialize XBee module with baudrate 9600 31 | Serial.print(F("[XBee] Initializing ... ")); 32 | int state = bee.begin(9600); 33 | if (state == ERR_NONE) { 34 | Serial.println(F("success!")); 35 | } else { 36 | Serial.print(F("failed, code ")); 37 | Serial.println(state); 38 | while (true); 39 | } 40 | 41 | // set PAN ID to 0x0123456789ABCDEF 42 | Serial.print(F("[XBee] Setting PAN ID ... ")); 43 | uint8_t panId[] = {0x01, 0x23, 0x45, 0x67, 44 | 0x89, 0xAB, 0xCD, 0xEF}; 45 | state = bee.setPanId(panId); 46 | if (state == ERR_NONE) { 47 | Serial.println(F("success!")); 48 | } else { 49 | Serial.print(F("failed, code ")); 50 | Serial.println(state); 51 | while (true); 52 | } 53 | } 54 | 55 | void loop() { 56 | // check if XBee received some data 57 | if (bee.available() > 0) { 58 | // print source address 59 | Serial.print(F("[XBee] Packet source:\t")); 60 | Serial.println(bee.getPacketSource()); 61 | 62 | // print data 63 | Serial.print(F("[XBee] Packet data:\t")); 64 | Serial.println(bee.getPacketData()); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /examples/XBee/XBee_Transmit/XBee_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib XBee API Transmit Example 3 | 4 | This example transmits packets using XBee API mode. 5 | In API mode, many XBee modules can form a mesh network. 6 | 7 | IMPORTANT: Before uploading this example, make sure that the XBee module 8 | is running API COORDINATOR firmware! 9 | 10 | For full API reference, see the GitHub Pages 11 | https://jgromes.github.io/RadioLib/ 12 | */ 13 | 14 | // include the library 15 | #include 16 | 17 | // XBee has the following connections: 18 | // TX pin: 9 19 | // RX pin: 8 20 | // RESET pin: 3 21 | XBee bee = new SerialModule(9, 8, 3); 22 | 23 | // or using RadioShield 24 | // https://github.com/jgromes/RadioShield 25 | //XBee bee = RadioShield.ModuleA; 26 | 27 | void setup() { 28 | Serial.begin(9600); 29 | 30 | // initialize XBee module with baudrate 9600 31 | Serial.print(F("[XBee] Initializing ... ")); 32 | int state = bee.begin(9600); 33 | if (state == ERR_NONE) { 34 | Serial.println(F("success!")); 35 | } else { 36 | Serial.print(F("failed, code ")); 37 | Serial.println(state); 38 | while (true); 39 | } 40 | 41 | // set PAN ID to 0x0123456789ABCDEF 42 | Serial.print(F("[XBee] Setting PAN ID ... ")); 43 | uint8_t panId[] = {0x01, 0x23, 0x45, 0x67, 44 | 0x89, 0xAB, 0xCD, 0xEF}; 45 | state = bee.setPanId(panId); 46 | if (state == ERR_NONE) { 47 | Serial.println(F("success!")); 48 | } else { 49 | Serial.print(F("failed, code ")); 50 | Serial.println(state); 51 | while (true); 52 | } 53 | } 54 | 55 | void loop() { 56 | // transmit data to the destination module 57 | uint8_t dest[] = {0x00, 0x13, 0xA2, 0x00, 58 | 0x40, 0xA5, 0x8A, 0x6B}; 59 | Serial.print(F("[XBee] Transmitting message ... ")); 60 | int state = bee.transmit(dest, "Hello World!"); 61 | if (state == ERR_NONE) { 62 | Serial.println(F("success!")); 63 | } else { 64 | Serial.print(F("failed, code ")); 65 | Serial.println(state); 66 | } 67 | 68 | delay(1000); 69 | } 70 | -------------------------------------------------------------------------------- /examples/XBee/XBee_Transparent/XBee_Transparent.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib XBee Transparent Operation Example 3 | 4 | This example transmits packets using XBee Transparent mode. 5 | In Transparent mode, two XBee modules act like a Serial line. 6 | Both modules must have the same PAN ID, and the destination 7 | addresses have to be set properly. 8 | 9 | IMPORTANT: Before uploading this example, make sure that the XBee modules 10 | are running AT COORDINATOR and AT ROUTER firmware! 11 | 12 | For full API reference, see the GitHub Pages 13 | https://jgromes.github.io/RadioLib/ 14 | */ 15 | 16 | // include the library 17 | #include 18 | 19 | // XBee has the following connections: 20 | // TX pin: 9 21 | // RX pin: 8 22 | // RESET pin: 3 23 | XBeeSerial bee = new SerialModule(9, 8, 3); 24 | 25 | // or using RadioShield 26 | // https://github.com/jgromes/RadioShield 27 | //XBeeSerial bee = RadioShield.ModuleA; 28 | 29 | void setup() { 30 | Serial.begin(9600); 31 | 32 | // initialize XBee module with baudrate 9600 33 | Serial.print(F("[XBee] Initializing ... ")); 34 | int state = bee.begin(9600); 35 | if (state == ERR_NONE) { 36 | Serial.println(F("success!")); 37 | } else { 38 | Serial.print(F("failed, code ")); 39 | Serial.println(state); 40 | while (true); 41 | } 42 | 43 | // set PAN ID to 0123456789ABCDEF 44 | Serial.print(F("[XBee] Setting PAN ID ... ")); 45 | state = bee.setPanId("0123456789ABCDEF"); 46 | if (state == ERR_NONE) { 47 | Serial.println(F("success!")); 48 | } else { 49 | Serial.print(F("failed, code ")); 50 | Serial.println(state); 51 | while (true); 52 | } 53 | 54 | // set destination address to the address of the second module 55 | Serial.print(F("[XBee] Setting destination address ... ")); 56 | state = bee.setDestinationAddress("0013A200", "40A58A5D"); 57 | if (state == ERR_NONE) { 58 | Serial.println(F("success!")); 59 | } else { 60 | Serial.print(F("failed, code ")); 61 | Serial.println(state); 62 | while (true); 63 | } 64 | } 65 | 66 | void loop() { 67 | // XBeeSerial supports all methods of the Serial class 68 | // read data incoming from Serial port and write them to XBee 69 | while (Serial.available() > 0) { 70 | bee.write(Serial.read()); 71 | } 72 | 73 | // read data incoming from XBee and write them to Serial port 74 | while (bee.available() > 0) { 75 | Serial.write(bee.read()); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /examples/nRF24/nRF24_Receive/nRF24_Receive.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib nRF24 Receive Example 3 | 4 | This example listens for FSK transmissions using nRF24 2.4 GHz radio module. 5 | To successfully receive data, the following settings have to be the same 6 | on both transmitter and receiver: 7 | - carrier frequency 8 | - data rate 9 | - transmit pipe on transmitter must match receive pipe 10 | on receiver 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // nRF24 has the following connections: 23 | // CS pin: 10 24 | // IRQ pin: 2 25 | // CE pin: 3 26 | nRF24 radio = new Module(10, 2, 3); 27 | 28 | // or using RadioShield 29 | // https://github.com/jgromes/RadioShield 30 | //nRF24 radio = RadioShield.ModuleA; 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | 35 | // initialize nRF24 with default settings 36 | Serial.print(F("[nRF24] Initializing ... ")); 37 | int state = radio.begin(); 38 | if(state == ERR_NONE) { 39 | Serial.println(F("success!")); 40 | } else { 41 | Serial.print(F("failed, code ")); 42 | Serial.println(state); 43 | while(true); 44 | } 45 | 46 | // set receive pipe 0 address 47 | // NOTE: address width in bytes MUST be equal to the 48 | // width set in begin() or setAddressWidth() 49 | // methods (5 by default) 50 | Serial.print(F("[nRF24] Setting address for receive pipe 0 ... ")); 51 | byte addr[] = {0x01, 0x23, 0x45, 0x67, 0x89}; 52 | state = radio.setReceivePipe(0, addr); 53 | if(state == ERR_NONE) { 54 | Serial.println(F("success!")); 55 | } else { 56 | Serial.print(F("failed, code ")); 57 | Serial.println(state); 58 | while(true); 59 | } 60 | } 61 | 62 | void loop() { 63 | Serial.print(F("[nRF24] Waiting for incoming transmission ... ")); 64 | 65 | // you can receive data as an Arduino String 66 | // NOTE: receive() is a blocking method! 67 | // See example ReceiveInterrupt for details 68 | // on non-blocking reception method. 69 | String str; 70 | int state = radio.receive(str); 71 | 72 | // you can also receive data as byte array 73 | /* 74 | byte byteArr[8]; 75 | int state = radio.receive(byteArr, 8); 76 | */ 77 | 78 | if (state == ERR_NONE) { 79 | // packet was successfully received 80 | Serial.println(F("success!")); 81 | 82 | // print the data of the packet 83 | Serial.print(F("[nRF24] Data:\t\t")); 84 | Serial.println(str); 85 | 86 | } else if (state == ERR_RX_TIMEOUT) { 87 | // timeout occurred while waiting for a packet 88 | Serial.println(F("timeout!")); 89 | 90 | } else { 91 | // some other error occurred 92 | Serial.print(F("failed, code ")); 93 | Serial.println(state); 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /examples/nRF24/nRF24_Transmit/nRF24_Transmit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RadioLib nRF24 Transmit Example 3 | 4 | This example transmits packets using nRF24 2.4 GHz radio module. 5 | Each packet contains up to 32 bytes of data, in the form of: 6 | - Arduino String 7 | - null-terminated char array (C-string) 8 | - arbitrary binary data (byte array) 9 | 10 | Packet delivery is automatically acknowledged by the receiver. 11 | 12 | For default module settings, see the wiki page 13 | https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24 14 | 15 | For full API reference, see the GitHub Pages 16 | https://jgromes.github.io/RadioLib/ 17 | */ 18 | 19 | // include the library 20 | #include 21 | 22 | // nRF24 has the following connections: 23 | // CS pin: 10 24 | // IRQ pin: 2 25 | // CE pin: 3 26 | nRF24 radio = new Module(10, 2, 3); 27 | 28 | // or using RadioShield 29 | // https://github.com/jgromes/RadioShield 30 | //nRF24 radio = RadioShield.ModuleA; 31 | 32 | void setup() { 33 | Serial.begin(9600); 34 | 35 | // initialize nRF24 with default settings 36 | Serial.print(F("[nRF24] Initializing ... ")); 37 | int state = radio.begin(); 38 | if(state == ERR_NONE) { 39 | Serial.println(F("success!")); 40 | } else { 41 | Serial.print(F("failed, code ")); 42 | Serial.println(state); 43 | while(true); 44 | } 45 | 46 | // set transmit address 47 | // NOTE: address width in bytes MUST be equal to the 48 | // width set in begin() or setAddressWidth() 49 | // methods (5 by default) 50 | byte addr[] = {0x01, 0x23, 0x45, 0x67, 0x89}; 51 | Serial.print(F("[nRF24] Setting transmit pipe ... ")); 52 | state = radio.setTransmitPipe(addr); 53 | if(state == ERR_NONE) { 54 | Serial.println(F("success!")); 55 | } else { 56 | Serial.print(F("failed, code ")); 57 | Serial.println(state); 58 | while(true); 59 | } 60 | } 61 | 62 | void loop() { 63 | Serial.print(F("[nRF24] Transmitting packet ... ")); 64 | 65 | // you can transmit C-string or Arduino string up to 66 | // 32 characters long 67 | int state = radio.transmit("Hello World!"); 68 | 69 | if (state == ERR_NONE) { 70 | // the packet was successfully transmitted 71 | Serial.println(F("success!")); 72 | 73 | } else if (state == ERR_PACKET_TOO_LONG) { 74 | // the supplied packet was longer than 32 bytes 75 | Serial.println(F("too long!")); 76 | 77 | } else if (state == ERR_ACK_NOT_RECEIVED) { 78 | // acknowledge from destination module 79 | // was not received within 15 retries 80 | Serial.println(F("ACK not received!")); 81 | 82 | } else if (state == ERR_TX_TIMEOUT) { 83 | // timed out while transmitting 84 | Serial.println(F("timeout!")); 85 | 86 | } else { 87 | // some other error occurred 88 | Serial.print(F("failed, code ")); 89 | Serial.println(state); 90 | 91 | } 92 | 93 | // wait for a second before transmitting again 94 | delay(1000); 95 | } 96 | -------------------------------------------------------------------------------- /extras/bin/AiThinker_ESP8266_DIO_32M_32M_20160615_V1.5.4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meshtastic/RadioLib/23002909f79f836cee68bcd582031f321da1df05/extras/bin/AiThinker_ESP8266_DIO_32M_32M_20160615_V1.5.4.bin -------------------------------------------------------------------------------- /extras/bin/AiThinker_ESP8266_DIO_8M_8M_20160615_V1.5.4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/meshtastic/RadioLib/23002909f79f836cee68bcd582031f321da1df05/extras/bin/AiThinker_ESP8266_DIO_8M_8M_20160615_V1.5.4.bin -------------------------------------------------------------------------------- /extras/template/ModuleTemplate.cpp: -------------------------------------------------------------------------------- 1 | #include ".h" 2 | #if !defined(RADIOLIB_EXCLUDE_) 3 | 4 | ::(Module* mod) { 5 | /* 6 | Constructor implementation MUST assign the provided "mod" pointer to the private "_mod" pointer. 7 | */ 8 | _mod = mod; 9 | } 10 | 11 | int16_t ::begin() { 12 | /* 13 | "begin" method implementation MUST call the "init" method with appropriate settings. 14 | */ 15 | _mod->init(); 16 | 17 | /* 18 | "begin" method SHOULD implement some sort of mechanism to verify the connection between Arduino and the module. 19 | 20 | For example, sending AT command for UART modules, or reading a version register for SPI/I2C modules 21 | */ 22 | } 23 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=RadioLib 2 | version=4.5.0 3 | author=Jan Gromes 4 | maintainer=Jan Gromes 5 | sentence=Universal wireless communication library for Arduino 6 | paragraph=Enables user-friendly control of the RadioShield and various wireless modules. 7 | category=Communication 8 | url=https://github.com/jgromes/RadioLib 9 | architectures=* 10 | includes=RadioLib.h 11 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Jan Gromeš 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/ISerial.cpp: -------------------------------------------------------------------------------- 1 | #include "ISerial.h" 2 | 3 | ISerial::ISerial(Module* mod) { 4 | _mod = mod; 5 | } 6 | 7 | void ISerial::begin(long speed) { 8 | _mod->ModuleSerial->begin(speed); 9 | } 10 | 11 | void ISerial::end() { 12 | _mod->ModuleSerial->end(); 13 | } 14 | 15 | 16 | int ISerial::peek() { 17 | return(_mod->ModuleSerial->peek()); 18 | } 19 | 20 | size_t ISerial::write(uint8_t b) { 21 | return(_mod->ModuleSerial->write(b)); 22 | } 23 | 24 | int ISerial::read() { 25 | return(_mod->ModuleSerial->read()); 26 | } 27 | 28 | int ISerial::available() { 29 | return(_mod->ModuleSerial->available()); 30 | } 31 | 32 | void ISerial::flush() { 33 | _mod->ModuleSerial->flush(); 34 | } 35 | 36 | #ifndef ARDUINO_ARCH_MEGAAVR 37 | size_t ISerial::print(const __FlashStringHelper *ifsh) { 38 | return(_mod->ModuleSerial->print(ifsh)); 39 | } 40 | #endif 41 | 42 | size_t ISerial::print(const String &s) { 43 | return(_mod->ModuleSerial->print(s)); 44 | } 45 | 46 | size_t ISerial::print(const char str[]) { 47 | return(_mod->ModuleSerial->print(str)); 48 | } 49 | 50 | size_t ISerial::print(char c) { 51 | return(_mod->ModuleSerial->print(c)); 52 | } 53 | 54 | size_t ISerial::print(unsigned char b, int base) { 55 | return(_mod->ModuleSerial->print(b, base)); 56 | } 57 | 58 | size_t ISerial::print(int n, int base) { 59 | return(_mod->ModuleSerial->print(n, base)); 60 | } 61 | 62 | size_t ISerial::print(unsigned int n, int base) { 63 | return(_mod->ModuleSerial->print(n, base)); 64 | } 65 | 66 | size_t ISerial::print(long n, int base) { 67 | return(_mod->ModuleSerial->print(n, base)); 68 | } 69 | 70 | size_t ISerial::print(unsigned long n, int base) { 71 | return(_mod->ModuleSerial->print(n, base)); 72 | } 73 | 74 | size_t ISerial::print(double n, int digits) { 75 | return(_mod->ModuleSerial->print(n, digits)); 76 | } 77 | 78 | size_t ISerial::print(const Printable& x) { 79 | return(_mod->ModuleSerial->print(x)); 80 | } 81 | 82 | #ifndef ARDUINO_ARCH_MEGAAVR 83 | size_t ISerial::println(const __FlashStringHelper *ifsh) { 84 | return(_mod->ModuleSerial->println(ifsh)); 85 | } 86 | #endif 87 | 88 | size_t ISerial::println(const String &s) { 89 | return(_mod->ModuleSerial->println(s)); 90 | } 91 | 92 | size_t ISerial::println(const char str[]) { 93 | return(_mod->ModuleSerial->println(str)); 94 | } 95 | 96 | size_t ISerial::println(char c) { 97 | return(_mod->ModuleSerial->println(c)); 98 | } 99 | 100 | size_t ISerial::println(unsigned char b, int base) { 101 | return(_mod->ModuleSerial->println(b, base)); 102 | } 103 | 104 | size_t ISerial::println(int n, int base) { 105 | return(_mod->ModuleSerial->println(n, base)); 106 | } 107 | 108 | size_t ISerial::println(unsigned int n, int base) { 109 | return(_mod->ModuleSerial->println(n, base)); 110 | } 111 | 112 | size_t ISerial::println(long n, int base) { 113 | return(_mod->ModuleSerial->println(n, base)); 114 | } 115 | 116 | size_t ISerial::println(unsigned long n, int base) { 117 | return(_mod->ModuleSerial->println(n, base)); 118 | } 119 | 120 | size_t ISerial::println(double n, int digits) { 121 | return(_mod->ModuleSerial->println(n, digits)); 122 | } 123 | 124 | size_t ISerial::println(const Printable& x) { 125 | return(_mod->ModuleSerial->println(x)); 126 | } 127 | 128 | size_t ISerial::println(void) { 129 | return(_mod->ModuleSerial->println()); 130 | } 131 | -------------------------------------------------------------------------------- /src/ISerial.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_ISERIAL_H) 2 | #define _RADIOLIB_ISERIAL_H 3 | 4 | #include "Module.h" 5 | 6 | /*! 7 | \class ISerial 8 | 9 | \brief Interface class for Arduino Serial. Only calls the appropriate methods for the active UART interface. 10 | */ 11 | class ISerial { 12 | public: 13 | explicit ISerial(Module* mod); 14 | 15 | void begin(long); 16 | void end(); 17 | int peek(); 18 | size_t write(uint8_t); 19 | int read(); 20 | int available(); 21 | void flush(); 22 | 23 | #if !defined(ARDUINO_ARCH_MEGAAVR) 24 | size_t print(const __FlashStringHelper *); 25 | #endif 26 | size_t print(const String &); 27 | size_t print(const char[]); 28 | size_t print(char); 29 | size_t print(unsigned char, int = DEC); 30 | size_t print(int, int = DEC); 31 | size_t print(unsigned int, int = DEC); 32 | size_t print(long, int = DEC); 33 | size_t print(unsigned long, int = DEC); 34 | size_t print(double, int = 2); 35 | size_t print(const Printable&); 36 | 37 | #if !defined(ARDUINO_ARCH_MEGAAVR) 38 | size_t println(const __FlashStringHelper *); 39 | #endif 40 | size_t println(const String &s); 41 | size_t println(const char[]); 42 | size_t println(char); 43 | size_t println(unsigned char, int = DEC); 44 | size_t println(int, int = DEC); 45 | size_t println(unsigned int, int = DEC); 46 | size_t println(long, int = DEC); 47 | size_t println(unsigned long, int = DEC); 48 | size_t println(double, int = 2); 49 | size_t println(const Printable&); 50 | size_t println(void); 51 | 52 | #if !(defined(RADIOLIB_LOW_LEVEL) || defined(RADIOLIB_GODMODE)) 53 | protected: 54 | #endif 55 | Module* _mod; 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/modules/ESP8266/ESP8266.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_ESP8266_H) && !defined(RADIOLIB_EXCLUDE_ESP8266) && !defined(ESP8266) 2 | #define _RADIOLIB_ESP8266_H 3 | 4 | #include "../../TypeDef.h" 5 | #include "../../Module.h" 6 | 7 | #include "../../protocols/TransportLayer/TransportLayer.h" 8 | 9 | /*! 10 | \class ESP8266 11 | 12 | \brief Control class for %ESP8266 module. Implements TransportLayer methods. 13 | */ 14 | class ESP8266: public TransportLayer { 15 | public: 16 | /*! 17 | \brief Default constructor. 18 | 19 | \param mod Instance of Module that will be used to communicate with the radio. 20 | */ 21 | ESP8266(Module* module); 22 | 23 | // basic methods 24 | 25 | /*! 26 | \brief Initialization method. 27 | 28 | \param speed Baud rate to use for UART interface. 29 | 30 | \returns \ref status_codes 31 | */ 32 | int16_t begin(long speed); 33 | 34 | /*! 35 | \brief Resets module using AT command. 36 | 37 | \returns \ref status_codes 38 | */ 39 | int16_t reset(); 40 | 41 | /*! 42 | \brief Joins access point. 43 | 44 | \param ssid Access point SSID. 45 | 46 | \param password Access point password. 47 | */ 48 | int16_t join(const char* ssid, const char* password); 49 | 50 | // transport layer methods (implementations of purely virtual methods in TransportLayer class) 51 | int16_t openTransportConnection(const char* host, const char* protocol, uint16_t port, uint16_t tcpKeepAlive = 0) override; 52 | int16_t closeTransportConnection() override; 53 | int16_t send(const char* data) override; 54 | int16_t send(uint8_t* data, size_t len) override; 55 | size_t receive(uint8_t* data, size_t len, uint32_t timeout = 10000) override; 56 | size_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10) override; 57 | 58 | #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL) 59 | protected: 60 | #endif 61 | Module* _mod; 62 | 63 | #if !defined(RADIOLIB_GODMODE) 64 | protected: 65 | #endif 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/modules/HC05/HC05.cpp: -------------------------------------------------------------------------------- 1 | #include "HC05.h" 2 | #if !defined(RADIOLIB_EXCLUDE_HC05) 3 | 4 | HC05::HC05(Module* mod) : ISerial(mod) { 5 | 6 | } 7 | 8 | void HC05::begin(long speed) { 9 | // set module properties 10 | _mod->baudrate = speed; 11 | _mod->init(RADIOLIB_USE_UART); 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/modules/HC05/HC05.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_HC05_H) && !defined(RADIOLIB_EXCLUDE_HC05) 2 | #define _RADIOLIB_HC05_H 3 | 4 | #include "../../ISerial.h" 5 | 6 | /*! 7 | \class HC05 8 | 9 | \brief Control class for %HC05 module. 10 | Most methods supported by this module are implemented in ISerial interface. 11 | */ 12 | class HC05: public ISerial { 13 | public: 14 | /*! 15 | \brief Default constructor. 16 | 17 | \param mod Instance of Module that will be used to communicate with the radio. 18 | */ 19 | HC05(Module* mod); 20 | 21 | /*! 22 | \brief Initialization method. 23 | 24 | \param speed Baud rate to use for UART interface. 25 | */ 26 | void begin(long speed); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/modules/JDY08/JDY08.cpp: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_JDY08_H) && !defined(RADIOLIB_EXCLUDE_JDY08) 2 | #include "JDY08.h" 3 | 4 | JDY08::JDY08(Module* mod) : ISerial(mod) { 5 | 6 | } 7 | 8 | void JDY08::begin(long speed) { 9 | // set module properties 10 | char lf[3] = ""; 11 | memcpy(_mod->AtLineFeed, lf, strlen(lf)); 12 | _mod->baudrate = speed; 13 | _mod->init(RADIOLIB_USE_UART); 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/modules/JDY08/JDY08.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_JDY08_H) && !defined(RADIOLIB_EXCLUDE_JDY08) 2 | #define _RADIOLIB_JDY08_H 3 | 4 | #include "../../ISerial.h" 5 | 6 | /*! 7 | \class JDY08 8 | 9 | \brief Control class for %JDY08 module. 10 | Most methods supported by this module are implemented in ISerial interface. 11 | */ 12 | class JDY08: public ISerial { 13 | public: 14 | /*! 15 | \brief Default constructor. 16 | 17 | \param mod Instance of Module that will be used to communicate with the radio. 18 | */ 19 | JDY08(Module* mod); 20 | 21 | /*! 22 | \brief Initialization method. 23 | 24 | \param speed Baud rate to use for UART interface. 25 | */ 26 | void begin(long speed); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/modules/LLCC68/LLCC68.cpp: -------------------------------------------------------------------------------- 1 | #include "LLCC68.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX126X) 3 | 4 | LLCC68::LLCC68(Module* mod) : SX1262(mod) { 5 | 6 | } 7 | 8 | int16_t LLCC68::setBandwidth(float bw) { 9 | RADIOLIB_CHECK_RANGE(bw, 100.0, 510.0, ERR_INVALID_BANDWIDTH); 10 | return(SX1262::setBandwidth(bw)); 11 | } 12 | 13 | int16_t LLCC68::setSpreadingFactor(uint8_t sf) { 14 | switch(SX126x::_bw) { 15 | case SX126X_LORA_BW_125_0: 16 | RADIOLIB_CHECK_RANGE(sf, 5, 9, ERR_INVALID_SPREADING_FACTOR); 17 | break; 18 | case SX126X_LORA_BW_250_0: 19 | RADIOLIB_CHECK_RANGE(sf, 5, 10, ERR_INVALID_SPREADING_FACTOR); 20 | break; 21 | case SX126X_LORA_BW_500_0: 22 | RADIOLIB_CHECK_RANGE(sf, 5, 11, ERR_INVALID_SPREADING_FACTOR); 23 | break; 24 | default: 25 | return(ERR_INVALID_SPREADING_FACTOR); 26 | } 27 | 28 | return(SX1262::setSpreadingFactor(sf)); 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/modules/LLCC68/LLCC68.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_LLCC68_H) 2 | #define _RADIOLIB_LLCC68_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SX126X) 7 | 8 | #include "../../Module.h" 9 | #include "../SX126x/SX1262.h" 10 | 11 | /*! 12 | \class LLCC68 13 | 14 | \brief Derived class for %LLCC68 modules. 15 | */ 16 | class LLCC68: public SX1262 { 17 | public: 18 | /*! 19 | \brief Default constructor. 20 | 21 | \param mod Instance of Module that will be used to communicate with the radio. 22 | */ 23 | LLCC68(Module* mod); 24 | 25 | // configuration methods 26 | 27 | /*! 28 | \brief Sets LoRa bandwidth. Allowed values are 125.0, 250.0 and 500.0 kHz. 29 | 30 | \param bw LoRa bandwidth to be set in kHz. 31 | 32 | \returns \ref status_codes 33 | */ 34 | int16_t setBandwidth(float bw); 35 | 36 | /*! 37 | \brief Sets LoRa spreading factor. Allowed values range from 5 to 11, depending on currently set spreading factor. 38 | 39 | \param sf LoRa spreading factor to be set. 40 | 41 | \returns \ref status_codes 42 | */ 43 | int16_t setSpreadingFactor(uint8_t sf); 44 | 45 | #if !defined(RADIOLIB_GODMODE) 46 | private: 47 | #endif 48 | 49 | }; 50 | 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/modules/RFM2x/RFM22.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_RFM22_H) 2 | #define _RADIOLIB_RFM22_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_RFM2X) 7 | 8 | #include "../../Module.h" 9 | #include "../Si443x/Si443x.h" 10 | #include "../Si443x/Si4432.h" 11 | 12 | /*! 13 | \class RFM22 14 | 15 | \brief Only exists as alias for Si4432, since there seems to be no difference between %RFM22 and %Si4432 modules. 16 | */ 17 | using RFM22 = Si4432; 18 | 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/modules/RFM2x/RFM23.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_RFM23_H) 2 | #define _RADIOLIB_RFM23_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_RFM2X) 7 | 8 | #include "../../Module.h" 9 | #include "../Si443x/Si443x.h" 10 | #include "../Si443x/Si4431.h" 11 | 12 | /*! 13 | \class RFM23 14 | 15 | \brief Only exists as alias for Si4431, since there seems to be no difference between %RFM23 and %Si4431 modules. 16 | */ 17 | using RFM23 = Si4431; 18 | 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/modules/RFM9x/RFM95.cpp: -------------------------------------------------------------------------------- 1 | #include "RFM95.h" 2 | #if !defined(RADIOLIB_EXCLUDE_RFM9X) 3 | 4 | RFM95::RFM95(Module* mod) : SX1278(mod) { 5 | 6 | } 7 | 8 | int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { 9 | // execute common part 10 | int16_t state = SX127x::begin(RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength); 11 | if(state == ERR_CHIP_NOT_FOUND) { 12 | // SX127X_REG_VERSION might be set 0x12 13 | state = SX127x::begin(RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength); 14 | RADIOLIB_ASSERT(state); 15 | } else if(state != ERR_NONE) { 16 | // some other error 17 | return(state); 18 | } 19 | RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278")); 20 | RADIOLIB_DEBUG_PRINTLN(F("M\tRFM95")); 21 | 22 | // configure publicly accessible settings 23 | state = setBandwidth(bw); 24 | RADIOLIB_ASSERT(state); 25 | 26 | state = setFrequency(freq); 27 | RADIOLIB_ASSERT(state); 28 | 29 | state = setSpreadingFactor(sf); 30 | RADIOLIB_ASSERT(state); 31 | 32 | state = setCodingRate(cr); 33 | RADIOLIB_ASSERT(state); 34 | 35 | state = setOutputPower(power); 36 | RADIOLIB_ASSERT(state); 37 | 38 | state = setGain(gain); 39 | 40 | return(state); 41 | } 42 | 43 | int16_t RFM95::setFrequency(float freq) { 44 | RADIOLIB_CHECK_RANGE(freq, 862.0, 1020.0, ERR_INVALID_FREQUENCY); 45 | 46 | // set frequency and if successful, save the new setting 47 | int16_t state = SX127x::setFrequencyRaw(freq); 48 | if(state == ERR_NONE) { 49 | SX127x::_freq = freq; 50 | } 51 | return(state); 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/modules/RFM9x/RFM95.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_RFM95_H) 2 | #define _RADIOLIB_RFM95_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_RFM9X) 7 | 8 | #include "../../Module.h" 9 | #include "../SX127x/SX127x.h" 10 | #include "../SX127x/SX1278.h" 11 | 12 | // SX127X_REG_VERSION 13 | #define RFM9X_CHIP_VERSION_OFFICIAL 0x11 14 | #define RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12 15 | 16 | /*! 17 | \class RFM95 18 | 19 | \brief Derived class for %RFM95 modules. Overrides some methods from SX1278 due to different parameter ranges. 20 | */ 21 | class RFM95: public SX1278 { 22 | public: 23 | 24 | // constructor 25 | 26 | /*! 27 | \brief Default constructor. Called from Arduino sketch when creating new LoRa instance. 28 | 29 | \param mod Instance of Module that will be used to communicate with the %LoRa chip. 30 | */ 31 | RFM95(Module* mod); 32 | 33 | // basic methods 34 | 35 | /*! 36 | \brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module. 37 | 38 | \param freq Carrier frequency in MHz. Allowed values range from 868.0 MHz to 915.0 MHz. 39 | 40 | \param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. 41 | 42 | \param sf %LoRa link spreading factor. Allowed values range from 6 to 12. 43 | 44 | \param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8. 45 | 46 | \param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. 47 | 48 | \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. 49 | 50 | \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. 51 | Allowed values range from 6 to 65535. 52 | 53 | \param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. 54 | Set to 0 to enable automatic gain control (recommended). 55 | 56 | \returns \ref status_codes 57 | */ 58 | int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); 59 | 60 | // configuration methods 61 | 62 | /*! 63 | \brief Sets carrier frequency. Allowed values range from 868.0 MHz to 915.0 MHz. 64 | 65 | \param freq Carrier frequency to be set in MHz. 66 | 67 | \returns \ref status_codes 68 | */ 69 | int16_t setFrequency(float freq); 70 | 71 | #if !defined(RADIOLIB_GODMODE) 72 | private: 73 | #endif 74 | 75 | }; 76 | 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/modules/RFM9x/RFM96.cpp: -------------------------------------------------------------------------------- 1 | #include "RFM96.h" 2 | #if !defined(RADIOLIB_EXCLUDE_RFM9X) 3 | 4 | RFM96::RFM96(Module* mod) : SX1278(mod) { 5 | 6 | } 7 | 8 | int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { 9 | // execute common part 10 | int16_t state = SX127x::begin(RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength); 11 | if(state == ERR_CHIP_NOT_FOUND) { 12 | // SX127X_REG_VERSION might be set 0x12 13 | state = SX127x::begin(RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength); 14 | RADIOLIB_ASSERT(state); 15 | } else if(state != ERR_NONE) { 16 | // some other error 17 | return(state); 18 | } 19 | RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278")); 20 | RADIOLIB_DEBUG_PRINTLN(F("M\tRFM96")); 21 | 22 | // configure publicly accessible settings 23 | state = setBandwidth(bw); 24 | RADIOLIB_ASSERT(state); 25 | 26 | state = setFrequency(freq); 27 | RADIOLIB_ASSERT(state); 28 | 29 | state = setSpreadingFactor(sf); 30 | RADIOLIB_ASSERT(state); 31 | 32 | state = setCodingRate(cr); 33 | RADIOLIB_ASSERT(state); 34 | 35 | state = setOutputPower(power); 36 | RADIOLIB_ASSERT(state); 37 | 38 | state = setGain(gain); 39 | RADIOLIB_ASSERT(state); 40 | 41 | return(state); 42 | } 43 | 44 | int16_t RFM96::setFrequency(float freq) { 45 | RADIOLIB_CHECK_RANGE(freq, 410.0, 525.0, ERR_INVALID_FREQUENCY); 46 | 47 | // set frequency and if successful, save the new setting 48 | int16_t state = SX127x::setFrequencyRaw(freq); 49 | if(state == ERR_NONE) { 50 | SX127x::_freq = freq; 51 | } 52 | return(state); 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/modules/RFM9x/RFM96.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_RFM96_H) 2 | #define _RADIOLIB_RFM96_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_RFM9X) 7 | 8 | #include "../../Module.h" 9 | #include "../SX127x/SX127x.h" 10 | #include "../SX127x/SX1278.h" 11 | 12 | // SX127X_REG_VERSION 13 | #define RFM9X_CHIP_VERSION_OFFICIAL 0x11 14 | #define RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12 15 | 16 | /*! 17 | \class RFM96 18 | 19 | \brief Derived class for %RFM96 modules. Overrides some methods from SX1278 due to different parameter ranges. 20 | */ 21 | class RFM96: public SX1278 { 22 | public: 23 | 24 | // constructor 25 | 26 | /*! 27 | \brief Default constructor. Called from Arduino sketch when creating new LoRa instance. 28 | 29 | \param mod Instance of Module that will be used to communicate with the %LoRa chip. 30 | */ 31 | RFM96(Module* mod); 32 | 33 | // basic methods 34 | 35 | /*! 36 | \brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module. 37 | 38 | \param freq Carrier frequency in MHz. Allowed values range from 433.0 MHz to 470.0 MHz. 39 | 40 | \param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. 41 | 42 | \param sf %LoRa link spreading factor. Allowed values range from 6 to 12. 43 | 44 | \param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8. 45 | 46 | \param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. 47 | 48 | \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. 49 | 50 | \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. 51 | Allowed values range from 6 to 65535. 52 | 53 | \param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. 54 | Set to 0 to enable automatic gain control (recommended). 55 | 56 | \returns \ref status_codes 57 | */ 58 | int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); 59 | 60 | // configuration methods 61 | 62 | /*! 63 | \brief Sets carrier frequency. Allowed values range from 433.0 MHz to 470.0 MHz. 64 | 65 | \param freq Carrier frequency to be set in MHz. 66 | 67 | \returns \ref status_codes 68 | */ 69 | int16_t setFrequency(float freq); 70 | 71 | #if !defined(RADIOLIB_GODMODE) 72 | private: 73 | #endif 74 | 75 | }; 76 | 77 | /*! 78 | \class RFM98 79 | 80 | \brief Only exists as alias for RFM96, since there seems to be no difference between %RFM96 and %RFM98 modules. 81 | */ 82 | using RFM98 = RFM96; 83 | 84 | #endif 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /src/modules/RFM9x/RFM97.cpp: -------------------------------------------------------------------------------- 1 | #include "RFM97.h" 2 | #if !defined(RADIOLIB_EXCLUDE_RFM9X) 3 | 4 | RFM97::RFM97(Module* mod) : RFM95(mod) { 5 | 6 | }; 7 | 8 | int16_t RFM97::setSpreadingFactor(uint8_t sf) { 9 | // check active modem 10 | if(getActiveModem() != SX127X_LORA) { 11 | return(ERR_WRONG_MODEM); 12 | } 13 | 14 | uint8_t newSpreadingFactor; 15 | 16 | // check allowed spreading factor values 17 | switch(sf) { 18 | case 6: 19 | newSpreadingFactor = SX127X_SF_6; 20 | break; 21 | case 7: 22 | newSpreadingFactor = SX127X_SF_7; 23 | break; 24 | case 8: 25 | newSpreadingFactor = SX127X_SF_8; 26 | break; 27 | case 9: 28 | newSpreadingFactor = SX127X_SF_9; 29 | break; 30 | default: 31 | return(ERR_INVALID_SPREADING_FACTOR); 32 | } 33 | 34 | // set spreading factor and if successful, save the new setting 35 | int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor); 36 | if(state == ERR_NONE) { 37 | SX127x::_sf = sf; 38 | } 39 | return(state); 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/modules/RFM9x/RFM97.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_RFM97_H) 2 | #define _RADIOLIB_RFM97_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_RFM9X) 7 | 8 | #include "../../Module.h" 9 | #include "../SX127x/SX127x.h" 10 | #include "../SX127x/SX1278.h" 11 | #include "RFM95.h" 12 | 13 | /*! 14 | \class RFM97 15 | 16 | \brief Derived class for %RFM97 modules. Overrides some methods from RFM95 due to different parameter ranges. 17 | */ 18 | class RFM97: public RFM95 { 19 | public: 20 | 21 | // constructor 22 | 23 | /*! 24 | \brief Default constructor. Called from Arduino sketch when creating new LoRa instance. 25 | 26 | \param mod Instance of Module that will be used to communicate with the %LoRa chip. 27 | */ 28 | RFM97(Module* mod); 29 | 30 | // configuration methods 31 | 32 | /*! 33 | \brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode. 34 | 35 | \param sf %LoRa link spreading factor to be set. 36 | 37 | \returns \ref status_codes 38 | */ 39 | int16_t setSpreadingFactor(uint8_t sf); 40 | 41 | #if !defined(RADIOLIB_GODMODE) 42 | private: 43 | #endif 44 | 45 | }; 46 | 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/modules/SX1231/SX1231.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1231.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX1231) 3 | 4 | SX1231::SX1231(Module* mod) : RF69(mod) { 5 | 6 | } 7 | 8 | int16_t SX1231::begin(float freq, float br, float rxBw, float freqDev, int8_t power, uint8_t preambleLen) { 9 | // set module properties 10 | _mod->init(RADIOLIB_USE_SPI); 11 | Module::pinMode(_mod->getIrq(), INPUT); 12 | Module::pinMode(_mod->getRst(), OUTPUT); 13 | 14 | // try to find the SX1231 chip 15 | uint8_t i = 0; 16 | bool flagFound = false; 17 | while((i < 10) && !flagFound) { 18 | int16_t version = getChipVersion(); 19 | if((version == 0x21) || (version == 0x22) || (version == 0x23)) { 20 | flagFound = true; 21 | _chipRevision = version; 22 | } else { 23 | #ifdef RADIOLIB_DEBUG 24 | RADIOLIB_DEBUG_PRINT(F("SX1231 not found! (")); 25 | RADIOLIB_DEBUG_PRINT(i + 1); 26 | RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RF69_REG_VERSION == ")); 27 | 28 | char buffHex[12]; 29 | sprintf(buffHex, "0x%04X", version); 30 | RADIOLIB_DEBUG_PRINT(buffHex); 31 | RADIOLIB_DEBUG_PRINT(F(", expected 0x0021 / 0x0022 / 0x0023")); 32 | RADIOLIB_DEBUG_PRINTLN(); 33 | #endif 34 | Module::delay(10); 35 | i++; 36 | } 37 | } 38 | 39 | if(!flagFound) { 40 | RADIOLIB_DEBUG_PRINTLN(F("No SX1231 found!")); 41 | _mod->term(RADIOLIB_USE_SPI); 42 | return(ERR_CHIP_NOT_FOUND); 43 | } 44 | RADIOLIB_DEBUG_PRINTLN(F("M\tSX1231")); 45 | 46 | // configure settings not accessible by API 47 | int16_t state = config(); 48 | RADIOLIB_ASSERT(state); 49 | RADIOLIB_DEBUG_PRINTLN(F("M\tRF69")); 50 | 51 | // configure publicly accessible settings 52 | state = setFrequency(freq); 53 | RADIOLIB_ASSERT(state); 54 | 55 | // configure bitrate 56 | _rxBw = 125.0; 57 | state = setBitRate(br); 58 | RADIOLIB_ASSERT(state); 59 | 60 | // configure default RX bandwidth 61 | state = setRxBandwidth(rxBw); 62 | RADIOLIB_ASSERT(state); 63 | 64 | // configure default frequency deviation 65 | state = setFrequencyDeviation(freqDev); 66 | RADIOLIB_ASSERT(state); 67 | 68 | // configure default TX output power 69 | state = setOutputPower(power); 70 | RADIOLIB_ASSERT(state); 71 | 72 | // configure default preamble length 73 | state = setPreambleLength(preambleLen); 74 | RADIOLIB_ASSERT(state); 75 | 76 | // default sync word values 0x2D01 is the same as the default in LowPowerLab RFM69 library 77 | uint8_t syncWord[] = {0x2D, 0x01}; 78 | state = setSyncWord(syncWord, 2); 79 | RADIOLIB_ASSERT(state); 80 | 81 | // set default packet length mode 82 | state = variablePacketLengthMode(); 83 | if (state != ERR_NONE) { 84 | return(state); 85 | } 86 | 87 | // SX1231 V2a only 88 | if(_chipRevision == SX1231_CHIP_REVISION_2_A) { 89 | // modify default OOK threshold value 90 | state = _mod->SPIsetRegValue(SX1231_REG_TEST_OOK, SX1231_OOK_DELTA_THRESHOLD); 91 | RADIOLIB_ASSERT(state); 92 | 93 | // enable OCP with 95 mA limit 94 | state = _mod->SPIsetRegValue(RF69_REG_OCP, RF69_OCP_ON | RF69_OCP_TRIM, 4, 0); 95 | RADIOLIB_ASSERT(state); 96 | } 97 | 98 | return(ERR_NONE); 99 | } 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /src/modules/SX1231/SX1231.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SX1231_H) 2 | #define _RADIOLIB_SX1231_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SX1231) 7 | 8 | #include "../../Module.h" 9 | #include "../RF69/RF69.h" 10 | 11 | #define SX1231_CHIP_REVISION_2_A 0x21 12 | #define SX1231_CHIP_REVISION_2_B 0x22 13 | #define SX1231_CHIP_REVISION_2_C 0x23 14 | 15 | //SX1231 specific register map 16 | #define SX1231_REG_TEST_OOK 0x6E 17 | 18 | //SX1231_REG_TEST_OOK 19 | #define SX1231_OOK_DELTA_THRESHOLD 0x0C 20 | 21 | /*! 22 | \class SX1231 23 | 24 | \brief Control class for %SX1231 module. Overrides some methods from RF69 due to different register values. 25 | */ 26 | class SX1231: public RF69 { 27 | public: 28 | /*! 29 | \brief Default constructor. 30 | 31 | \param mod Instance of Module that will be used to communicate with the radio. 32 | */ 33 | SX1231(Module* mod); 34 | 35 | /*! 36 | \brief Initialization method. 37 | 38 | \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. 39 | 40 | \param br Bit rate to be used in kbps. Defaults to 48.0 kbps. 41 | 42 | \param rxBw Receiver bandwidth in kHz. Defaults to 125.0 kHz. 43 | 44 | \param freqDev Frequency deviation from carrier frequency in kHz Defaults to 50.0 kHz. 45 | 46 | \param power Output power in dBm. Defaults to 10 dBm. 47 | 48 | \param preambleLen Preamble Length in bits. Defaults to 16 bits. 49 | 50 | \returns \ref status_codes 51 | */ 52 | int16_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 10, uint8_t preambleLen = 16); 53 | 54 | #if !defined(RADIOLIB_GODMODE) 55 | private: 56 | #endif 57 | uint8_t _chipRevision = 0; 58 | }; 59 | 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/modules/SX126x/SX1261.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1261.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX126X) 3 | 4 | SX1261::SX1261(Module* mod): SX1262(mod) { 5 | 6 | } 7 | 8 | int16_t SX1261::setOutputPower(int8_t power) { 9 | RADIOLIB_CHECK_RANGE(power, -17, 14, ERR_INVALID_OUTPUT_POWER); 10 | 11 | // get current OCP configuration 12 | uint8_t ocp = 0; 13 | int16_t state = readRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1); 14 | RADIOLIB_ASSERT(state); 15 | 16 | // set PA config 17 | state = SX126x::setPaConfig(0x04, SX126X_PA_CONFIG_SX1261, 0x00); 18 | RADIOLIB_ASSERT(state); 19 | 20 | // set output power 21 | /// \todo power ramp time configuration 22 | state = SX126x::setTxParams(power); 23 | RADIOLIB_ASSERT(state); 24 | 25 | // restore OCP configuration 26 | return(writeRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/modules/SX126x/SX1261.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SX1261_H) 2 | #define _RADIOLIB_SX1261_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SX126X) 7 | 8 | #include "../../Module.h" 9 | #include "SX126x.h" 10 | #include "SX1262.h" 11 | 12 | //SX126X_CMD_SET_PA_CONFIG 13 | #define SX126X_PA_CONFIG_SX1261 0x01 14 | 15 | /*! 16 | \class SX1261 17 | 18 | \brief Derived class for %SX1261 modules. 19 | */ 20 | class SX1261 : public SX1262 { 21 | public: 22 | /*! 23 | \brief Default constructor. 24 | 25 | \param mod Instance of Module that will be used to communicate with the radio. 26 | */ 27 | SX1261(Module* mod); 28 | 29 | /*! 30 | \brief Sets output power. Allowed values are in range from -17 to 14 dBm. 31 | 32 | \param power Output power to be set in dBm. 33 | 34 | \returns \ref status_codes 35 | */ 36 | int16_t setOutputPower(int8_t power); 37 | 38 | #if !defined(RADIOLIB_GODMODE) 39 | private: 40 | #endif 41 | 42 | }; 43 | 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/modules/SX126x/SX1262.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1262.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX126X) 3 | 4 | SX1262::SX1262(Module* mod) : SX126x(mod) { 5 | 6 | } 7 | 8 | int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { 9 | // execute common part 10 | int16_t state = SX126x::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO); 11 | RADIOLIB_ASSERT(state); 12 | 13 | // configure publicly accessible settings 14 | state = setFrequency(freq); 15 | RADIOLIB_ASSERT(state); 16 | 17 | state = setOutputPower(power); 18 | RADIOLIB_ASSERT(state); 19 | 20 | state = SX126x::fixPaClamping(); 21 | RADIOLIB_ASSERT(state); 22 | 23 | return(state); 24 | } 25 | 26 | int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { 27 | // execute common part 28 | int16_t state = SX126x::beginFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage, useRegulatorLDO); 29 | RADIOLIB_ASSERT(state); 30 | 31 | // configure publicly accessible settings 32 | state = setFrequency(freq); 33 | RADIOLIB_ASSERT(state); 34 | 35 | state = setOutputPower(power); 36 | RADIOLIB_ASSERT(state); 37 | 38 | state = SX126x::fixPaClamping(); 39 | RADIOLIB_ASSERT(state); 40 | 41 | return(state); 42 | } 43 | 44 | int16_t SX1262::setFrequency(float freq, bool calibrate) { 45 | RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, ERR_INVALID_FREQUENCY); 46 | 47 | // calibrate image 48 | if(calibrate) { 49 | uint8_t data[2]; 50 | if(freq > 900.0) { 51 | data[0] = SX126X_CAL_IMG_902_MHZ_1; 52 | data[1] = SX126X_CAL_IMG_902_MHZ_2; 53 | } else if(freq > 850.0) { 54 | data[0] = SX126X_CAL_IMG_863_MHZ_1; 55 | data[1] = SX126X_CAL_IMG_863_MHZ_2; 56 | } else if(freq > 770.0) { 57 | data[0] = SX126X_CAL_IMG_779_MHZ_1; 58 | data[1] = SX126X_CAL_IMG_779_MHZ_2; 59 | } else if(freq > 460.0) { 60 | data[0] = SX126X_CAL_IMG_470_MHZ_1; 61 | data[1] = SX126X_CAL_IMG_470_MHZ_2; 62 | } else { 63 | data[0] = SX126X_CAL_IMG_430_MHZ_1; 64 | data[1] = SX126X_CAL_IMG_430_MHZ_2; 65 | } 66 | int16_t state = SX126x::calibrateImage(data); 67 | RADIOLIB_ASSERT(state); 68 | } 69 | 70 | // set frequency 71 | int16_t res = SX126x::setFrequencyRaw(freq); 72 | if(res != ERR_NONE) { 73 | // The first setFreq after calibrate might return an error, just retry once 74 | res = SX126x::setFrequencyRaw(freq); 75 | } 76 | return(res); 77 | } 78 | 79 | int16_t SX1262::setOutputPower(int8_t power) { 80 | RADIOLIB_CHECK_RANGE(power, -17, 22, ERR_INVALID_OUTPUT_POWER); 81 | 82 | // get current OCP configuration 83 | uint8_t ocp = 0; 84 | int16_t state = readRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1); 85 | RADIOLIB_ASSERT(state); 86 | 87 | // set PA config 88 | state = SX126x::setPaConfig(0x04, SX126X_PA_CONFIG_SX1262); 89 | RADIOLIB_ASSERT(state); 90 | 91 | // set output power 92 | /// \todo power ramp time configuration 93 | state = SX126x::setTxParams(power); 94 | RADIOLIB_ASSERT(state); 95 | 96 | // restore OCP configuration 97 | return(writeRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); 98 | } 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /src/modules/SX126x/SX1262.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SX1262_H) 2 | #define _RADIOLIB_SX1262_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SX126X) 7 | 8 | #include "../../Module.h" 9 | #include "SX126x.h" 10 | 11 | //SX126X_CMD_SET_PA_CONFIG 12 | #define SX126X_PA_CONFIG_SX1262 0x00 13 | 14 | /*! 15 | \class SX1262 16 | 17 | \brief Derived class for %SX1262 modules. 18 | */ 19 | class SX1262: public SX126x { 20 | public: 21 | /*! 22 | \brief Default constructor. 23 | 24 | \param mod Instance of Module that will be used to communicate with the radio. 25 | */ 26 | SX1262(Module* mod); 27 | 28 | // basic methods 29 | 30 | /*! 31 | \brief Initialization method for LoRa modem. 32 | 33 | \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. 34 | 35 | \param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz. 36 | 37 | \param sf LoRa spreading factor. Defaults to 9. 38 | 39 | \param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7). 40 | 41 | \param syncWord 2-byte LoRa sync word. Defaults to SX126X_SYNC_WORD_PRIVATE (0x12). 42 | 43 | \param power Output power in dBm. Defaults to 10 dBm. 44 | 45 | \param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols. 46 | 47 | \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. 48 | 49 | \returns \ref status_codes 50 | */ 51 | int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); 52 | 53 | /*! 54 | \brief Initialization method for FSK modem. 55 | 56 | \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. 57 | 58 | \param br FSK bit rate in kbps. Defaults to 48.0 kbps. 59 | 60 | \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 50.0 kHz. 61 | 62 | \param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz. 63 | 64 | \param power Output power in dBm. Defaults to 10 dBm. 65 | 66 | \parma preambleLength FSK preamble length in bits. Defaults to 16 bits. 67 | 68 | \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. 69 | 70 | \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. 71 | 72 | \returns \ref status_codes 73 | */ 74 | int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); 75 | 76 | // configuration methods 77 | 78 | /*! 79 | \brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz. 80 | 81 | \param freq Carrier frequency to be set in MHz. 82 | 83 | \param calibrate Run image calibration. 84 | 85 | \returns \ref status_codes 86 | */ 87 | int16_t setFrequency(float freq, bool calibrate = true); 88 | 89 | /*! 90 | \brief Sets output power. Allowed values are in range from -17 to 22 dBm. 91 | 92 | \param power Output power to be set in dBm. 93 | 94 | \returns \ref status_codes 95 | */ 96 | int16_t setOutputPower(int8_t power); 97 | 98 | #if !defined(RADIOLIB_GODMODE) 99 | private: 100 | #endif 101 | 102 | }; 103 | 104 | #endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /src/modules/SX126x/SX1268.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1268.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX126X) 3 | 4 | SX1268::SX1268(Module* mod) : SX126x(mod) { 5 | 6 | } 7 | 8 | int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { 9 | // execute common part 10 | int16_t state = SX126x::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO); 11 | RADIOLIB_ASSERT(state); 12 | 13 | // configure publicly accessible settings 14 | state = setFrequency(freq); 15 | RADIOLIB_ASSERT(state); 16 | 17 | state = setOutputPower(power); 18 | RADIOLIB_ASSERT(state); 19 | 20 | state = SX126x::fixPaClamping(); 21 | RADIOLIB_ASSERT(state); 22 | 23 | return(state); 24 | } 25 | 26 | int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) { 27 | // execute common part 28 | int16_t state = SX126x::beginFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage, useRegulatorLDO); 29 | RADIOLIB_ASSERT(state); 30 | 31 | // configure publicly accessible settings 32 | state = setFrequency(freq); 33 | RADIOLIB_ASSERT(state); 34 | 35 | state = setOutputPower(power); 36 | RADIOLIB_ASSERT(state); 37 | 38 | state = SX126x::fixPaClamping(); 39 | RADIOLIB_ASSERT(state); 40 | 41 | return(state); 42 | } 43 | 44 | /// \todo integers only (all modules - frequency, data rate, bandwidth etc.) 45 | int16_t SX1268::setFrequency(float freq, bool calibrate) { 46 | RADIOLIB_CHECK_RANGE(freq, 410.0, 810.0, ERR_INVALID_FREQUENCY); 47 | 48 | // calibrate image 49 | if(calibrate) { 50 | uint8_t data[2]; 51 | if(freq > 770.0) { 52 | data[0] = SX126X_CAL_IMG_779_MHZ_1; 53 | data[1] = SX126X_CAL_IMG_779_MHZ_2; 54 | } else if(freq > 460.0) { 55 | data[0] = SX126X_CAL_IMG_470_MHZ_1; 56 | data[1] = SX126X_CAL_IMG_470_MHZ_2; 57 | } else { 58 | data[0] = SX126X_CAL_IMG_430_MHZ_1; 59 | data[1] = SX126X_CAL_IMG_430_MHZ_2; 60 | } 61 | int16_t state = SX126x::calibrateImage(data); 62 | RADIOLIB_ASSERT(state); 63 | } 64 | 65 | // set frequency 66 | return(SX126x::setFrequencyRaw(freq)); 67 | } 68 | 69 | int16_t SX1268::setOutputPower(int8_t power) { 70 | RADIOLIB_CHECK_RANGE(power, -9, 22, ERR_INVALID_OUTPUT_POWER); 71 | 72 | // get current OCP configuration 73 | uint8_t ocp = 0; 74 | int16_t state = readRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1); 75 | RADIOLIB_ASSERT(state); 76 | 77 | // set PA config 78 | state = SX126x::setPaConfig(0x04, SX126X_PA_CONFIG_SX1268); 79 | RADIOLIB_ASSERT(state); 80 | 81 | // set output power 82 | /// \todo power ramp time configuration 83 | state = SX126x::setTxParams(power); 84 | RADIOLIB_ASSERT(state); 85 | 86 | // restore OCP configuration 87 | return(writeRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /src/modules/SX126x/SX1268.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SX1268_H) 2 | #define _RADIOLIB_SX1268_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SX126X) 7 | 8 | #include "../../Module.h" 9 | #include "SX126x.h" 10 | 11 | //SX126X_CMD_SET_PA_CONFIG 12 | #define SX126X_PA_CONFIG_SX1268 0x00 13 | 14 | /*! 15 | \class SX1268 16 | 17 | \brief Derived class for %SX1268 modules. 18 | */ 19 | class SX1268: public SX126x { 20 | public: 21 | /*! 22 | \brief Default constructor. 23 | 24 | \param mod Instance of Module that will be used to communicate with the radio. 25 | */ 26 | SX1268(Module* mod); 27 | 28 | // basic methods 29 | 30 | /*! 31 | \brief Initialization method for LoRa modem. 32 | 33 | \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. 34 | 35 | \param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz. 36 | 37 | \param sf LoRa spreading factor. Defaults to 9. 38 | 39 | \param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7). 40 | 41 | \param syncWord 2-byte LoRa sync word. Defaults to SX126X_SYNC_WORD_PRIVATE (0x12). 42 | 43 | \param power Output power in dBm. Defaults to 10 dBm. 44 | 45 | \param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols. 46 | 47 | \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. 48 | 49 | \returns \ref status_codes 50 | */ 51 | int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); 52 | 53 | /*! 54 | \brief Initialization method for FSK modem. 55 | 56 | \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. 57 | 58 | \param br FSK bit rate in kbps. Defaults to 48.0 kbps. 59 | 60 | \param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 50.0 kHz. 61 | 62 | \param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz. 63 | 64 | \param power Output power in dBm. Defaults to 10 dBm. 65 | 66 | \parma preambleLength FSK preamble length in bits. Defaults to 16 bits. 67 | 68 | \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. 69 | 70 | \param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false. 71 | 72 | \returns \ref status_codes 73 | */ 74 | int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false); 75 | 76 | // configuration methods 77 | 78 | /*! 79 | \brief Sets carrier frequency. Allowed values are in range from 410.0 to 810.0 MHz. 80 | 81 | \param freq Carrier frequency to be set in MHz. 82 | 83 | \param calibrate Run image calibration. 84 | 85 | \returns \ref status_codes 86 | */ 87 | int16_t setFrequency(float freq, bool calibrate = true); 88 | 89 | /*! 90 | \brief Sets output power. Allowed values are in range from -9 to 22 dBm. 91 | 92 | \param power Output power to be set in dBm. 93 | 94 | \returns \ref status_codes 95 | */ 96 | int16_t setOutputPower(int8_t power); 97 | 98 | #if !defined(RADIOLIB_GODMODE) 99 | private: 100 | #endif 101 | 102 | }; 103 | 104 | #endif 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /src/modules/SX127x/SX1273.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1273.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX127X) 3 | 4 | SX1273::SX1273(Module* mod) : SX1272(mod) { 5 | 6 | } 7 | 8 | int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { 9 | // execute common part 10 | int16_t state = SX127x::begin(SX1272_CHIP_VERSION, syncWord, preambleLength); 11 | RADIOLIB_ASSERT(state); 12 | 13 | // configure publicly accessible settings 14 | state = setBandwidth(bw); 15 | RADIOLIB_ASSERT(state); 16 | 17 | state = setFrequency(freq); 18 | RADIOLIB_ASSERT(state); 19 | 20 | state = setSpreadingFactor(sf); 21 | RADIOLIB_ASSERT(state); 22 | 23 | state = setCodingRate(cr); 24 | RADIOLIB_ASSERT(state); 25 | 26 | state = setOutputPower(power); 27 | RADIOLIB_ASSERT(state); 28 | 29 | state = setGain(gain); 30 | RADIOLIB_ASSERT(state); 31 | 32 | return(state); 33 | } 34 | 35 | int16_t SX1273::setSpreadingFactor(uint8_t sf) { 36 | uint8_t newSpreadingFactor; 37 | 38 | // check allowed spreading factor values 39 | switch(sf) { 40 | case 6: 41 | newSpreadingFactor = SX127X_SF_6; 42 | break; 43 | case 7: 44 | newSpreadingFactor = SX127X_SF_7; 45 | break; 46 | case 8: 47 | newSpreadingFactor = SX127X_SF_8; 48 | break; 49 | case 9: 50 | newSpreadingFactor = SX127X_SF_9; 51 | break; 52 | default: 53 | return(ERR_INVALID_SPREADING_FACTOR); 54 | } 55 | 56 | // set spreading factor and if successful, save the new setting 57 | int16_t state = setSpreadingFactorRaw(newSpreadingFactor); 58 | if(state == ERR_NONE) { 59 | SX127x::_sf = sf; 60 | } 61 | 62 | return(state); 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/modules/SX127x/SX1273.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SX1273_H) 2 | #define _RADIOLIB_SX1273_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SX127X) 7 | 8 | #include "SX1272.h" 9 | 10 | /*! 11 | \class SX1273 12 | 13 | \brief Derived class for %SX1273 modules. Overrides some methods from SX1272 due to different parameter ranges. 14 | */ 15 | class SX1273: public SX1272 { 16 | public: 17 | 18 | // constructor 19 | 20 | /*! 21 | \brief Default constructor. Called from Arduino sketch when creating new LoRa instance. 22 | 23 | \param mod Instance of Module that will be used to communicate with the %LoRa chip. 24 | */ 25 | SX1273(Module* mod); 26 | 27 | // basic methods 28 | 29 | /*! 30 | \brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module. 31 | 32 | \param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz. 33 | 34 | \param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz. 35 | 36 | \param sf %LoRa link spreading factor. Allowed values range from 6 to 9. 37 | 38 | \param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8. 39 | 40 | \param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. 41 | 42 | \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. 43 | 44 | \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. 45 | Allowed values range from 6 to 65535. 46 | 47 | \param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. 48 | Set to 0 to enable automatic gain control (recommended). 49 | 50 | \returns \ref status_codes 51 | */ 52 | int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); 53 | 54 | // configuration methods 55 | 56 | /*! 57 | \brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode. 58 | 59 | \param sf %LoRa link spreading factor to be set. 60 | 61 | \returns \ref status_codes 62 | */ 63 | int16_t setSpreadingFactor(uint8_t sf); 64 | 65 | #if !defined(RADIOLIB_GODMODE) 66 | private: 67 | #endif 68 | 69 | }; 70 | 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/modules/SX127x/SX1276.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1276.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX127X) 3 | 4 | SX1276::SX1276(Module* mod) : SX1278(mod) { 5 | 6 | } 7 | 8 | int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { 9 | // execute common part 10 | int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, preambleLength); 11 | RADIOLIB_ASSERT(state); 12 | 13 | // configure publicly accessible settings 14 | state = setBandwidth(bw); 15 | RADIOLIB_ASSERT(state); 16 | 17 | state = setFrequency(freq); 18 | RADIOLIB_ASSERT(state); 19 | 20 | state = setSpreadingFactor(sf); 21 | RADIOLIB_ASSERT(state); 22 | 23 | state = setCodingRate(cr); 24 | RADIOLIB_ASSERT(state); 25 | 26 | state = setOutputPower(power); 27 | RADIOLIB_ASSERT(state); 28 | 29 | state = setGain(gain); 30 | RADIOLIB_ASSERT(state); 31 | 32 | return(state); 33 | } 34 | 35 | int16_t SX1276::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { 36 | // execute common part 37 | int16_t state = SX127x::beginFSK(SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK); 38 | RADIOLIB_ASSERT(state); 39 | 40 | // configure publicly accessible settings 41 | state = setFrequency(freq); 42 | RADIOLIB_ASSERT(state); 43 | 44 | state = setOutputPower(power); 45 | RADIOLIB_ASSERT(state); 46 | 47 | state = setDataShaping(RADIOLIB_SHAPING_NONE); 48 | RADIOLIB_ASSERT(state); 49 | 50 | return(state); 51 | } 52 | 53 | int16_t SX1276::setFrequency(float freq) { 54 | RADIOLIB_CHECK_RANGE(freq, 137.0, 1020.0, ERR_INVALID_FREQUENCY); 55 | 56 | // set frequency and if successful, save the new setting 57 | int16_t state = SX127x::setFrequencyRaw(freq); 58 | if(state == ERR_NONE) { 59 | SX127x::_freq = freq; 60 | } 61 | return(state); 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/modules/SX127x/SX1277.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1277.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX127X) 3 | 4 | SX1277::SX1277(Module* mod) : SX1278(mod) { 5 | 6 | } 7 | 8 | int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { 9 | // execute common part 10 | int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, preambleLength); 11 | RADIOLIB_ASSERT(state); 12 | 13 | // configure publicly accessible settings 14 | state = setBandwidth(bw); 15 | RADIOLIB_ASSERT(state); 16 | 17 | state = setFrequency(freq); 18 | RADIOLIB_ASSERT(state); 19 | 20 | state = setSpreadingFactor(sf); 21 | RADIOLIB_ASSERT(state); 22 | 23 | state = setCodingRate(cr); 24 | RADIOLIB_ASSERT(state); 25 | 26 | state = setOutputPower(power); 27 | RADIOLIB_ASSERT(state); 28 | 29 | state = setGain(gain); 30 | RADIOLIB_ASSERT(state); 31 | 32 | return(state); 33 | } 34 | 35 | int16_t SX1277::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { 36 | // execute common part 37 | int16_t state = SX127x::beginFSK(SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK); 38 | RADIOLIB_ASSERT(state); 39 | 40 | // configure publicly accessible settings 41 | state = setFrequency(freq); 42 | RADIOLIB_ASSERT(state); 43 | 44 | state = setOutputPower(power); 45 | RADIOLIB_ASSERT(state); 46 | 47 | state = setDataShaping(RADIOLIB_SHAPING_NONE); 48 | RADIOLIB_ASSERT(state); 49 | 50 | return(state); 51 | } 52 | 53 | int16_t SX1277::setFrequency(float freq) { 54 | RADIOLIB_CHECK_RANGE(freq, 137.0, 1020.0, ERR_INVALID_FREQUENCY); 55 | 56 | // set frequency and if successful, save the new setting 57 | int16_t state = SX127x::setFrequencyRaw(freq); 58 | if(state == ERR_NONE) { 59 | SX127x::_freq = freq; 60 | } 61 | return(state); 62 | } 63 | 64 | int16_t SX1277::setSpreadingFactor(uint8_t sf) { 65 | uint8_t newSpreadingFactor; 66 | 67 | // check allowed spreading factor values 68 | switch(sf) { 69 | case 6: 70 | newSpreadingFactor = SX127X_SF_6; 71 | break; 72 | case 7: 73 | newSpreadingFactor = SX127X_SF_7; 74 | break; 75 | case 8: 76 | newSpreadingFactor = SX127X_SF_8; 77 | break; 78 | case 9: 79 | newSpreadingFactor = SX127X_SF_9; 80 | break; 81 | default: 82 | return(ERR_INVALID_SPREADING_FACTOR); 83 | } 84 | 85 | // set spreading factor and if successful, save the new setting 86 | int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor); 87 | if(state == ERR_NONE) { 88 | SX127x::_sf = sf; 89 | } 90 | 91 | return(state); 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /src/modules/SX127x/SX1279.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1279.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX127X) 3 | 4 | SX1279::SX1279(Module* mod) : SX1278(mod) { 5 | 6 | } 7 | 8 | int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { 9 | // execute common part 10 | int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, preambleLength); 11 | RADIOLIB_ASSERT(state); 12 | 13 | // configure publicly accessible settings 14 | state = setBandwidth(bw); 15 | RADIOLIB_ASSERT(state); 16 | 17 | state = setFrequency(freq); 18 | RADIOLIB_ASSERT(state); 19 | 20 | state = setSpreadingFactor(sf); 21 | RADIOLIB_ASSERT(state); 22 | 23 | state = setCodingRate(cr); 24 | RADIOLIB_ASSERT(state); 25 | 26 | state = setOutputPower(power); 27 | RADIOLIB_ASSERT(state); 28 | 29 | state = setGain(gain); 30 | RADIOLIB_ASSERT(state); 31 | 32 | return(state); 33 | } 34 | 35 | int16_t SX1279::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { 36 | // execute common part 37 | int16_t state = SX127x::beginFSK(SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK); 38 | RADIOLIB_ASSERT(state); 39 | 40 | // configure publicly accessible settings 41 | state = setFrequency(freq); 42 | RADIOLIB_ASSERT(state); 43 | 44 | state = setOutputPower(power); 45 | RADIOLIB_ASSERT(state); 46 | 47 | state = setDataShaping(RADIOLIB_SHAPING_NONE); 48 | RADIOLIB_ASSERT(state); 49 | 50 | return(state); 51 | } 52 | 53 | int16_t SX1279::setFrequency(float freq) { 54 | RADIOLIB_CHECK_RANGE(freq, 137.0, 960.0, ERR_INVALID_FREQUENCY); 55 | 56 | // set frequency and if successful, save the new setting 57 | int16_t state = SX127x::setFrequencyRaw(freq); 58 | if(state == ERR_NONE) { 59 | SX127x::_freq = freq; 60 | } 61 | return(state); 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/modules/SX128x/SX1280.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SX1280_H) 2 | #define _RADIOLIB_SX1280_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SX128X) 7 | 8 | #include "../../Module.h" 9 | #include "SX128x.h" 10 | #include "SX1281.h" 11 | 12 | /*! 13 | \class SX1280 14 | 15 | \brief Derived class for %SX1280 modules. 16 | */ 17 | class SX1280: public SX1281 { 18 | public: 19 | /*! 20 | \brief Default constructor. 21 | 22 | \param mod Instance of Module that will be used to communicate with the radio. 23 | */ 24 | SX1280(Module* mod); 25 | 26 | /*! 27 | \brief Blocking ranging method. 28 | 29 | \param master Whether to execute ranging in master mode (true) or slave mode (false). 30 | 31 | \param addr Ranging address to be used. 32 | 33 | \returns \ref status_codes 34 | */ 35 | int16_t range(bool master, uint32_t addr); 36 | 37 | /*! 38 | \brief Interrupt-driven ranging method. 39 | 40 | \param master Whether to execute ranging in master mode (true) or slave mode (false). 41 | 42 | \param addr Ranging address to be used. 43 | 44 | \returns \ref status_codes 45 | */ 46 | int16_t startRanging(bool master, uint32_t addr); 47 | 48 | /*! 49 | \brief Gets ranging result of the last ranging exchange. 50 | 51 | \returns Ranging result in meters. 52 | */ 53 | float getRangingResult(); 54 | 55 | #if !defined(RADIOLIB_GODMODE) 56 | private: 57 | #endif 58 | 59 | }; 60 | 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/modules/SX128x/SX1281.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1281.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX128X) 3 | 4 | SX1281::SX1281(Module* mod) : SX128x(mod) { 5 | 6 | } 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/modules/SX128x/SX1281.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SX1281_H) 2 | #define _RADIOLIB_SX1281_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SX128X) 7 | 8 | #include "../../Module.h" 9 | #include "SX128x.h" 10 | 11 | /*! 12 | \class SX1281 13 | 14 | \brief Derived class for %SX1281 modules. 15 | */ 16 | class SX1281: public SX128x { 17 | public: 18 | /*! 19 | \brief Default constructor. 20 | 21 | \param mod Instance of Module that will be used to communicate with the radio. 22 | */ 23 | SX1281(Module* mod); 24 | 25 | #if !defined(RADIOLIB_GODMODE) 26 | private: 27 | #endif 28 | 29 | }; 30 | 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/modules/SX128x/SX1282.cpp: -------------------------------------------------------------------------------- 1 | #include "SX1282.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SX128X) 3 | 4 | /// \todo implement advanced ranging 5 | SX1282::SX1282(Module* mod) : SX1280(mod) { 6 | 7 | } 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/modules/SX128x/SX1282.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SX1282_H) 2 | #define _RADIOLIB_SX1282_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SX128X) 7 | 8 | #include "../../Module.h" 9 | #include "SX128x.h" 10 | #include "SX1280.h" 11 | 12 | /*! 13 | \class SX1282 14 | 15 | \brief Derived class for %SX1282 modules. 16 | */ 17 | class SX1282: public SX1280 { 18 | public: 19 | /*! 20 | \brief Default constructor. 21 | 22 | \param mod Instance of Module that will be used to communicate with the radio. 23 | */ 24 | SX1282(Module* mod); 25 | 26 | #if !defined(RADIOLIB_GODMODE) 27 | private: 28 | #endif 29 | 30 | }; 31 | 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/modules/Si443x/Si4430.cpp: -------------------------------------------------------------------------------- 1 | #include "Si4430.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SI443X) 3 | 4 | Si4430::Si4430(Module* mod) : Si4432(mod) { 5 | 6 | } 7 | 8 | int16_t Si4430::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { 9 | // execute common part 10 | int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen); 11 | RADIOLIB_ASSERT(state); 12 | RADIOLIB_DEBUG_PRINTLN(F("M\tSi4430")); 13 | 14 | // configure publicly accessible settings 15 | state = setFrequency(freq); 16 | RADIOLIB_ASSERT(state); 17 | 18 | state = setOutputPower(power); 19 | RADIOLIB_ASSERT(state); 20 | 21 | return(state); 22 | } 23 | 24 | int16_t Si4430::setFrequency(float freq) { 25 | RADIOLIB_CHECK_RANGE(freq, 900.0, 960.0, ERR_INVALID_FREQUENCY); 26 | 27 | // set frequency 28 | return(Si443x::setFrequencyRaw(freq)); 29 | } 30 | 31 | int16_t Si4430::setOutputPower(int8_t power) { 32 | RADIOLIB_CHECK_RANGE(power, -8, 13, ERR_INVALID_OUTPUT_POWER); 33 | 34 | // set output power 35 | return(_mod->SPIsetRegValue(SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0)); 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/modules/Si443x/Si4430.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SI4430_H) 2 | #define _RADIOLIB_SI4430_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SI443X) 7 | 8 | #include "../../Module.h" 9 | #include "Si4432.h" 10 | 11 | /*! 12 | \class Si4430 13 | 14 | \brief Derived class for %Si4430 modules. 15 | */ 16 | class Si4430: public Si4432 { 17 | public: 18 | 19 | // constructor 20 | 21 | /*! 22 | \brief Default constructor. 23 | 24 | \param mod Instance of Module that will be used to communicate with the radio chip. 25 | */ 26 | Si4430(Module* mod); 27 | 28 | // basic methods 29 | 30 | /*! 31 | \brief Initialization method. Must be called at least once from Arduino sketch to initialize the module. 32 | 33 | \param freq Carrier frequency in MHz. Allowed values range from 900.0 MHz to 960.0 MHz. 34 | 35 | \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps. 36 | 37 | \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps. 38 | 39 | \param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz. 40 | 41 | \param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps. 42 | 43 | \param preambleLen Preamble Length in bits. Defaults to 16 bits. 44 | 45 | \returns \ref status_codes 46 | */ 47 | int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16); 48 | 49 | // configuration methods 50 | 51 | /*! 52 | \brief Sets carrier frequency. Allowed values range from 900.0 MHz to 960.0 MHz. 53 | 54 | \param freq Carrier frequency to be set in MHz. 55 | 56 | \returns \ref status_codes 57 | */ 58 | int16_t setFrequency(float freq); 59 | 60 | /*! 61 | \brief Sets output power. Allowed values range from -8 to 13 dBm in 3 dBm steps. 62 | 63 | \param power Output power to be set in dBm. 64 | 65 | \returns \ref status_codes 66 | */ 67 | int16_t setOutputPower(int8_t power); 68 | 69 | 70 | #if !defined(RADIOLIB_GODMODE) 71 | protected: 72 | #endif 73 | 74 | #if !defined(RADIOLIB_GODMODE) 75 | private: 76 | #endif 77 | }; 78 | 79 | #endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/modules/Si443x/Si4431.cpp: -------------------------------------------------------------------------------- 1 | #include "Si4431.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SI443X) 3 | 4 | Si4431::Si4431(Module* mod) : Si4432(mod) { 5 | 6 | } 7 | 8 | int16_t Si4431::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { 9 | // execute common part 10 | int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen); 11 | RADIOLIB_ASSERT(state); 12 | RADIOLIB_DEBUG_PRINTLN(F("M\tSi4431")); 13 | 14 | // configure publicly accessible settings 15 | state = setFrequency(freq); 16 | RADIOLIB_ASSERT(state); 17 | 18 | state = setOutputPower(power); 19 | RADIOLIB_ASSERT(state); 20 | 21 | return(state); 22 | } 23 | 24 | int16_t Si4431::setOutputPower(int8_t power) { 25 | RADIOLIB_CHECK_RANGE(power, -8, 13, ERR_INVALID_OUTPUT_POWER); 26 | 27 | // set output power 28 | return(_mod->SPIsetRegValue(SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0)); 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/modules/Si443x/Si4431.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SI4431_H) 2 | #define _RADIOLIB_SI4431_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SI443X) 7 | 8 | #include "../../Module.h" 9 | #include "Si4432.h" 10 | 11 | /*! 12 | \class Si4431 13 | 14 | \brief Derived class for %Si4431 modules. 15 | */ 16 | class Si4431: public Si4432 { 17 | public: 18 | 19 | // constructor 20 | 21 | /*! 22 | \brief Default constructor. 23 | 24 | \param mod Instance of Module that will be used to communicate with the radio chip. 25 | */ 26 | Si4431(Module* mod); 27 | 28 | // basic methods 29 | 30 | /*! 31 | \brief Initialization method. Must be called at least once from Arduino sketch to initialize the module. 32 | 33 | \param freq Carrier frequency in MHz. Allowed values range from 240.0 MHz to 930.0 MHz. 34 | 35 | \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps. 36 | 37 | \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps. 38 | 39 | \param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz. 40 | 41 | \param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps. 42 | 43 | \param preambleLen Preamble Length in bits. Defaults to 16 bits. 44 | 45 | \returns \ref status_codes 46 | */ 47 | int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16); 48 | 49 | // configuration methods 50 | 51 | /*! 52 | \brief Sets output power. Allowed values range from -8 to 13 dBm in 3 dBm steps. 53 | 54 | \param power Output power to be set in dBm. 55 | 56 | \returns \ref status_codes 57 | */ 58 | int16_t setOutputPower(int8_t power); 59 | 60 | 61 | #if !defined(RADIOLIB_GODMODE) 62 | protected: 63 | #endif 64 | 65 | #if !defined(RADIOLIB_GODMODE) 66 | private: 67 | #endif 68 | }; 69 | 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/modules/Si443x/Si4432.cpp: -------------------------------------------------------------------------------- 1 | #include "Si4432.h" 2 | #if !defined(RADIOLIB_EXCLUDE_SI443X) 3 | 4 | Si4432::Si4432(Module* mod) : Si443x(mod) { 5 | 6 | } 7 | 8 | int16_t Si4432::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { 9 | // execute common part 10 | int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen); 11 | RADIOLIB_ASSERT(state); 12 | RADIOLIB_DEBUG_PRINTLN(F("M\tSi4432")); 13 | 14 | // configure publicly accessible settings 15 | state = setFrequency(freq); 16 | RADIOLIB_ASSERT(state); 17 | 18 | state = setOutputPower(power); 19 | RADIOLIB_ASSERT(state); 20 | 21 | return(state); 22 | } 23 | 24 | int16_t Si4432::setFrequency(float freq) { 25 | RADIOLIB_CHECK_RANGE(freq, 240.0, 930.0, ERR_INVALID_FREQUENCY); 26 | 27 | // set frequency 28 | return(Si443x::setFrequencyRaw(freq)); 29 | } 30 | 31 | int16_t Si4432::setOutputPower(int8_t power) { 32 | RADIOLIB_CHECK_RANGE(power, -1, 20, ERR_INVALID_OUTPUT_POWER); 33 | 34 | // set output power 35 | return(_mod->SPIsetRegValue(SI443X_REG_TX_POWER, (uint8_t)((power + 1) / 3), 2, 0)); 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/modules/Si443x/Si4432.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_SI4432_H) 2 | #define _RADIOLIB_SI4432_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_SI443X) 7 | 8 | #include "../../Module.h" 9 | #include "Si443x.h" 10 | 11 | /*! 12 | \class Si4432 13 | 14 | \brief Derived class for %Si4432 modules. 15 | */ 16 | class Si4432: public Si443x { 17 | public: 18 | 19 | // constructor 20 | 21 | /*! 22 | \brief Default constructor. 23 | 24 | \param mod Instance of Module that will be used to communicate with the radio chip. 25 | */ 26 | Si4432(Module* mod); 27 | 28 | // basic methods 29 | 30 | /*! 31 | \brief Initialization method. Must be called at least once from Arduino sketch to initialize the module. 32 | 33 | \param freq Carrier frequency in MHz. Allowed values range from 240.0 MHz to 930.0 MHz. 34 | 35 | \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps. 36 | 37 | \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps. 38 | 39 | \param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz. 40 | 41 | \param power Transmission output power in dBm. Allowed values range from -1 to 20 dBm in 3 dBm steps. 42 | 43 | \param preambleLen Preamble Length in bits. Defaults to 16 bits. 44 | 45 | \returns \ref status_codes 46 | */ 47 | int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16); 48 | 49 | // configuration methods 50 | 51 | /*! 52 | \brief Sets carrier frequency. Allowed values range from 240.0 MHz to 930.0 MHz. 53 | 54 | \param freq Carrier frequency to be set in MHz. 55 | 56 | \returns \ref status_codes 57 | */ 58 | int16_t setFrequency(float freq); 59 | 60 | /*! 61 | \brief Sets output power. Allowed values range from -1 to 20 dBm in 3 dBm steps. 62 | 63 | \param power Output power to be set in dBm. 64 | 65 | \returns \ref status_codes 66 | */ 67 | int16_t setOutputPower(int8_t power); 68 | 69 | 70 | #if !defined(RADIOLIB_GODMODE) 71 | protected: 72 | #endif 73 | 74 | #if !defined(RADIOLIB_GODMODE) 75 | private: 76 | #endif 77 | }; 78 | 79 | #endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/protocols/AFSK/AFSK.cpp: -------------------------------------------------------------------------------- 1 | #include "AFSK.h" 2 | #if !defined(RADIOLIB_EXCLUDE_AFSK) 3 | 4 | AFSKClient::AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin): _pin(pin) { 5 | _phy = phy; 6 | } 7 | 8 | int16_t AFSKClient::begin() { 9 | return(_phy->startDirect()); 10 | } 11 | 12 | int16_t AFSKClient::tone(uint16_t freq, bool autoStart) { 13 | if(freq == 0) { 14 | return(ERR_INVALID_FREQUENCY); 15 | } 16 | 17 | if(autoStart) { 18 | int16_t state = _phy->transmitDirect(); 19 | RADIOLIB_ASSERT(state); 20 | } 21 | 22 | Module::tone(_pin, freq); 23 | return(ERR_NONE); 24 | } 25 | 26 | int16_t AFSKClient::noTone() { 27 | Module::noTone(_pin); 28 | return(_phy->standby()); 29 | } 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/protocols/AFSK/AFSK.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_AFSK_H) 2 | #define _RADIOLIB_AFSK_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_AFSK) 7 | 8 | #include "../../Module.h" 9 | 10 | #include "../PhysicalLayer/PhysicalLayer.h" 11 | 12 | /*! 13 | \class AFSKClient 14 | 15 | \brief Client for audio-based transmissions. Requires Arduino tone() function, and a module capable of direct mode transmission using DIO pins. 16 | */ 17 | class AFSKClient { 18 | public: 19 | /*! 20 | \brief Default contructor. 21 | 22 | \param phy Pointer to the wireless module providing PhysicalLayer communication. 23 | 24 | \param pin The pin that will be used for audio output. 25 | */ 26 | AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin); 27 | 28 | /*! 29 | \brief Initialization method. 30 | 31 | \returns \ref status_codes 32 | */ 33 | int16_t begin(); 34 | 35 | /*! 36 | \brief Start transmitting audio tone. 37 | 38 | \param freq Frequency of the tone in Hz. 39 | 40 | \param autoStart Whether to automatically enter transmission mode. Defaults to true. 41 | 42 | \returns \ref status_codes 43 | */ 44 | int16_t tone(uint16_t freq, bool autoStart = true); 45 | 46 | /*! 47 | \brief Stops transmitting audio tone. 48 | 49 | \returns \ref status_codes 50 | */ 51 | int16_t noTone(); 52 | 53 | #ifndef RADIOLIB_GODMODE 54 | private: 55 | #endif 56 | PhysicalLayer* _phy; 57 | RADIOLIB_PIN_TYPE _pin; 58 | 59 | // allow specific classes access the private PhysicalLayer pointer 60 | friend class RTTYClient; 61 | friend class MorseClient; 62 | friend class HellClient; 63 | friend class SSTVClient; 64 | friend class AX25Client; 65 | friend class FSK4Client; 66 | }; 67 | 68 | #endif 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /src/protocols/FSK4/FSK4.cpp: -------------------------------------------------------------------------------- 1 | #include "FSK4.h" 2 | #if !defined(RADIOLIB_EXCLUDE_FSK4) 3 | 4 | FSK4Client::FSK4Client(PhysicalLayer* phy) { 5 | _phy = phy; 6 | #if !defined(RADIOLIB_EXCLUDE_AFSK) 7 | _audio = nullptr; 8 | #endif 9 | } 10 | 11 | #if !defined(RADIOLIB_EXCLUDE_AFSK) 12 | FSK4Client::FSK4Client(AFSKClient* audio) { 13 | _phy = audio->_phy; 14 | _audio = audio; 15 | } 16 | #endif 17 | 18 | int16_t FSK4Client::begin(float base, uint32_t shift, uint16_t rate) { 19 | // save configuration 20 | _baseHz = base; 21 | _shiftHz = shift; 22 | 23 | // calculate duration of 1 bit 24 | _bitDuration = (uint32_t)1000000/rate; 25 | 26 | // calculate module carrier frequency resolution 27 | uint32_t step = round(_phy->getFreqStep()); 28 | 29 | // check minimum shift value 30 | if(shift < step / 2) { 31 | return(ERR_INVALID_RTTY_SHIFT); 32 | } 33 | 34 | // round shift to multiples of frequency step size 35 | if(shift % step < (step / 2)) { 36 | _shift = shift / step; 37 | } else { 38 | _shift = (shift / step) + 1; 39 | } 40 | 41 | // Write resultant tones into arrays for quick lookup when modulating. 42 | _tones[0] = 0; 43 | _tones[1] = _shift; 44 | _tones[2] = _shift*2; 45 | _tones[3] = _shift*3; 46 | 47 | _tonesHz[0] = 0; 48 | _tonesHz[1] = _shiftHz; 49 | _tonesHz[2] = _shiftHz*2; 50 | _tonesHz[3] = _shiftHz*3; 51 | 52 | // calculate 24-bit frequency 53 | _base = (base * 1000000.0) / _phy->getFreqStep(); 54 | 55 | // configure for direct mode 56 | return(_phy->startDirect()); 57 | } 58 | 59 | void FSK4Client::idle() { 60 | // Idle at Tone 0. 61 | tone(0); 62 | } 63 | 64 | size_t FSK4Client::write(uint8_t* buff, size_t len) { 65 | size_t n = 0; 66 | for(size_t i = 0; i < len; i++) { 67 | n += FSK4Client::write(buff[i]); 68 | } 69 | FSK4Client::standby(); 70 | return(n); 71 | } 72 | 73 | size_t FSK4Client::write(uint8_t b) { 74 | // send symbols MSB first 75 | for(uint8_t i = 0; i < 4; i++) { 76 | // Extract 4FSK symbol (2 bits) 77 | uint8_t symbol = (b & 0xC0) >> 6; 78 | 79 | // Modulate 80 | FSK4Client::tone(symbol); 81 | 82 | // Shift to next symbol 83 | b = b << 2; 84 | } 85 | 86 | return(1); 87 | } 88 | 89 | void FSK4Client::tone(uint8_t i) { 90 | uint32_t start = Module::micros(); 91 | transmitDirect(_base + _tones[i], _baseHz + _tonesHz[i]); 92 | while(Module::micros() - start < _bitDuration) { 93 | Module::yield(); 94 | } 95 | } 96 | 97 | int16_t FSK4Client::transmitDirect(uint32_t freq, uint32_t freqHz) { 98 | #if !defined(RADIOLIB_EXCLUDE_AFSK) 99 | if(_audio != nullptr) { 100 | return(_audio->tone(freqHz)); 101 | } 102 | #endif 103 | return(_phy->transmitDirect(freq)); 104 | } 105 | 106 | int16_t FSK4Client::standby() { 107 | #if !defined(RADIOLIB_EXCLUDE_AFSK) 108 | if(_audio != nullptr) { 109 | return(_audio->noTone()); 110 | } 111 | #endif 112 | return(_phy->standby()); 113 | } 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /src/protocols/FSK4/FSK4.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_FSK4_H) 2 | #define _RADIOLIB_FSK4_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_FSK4) 7 | 8 | #include "../PhysicalLayer/PhysicalLayer.h" 9 | #include "../AFSK/AFSK.h" 10 | 11 | /*! 12 | \class FSK4Client 13 | 14 | \brief Client for FSK-4 communication. The public interface is the same as Arduino Serial. 15 | */ 16 | class FSK4Client { 17 | public: 18 | /*! 19 | \brief Constructor for FSK-4 mode. 20 | 21 | \param phy Pointer to the wireless module providing PhysicalLayer communication. 22 | */ 23 | explicit FSK4Client(PhysicalLayer* phy); 24 | 25 | #if !defined(RADIOLIB_EXCLUDE_AFSK) 26 | /*! 27 | \brief Constructor for AFSK mode. 28 | 29 | \param audio Pointer to the AFSK instance providing audio. 30 | */ 31 | explicit FSK4Client(AFSKClient* audio); 32 | #endif 33 | 34 | // basic methods 35 | 36 | /*! 37 | \brief Initialization method. 38 | 39 | \param base Base (space) frequency to be used in MHz (in FSK-4 mode), or the space tone frequency in Hz (in AFSK mode) 40 | 41 | \param shift Frequency shift between each tone in Hz. 42 | 43 | \param rate Baud rate to be used during transmission. 44 | 45 | 46 | \returns \ref status_codes 47 | */ 48 | int16_t begin(float base, uint32_t shift, uint16_t rate); 49 | 50 | /*! 51 | \brief Send out idle condition (RF tone at mark frequency). 52 | */ 53 | void idle(); 54 | 55 | size_t write(uint8_t* buff, size_t len); 56 | size_t write(uint8_t b); 57 | 58 | 59 | #ifndef RADIOLIB_GODMODE 60 | private: 61 | #endif 62 | PhysicalLayer* _phy; 63 | #if !defined(RADIOLIB_EXCLUDE_AFSK) 64 | AFSKClient* _audio; 65 | #endif 66 | 67 | uint32_t _base = 0, _baseHz = 0; 68 | uint32_t _shift = 0, _shiftHz = 0; 69 | uint32_t _bitDuration = 0; 70 | uint32_t _tones[4]; 71 | uint32_t _tonesHz[4]; 72 | 73 | void tone(uint8_t i); 74 | 75 | int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0); 76 | int16_t standby(); 77 | }; 78 | 79 | #endif 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/protocols/HTTP/HTTP.h: -------------------------------------------------------------------------------- 1 | #if !defined(_RADIOLIB_HTTP_H) 2 | #define _RADIOLIB_HTTP_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | #if !defined(RADIOLIB_EXCLUDE_HTTP) 7 | 8 | #include "../TransportLayer/TransportLayer.h" 9 | 10 | /*! 11 | \class HTTPClient 12 | 13 | \brief Client for simple HTTP communication. 14 | */ 15 | class HTTPClient { 16 | public: 17 | /*! 18 | \brief Default constructor. 19 | 20 | \param tl Pointer to the wireless module providing TransportLayer communication. 21 | 22 | \param port Port to be used for HTTP. Defaults to 80. 23 | */ 24 | explicit HTTPClient(TransportLayer* tl, uint16_t port = 80); 25 | 26 | /*! 27 | \brief Sends HTTP GET request. 28 | 29 | \param url URL to send the request to. 30 | 31 | \param response Arduino String object that will save the response. 32 | 33 | \returns \ref status_codes 34 | */ 35 | int16_t get(String& url, String& response); 36 | 37 | /*! 38 | \brief Sends HTTP GET request. 39 | 40 | \param url URL to send the request to. 41 | 42 | \param response Arduino String object that will save the response. 43 | 44 | \returns \ref status_codes 45 | */ 46 | int16_t get(const char* url, String& response); 47 | 48 | /*! 49 | \brief Sends HTTP POST request. 50 | 51 | \param url URL to send the request to. 52 | 53 | \param content Request content. 54 | 55 | \param response Arduino String object that will save the response. 56 | 57 | \param contentType MIME type of request content. Defaults to "text/plain". 58 | 59 | \returns \ref status_codes 60 | */ 61 | int16_t post(const char* url, const char* content, String& response, const char* contentType = "text/plain"); 62 | 63 | #ifndef RADIOLIB_GODMODE 64 | private: 65 | #endif 66 | TransportLayer* _tl; 67 | 68 | uint16_t _port; 69 | }; 70 | 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/protocols/TransportLayer/TransportLayer.h: -------------------------------------------------------------------------------- 1 | #ifndef _RADIOLIB_TRANSPORT_LAYER_H 2 | #define _RADIOLIB_TRANSPORT_LAYER_H 3 | 4 | #include "../../TypeDef.h" 5 | 6 | /*! 7 | \class TransportLayer 8 | 9 | \brief Provides common interface for protocols that run on modules with Internet connectivity, such as HTTP or MQTT. 10 | Because this class is used mainly as interface, all of its virtual members must be implemented in the module class. 11 | */ 12 | class TransportLayer { 13 | public: 14 | // constructor 15 | // this class is purely virtual and does not require explicit constructor 16 | 17 | // basic methods 18 | 19 | /*! 20 | \brief Open transport layer connection. 21 | 22 | \param host Host to connect to. 23 | 24 | \param protocol Transport protocol to use. Usually "TCP" or "UDP". 25 | 26 | \param port to be used for the connection. 27 | 28 | \param tcpKeepAlive TCP keep alive interval. Defaults to 0. 29 | 30 | \returns \ref status_codes 31 | */ 32 | virtual int16_t openTransportConnection(const char* host, const char* protocol, uint16_t port, uint16_t tcpKeepAlive = 0) = 0; 33 | 34 | /*! 35 | \brief Close transport layer connection. 36 | 37 | \returns \ref status_codes 38 | */ 39 | virtual int16_t closeTransportConnection() = 0; 40 | 41 | /*! 42 | \brief Send string-based data. 43 | 44 | \param string String data to be sent. 45 | 46 | \returns \ref status_codes 47 | */ 48 | virtual int16_t send(const char* data) = 0; 49 | 50 | /*! 51 | \brief Send arbitrary binary data. 52 | 53 | \param data Data to be sent. 54 | 55 | \param len Number of bytes to send. 56 | 57 | \returns \ref status_codes 58 | */ 59 | virtual int16_t send(uint8_t* data, size_t len) = 0; 60 | 61 | /*! 62 | \brief Receive data. 63 | 64 | \param data Pointer to array to save the received data. 65 | 66 | \param len Number of bytes to read. 67 | 68 | \param timeout Reception timeout in ms. Defaults to 10000. 69 | 70 | \returns \ref status_codes 71 | */ 72 | virtual size_t receive(uint8_t* data, size_t len, uint32_t timeout = 10000) = 0; 73 | 74 | /*! 75 | \brief Get number of received bytes. 76 | 77 | \param timeout Reception timeout in ms. Defaults to 10000. 78 | 79 | \param minBytes Minimum required number of bytes that must be received. 80 | 81 | \returns Number of received bytes, or 0 on timeout. 82 | */ 83 | virtual size_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10) = 0; 84 | }; 85 | 86 | #endif 87 | --------------------------------------------------------------------------------