GyverLibs / FastBot

Многофункциональная быстрая библиотека для Телеграм бота на esp8266/esp32
MIT License
187 stars 32 forks source link

не работает отправка из бота в клиента #61

Closed ChaosPrometheus closed 10 months ago

ChaosPrometheus commented 10 months ago

include

include

include

include

define WIFI_SSID ""

define WIFI_PASS ""

define BOT_TOKEN ""

const char *apiKey = ""; FastBot bot(BOT_TOKEN);

float kelvinToCelsius(float kelvin) { return kelvin - 273.15; }

void newMsg(FB_msg& msg) { bot.sendMessage("проверка чата", msg.chatID); String cityName = msg.text; cityName.trim();

HTTPClient http; WiFiClient client;

String url = "http://api.openweathermap.org/data/2.5/weather?q=" + cityName + "&lang=ru&appid=" + String(apiKey);

http.begin(client, url); int httpCode = http.GET();

if (httpCode > 0) { String payload = http.getString(); DynamicJsonDocument doc(1024); deserializeJson(doc, payload); float temperature = doc["main"]["temp"]; temperature = kelvinToCelsius(temperature); String weatherDescription = doc["weather"][0]["description"]; int humidity = doc["main"]["humidity"]; float windSpeed = doc["wind"]["speed"];

String message = "Температура: " + String(temperature) + "°C\n"
               + "Состояние облачности: " + weatherDescription + "\n"
               + "Влажность: " + String(humidity) + "%\n"
               + "Скорость ветра: " + String(windSpeed) + " м/с";

// Send weather information to Telegram bot
bot.sendMessage(message, msg.chatID);
Serial.println(msg.toString());

} else { bot.sendMessage("ошибка", msg.chatID); }

http.end(); }

void setup() { // Your setup code goes here }

void loop() { bot.tick(); }

void connectWiFi() { delay(2000); WiFi.begin(WIFI_SSID, WIFI_PASS); while (WiFi.status() != WL_CONNECTED) { delay(500); if (millis() > 15000) ESP.restart(); } }