acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

SX127x_Channel_Activity_Detection.ino (1705B)

      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 <RadioLib.h>
     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 == RADIOLIB_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 == RADIOLIB_PREAMBLE_DETECTED) {
     55     // LoRa preamble was detected
     56     Serial.println(F("detected preamble!"));
     57 
     58   } else if (state == RADIOLIB_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 }