Код: Выделить всё
#include
#include
#include
// Wi-Fi credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
// API URL (returns JSON)
const char* apiUrl = "url-api";
void setup() {
Serial.begin(115200);
delay(1000);
Serial.print("Connecting to Wi-Fi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(700);
Serial.print("=");
}
Serial.println("\nWi-Fi connected successfully!");
}
void loop() {
// Check if connected before making the request
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(apiUrl);
int responseCode = http.GET();
if (responseCode > 0) {
// If request was successful, get the response
String response = http.getString();
// Create a JSON document
StaticJsonDocument doc;
// Try to parse the JSON
DeserializationError error = deserializeJson(doc, response);
if (!error) {
// Access data from the parsed JSON
bool led2Status = doc["status"];
Serial.print(led2Status);
} else {
Serial.print("Failed to parse JSON: ");
}
} else {
Serial.print("HTTP Request failed. Code: ");
};
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... sing-esp32