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

RF69_Receive_Address.ino (3299B)

      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 <RadioLib.h>
     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 == RADIOLIB_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 == RADIOLIB_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 == RADIOLIB_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 == RADIOLIB_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 == RADIOLIB_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 == RADIOLIB_ERR_RX_TIMEOUT) {
    108     // timeout occurred while waiting for a packet
    109     Serial.println(F("timeout!"));
    110 
    111   } else if (state == RADIOLIB_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 }