esp8266 / esp8266/Arduino

[HTTPS] GET... failed, error: connection failed

Aperta
#8,741 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
16.7k
Fork
13.1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I am using the following code to send data to the server periodically every 1 minute.

```
void sendData(char *h, char *t) {
const char api_key[] = "myapiKey";
String serve_url = "http://myserver/input/post?";

char spath[250];
sprintf(spath, "node=%s&fulljson={\"humidity\":%s,\"temp\":%s}&apikey=%s", clientId.c_str(), h, t, api_key);
String p = serve_url + spath;

Serial.println("Connecting to: ");
Serial.println(p);
HTTPClient https;

Serial.print("[HTTPS] begin...\n");
https.begin(client, p);

Serial.print("[HTTPS] GET...\n");

int httpCode = https.GET();
if (httpCode > 0) {

Serial.printf("[HTTPS] GET... code: %d\n", httpCode);

if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str());
}

https.end();
}
```
This works once or twice in a loop, but after that, it fails continuously.
with error:
```
[HTTPS] GET... failed, error: connection failed
```
The same code runs when I use the same URL printed in the console directly in the same code.

What could be wrong here?

Environment:

ESP8266
toll chain SDK "version": "5.100300.220621"
framework: "version": "3.1.0-dev"

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia da sendData e traccia la sequenza ripetuta HTTPClient begin(), GET() e end() nell’implementazione ESP8266 Arduino. Riproduci il fallimento dopo diverse iterazioni del ciclo, esamina l’errore restituito e il ciclo di vita della connessione e confronta il comportamento con la richiesta URL diretta. Il lavoro è completato quando la richiesta periodica continua ad avere successo invece di restituire „connection failed“.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
arduino, cpp
Ambito
embedded-iot, networking
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.