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_AES.ino (2341B)
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 <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 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 == RADIOLIB_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 == RADIOLIB_ERR_RX_TIMEOUT) { 79 // timeout occurred while waiting for a packet 80 Serial.println(F("timeout!")); 81 82 } else if (state == RADIOLIB_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 }