This is my final year project and for some reason, the max30100 sensor defaults to static values once the HTTP post request has been performed.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <SimpleTimer.h>
#define REPORTING_PERIOD_MS 1000
const char* ssid = "SDsouza";
const char* password = "dsouza@8104045917";
const char* serverName = "http://10.0.0.13/post-sensor-data.php";
String systolic_pressure;
String diastolic_pressure;
String pulse_rate;
String temperature_body;
String BPM;
String SpO2;
PulseOximeter pox;
uint32_t tsLastReport = 0;
SimpleTimer timer;
String sensor_data;
bool Sr;
String machineid = "MR1";
String room_number= "A1";
String bed_number= "1";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(16,OUTPUT);
WiFi.begin(ssid , password);
Serial.print("Connecting to SSID:");
Serial.print(ssid);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected Successfully!!");
Serial.println(WiFi.localIP());
if(!pox.begin())
{
Serial.println("Failed");
for(;;);
}
else
{
Serial.println("Pox Success");
}
pox.setOnBeatDetectedCallback(onBeatDetected);
//pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
timer.setInterval(1000L , getsendata);
}
void loop() {
// put your main code here, to run repeatedly:
pox.update();
if(millis() - tsLastReport > REPORTING_PERIOD_MS)
{
BPM = pox.getHeartRate();
SpO2 = pox.getSpO2();
Serial.print("Bpm: ");
Serial.println(BPM);
Serial.print("SpO2: ");
Serial.println(SpO2);
tsLastReport = millis();
}
timer.run();
}
void onBeatDetected()
{
Serial.println("Beat Detected");
}
void getsendata()
{
while (Serial.available())
{
sensor_data = Serial.readString();
Sr = true;
int firstcommaindex = sensor_data.indexOf(",");
int secondcommaindex = sensor_data.indexOf(",", firstcommaindex + 1);
int thirdcommaindex = sensor_data.indexOf(",", secondcommaindex + 1);
int fourthcommaindex = sensor_data.indexOf(",", thirdcommaindex + 1);
systolic_pressure = sensor_data.substring(0, firstcommaindex);
diastolic_pressure = sensor_data.substring(firstcommaindex + 1, secondcommaindex);
pulse_rate = sensor_data.substring(secondcommaindex + 1, thirdcommaindex);
temperature_body = sensor_data.substring(thirdcommaindex + 1);
HTTPClient http;
http.begin(serverName);
http.addHeader("Content-Type" , "application/x-www-form-urlencoded");
String httpRequestData = "machine_identifier=" + machineid + "&temp=" + temperature_body + "&hr=" + pulse_rate + "&sys_pressure=" + systolic_pressure + "&dias_pressure=" + diastolic_pressure + "&oxy_lvl=" + SpO2 + "&room_number=" + room_number + "&bed_number=" + bed_number + "";
Serial.print("HTTP Request Data: ");
Serial.println(httpRequestData);
int httpResponseCode = http.POST(httpRequestData);
if(httpResponseCode > 0)
{
Serial.print("HTTP Response Code: ");
Serial.println(httpResponseCode);
}
else
{
Serial.print("Error Code: ");
Serial.println(httpResponseCode);
}
http.end();
}
}
The arduino mega is sending a string with the variable values set to 0 at startup. The MAX30100 sensor is doing its job of taking the readings however, as soon as the HTTP Post Request is done, the oximeter then defaults to it's static values and refuses to detect further readings.
Output:
This is output before HTTP Post
Once the http post request on arduino startup is done, or if i am taking readings from arduino after startup, the max30100 oximeter stops working and refuses to take further readings or update the values further.
The data is sent to mysql db where i will bbe fetching it on the website using php js and html css. This issue of the oximeter has been bothering me since so many days now and my final year project is nearing. Could anyone please guide me as to how to solve this problem?
Here is the library im using for the MAX30100: https://github.com/oxullo/Arduino-MAX30100