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 ?
- 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();
}
- 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.