#include <WiFi.h>
#include <HTTPClient.h>
// Настройки Wi-Fi
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// URL сервера
const char* serverUrl =
"https://portal.ru/DroneResponses/BaseRequest"; // Замените на URL
// вашего сервера
// API-ключ для заголовка
const char* apiKey = "d655f4fe9fd831bc2793ce64721cac36";
// JSON-тело запроса
const char* jsonBody = R"(
{
"lat":"40.4515468",
"lon":"50.0662282",
"arm":"0",
"mode":"0",
"vx":"1",
"vy":"0",
"vz":"0",
"sats":"11",
"fix":"3",
"rssi":"100",
"cpu":"65",
"heading":"3",
"velocity":"0",
"gpsalt":"41",
"relativealt":"2",
"cur":"65.53",
"vbat":"0.00",
"batremaining":"0",
"message":"",
"missionid":"0",
"droneid":"1",
"device":"dron"
}
)";
void setup() {
Serial.begin(115200);
// Подключение к Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to Wi-Fi");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
// Инициализация запроса
http.begin(serverUrl);
http.addHeader("Content-Type", "application/json");
http.addHeader("x-api-key", apiKey);
// Отправка POST-запроса
int httpResponseCode = http.POST(jsonBody);
// Обработка ответа
if (httpResponseCode > 0) {
String response = http.getString();
Serial.printf("HTTP Response Code: %d\n", httpResponseCode);
Serial.println("Response:");
Serial.println(response);
} else {
Serial.printf("Error in sending POST: %s\n",
http.errorToString(httpResponseCode).c_str());
}
http.end();
} else {
Serial.println("Wi-Fi Disconnected");
}
// Задержка 3 секунды
delay(500);
}