Grove ear clip sensor and ESP 8266 Wi-Fi module on FRDM-K64F over Thingspeak Server Cloud

Dependencies:   mbed GroveEarbudSensor ESP8266_eduvance_shield

Files at this revision

API Documentation at this revision

Comitter:
bhshruthi92
Date:
Sun Dec 02 20:37:25 2018 +0000
Commit message:
Uses Grove ear clip sensor and ESP 8266 Wi-Fi module on FRDM-K64F and sent to patient using Thingspeak Server cloud.

Changed in this revision

ESP8266.lib Show annotated file Show diff for this revision Revisions of this file
GroveEarbudSensor.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ESP8266.lib	Sun Dec 02 20:37:25 2018 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/naray23/code/ESP8266_eduvance_shield/#9f5d26a20e0e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GroveEarbudSensor.lib	Sun Dec 02 20:37:25 2018 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/ansond/code/GroveEarbudSensor/#8687d42d6798
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Dec 02 20:37:25 2018 +0000
@@ -0,0 +1,152 @@
+#include "mbed.h"
+#include "ESP8266.h"
+#include <string.h>
+#include <stdio.h>
+#include "GroveEarbudSensor.h"
+
+#define APIKEY SJYFHXQEDBQ75N91    //Put "Write key" of your channel in thingspeak.com 
+#define IP "184.106.153.149"       // IP Address of "api.thingspeak.com\"
+#define WIFI_SSID "BHNTG1682GF6C2"
+#define WIFI_PASS "ef8df304"
+#define sendnumber "3178208811"
+
+char snd[255],rcv[1000],snd_Data[255];
+float hrt;
+
+ESP8266 esp(PTC17, PTC16, 115200); // baud rate for wifi
+Serial pc(USBTX, USBRX);
+
+// callback for receiving heartrate values 
+void heartrateCallback(float heartrate,void *data) 
+{
+         printf("Callback: heartrate = %.1f\r\n",heartrate);
+}  
+
+// Blinky
+DigitalOut led(LED1);
+
+// Our sensor as an InterruptIn
+InterruptIn sensor(D2);
+
+GroveEarbudSensor earbud(&sensor); 
+
+void esp_initialize(void);
+void esp_send(void);
+
+int main(void)
+{   
+pc.baud(115200);
+    esp_initialize();
+    
+    // announce
+    printf("Grove Earbud Sensor Example v1.0.0\r\n");
+    
+    // allocate the earbud sensor
+    printf("Allocating earbud sensor instance...\r\n");
+    
+     // register our callback function     
+     printf("registering callback...\r\n");     
+     earbud.registerCallback(heartrateCallback); 
+    
+    // begin main loop
+    printf("Beginning main loop...\r\n");
+    while (true) 
+    {
+        // blink... 
+        led = !led; 
+        wait(1);
+           
+    // we can also call directly 
+ printf("Direct: heartrate = %.1f\r\n", earbud.getHeartRate());
+ 
+ }
+ }
+void esp_initialize(void)
+{
+    pc.printf("Initializing ESP\r\n");
+
+    pc.printf("Reset ESP\r\n");
+    esp.Reset();                   //RESET ESP
+    esp.RcvReply(rcv, 400);        //receive a response from ESP
+    wait(2);
+
+    strcpy(snd,"AT");
+    esp.SendCMD(snd);
+    pc.printf(snd);
+    esp.RcvReply(rcv, 400);
+    pc.printf(rcv);
+    wait(0.1);
+
+    strcpy(snd,"AT+CWMODE=1");
+    esp.SendCMD(snd);
+    pc.printf(snd);
+    wait(2);
+
+    strcpy(snd,"AT+CWJAP=\"");
+    strcat(snd,WIFI_SSID);
+    strcat(snd,"\",\"");
+    strcat(snd,WIFI_PASS);
+    strcat(snd,"\"");
+
+
+    esp.SendCMD(snd);
+    pc.printf(snd);
+    wait(5);
+    esp.RcvReply(rcv, 400);
+    pc.printf("\n %s \n", rcv);
+
+    strcpy(snd,"AT+CIPMUX=1");
+    esp.SendCMD(snd);
+    pc.printf(snd);
+    esp.RcvReply(rcv, 400);
+    pc.printf("\n %s \n", rcv);
+
+}
+void esp_send(void)
+{
+    //ESP updates the Status of Thingspeak channel//
+
+    strcpy(snd,"AT+CIPSTART=");
+    strcat(snd,"\"TCP\",\"");
+    strcat(snd,IP);
+    strcat(snd,"\",80");
+
+    esp.SendCMD(snd);
+    pc.printf("Send\r\n%s",snd);
+    esp.RcvReply(rcv, 1000);
+    pc.printf("Receive\r\n%s",rcv);
+    wait(1);
+
+    hrt = earbud.getHeartRate();
+    pc.printf("Sending this data to thingspeak.com \r \n");
+    sprintf(snd,"GET https://api.thingspeak.com/update?api_key=SJYFHXQEDBQ75N91&field1=%f\r\n", hrt);
+
+    int i=0;
+    for(i=0; snd[i]!='\0'; i++);
+    i++;
+    char cmd[255];
+
+    sprintf(cmd,"AT+CIPSEND=%d",i);           //Send Number of open connection and Characters to send
+    esp.SendCMD(cmd);
+    pc.printf("Send\r\n%s",cmd);
+    while(i<=20 || rcv == ">")
+ {
+        esp.RcvReply(rcv, 1000);
+        wait(100);
+        i++;
+    }
+    pc.printf("Receive\r\n%s",rcv);
+
+    esp.SendCMD(snd);       //Post value to thingspeak channel
+    pc.printf("Send\r\n%s",snd);
+
+    while(i<=20 || rcv == "OK") 
+    {
+        esp.RcvReply(rcv, 1000);
+        wait(100);
+        i++;
+    }
+    pc.printf("Receive\r\n%s",rcv);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Dec 02 20:37:25 2018 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/97feb9bacc10
\ No newline at end of file