c++
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266HTTPClient.h>
// Substitua pelos detalhes da sua rede Wi-Fi
const char* ssid = "SSID";
const char* password = "PASS";
// Endereço da API
const char* host = "API_URL";
void setup() {
Serial.begin(9600);
delay(10);
// Conecta-se à rede Wi-Fi
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 Conn established!");
Serial.println("IP address: " + WiFi.localIP().toString());
}
void loop() {
// Use a conexão WiFiClientSecure
HTTPClient https;
WiFiClientSecure client;
client.setInsecure();
Serial.print("Connecting to: ");
Serial.println(host);
https.begin(client, host);
int httpCode = https.GET();
if (httpCode > 0){
String payload = https.getString();
Serial.print("Http code: ");
Serial.println(httpCode);
Serial.print("\nPayload: ");
Serial.println(payload);
}
delay(500);
// Verificar se a conexão é bem-sucedida
if (client.connected()) {
Serial.println("Conn sucess!");
} else {
Serial.println("Conn failed!");
return;
}
// Ler a resposta do servidor
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("Conn Close!");
client.stop();
// Aguarda alguns segundos antes de fazer uma nova requisição
delay(5000);
}