Hey all-I am trying to make a project which involves a pulse sensor sending output when the BPM is over 90 to an API bot through whatsapp. I have each of these up and working, but I have no idea where to start to how to combine these. I don't know how to have the output act as a variable of some sort to replace the message. Help is needed.
For the Whatsapp code:
#include <WiFi.h>
#include <HTTPClient.h>
const char WIFI_SSID[] = "XXX"; // CHANGE IT // CHANGE IT
const char WIFI_PASSWORD[] = "XXX"; // CHANGE IT
String HOST_NAME = "https://api.callmebot.com"; // CHANGE IT
String PATH_NAME = "/whatsapp.php?phone=PHONENUMBER&text=TEXT&apikey=APIKEY"; // CHANGE IT
void setup() {
Serial.begin(9600);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
HTTPClient http;
http.begin(HOST_NAME + PATH_NAME); //HTTP
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
} else {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
void loop() {
}
For the Pulse Sensor Code:
#include <PulseSensorPlayground.h>
const int OUTPUT_TYPE = PROCESSING_VISUALIZER;
const int PULSE_INPUT = 36;
const int PULSE_BLINK = 13;
const int PULSE_FADE = 5;
const int THRESHOLD = 550;
PulseSensorPlayground pulseSensor;
void setup() {
Serial.begin(115200);
pulseSensor.analogInput(PULSE_INPUT);
pulseSensor.blinkOnPulse(PULSE_BLINK);
pulseSensor.fadeOnPulse(PULSE_FADE);
pulseSensor.setSerial(Serial);
pulseSensor.setOutputType(OUTPUT_TYPE);
pulseSensor.setThreshold(THRESHOLD);
if (!pulseSensor.begin()) {
for(;;) {
digitalWrite(PULSE_BLINK, LOW);
delay(50); Serial.println('!');
digitalWrite(PULSE_BLINK, HIGH);
delay(50);
}
}
}
void loop() {
if(pulseSensor.UsingHardwareTimer){
delay(20);
pulseSensor.outputSample();
} else {
if (pulseSensor.sawNewSample()) {
if (--pulseSensor.samplesUntilReport == (byte) 0) {
pulseSensor.samplesUntilReport = SAMPLES_PER_SERIAL_SAMPLE;
pulseSensor.outputSample();
}
}
}
if (pulseSensor.sawStartOfBeat()) {
pulseSensor.outputBeat();
}
}
6 posts - 2 participants