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_Transmit_AES.ino (2242B)

      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 <RadioLib.h>
     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 == RADIOLIB_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 == RADIOLIB_ERR_NONE) {
     70     // the packet was successfully transmitted
     71     Serial.println(F("success!"));
     72 
     73   } else if (state == RADIOLIB_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 }