![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Test program for RFM69 library. Listens and prints packets from "RFM69_Sender" nodes
Listener.cpp@1:7bc722e656a5, 2015-02-26 (annotated)
- Committer:
- br549
- Date:
- Thu Feb 26 14:52:03 2015 +0000
- Revision:
- 1:7bc722e656a5
- Parent:
- 0:52becca880bd
- Child:
- 2:08246d6498ce
Clean up compiler check for various Mbeds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
br549 | 0:52becca880bd | 1 | // Listener - print sender messages |
br549 | 0:52becca880bd | 2 | // From Tnode/Tsender @ anarduino.com |
br549 | 0:52becca880bd | 3 | // 2014 - anarduino.com |
br549 | 0:52becca880bd | 4 | // |
br549 | 0:52becca880bd | 5 | #include <RFM69.h> |
br549 | 0:52becca880bd | 6 | #include <SPI.h> |
br549 | 0:52becca880bd | 7 | |
br549 | 0:52becca880bd | 8 | #define GATEWAY_ID 1 // this is ME, TGateway |
br549 | 0:52becca880bd | 9 | #define NETWORKID 101 //the same on all nodes that talk to each other |
br549 | 0:52becca880bd | 10 | |
br549 | 0:52becca880bd | 11 | // Uncomment only one of the following three to match radio frequency |
br549 | 0:52becca880bd | 12 | //#define FREQUENCY RF69_433MHZ |
br549 | 0:52becca880bd | 13 | //#define FREQUENCY RF69_868MHZ |
br549 | 0:52becca880bd | 14 | #define FREQUENCY RF69_915MHZ |
br549 | 0:52becca880bd | 15 | |
br549 | 0:52becca880bd | 16 | //#define IS_RFM69HW //NOTE: uncomment this ONLY for RFM69HW or RFM69HCW |
br549 | 0:52becca880bd | 17 | #define ENCRYPT_KEY "EncryptKey123456" // use same 16byte encryption key for all devices on net |
br549 | 0:52becca880bd | 18 | #define ACK_TIME 50 // max msec for ACK wait |
br549 | 0:52becca880bd | 19 | #define LED 9 // Anardino miniWireless has LEDs on D9 |
br549 | 0:52becca880bd | 20 | #define SERIAL_BAUD 115200 |
br549 | 0:52becca880bd | 21 | #define VERSION "1.0" |
br549 | 0:52becca880bd | 22 | |
br549 | 0:52becca880bd | 23 | #define MSGBUFSIZE 64 // message buffersize, but for this demo we only use: |
br549 | 0:52becca880bd | 24 | // 1-byte NODEID + 4-bytes for time + 1-byte for temp in C + 2-bytes for vcc(mV) |
br549 | 0:52becca880bd | 25 | uint8_t msgBuf[MSGBUFSIZE]; |
br549 | 0:52becca880bd | 26 | InterruptIn mybutton(USER_BUTTON); |
br549 | 0:52becca880bd | 27 | |
br549 | 1:7bc722e656a5 | 28 | #ifdef TARGET_NUCLEO_F401RE |
br549 | 1:7bc722e656a5 | 29 | Serial pc(USBTX, USBRX); |
br549 | 1:7bc722e656a5 | 30 | DigitalOut myled(D9); //"Moteino Half Shield" has LED on D9 |
br549 | 1:7bc722e656a5 | 31 | //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int) |
br549 | 1:7bc722e656a5 | 32 | RFM69 radio(D11,D12,D13,D10,D8); |
br549 | 1:7bc722e656a5 | 33 | #elif defined(TARGET_NUCLEO_L152RE) |
br549 | 0:52becca880bd | 34 | Serial pc(USBTX, USBRX); |
br549 | 1:7bc722e656a5 | 35 | DigitalOut myled(D9); //"Moteino Half Shield" has LED on D9 |
br549 | 1:7bc722e656a5 | 36 | //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int) |
br549 | 0:52becca880bd | 37 | RFM69 radio(D11,D12,D13,D10,D8); |
br549 | 1:7bc722e656a5 | 38 | #elif defined(TARGET_LPC1114) |
br549 | 1:7bc722e656a5 | 39 | Serial pc(USBTX, USBRX); |
br549 | 1:7bc722e656a5 | 40 | DigitalOut myled(LED1); |
br549 | 1:7bc722e656a5 | 41 | //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int) |
br549 | 1:7bc722e656a5 | 42 | RFM69 radio(dp2,dp1,dp6,dp4,dp9); |
br549 | 1:7bc722e656a5 | 43 | #elif defined(TARGET_LPC1768) |
br549 | 1:7bc722e656a5 | 44 | Serial pc(USBTX, USBRX); |
br549 | 1:7bc722e656a5 | 45 | DigitalOut myled(D9); //"Moteino Half Shield" has LED on D9 |
br549 | 1:7bc722e656a5 | 46 | //RFM69::RFM69(PinName PinName mosi, PinName miso, PinName sclk,slaveSelectPin, PinName int) |
br549 | 1:7bc722e656a5 | 47 | RFM69 radio(D11,D12,D13,D10,D8); // Seeedstudio Arch Pro |
br549 | 1:7bc722e656a5 | 48 | //RFM69 radio(p5, p6, p7, p10, p9,p8) // Mbed 1768 ? |
br549 | 1:7bc722e656a5 | 49 | #endif |
br549 | 0:52becca880bd | 50 | bool promiscuousMode = false; // set 'true' to sniff all packets on the same network |
br549 | 0:52becca880bd | 51 | bool requestACK=false; |
br549 | 0:52becca880bd | 52 | Timer tmr; |
br549 | 0:52becca880bd | 53 | |
br549 | 0:52becca880bd | 54 | main() { |
br549 | 0:52becca880bd | 55 | memset(msgBuf,0,sizeof(msgBuf)); |
br549 | 0:52becca880bd | 56 | uint8_t theNodeID; |
br549 | 0:52becca880bd | 57 | tmr.start(); |
br549 | 0:52becca880bd | 58 | |
br549 | 0:52becca880bd | 59 | pc.baud(SERIAL_BAUD); |
br549 | 0:52becca880bd | 60 | pc.printf("\r\nListener %s startup at %d Mhz...\r\n",VERSION,(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915)); |
br549 | 0:52becca880bd | 61 | wait(1); |
br549 | 0:52becca880bd | 62 | radio.initialize(FREQUENCY, GATEWAY_ID, NETWORKID); |
br549 | 0:52becca880bd | 63 | radio.encrypt(0); |
br549 | 0:52becca880bd | 64 | radio.promiscuous(promiscuousMode); |
br549 | 1:7bc722e656a5 | 65 | // radio.setPowerLevel(5); |
br549 | 0:52becca880bd | 66 | #ifdef IS_RFM69HW |
br549 | 0:52becca880bd | 67 | radio.setHighPower(); //uncomment #define ONLY if radio is of type: RFM69HW or RFM69HCW |
br549 | 0:52becca880bd | 68 | #endif |
br549 | 0:52becca880bd | 69 | |
br549 | 0:52becca880bd | 70 | while(1) { |
br549 | 0:52becca880bd | 71 | if (radio.receiveDone()) { |
br549 | 0:52becca880bd | 72 | pc.printf("Received from TNODE: %d ",radio.SENDERID); |
br549 | 0:52becca880bd | 73 | pc.printf((char*)radio.DATA); |
br549 | 0:52becca880bd | 74 | if (radio.ACKRequested()){ |
br549 | 0:52becca880bd | 75 | theNodeID = radio.SENDERID; |
br549 | 0:52becca880bd | 76 | radio.sendACK(); |
br549 | 0:52becca880bd | 77 | pc.printf(" - ACK sent. Receive RSSI: %d\r\n",radio.RSSI); |
br549 | 0:52becca880bd | 78 | } else pc.printf("Receive RSSI: %d\r\n",radio.RSSI); |
br549 | 0:52becca880bd | 79 | } |
br549 | 0:52becca880bd | 80 | myled = !myled; |
br549 | 0:52becca880bd | 81 | } |
br549 | 0:52becca880bd | 82 | } |