Hello
I tried to send a easy http get parameter to my lokal server script, to save it.
I only got a fail message:
http.begin(serverPath.c_str());
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
exit status 1
Compilation error: call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)
does anyone have a solution?
my code:
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include "certs.h"
#include <ESP8266HTTPClient.h>
#ifndef STASSID
#define STASSID "ssid"
#define STAPSK "pw!"
#endif
//Your Domain name with URL path or IP address with path
String serverName = "myserver/script.php";
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
const char* ssid = STASSID;
const char* password = STAPSK;
X509List cert(cert_DigiCert_Global_Root_CA);
HTTPClient http;
WiFiClient client;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
//Send an HTTP POST request every 10 minutes
if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
String serverPath = serverName + "?temperature=24.37";
// Your Domain name with URL path or IP address with path
http.begin(serverPath.c_str());
// Send HTTP GET request
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
lastTime = millis();
}
}
The code seems to be missing the definition of the cert_DigiCert_Global_Root_CA variable, which is used to verify the server's SSL certificate when making HTTPS requests.
Try to include this:
const unsigned char cert_DigiCert_Global_Root_CA[] PROGMEM = R"EOF(
-----BEGIN CERTIFICATE-----
MIIEkjCCA3qgAwIBAgIQAf2jgdBh8NdJqzPxfMfjtzANBgkqhkiG9w0BAQsFADBa
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QSAyMDE5MB4XDTE5MDUyMTAwMDAwMFoXDTIwMDUyMTIzNTk1OVowWjELMAkGA1UE
BhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3LmRpZ2lj
ZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgR2xvYmFsIFJvb3QgQ0EgMjAxOTCC
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJgIvglRHhN/tJjL1YdbTtla
TJdKjwV0Bp8Wmuq3rfsjLmz7SWLlY8Wuc7VQ2ZxDw6b5ys6S5j6Rrp+C/7YPfqE
e+9k4JqNrb4pBlZgEKcZm0B0puSEjTDrcLO2gDLEwk0XFTlnwuC0JmLhQbZ1M0sK
Hn0t8Wc42iUBkLjXSPnDSeTtYNI1jKwJiG86x7r3vLL8W+7Fl/ejNUFWFYzQV22e
8WxlKjJNFGiC+zrKLq3rNpWLV7jKzxcbluV2vF8RcWzk2m45fZKs52t0m8fuCtzT
aETrKpXbGv+YtIHiBXwZji88EkwIh/xAUEKj1WJKQ1D9n9XoF0MCAwEAAaOCAZMw
ggGTMB8GA1UdIwQYMBaAFE4y4/d3vYb/Lgc+/vdC7x0VcVgUMA4GA1UdDwEB/wQE
Aw
If I send a get request to my php script and write in the php script a output. How can I use this?
For example:
I send the number "2". The php script multiplicate it with 5. The result is 10.