Connettersi alla rete WiFi e scaricare un file da un sito http(s):
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
const char* ssid = "yyy";
const char* password = "xxx";
const char* hostName = "https://www.vincenzov.net";
void setup() {
Serial.begin(115200);
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Gateway: ");
Serial.println (WiFi.gatewayIP());
}
void loop() {
HTTPClient http;
http.begin(hostName);
int httpCode = http.GET();
if (httpCode > 0) {
Serial.print("Code: ");
Serial.println(httpCode);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("Failed. Error code: ");
Serial.println(http.errorToString(httpCode).c_str());
}
http.end();
delay(5000);
}
Pagina creata nel gennaio 2022
Ultima modifica: 14 gennaio 2022