RF24Network Send example program. Tested on Nucleo-F411.

Dependencies:   RF24 RF24Network mbed

Revision:
2:926b93a68399
Parent:
1:5be48a9550c3
Child:
3:d605536db315
--- a/main.cpp	Mon Jul 06 04:03:48 2015 +0000
+++ b/main.cpp	Mon Jul 06 05:24:49 2015 +0000
@@ -1,30 +1,28 @@
 #include "mbed.h"
 #include <RF24Network.h>
-#include <nRF24L01P_Maniacbug.h>
+#include <RF24.h>
 
 Serial pc(USBTX, USBRX);
 
 #define nrf_CE      D9
 #define nrf_CSN     D10
-#define nrf_IRQ     PB_0
 #define spi_SCK     D3
 #define spi_MOSI    D4
 #define spi_MISO    D5
 
-//RF24 radio(D11, D12, D13, D10, D9);
 RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CSN, nrf_CE);
 
 // Network uses that radio
 RF24Network network(radio);
 
 // Address of our node
-const uint16_t this_node = 1;
+const uint16_t this_node = 0;
 
 // Address of the other node
-const uint16_t other_node = 0;
+const uint16_t other_node = 1;
 
-// How often to send 'hello world to the other unit
-const unsigned long interval = 100; //ms
+// How often to send payload packet to the other unit
+const unsigned long interval = 1000; //ms
 
 // When did we last send?
 unsigned long last_sent;
@@ -35,69 +33,56 @@
 Timer t_packet;
 
 // Structure of our payload
-struct payload_t
+struct payload_t 
 {
-  unsigned long ms;
-  unsigned long counter;
-  
-  float vector_4d[4];
+    unsigned long ms;
+    unsigned long counter;
+
+    float vector_4d[4];
 };
 
 
-int main() 
+int main()
 {
     pc.baud(921600);
     wait_ms(1000);
-    
-    
-    
-    pc.printf("mBed RF24 network node - Rx only\n");
+
+    pc.printf("mBed RF24Network node: Tx\n");
     radio.begin();
     network.begin(/*channel*/ 90, /*node address*/ this_node);
     wait_ms(2000);
     t.start();
     t_packet.start();
-    while(1)
+    while(1) 
     {
         // Pump the network regularly
         network.update();
-  
-        // Is there anything ready for us?
-        while ( network.available() )
-        {
-            // If so, grab it and print it out
-            RF24NetworkHeader header_rx;
-            payload_t payload_rx;
-            network.read(header_rx,&payload_rx,sizeof(payload_rx));
-            pc.printf("Received packet # %d at %d ms, message: V4 %f, %f, %f, %f \n",payload_rx.counter,payload_rx.ms, payload_rx.vector_4d[0],payload_rx.vector_4d[1],payload_rx.vector_4d[2],payload_rx.vector_4d[3]);
-        }
-        
+
         /* If it's time to send a message, send it! */
         unsigned long now = t.read_ms();
-        if ( now >= interval  )
+        if ( now >= interval  ) 
         {
             t.reset();
 
             pc.printf("Sending...");
-            //payload_t payload_tx = { millis(), packets_sent++, "Hello from node 0" };
             payload_t payload_tx;
             payload_tx.ms = t_packet.read_ms();
             payload_tx.counter = packets_sent++;
-            for(int i=0;i<=3;i++)
+            for(int i=0; i<=3; i++) 
             {
                 payload_tx.vector_4d[i] = i + 1.00f;
             }
-    
-    
+
+
             RF24NetworkHeader header_tx(/*to node*/ other_node);
             bool ok = network.write(header_tx,&payload_tx,sizeof(payload_tx));
             if (ok)
-            pc.printf("ok.\n");
+                pc.printf("ok.\n");
             else
-            pc.printf("failed.\n");
-        } 
-        
-        
+                pc.printf("failed.\n");
+        }
+
+
     }
-        
+
 }
\ No newline at end of file