Test program for RFM69 library. Listens and prints packets from "RFM69_Sender" nodes

Dependencies:   mbed RFM69

Revision:
0:52becca880bd
Child:
1:7bc722e656a5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Listener.cpp	Thu Feb 26 04:21:40 2015 +0000
@@ -0,0 +1,74 @@
+// Listener - print sender messages
+// From Tnode/Tsender @ anarduino.com
+// 2014 - anarduino.com
+//
+#include <RFM69.h>
+#include <SPI.h>
+
+#define GATEWAY_ID    1     // this is ME, TGateway
+#define NETWORKID     101   //the same on all nodes that talk to each other
+
+// Uncomment only one of the following three to match radio frequency
+//#define FREQUENCY     RF69_433MHZ    
+//#define FREQUENCY     RF69_868MHZ
+#define FREQUENCY     RF69_915MHZ
+
+//#define IS_RFM69HW   //NOTE: uncomment this ONLY for RFM69HW or RFM69HCW
+#define ENCRYPT_KEY    "EncryptKey123456"  // use same 16byte encryption key for all devices on net
+#define ACK_TIME       50                  // max msec for ACK wait
+#define LED            9                   // Anardino miniWireless has LEDs on D9
+#define SERIAL_BAUD    115200
+#define VERSION  "1.0"
+
+#define MSGBUFSIZE 64   // message buffersize, but for this demo we only use: 
+                        // 1-byte NODEID + 4-bytes for time + 1-byte for temp in C + 2-bytes for vcc(mV)
+uint8_t msgBuf[MSGBUFSIZE];
+InterruptIn mybutton(USER_BUTTON);
+DigitalOut myled(D9);
+
+//Serial pc(SERIAL_TX, SERIAL_RX);
+Serial pc(USBTX, USBRX);
+//RFM69::RFM69(PinName mosi, PinName miso, PinName sclk,PinName slaveSelectPin,PinName interrupt)
+RFM69 radio(D11,D12,D13,D10,D8);
+bool promiscuousMode = false; // set 'true' to sniff all packets on the same network
+bool requestACK=false;
+Timer tmr;
+#pragma pack(1)
+union itag {
+  uint8_t b[2];
+  uint16_t i;
+}it;
+union ltag {
+  uint8_t b[4];
+  long l;
+}lt; // used to force byte order in case we end up using result in various endian targets...
+
+main() {
+  memset(msgBuf,0,sizeof(msgBuf));
+  uint8_t theNodeID;
+  tmr.start();
+
+   pc.baud(SERIAL_BAUD);
+  pc.printf("\r\nListener %s startup at %d Mhz...\r\n",VERSION,(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915));
+  wait(1);
+  radio.initialize(FREQUENCY, GATEWAY_ID, NETWORKID);
+  radio.encrypt(0);
+  radio.promiscuous(promiscuousMode);
+  radio.setPowerLevel(5);
+#ifdef IS_RFM69HW
+  radio.setHighPower(); //uncomment #define ONLY if radio is of type: RFM69HW or RFM69HCW 
+#endif
+
+while(1) {
+  if (radio.receiveDone()) {
+     pc.printf("Received from TNODE: %d ",radio.SENDERID);
+     pc.printf((char*)radio.DATA);
+     if (radio.ACKRequested()){
+        theNodeID = radio.SENDERID;
+        radio.sendACK();
+        pc.printf(" - ACK sent. Receive RSSI: %d\r\n",radio.RSSI);
+     } else pc.printf("Receive RSSI: %d\r\n",radio.RSSI);
+  }
+         myled = !myled; 
+ }
+}
\ No newline at end of file