Heart rate monitoring system design using FRDM K64F and MIT App Inventor II

Dependencies:   ESP8266 GroveEarbudSensor mbed

Fork of Heart-rate-monitor by Sarada Gajjala

Committer:
spriyanka
Date:
Thu May 04 04:24:48 2017 +0000
Revision:
6:37829af7bfbd
Parent:
5:f1b55ff3cda0
Heart rate monitor keeps you informed and indeed helps you monitor your heart rate all the time with which you can protect yourself from being prone to heart attacks or any abnormal heart functionality.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spriyanka 6:37829af7bfbd 1 #include "mbed.h"
spriyanka 6:37829af7bfbd 2 #include "ESP8266.h"
spriyanka 6:37829af7bfbd 3 #include <string>
spriyanka 6:37829af7bfbd 4 #include <stdio.h>
spriyanka 6:37829af7bfbd 5 #include "GroveEarbudSensor.h"
spriyanka 6:37829af7bfbd 6 #define APIKEY SJYFHXQEDBQ75N91 //Put "Write key" of your channel in thingspeak.com
spriyanka 6:37829af7bfbd 7 #define IP "184.106.153.149" // IP Address of "api.thingspeak.com\"
spriyanka 6:37829af7bfbd 8 #define WIFI_SSID "vivo 1601"
spriyanka 6:37829af7bfbd 9 #define WIFI_PASS "bschitta"
spriyanka 6:37829af7bfbd 10
ansond 0:1358c23ecb2e 11
spriyanka 6:37829af7bfbd 12 char snd[255],rcv[1000],snd_Data[255];
spriyanka 6:37829af7bfbd 13 float hrt;
spriyanka 6:37829af7bfbd 14
spriyanka 6:37829af7bfbd 15 ESP8266 esp(PTC17, PTC16, 115200); // baud rate for wifi
spriyanka 6:37829af7bfbd 16 Serial pc(USBTX, USBRX);
spriyanka 6:37829af7bfbd 17
spriyanka 6:37829af7bfbd 18 // callback for receiving heartrate values
spriyanka 6:37829af7bfbd 19 void heartrateCallback(float heartrate,void *data)
spriyanka 6:37829af7bfbd 20 {
spriyanka 6:37829af7bfbd 21 printf("Callback: heartrate = %.1f\r\n",heartrate);
spriyanka 6:37829af7bfbd 22 }
ansond 0:1358c23ecb2e 23
ansond 0:1358c23ecb2e 24 // Blinky
ansond 0:1358c23ecb2e 25 DigitalOut led(LED1);
ansond 0:1358c23ecb2e 26
ansond 0:1358c23ecb2e 27 // Our sensor as an InterruptIn
spriyanka 6:37829af7bfbd 28 InterruptIn sensor(D2);
ansond 0:1358c23ecb2e 29
spriyanka 6:37829af7bfbd 30 GroveEarbudSensor earbud(&sensor);
ansond 0:1358c23ecb2e 31
spriyanka 6:37829af7bfbd 32 void esp_initialize(void);
spriyanka 6:37829af7bfbd 33 void esp_send(void);
ansond 0:1358c23ecb2e 34
spriyanka 6:37829af7bfbd 35 int main(void)
ansond 0:1358c23ecb2e 36 {
spriyanka 6:37829af7bfbd 37 pc.baud(115200);
spriyanka 6:37829af7bfbd 38 esp_initialize();
spriyanka 6:37829af7bfbd 39
ansond 0:1358c23ecb2e 40 // announce
sam_grove 5:f1b55ff3cda0 41 printf("Grove Earbud Sensor Example v1.0.0\r\n");
ansond 0:1358c23ecb2e 42
ansond 0:1358c23ecb2e 43 // allocate the earbud sensor
sam_grove 5:f1b55ff3cda0 44 printf("Allocating earbud sensor instance...\r\n");
ansond 0:1358c23ecb2e 45
spriyanka 6:37829af7bfbd 46 // register our callback function
spriyanka 6:37829af7bfbd 47 printf("registering callback...\r\n");
spriyanka 6:37829af7bfbd 48 earbud.registerCallback(heartrateCallback);
ansond 0:1358c23ecb2e 49
ansond 0:1358c23ecb2e 50 // begin main loop
sam_grove 5:f1b55ff3cda0 51 printf("Beginning main loop...\r\n");
spriyanka 6:37829af7bfbd 52 while (true)
spriyanka 6:37829af7bfbd 53 {
ansond 0:1358c23ecb2e 54 // blink...
ansond 0:1358c23ecb2e 55 led = !led;
spriyanka 6:37829af7bfbd 56 wait(1);
spriyanka 6:37829af7bfbd 57
spriyanka 6:37829af7bfbd 58 // we can also call directly
spriyanka 6:37829af7bfbd 59 printf("Direct: heartrate = %.1f\r\n", earbud.getHeartRate());
spriyanka 6:37829af7bfbd 60
spriyanka 6:37829af7bfbd 61 esp_send();
ansond 0:1358c23ecb2e 62 }
spriyanka 6:37829af7bfbd 63 }
spriyanka 6:37829af7bfbd 64
spriyanka 6:37829af7bfbd 65 void esp_initialize(void)
spriyanka 6:37829af7bfbd 66 {
spriyanka 6:37829af7bfbd 67 //AT+CWJAP="vivo 1601","bschitta" ;
spriyanka 6:37829af7bfbd 68
spriyanka 6:37829af7bfbd 69 pc.printf("Initializing ESP\r\n");
spriyanka 6:37829af7bfbd 70 pc.printf("Reset ESP\r\n");
spriyanka 6:37829af7bfbd 71 esp.Reset(); //RESET ESP
spriyanka 6:37829af7bfbd 72 esp.RcvReply(rcv, 400); //receive a response from ESP
spriyanka 6:37829af7bfbd 73 wait(2);
spriyanka 6:37829af7bfbd 74
spriyanka 6:37829af7bfbd 75 strcpy(snd,"AT");
spriyanka 6:37829af7bfbd 76 esp.SendCMD(snd);
spriyanka 6:37829af7bfbd 77 pc.printf(snd);
spriyanka 6:37829af7bfbd 78 esp.RcvReply(rcv, 400);
spriyanka 6:37829af7bfbd 79 pc.printf(rcv);
spriyanka 6:37829af7bfbd 80 wait(2);
spriyanka 6:37829af7bfbd 81
spriyanka 6:37829af7bfbd 82 strcpy(snd,"AT+CWMODE=1");
spriyanka 6:37829af7bfbd 83 esp.SendCMD(snd);
spriyanka 6:37829af7bfbd 84 pc.printf(snd);
spriyanka 6:37829af7bfbd 85 wait(2);
spriyanka 6:37829af7bfbd 86
spriyanka 6:37829af7bfbd 87 strcpy(snd,"AT+CWJAP=\"");
spriyanka 6:37829af7bfbd 88 strcat(snd,WIFI_SSID);
spriyanka 6:37829af7bfbd 89 strcat(snd,"\",\"");
spriyanka 6:37829af7bfbd 90 strcat(snd,WIFI_PASS);
spriyanka 6:37829af7bfbd 91 strcat(snd,"\"");
spriyanka 6:37829af7bfbd 92
spriyanka 6:37829af7bfbd 93 esp.SendCMD(snd);
spriyanka 6:37829af7bfbd 94 pc.printf(snd);
spriyanka 6:37829af7bfbd 95 wait(5);
spriyanka 6:37829af7bfbd 96 esp.RcvReply(rcv, 400);
spriyanka 6:37829af7bfbd 97 pc.printf("\n %s \n", rcv);
spriyanka 6:37829af7bfbd 98
spriyanka 6:37829af7bfbd 99 strcpy(snd,"AT+CIPMUX=1");
spriyanka 6:37829af7bfbd 100 esp.SendCMD(snd);
spriyanka 6:37829af7bfbd 101 pc.printf(snd);
spriyanka 6:37829af7bfbd 102 esp.RcvReply(rcv, 400);
spriyanka 6:37829af7bfbd 103 pc.printf("\n %s \n", rcv);
spriyanka 6:37829af7bfbd 104 }
spriyanka 6:37829af7bfbd 105
spriyanka 6:37829af7bfbd 106 void esp_send(void)
spriyanka 6:37829af7bfbd 107 {
spriyanka 6:37829af7bfbd 108 //ESP updates the Status of Thingspeak channel//
spriyanka 6:37829af7bfbd 109
spriyanka 6:37829af7bfbd 110 strcpy(snd,"AT+CIPSTART=");
spriyanka 6:37829af7bfbd 111 strcat(snd,"\"TCP\",\"");
spriyanka 6:37829af7bfbd 112 strcat(snd,IP);
spriyanka 6:37829af7bfbd 113 strcat(snd,"\",80");
spriyanka 6:37829af7bfbd 114
spriyanka 6:37829af7bfbd 115 esp.SendCMD(snd);
spriyanka 6:37829af7bfbd 116 pc.printf("Send\r\n%s",snd);
spriyanka 6:37829af7bfbd 117 esp.RcvReply(rcv, 1000);
spriyanka 6:37829af7bfbd 118 pc.printf("Receive\r\n%s",rcv);
spriyanka 6:37829af7bfbd 119 wait(2);
spriyanka 6:37829af7bfbd 120
spriyanka 6:37829af7bfbd 121 hrt = earbud.getHeartRate();
spriyanka 6:37829af7bfbd 122 pc.printf("Sending this information to thingspeak.com \r\n");
spriyanka 6:37829af7bfbd 123 sprintf(snd,"GET https://api.thingspeak.com/update?api_key=SJYFHXQEDBQ75N91&field1=%f\r\n", hrt);
spriyanka 6:37829af7bfbd 124 //wait(5);
spriyanka 6:37829af7bfbd 125 //https://api.thingspeak.com/update?api_key=SJYFHXQEDBQ75N91&field1=%f\r\n", hrt
spriyanka 6:37829af7bfbd 126
spriyanka 6:37829af7bfbd 127 int i=0;
spriyanka 6:37829af7bfbd 128 for(i=0; snd[i]!='\0'; i++);
spriyanka 6:37829af7bfbd 129 i++;
spriyanka 6:37829af7bfbd 130 char cmd[255];
spriyanka 6:37829af7bfbd 131
spriyanka 6:37829af7bfbd 132 sprintf(cmd,"AT+CIPSEND=%d",i); //Send Number of open connection and Characters to send
spriyanka 6:37829af7bfbd 133 esp.SendCMD(cmd);
spriyanka 6:37829af7bfbd 134 pc.printf("Send\r\n%s",cmd);
spriyanka 6:37829af7bfbd 135 while(i<=20 || rcv == ">")
spriyanka 6:37829af7bfbd 136 {
spriyanka 6:37829af7bfbd 137 esp.RcvReply(rcv, 1000);
spriyanka 6:37829af7bfbd 138 wait(100);
spriyanka 6:37829af7bfbd 139 i++;
spriyanka 6:37829af7bfbd 140 }
spriyanka 6:37829af7bfbd 141 pc.printf("Receive\r\n%s",rcv);
spriyanka 6:37829af7bfbd 142
spriyanka 6:37829af7bfbd 143 esp.SendCMD(snd); //Post value to thingspeak channel
spriyanka 6:37829af7bfbd 144 pc.printf("Send\r\n%s",snd);
spriyanka 6:37829af7bfbd 145
spriyanka 6:37829af7bfbd 146 while(i<=20 || rcv == "OK")
spriyanka 6:37829af7bfbd 147 {
spriyanka 6:37829af7bfbd 148 esp.RcvReply(rcv, 1000);
spriyanka 6:37829af7bfbd 149 wait(100);
spriyanka 6:37829af7bfbd 150 i++;
spriyanka 6:37829af7bfbd 151 }
spriyanka 6:37829af7bfbd 152 pc.printf("Receive\r\n%s",rcv);
spriyanka 6:37829af7bfbd 153
spriyanka 6:37829af7bfbd 154 }
spriyanka 6:37829af7bfbd 155
spriyanka 6:37829af7bfbd 156