My httpget is getting value -1

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

// Replace with your network credentials
const char* ssid = "ANIKET 3171";
const char* password = "K06v5|10";

// Replace with your PHP script URL
const char* phpScriptUrl = "http://192.168.1.3/madarchod/c1.php";

// IR sensor pin
const int irSensorPin = D1;

// Variables for counting events
int eventCount = 0;
int previousState = LOW;

WiFiClientSecure wifiClient;

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

pinMode(irSensorPin, INPUT);

WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}

void loop() {
// Read current state of the IR sensor
int currentState = digitalRead(irSensorPin);

// Check for event (transition from LOW to HIGH)
if (currentState == HIGH && previousState == LOW) {
eventCount++;
Serial.println("Event detected!");

// Create HTTP client object
HTTPClient http;
Serial.println(eventCount);
// Prepare GET request with event count as parameter
String url = String(phpScriptUrl) + "?event_count=" + String(eventCount);
Serial.println("url="+url);

// Send GET request
http.begin(wifiClient,url);
int httpResponseCode = http.GET();

// Check response
if (httpResponseCode > 0) {
  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
  String response = http.getString();
  Serial.println(response);
} else {
  Serial.print("Error code: ");
  Serial.println(httpResponseCode);
}

// Close connection
http.end();

}

// Update previous state
previousState = currentState;

delay(10); // Debounce delay
}

//this is my code for arduino

i am getting the httpget value as -1 the connecting between the php and anodemcu is failed

<?php // Database connection parameters $host = 'localhost'; // Hostname $db = 'hojabsdk'; // Database name $user = 'root'; // Database username $password = ''; // Database password // Connect to MySQL database $conn = new mysqli($host, $user, $password, $db); error_reporting(E_ALL); ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', 'http://192.168.1.3//madarchod/error.log'); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Get event count from NodeMCU $eventCount = $_GET['event_count']; // Assuming the NodeMCU sends the event count via GET parameter 'event_count' // Insert event count into MySQL database $sql = "INSERT INTO event_counts (count) VALUES ('$eventCount')"; if ($conn->query($sql) === TRUE) { echo "Event count inserted successfully!"; } else { echo "Error inserting event count: " . $conn->error; } // Close the database connection $conn->close(); ?>

this is the php code

this code was working yesterday and the data from nodecu was succesfully updated in the myphpadmin but today the connection isnt working

if anyone can help me solve this they can feel free to please contact me on whatsapp if not here

+91 9096888012

Your SSID has a space character in it which might be considered a delimiter or end-of-line.

The Wifi is being connected . The I am getting httpresonpsose code=-1 but the http.begin is giving true as output. It seems that there is problem with http.get(). Can you suggest any thing for this?

The -1 suggests to me a "no response" rather than an error response in the php (for example, "Connection failed").

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