nodemcu sensor data send to database

I am doing my schoolwork to send sensor data to PHP. I’m using wampserver and phpMyAdmin. I have connected NodeMCU WIFI and saw a data but I can’t save data in my DB. The error says "GET FAILED, error no: -1, error: connection refused " Here’s my code, Please help me.
http.GET() continually has -1 value. So I think this is where the problem is, but I’m not an expert in web code. please help TT

This is my arduino code
#include <ESP8266HTTPClient.h>
#include <ESP8266HTTPUpdateServer.h>
#include <PulseSensorPlayground.h>
#include <BearSSLHelpers.h>
#include <CertStoreBearSSL.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiClientSecureAxTLS.h>
#include <WiFiClientSecureBearSSL.h>
#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiServerSecureAxTLS.h>
#include <WiFiServerSecureBearSSL.h>
#include <WiFiUdp.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>

//Vib sensor set
#include <EEPROM.h>
#define Vib D0 // Vib sensor
int val; //sensor value
//

//heartbeat set
#define UpperThreshold 550
#define LowerThreshold 500

bool BPMTiming=false;
bool BeatComplete=false;
int LastTime=0;
int BPM;
//

//server
const char* ssid = “iPhone”; // id
const char* password = “0123456789”; // pw
const char* host=“http://223.38.34.156”;
//const char* host=“http://localhost”;
const long interval=5000;
unsigned long previousMillis = 0;
WiFiClient client;
WiFiServer server(80);
HTTPClient http;

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
PulseSensorPlayground pulseSensor;

void setup() {

//WiFi.forceSleepBegin();
delay(1);

Serial.println(“Adafruit MLX90614 TEST”);

mlx.begin();
Serial.begin(57600);
Wire.begin(D1,D2);
delay(10);

WiFi.mode(WIFI_STA);
WiFi.disconnect();

delay(100);

Serial.println(“Setup done”);

// Connect to WiFi network

Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println(“WiFi connected”);

// Start the server

server.begin();
Serial.println(“Server started”);

// Print the IP address

Serial.print(“Use this URL to connect: “);
Serial.print(“http://”);
Serial.print(WiFi.localIP()); //ip print
Serial.println(”/”);
}

void loop() {

unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;

int value=analogRead(A0);
int heartbeat=int(60/(float(value)/1000));
float heart = heartbeat; //heartbeat
float temp = mlx.readObjectTempC(); //temp

String phpHost =host;
phpHost+="/doginsert.php?temp=" + String(temp) + “&heart=” + String(heart);
Serial.print("Connect to ");
Serial.println(phpHost);

http.begin(client, phpHost);
//http.addHeader(“Content-Type”, “application/json”);

//String thumbprint=“08:3B:71:72:02:43:6E:CA:ED:42:86:93:BA:7E:DF:81:C4:BC:62:30”;
//String path = “https://calm-falls-41696.herokuapp.com/api/v1/cards.json”;
// http.begin(path, thumbprint);

http.setTimeout(8000);
int httpCode = http.GET();

if(httpCode > 0) {
Serial.printf(“GET code : %d\n\n”, httpCode);

if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
}
else {
Serial.printf(“GET failed, error no: %d, error: %s\n”, httpCode , http.errorToString(httpCode).c_str());
}
http.end();
}

// web server
client = server.available();
if(!client) return;

Serial.println(“new client”);
client.setTimeout(5000);

String request = client.readStringUntil(’\r’);
Serial.println("request: ");
Serial.println(request);

while(client.available()) {
client.read();
}
int value=analogRead(A0);
int heartbeat=int(60/(float(value)/1000));
float heart = heartbeat;
float temp = mlx.readObjectTempC();

client.print(“HTTP/1.1 200 OK”);
client.print(“Content-Type: text/html\r\n\r\n”);
client.print("");
client.print("");
client.print("");
client.print("<meta charset=“UTF-8” http-equiv=“refresh” content=“1”>");
client.print(“DHT senrsor test Webpage”);
client.print("");
client.print("");
client.print(“

DHT senrsor test Webpage

”);
client.print("
“);
client.print(“Temperature : “);
client.print(temp);
client.print(” °C”);
client.print(”
“);
client.print(“Heart : “);
client.print(heart);
client.print(” BPM”);
client.print(”");
client.print("");
delay(5000);
Serial.println(“client conn release”);

}

This is my php code

<?php $servername="223.38.34.156"; $username="jjj"; $password="0000"; $dbname="dog"; $conn = mysqli_connect($servername, $username, $password, $dbname); if(mysqli_connect_errno()){ echo "Failed to connect to MySql: "; mysqli_connect_error(); } $temp = $_GET["temp"]; $heart = $_GET["heart"]; $sql = "INSERT INTO dog.doginsert(temp, heart) VALUES($temp, $heart)"; mysqli_query($conn, $sql); mysqli_close($conn); $response = 13; echo json_encode($response); ?>

source.ino (4.58 KB)

source.ino (4.58 KB)

const char* host="http://223.38.34.156";

That is NOT a host name. A host NAME does not include a protocol. The host name might be "223.38.34.156".

PaulS:

const char* host="http://223.38.34.156";

That is NOT a host name. A host NAME does not include a protocol. The host name might be "223.38.34.156".

I do thisㅜㅜ but error is still exist..

rlarlawltn:
I do thisㅜㅜ but error is still exist..

What error? Post your serial output.

    float heart = heartbeat; //heartbeat
    float temp = mlx.readObjectTempC(); //temp
   
    String phpHost =host;
    phpHost+="/doginsert.php?temp=" + String(temp) + "&heart=" + String(heart);

What is the point of storing an integral value in a float variable? Does your PHP script stupidly expect a float?

Have you ever heard of a heart rate of 74.2 beats per minute?