[RF69] Updated examples
This commit is contained in:
parent
8fbfb68749
commit
a49f1da093
9 changed files with 167 additions and 36 deletions
|
@ -2,13 +2,29 @@
|
||||||
RadioLib RF69 Receive Example
|
RadioLib RF69 Receive Example
|
||||||
|
|
||||||
This example receives packets using RF69 FSK radio module.
|
This example receives packets using RF69 FSK radio module.
|
||||||
|
To successfully receive data, the following settings have to be the same
|
||||||
|
on both transmitter and receiver:
|
||||||
|
- carrier frequency
|
||||||
|
- bit rate
|
||||||
|
- frequency deviation
|
||||||
|
- sync word
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 module is in slot A on the shield
|
// RF69 has the following connections:
|
||||||
RF69 rf = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO0 pin: 2
|
||||||
|
// DIO1 pin: 3
|
||||||
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//RF69 rf = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -60,5 +76,10 @@ void loop() {
|
||||||
// packet was received, but is malformed
|
// packet was received, but is malformed
|
||||||
Serial.println(F("CRC error!"));
|
Serial.println(F("CRC error!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,23 @@
|
||||||
This example receives packets using RF69 FSK radio module.
|
This example receives packets using RF69 FSK radio module.
|
||||||
Packets are decrypted using hardware AES.
|
Packets are decrypted using hardware AES.
|
||||||
NOTE: When using address filtering, the address byte is NOT encrypted!
|
NOTE: When using address filtering, the address byte is NOT encrypted!
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 module is in slot A on the shield
|
// RF69 has the following connections:
|
||||||
RF69 rf = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO0 pin: 2
|
||||||
|
// DIO1 pin: 3
|
||||||
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//RF69 rf = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -35,8 +45,7 @@ void setup() {
|
||||||
// set AES key that will be used to decrypt the packet
|
// set AES key that will be used to decrypt the packet
|
||||||
// NOTE: the key must be exactly 16 bytes long!
|
// NOTE: the key must be exactly 16 bytes long!
|
||||||
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
|
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
|
||||||
};
|
|
||||||
rf.setAESKey(key);
|
rf.setAESKey(key);
|
||||||
|
|
||||||
// enable AES encryption
|
// enable AES encryption
|
||||||
|
@ -77,5 +86,10 @@ void loop() {
|
||||||
// packet was received, but is malformed
|
// packet was received, but is malformed
|
||||||
Serial.println(F("CRC error!"));
|
Serial.println(F("CRC error!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,23 @@
|
||||||
After setting node (or broadcast) address, this node will
|
After setting node (or broadcast) address, this node will
|
||||||
automatically filter out any packets that do not contain
|
automatically filter out any packets that do not contain
|
||||||
either node address or broadcast address.
|
either node address or broadcast address.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 module is in slot A on the shield
|
// RF69 has the following connections:
|
||||||
RF69 rf = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO0 pin: 2
|
||||||
|
// DIO1 pin: 3
|
||||||
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//RF69 rf = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -105,5 +115,10 @@ void loop() {
|
||||||
// packet was received, but is malformed
|
// packet was received, but is malformed
|
||||||
Serial.println(F("CRC error!"));
|
Serial.println(F("CRC error!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,23 @@
|
||||||
This example listens for FSK transmissions and tries to
|
This example listens for FSK transmissions and tries to
|
||||||
receive them. Once a packet is received, an interrupt is
|
receive them. Once a packet is received, an interrupt is
|
||||||
triggered.
|
triggered.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 module is in slot A on the shield
|
// RF69 has the following connections:
|
||||||
RF69 rf = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO0 pin: 2
|
||||||
|
// DIO1 pin: 3
|
||||||
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//RF69 rf = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -103,6 +113,16 @@ void loop() {
|
||||||
// print data of the packet
|
// print data of the packet
|
||||||
Serial.print(F("[RF69] Data:\t\t\t"));
|
Serial.print(F("[RF69] Data:\t\t\t"));
|
||||||
Serial.println(str);
|
Serial.println(str);
|
||||||
|
|
||||||
|
} else if (state == ERR_CRC_MISMATCH) {
|
||||||
|
// packet was received, but is malformed
|
||||||
|
Serial.println(F("CRC error!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we're ready to receive more packets,
|
// we're ready to receive more packets,
|
||||||
|
|
|
@ -10,20 +10,23 @@
|
||||||
- allowed frequency deviation
|
- allowed frequency deviation
|
||||||
- output power during transmission
|
- output power during transmission
|
||||||
- sync word
|
- sync word
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 module is in slot A on the shield
|
// RF69 has the following connections:
|
||||||
RF69 rf1 = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO0 pin: 2
|
||||||
|
// DIO1 pin: 3
|
||||||
|
RF69 rf1 = new Module(10, 2, 3);
|
||||||
|
|
||||||
// if you're not using RadioShield, you can specify
|
// or using RadioShield
|
||||||
// the connection yourself
|
// https://github.com/jgromes/RadioShield
|
||||||
// NSS pin: 6
|
RF69 rf2 = RadioShield.ModuleB;
|
||||||
// DIO0 pin: 4
|
|
||||||
// DIO1 pin: 5
|
|
||||||
RF69 rf2 = new Module(6, 4, 5);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
|
@ -2,13 +2,27 @@
|
||||||
RadioLib RF69 Transmit Example
|
RadioLib RF69 Transmit Example
|
||||||
|
|
||||||
This example transmits packets using RF69 FSK radio module.
|
This example transmits packets using RF69 FSK radio module.
|
||||||
|
Each packet contains up to 64 bytes of data, in the form of:
|
||||||
|
- Arduino String
|
||||||
|
- null-terminated char array (C-string)
|
||||||
|
- arbitrary binary data (byte array)
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 module is in slot A on the shield
|
// RF69 has the following connections:
|
||||||
RF69 rf = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO0 pin: 2
|
||||||
|
// DIO1 pin: 3
|
||||||
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//RF69 rf = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -51,6 +65,11 @@ void loop() {
|
||||||
// the supplied packet was longer than 64 bytes
|
// the supplied packet was longer than 64 bytes
|
||||||
Serial.println(F(" too long!"));
|
Serial.println(F(" too long!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for a second before transmitting again
|
// wait for a second before transmitting again
|
||||||
|
|
|
@ -4,13 +4,23 @@
|
||||||
This example transmits packets using RF69 FSK radio module.
|
This example transmits packets using RF69 FSK radio module.
|
||||||
Packets are encrypted using hardware AES.
|
Packets are encrypted using hardware AES.
|
||||||
NOTE: When using address filtering, the address byte is NOT encrypted!
|
NOTE: When using address filtering, the address byte is NOT encrypted!
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 module is in slot A on the shield
|
// RF69 has the following connections:
|
||||||
RF69 rf = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO0 pin: 2
|
||||||
|
// DIO1 pin: 3
|
||||||
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//RF69 rf = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -35,8 +45,7 @@ void setup() {
|
||||||
// set AES key to encrypt the packet
|
// set AES key to encrypt the packet
|
||||||
// NOTE: the key must be exactly 16 bytes long!
|
// NOTE: the key must be exactly 16 bytes long!
|
||||||
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
|
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
|
||||||
};
|
|
||||||
rf.setAESKey(key);
|
rf.setAESKey(key);
|
||||||
|
|
||||||
// enable AES encryption
|
// enable AES encryption
|
||||||
|
@ -65,9 +74,14 @@ void loop() {
|
||||||
Serial.println(F(" success!"));
|
Serial.println(F(" success!"));
|
||||||
|
|
||||||
} else if (state == ERR_PACKET_TOO_LONG) {
|
} else if (state == ERR_PACKET_TOO_LONG) {
|
||||||
// the supplied packet was longer than 256 bytes
|
// the supplied packet was longer than 64 bytes
|
||||||
Serial.println(F(" too long!"));
|
Serial.println(F(" too long!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for a second before transmitting again
|
// wait for a second before transmitting again
|
||||||
|
|
|
@ -6,13 +6,23 @@
|
||||||
After setting node (or broadcast) address, this node will
|
After setting node (or broadcast) address, this node will
|
||||||
automatically filter out any packets that do not contain
|
automatically filter out any packets that do not contain
|
||||||
either node address or broadcast address.
|
either node address or broadcast address.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 module is in slot A on the shield
|
// RF69 has the following connections:
|
||||||
RF69 rf = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO0 pin: 2
|
||||||
|
// DIO1 pin: 3
|
||||||
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//RF69 rf = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -35,7 +45,7 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set node address
|
// set node address
|
||||||
// NOTE: calling this method will autmatically enable
|
// NOTE: calling this method will automatically enable
|
||||||
// address filtering (node address only)
|
// address filtering (node address only)
|
||||||
Serial.print(F("[RF69] Setting node address ... "));
|
Serial.print(F("[RF69] Setting node address ... "));
|
||||||
state = rf.setNodeAddress(0x01);
|
state = rf.setNodeAddress(0x01);
|
||||||
|
@ -104,9 +114,14 @@ void loop() {
|
||||||
Serial.println(F(" success!"));
|
Serial.println(F(" success!"));
|
||||||
|
|
||||||
} else if (state == ERR_PACKET_TOO_LONG) {
|
} else if (state == ERR_PACKET_TOO_LONG) {
|
||||||
// the supplied packet was longer than 256 bytes
|
// the supplied packet was longer than 64 bytes
|
||||||
Serial.println(F(" too long!"));
|
Serial.println(F(" too long!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for a second before transmitting again
|
// wait for a second before transmitting again
|
||||||
|
|
|
@ -7,13 +7,23 @@
|
||||||
- Arduino String
|
- Arduino String
|
||||||
- null-terminated char array (C-string)
|
- null-terminated char array (C-string)
|
||||||
- arbitrary binary data (byte array)
|
- arbitrary binary data (byte array)
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 module is in slot A on the shield
|
// RF69 has the following connections:
|
||||||
RF69 rf = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO0 pin: 2
|
||||||
|
// DIO1 pin: 3
|
||||||
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//RF69 rf = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -70,7 +80,7 @@ void setFlag(void) {
|
||||||
void loop() {
|
void loop() {
|
||||||
// check if the previous transmission finished
|
// check if the previous transmission finished
|
||||||
if(transmittedFlag) {
|
if(transmittedFlag) {
|
||||||
Serial.println(F("[RF69] Packet transmission finished!"));
|
Serial.println(F("packet transmission finished!"));
|
||||||
|
|
||||||
// wait one second before next transmission
|
// wait one second before next transmission
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
Loading…
Add table
Reference in a new issue