softwarecrash / Solar2MQTT

ESP8266 based WiFi and MQTT interface for MPPT Inverters that use watchpower
Other
105 stars 25 forks source link

HTTPS Requests #94

Closed dotumair closed 1 month ago

dotumair commented 1 month ago

A clear and concise description of what the problem is.

I'm trying to send data to Firebase realtime database using HTTP REST API. I'm using the below code

` StaticJsonDocument<200> doc; doc["name"] = "John Doe"; doc["age"] = 30; doc["email"] = "john.doe@example.com";

char jsonBuffer[512]; serializeJson(doc, jsonBuffer);

// Firebase URL with authentication token String url = String("https://") + firebaseHost + "/users/user123.json?auth=" + firebaseAuth; Serial.println(url);

// Send HTTP PUT request HTTPClient http; http.begin(wifiClient, url); // Specify the URL http.addHeader("Content-Type", "application/json"); // Specify content-type header int httpResponseCode = http.PUT(jsonBuffer); // Send the request

if (httpResponseCode > 0) { String response = http.getString(); // Get the response to the request Serial.println(httpResponseCode); // Print return code Serial.println(response); // Print request answer } else { Serial.print("Error on sending PUT request: "); Serial.println(httpResponseCode); } `

but the request failed with error code -1, and the error message says that the connection failed. I'm calling this code from loop method, after Wifi connection. How can I send HTTPS requests?

Additional context

No response

softwarecrash commented 1 month ago

i dont support miscellaneous rewrites of my code.

just a hint: