Ви не увійшли.
Написав на пошту
Дякую, запрацювало!
Напишіть мені в телеграм номер карти @batm_n
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "SSID";
const char* password = "PASS";
BearSSL::WiFiClientSecure client;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
client.setInsecure();
}
void getStat() {
HTTPClient https;
https.begin(client, "https://russianwarship.rip/api/v2/statistics/latest");
int httpCode = https.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
String payload = https.getString();
Serial.println(payload);
} else {
Serial.printf("[HTTPS] GET... failed, error: %sn", https.errorToString(httpCode).c_str());
}
https.end();
}
}
void loop() {
getStat();
delay(10000);
}
Привіт!
Я ж правильно зрозумів, що ця бібліотека іде в комплекті з ESP8266?
Я просто зараз зайшов в папку і навіть не маю такої назви(WifiClientSecure & WifiClient)...
__
Є бібліотека WIFi
lib
Заархівуйте і викладіть вашу бібліотеку WiFiClientSecure
Привіт, треба виправити парсер, для роботи з API не підключається.
Розрахунок за виконану роботу відразу на карту.
___
ESP8266
WiFiClientSecure httpsClient;
___
09:06:32.197 -> connecting to russianwarship.rip
09:06:32.329 -> connection failed
// ===================================================
// https://russianwarship.rip/api/v2/statistics/latest
// ===================================================
void getStat() {
Serial.print("connecting to ");
Serial.println(serverFuckrussian);
if (!httpsClient.connect(serverFuckrussian, httpsPort)) {
Serial.println("connection failed");
return ;
}
String request = String("GET /api/v2/statistics/") + latest + " HTTP/1.1rn"+
"Host: " + serverFuckrussian + "rnUser-Agent: ESP8266HTTPClient/1.1rnConnection: closernrn";
if (!httpsClient.connected()) {
Serial.println("connection lost");
return ;
}
httpsClient.print(request);
String response = "";
while (httpsClient.connected()) {
String line = httpsClient.readStringUntil('n');
if (line == "r") {
break;
}
}
DynamicJsonDocument doc(1536);
DeserializationError error = deserializeJson(doc, httpsClient);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}
//const char* message = doc["message"]; // "The data were fetched successfully."
JsonObject data = doc["data"];
//const char* data_date = data["date"]; // "2023-05-05"
//int data_day = data["day"]; // 436
//const char* data_resource = data["resource"];
int data_war_status_code = data["war_status"]["code"]; // 1
const char* data_war_status_alias = data["war_status"]["alias"]; // "in_progress"
JsonObject data_stats = data["stats"];
long data_stats_personnel_units = data_stats["personnel_units"]; // 193210
//int data_stats_tanks = data_stats["tanks"]; // 3710
// int data_stats_armoured_fighting_vehicles = data_stats["armoured_fighting_vehicles"]; // 7224
// int data_stats_artillery_systems = data_stats["artillery_systems"]; // 2978
// int data_stats_mlrs = data_stats["mlrs"]; // 550
// int data_stats_aa_warfare_systems = data_stats["aa_warfare_systems"]; // 304
// int data_stats_planes = data_stats["planes"]; // 308
// int data_stats_helicopters = data_stats["helicopters"]; // 294
// int data_stats_vehicles_fuel_tanks = data_stats["vehicles_fuel_tanks"]; // 5916
// int data_stats_warships_cutters = data_stats["warships_cutters"]; // 18
// int data_stats_cruise_missiles = data_stats["cruise_missiles"]; // 947
// int data_stats_uav_systems = data_stats["uav_systems"]; // 2540
// int data_stats_special_military_equip = data_stats["special_military_equip"]; // 373
// int data_stats_atgm_srbm_systems = data_stats["atgm_srbm_systems"]; // 4
JsonObject data_increase = data["increase"];
int data_increase_personnel_units = data_increase["personnel_units"]; // 620
// int data_increase_tanks = data_increase["tanks"]; // 3
// int data_increase_armoured_fighting_vehicles = data_increase["armoured_fighting_vehicles"]; // 8
// int data_increase_artillery_systems = data_increase["artillery_systems"]; // 16
// int data_increase_mlrs = data_increase["mlrs"]; // 3
// int data_increase_aa_warfare_systems = data_increase["aa_warfare_systems"]; // 0
// int data_increase_planes = data_increase["planes"]; // 0
// int data_increase_helicopters = data_increase["helicopters"]; // 0
// int data_increase_vehicles_fuel_tanks = data_increase["vehicles_fuel_tanks"]; // 30
// int data_increase_warships_cutters = data_increase["warships_cutters"]; // 0
// int data_increase_cruise_missiles = data_increase["cruise_missiles"]; // 0
// int data_increase_uav_systems = data_increase["uav_systems"]; // 17
// int data_increase_special_military_equip = data_increase["special_military_equip"]; // 3
// int data_increase_atgm_srbm_systems = data_increase["atgm_srbm_systems"]; // 0
string_stat = String("fr " + String(data_stats_personnel_units) + "(+" + String(data_increase_personnel_units + ")"));
Serial.print("Personnel Units: ");
Serial.println(string_stat);
httpsClient.stop();
}