Hello, I am trying to make this pulsesensor restful.
I just took the sample code from the website for my arduino yun.I modified it in the restful manner using bridge lib , yun server and yun client. The compiler returns no error messages. when i call the website e.g. localhost/arduino/heartbeat , nothing returns. What could be the problem? Timing Problem between server request and interrupt?I am very thankful for solutions ! Kris
My modified code:
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
YunServer server;
// VARIABLES
int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin
// these variables are volatile because they are used during the interrupt service routine!
volatile int BPM; // used to hold the pulse rate
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // holds the time between beats, the Inter-Beat Interval
volatile boolean Pulse = false; // true when pulse wave is high, false when it's low
volatile boolean QS = false; // becomes true when Arduoino finds a beat.
void setup(){
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(115200); // we agree to talk fast!
Bridge.begin();
server.listenOnLocalhost();
server.begin();
interruptSetup();
}
void loop(){
// Get clients coming from server
YunClient client = server.accept();
// There is a new client?
if (client) {
// Process request
process(client);
// Close connection and free resources.
client.stop();
}
}
void process(YunClient client) {
String command = client.readStringUntil('/');
if (command == "heartbeat") {
heartbeatCommand(client);
}
}
void heartbeatCommand(YunClient client) {
sendDataToProcessing('S', Signal); // send Processing the raw Pulse Sensor data
if (QS == true){ // Quantified Self flag is true when arduino finds a heartbeat
fadeRate = 255; // Set 'fadeRate' Variable to 255 to fade LED with pulse
sendDataToProcessing('B',BPM);
client.print('B:'+BPM); // send heart rate with a 'B' prefix
sendDataToProcessing('Q',IBI); // send time between beats with a 'Q' prefix
client.print('Q:'+IBI);
QS = false; // reset the Quantified Self flag for next time
}
ledFadeToBeat();
delay(50); // Poll every 50ms
}
void ledFadeToBeat(){
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(fadePin,fadeRate); // fade LED
}
void sendDataToProcessing(char symbol, int data ){
Serial.print(symbol); // symbol prefix tells Processing what type of data is coming
Serial.println(data); // the data to send culminating in a carriage return
}