RF24Network Send example program.

Dependencies:   xtoff RF24Network mbed

Fork of RF24Network_Send by Akash Vibhute

Revision:
4:bc1126d78e55
Parent:
3:d605536db315
Child:
5:e6067799a414
diff -r d605536db315 -r bc1126d78e55 main.cpp
--- a/main.cpp	Thu Nov 05 05:59:18 2015 +0000
+++ b/main.cpp	Mon Feb 12 16:50:37 2018 +0000
@@ -1,82 +1,72 @@
 #include "mbed.h"
 #include <RF24Network.h>
 #include <RF24.h>
+#include <string> 
 
 Serial pc(USBTX, USBRX);
 
-#define nrf_CE      D9
-#define nrf_CSN     D10
-#define spi_SCK     D3
-#define spi_MOSI    D4
-#define spi_MISO    D5
+#define nrf_CE      p9
+#define nrf_CSN     p8
+#define spi_SCK     p7
+#define spi_MOSI    p5
+#define spi_MISO    p6
 
 RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN );
-
-// Network uses that radio
 RF24Network network(radio);
 
-// Address of our node
 const uint16_t this_node = 01;
-
-// Address of the other node
 const uint16_t other_node = 00;
-
-// How often to send payload packet to the other unit
 const unsigned long interval = 100; //ms
-
-// When did we last send?
 unsigned long last_sent;
 Timer t;
 
-// How many have we sent already
 unsigned long packets_sent;
 Timer t_packet;
 
+DigitalIn pb(p25);
+
+
 // Structure of our payload
 struct payload_t 
 {
-    unsigned long ms;
-    unsigned long counter;
+    bool reedsensor;
+    int milligram; 
 };
 
 
 int main()
 {
-    pc.baud(921600);
+    pb.mode(PullUp);
+    pc.baud(9600);
     wait_ms(1000);
 
-    pc.printf("mBed RF24Network node: Tx\n");
+    pc.printf("mBed RF24Network node: Tx\n\r");
     radio.begin();
-    network.begin(/*channel*/ 90, /*node address*/ this_node);
+    network.begin(90,this_node);
     wait_ms(2000);
     t.start();
     t_packet.start();
     while(1) 
     {
-        // Pump the network regularly
         network.update();
-
-        /* If it's time to send a message, send it! */
         unsigned long now = t.read_ms();
-        if ( now >= interval  ) 
+        if (!pb) 
         {
             t.reset();
 
             pc.printf("Sending...");
             payload_t payload_tx;
-            payload_tx.ms = t_packet.read_ms();
-            payload_tx.counter = packets_sent++;
+            payload_tx.reedsensor = !pb;
+            payload_tx.milligram = 521000;
 
 
-            RF24NetworkHeader header_tx(/*to node*/ other_node);
+            RF24NetworkHeader header_tx(other_node);
+            
             bool ok = network.write(header_tx,&payload_tx,sizeof(payload_tx));
             if (ok)
-                pc.printf("ok.\n");
+                pc.printf("ok.\n\r");
             else
-                pc.printf("failed.\n");
+                pc.printf("failed.\n\r");
         }
-
-
     }
-
 }
\ No newline at end of file