MAX30100 sensor data not post in localdatabse

Hello,

i used ESP8266 node MCU module and i want to post Max30100 PulseOximeter sensor data into the local database but data not post in local database. below some obesrvation point is mentioned. may you help me to solve my issue ?

  1. when i print the data on serial monitor then sensor reading is desplayed and that code is below mentioned.
    #ifdef ESP32
    #include
    #include
    #include
    #include "MAX30100_PulseOximeter.h"
    #else
    #include
    #include
    #include
    #include
    #include "MAX30100_PulseOximeter.h"
    #endif

unsigned long lastTime = 0;

// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;

// Create a PulseOximeter object
PulseOximeter pox;

String BPM, SPO;

// Replace with your network credentials
const char* ssid = "JioFi2_C8304B";
const char* password = "v6m36nizia";

// REPLACE with your Domain name and URL path or IP address with path
const char* serverName = "http://ip address/dht11/post-esp-data.php";

// Keep this API Key value to be compatible with the PHP code provided in the project page.
// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key
String apiKeyValue = "tPmAT5Ab3j7F9";

void setup()
{
Serial.begin(115200);

WiFi.begin(ssid, 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());

if (!pox.begin()) // Initialize sensor
{
Serial.println("FAILED");
for (;;);
}
else
{
Serial.println("SUCCESS");
}

pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA); // Configure sensor to use 7.6mA for LED drive

}

void loop()
{

pox.update();

if ((millis() - lastTime) > timerDelay) //Send an HTTP POST request every 5 Sec.
{

int A = pox.getHeartRate();
int B = pox.getSpO2();

String httpRequestData = "api_key=" + apiKeyValue + "&value4=" + String(A) + "&value5=" + String(B) + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);

}
lastTime = millis();
}

  1. but when i written code for post data into the database that time sensor reading not getting on serial monitor as well as database and that code is below mentioned.

#ifdef ESP32
#include
#include
#include
#include "MAX30100_PulseOximeter.h"
#else
#include
#include
#include
#include
#include "MAX30100_PulseOximeter.h"
#endif

unsigned long lastTime = 0;

// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;

// Create a PulseOximeter object
PulseOximeter pox;

// Replace with your network credentials
const char* ssid = "JioFi2_C8304B";
const char* password = "v6m36nizia";

// REPLACE with your Domain name and URL path or IP address with path
const char* serverName = "http://ip address /dht11/post-esp-data.php";

// Keep this API Key value to be compatible with the PHP code provided in the project page.
// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key
String apiKeyValue = "tPmAT5Ab3j7F9";

void setup()
{
Serial.begin(115200);

WiFi.begin(ssid, 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());

if (!pox.begin()) // Initialize sensor
{
Serial.println("FAILED");
for (;;);
}
else
{
Serial.println("SUCCESS");
}

pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA); // Configure sensor to use 7.6mA for LED drive

}

void loop()
{

pox.update();

if ((millis() - lastTime) > timerDelay) //Send an HTTP POST request every 5 Sec.
{

if (WiFi.status() == WL_CONNECTED) //Check WiFi connection status

{
WiFiClient client;

HTTPClient http;

http.begin(client, serverName); // Your Domain name with URL path or IP address with path

http.addHeader("Content-Type", "application/x-www-form-urlencoded"); // Specify content-type header

int A = pox.getHeartRate();
int B = pox.getSpO2();

String httpRequestData = "api_key=" + apiKeyValue + "&value4=" + String(A) + "&value5=" + String(B) + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);

int httpResponseCode = http.POST(httpRequestData); //Send HTTP POST requests
Serial.println(httpResponseCode);

if (httpResponseCode > 0)
{
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
}
else
{
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}

http.end(); // Free resources

}
lastTime = millis();
}
}

PHP Code

<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "dhtt"; /*$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);*/ $api_key_value = "tPmAT5Ab3j7F9"; $api_key= $sensor = $location = $value1 = $value2 = $value3 = $value4 = $value5 = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $api_key = test_input($_POST["api_key"]); if($api_key == $api_key_value) { $value1 = test_input($_POST["value1"]); $value2 = test_input($_POST["value2"]); $value3 = test_input($_POST["value3"]); $value4 = test_input($_POST["value4"]); $value5 = test_input($_POST["value5"]); // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "INSERT INTO phms ( value1, value2, value3, value4, value5) VALUES ('" . $value1 . "', '" . $value2 . "', '" . $value3 . "','" . $value4 . "','" . $value5 . "')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "
" . $conn->error; } $conn->close(); } else { echo "Wrong API Key provided."; } } else { echo "No data posted with HTTP POST."; } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } please support me for this issue thanks in advance.

Edit your post and insert code tags!

I guess your ESP doesn't have network connectivity as the serial print is only done if WiFi is connected.

Hello Everyone,

finally i resolved this issue and i got the sensor data reading in the localdatabase. i put here my code for your future reference.

Code :slight_smile:

#ifdef ESP32
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#else
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include "MAX30100.h"
#include "MAX30100_PulseOximeter.h"
#endif

unsigned long lastTime = 0;

unsigned long timerDelay = 5000; // Set timer to 5 seconds (5000)
MAX30100 maxim;
PulseOximeter pox; // Create a PulseOximeter object

// Replace with your network credentials
const char* ssid = "JioFi2_C8304B";
const char* password = "v6m36nizia";

const char* serverName = "http://localhost/dht11/post-esp-data.php"; // REPLACE with your Domain name and URL path or IP address with path

String apiKeyValue = "tPmAT5Ab3j7F9"; // If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key

void initpox() // Init POX => MAX30100
{
if (!pox.begin()) // Initialize sensor
{
Serial.println("FAILED");
for (;;);
}
else
{
Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA); // Configure sensor to use 7.6mA for LED drive
}

// Initialize WiFi
void initWiFi()
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print('.');
delay(1000);
}
Serial.println(WiFi.localIP());
}

void setup()
{
Serial.begin(115200);
initWiFi();
initpox();
}

void postData(float value4, float value5) // This is the main method where data gets pushed to the local server
{
WiFiClient client; // Creates a client that can connect to to a specified internet IP address and port as defined in client.connect().

HTTPClient http; //HttpClient is a library to make it easier to interact with web servers from Arduino.

http.begin(client, serverName); // Your Domain name with URL path or IP address with path

http.addHeader("Content-Type", "application/x-www-form-urlencoded"); // Specify content-type header

String httpRequestData = "api_key=" + apiKeyValue + "&value5=" + String(value5) + "&value4=" + String(value4) + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);
int httpResponseCode = http.POST(httpRequestData); // Send HTTP POST requests
Serial.println(httpResponseCode);
maxim.resetFifo();
if (httpResponseCode > 0)
{
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
}
else
{
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end(); // Free resources

}

void loop()
{
// Read from the sensor

pox.update();

// Grab the updated heart rate and SpO2 levels
if ((millis() - lastTime) > timerDelay)
{

float temperatureC = sensors.getTempCByIndex(0);
float temperatureF = sensors.getTempFByIndex(0);
float A = pox.getHeartRate();
float B = pox.getSpO2();
Serial.print("bpm: ");
Serial.println(A);
Serial.print("SpO2: ");
Serial.println(B);

postData(A, B);
lastTime = millis();

}
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.