NRF24L01P with FRDM KL-25Z as Receiver

Dependencies:   ESP8266 mbed nRF24L01P

Fork of NRFRxCode by Karkhana Makerspace

Files at this revision

API Documentation at this revision

Comitter:
mrbhatter
Date:
Mon Dec 04 09:44:41 2017 +0000
Parent:
0:ec3b5f850a28
Commit message:
NRF and ESP data to thingspeak;

Changed in this revision

ESP8266.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ec3b5f850a28 -r 44646476456d ESP8266.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ESP8266.lib	Mon Dec 04 09:44:41 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/janhavi/code/ESP8266/#4f24e7e803a1
diff -r ec3b5f850a28 -r 44646476456d main.cpp
--- a/main.cpp	Sat Dec 02 05:57:01 2017 +0000
+++ b/main.cpp	Mon Dec 04 09:44:41 2017 +0000
@@ -1,20 +1,131 @@
 #include "mbed.h"
 #include "nRF24L01P.h"
+#include "ESP8266.h"
 
 Serial pc(USBTX, USBRX); // tx, rx
 
 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4);    // MOSI, MISO, SCK, CSN, CE, IRQ
-DigitalOut GreenLED(PTA12);
+DigitalOut GreenLED(LED2);
+
+
+ESP8266 wifi(PTE0, PTE1, 115200);
+
+//buffers for wifi library
+char resp[1000];
+char http_cmd[300], comm[300];
+char count[1];
+int timeout = 8000;
+
+//SSID and password for connection
+#define SSID "TAT"
+#define PASS "tatuniversity"
+
+//Remote IP
+#define IP "184.106.153.149" //  52.202.122.57
+//global variable
+//float potvalue = 0;
+//float litvalue = 0;
+
+//Update key for thingspeak
+char* Update_Key = "P2GMSKA9NY7KV0LW";
+
+
+
+
+void wifi_initialize(void)
+{
+    pc.printf("******** Resetting wifi module ********\r\n");
+    wifi.Reset();
+
+    //wait for 5 seconds for response, else display no response receiveed
+    if (wifi.RcvReply(resp, 5000))
+        pc.printf("%s",resp);
+    else
+        pc.printf("No response");
+
+
+    pc.printf("******** Setting Station mode of wifi with AP ********\r\n");
+    wifi.SetMode(1);    // set transparent  mode
+    if (wifi.RcvReply(resp, timeout))    //receive a response from ESP
+        pc.printf("%s",resp);    //Print the response onscreen
+    else
+        pc.printf("No response while setting mode. \r\n");
+
+
+    pc.printf("******** Joining network with SSID and PASS ********\r\n");
+    wifi.Join(SSID, PASS);
+    if (wifi.RcvReply(resp, timeout))
+        pc.printf("%s",resp);
+    else
+        pc.printf("No response while connecting to network \r\n");
 
 
-int main() {
-    
-    char count[2];
+    pc.printf("******** Getting IP and MAC of module ********\r\n");
+    wifi.GetIP(resp);
+    if (wifi.RcvReply(resp, timeout))
+        pc.printf("%s",resp);
+    else
+        pc.printf("No response while getting IP \r\n");
+
+
+    pc.printf("******** Setting WIFI UART passthrough ********\r\n");
+    wifi.setTransparent();
+    if (wifi.RcvReply(resp, timeout))
+        pc.printf("%s",resp);
+    else
+        pc.printf("No response while setting wifi passthrough. \r\n");
+    wait(1);
+
+
+    pc.printf("******** Setting single connection mode ********\r\n");
+    wifi.SetSingle();
+    wifi.RcvReply(resp, timeout);
+    if (wifi.RcvReply(resp, timeout))
+        pc.printf("%s",resp);
+    else
+        pc.printf("No response while setting single connection \r\n");
+    wait(1);
+}
+
+
+
+
+
+void wifi_send(void)
+{
+    pc.printf("******** Starting TCP connection on IP and port ********\r\n");
+    wifi.startTCPConn(IP,80);    //cipstart
+    wifi.RcvReply(resp, timeout);
+    if (wifi.RcvReply(resp, timeout))
+        pc.printf("%s",resp);
+    else
+        pc.printf("No response while starting TCP connection \r\n");
+    wait(1);
+
+    //create link
+    sprintf(http_cmd,"/update?api_key=%s&field1=%d",Update_Key,count);
+
+    pc.printf(http_cmd);
+
+    pc.printf("******** Sending URL to wifi ********\r\n");
+    wifi.sendURL(http_cmd, comm);   //cipsend and get command
+    if (wifi.RcvReply(resp, timeout))
+        pc.printf("%s",resp);
+    else
+        pc.printf("No response while sending URL \r\n");
+}
+
+
+
+
+
+int main()
+{
     char RxDataCnt;
     char temp;
 
     my_nrf24l01p.powerUp();
-    my_nrf24l01p.setRfFrequency(2410);
+    my_nrf24l01p.setRfFrequency(2500);
 
     // Display the (default) setup of the nRF24L01+ chip
     pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
@@ -23,29 +134,18 @@
     pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
     pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
 
-    pc.printf( "Simple 2 Byte Receiver\r\n" );
-    
     RxDataCnt = 2;
     my_nrf24l01p.setTransferSize( RxDataCnt );
-    
     my_nrf24l01p.setReceiveMode();
     my_nrf24l01p.enable();
-
+    wifi_initialize();
     while (1) {
-
-        // If we've received anything in the nRF24L01+...
-        if ( my_nrf24l01p.readable() ) {
-
-            // ...read the data into the receive buffer
+        //if ( my_nrf24l01p.readable() ) {
             temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt );
-
-
-            pc.printf( "Cnt %d = %d %d\r\n",temp,count[0],count[1]);
-
-
-            // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
-            GreenLED = !GreenLED;
+            pc.printf( "%d\r\n",count[0]);
             wait_ms(10);
-        }
+        //}
+        wifi_send();
+        wait(30);
     }
 }