#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <FastLED.h> // конфигурация матрицы
#define NUM_LEDS 64 // количество светодиодов в матрице
CRGB leds[NUM_LEDS]; // определяем матрицу (FastLED библиотека)
#define LED_PIN 14 // пин к которому подключена матрица
#define COLOR_ORDER GRB // порядок цветов матрицы
#define CHIPSET WS2812 // тип светодиодов
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define BOT_TOKEN "6791079592:AAEnQZpvDGjf7sqrKjlcYCsBnU6x3Haf8cE" //<----------------- Вставьте сюда ваш токен бота
const unsigned long BOT_MTBS = 1000; // mean time between scan messages
WiFiClientSecure secured_client;
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
unsigned long bot_lasttime; // last time messages' scan has been done
void handleNewMessages(int numNewMessages)
{
Serial.print("handleNewMessages ");
Serial.println(numNewMessages);
for (int i = 0; i < numNewMessages; i++)
{
String chat_id = bot.messages[i].chat_id;
String text = bot.messages[i].text;
String from_name = bot.messages[i].from_name;
if (from_name == "")
from_name = "Guest";
if (text == "/doklad")
{
int h = 100;
bot.sendMessage(chat_id,String(h), "");
}
if (text == "/start")
{
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
welcome += "/doklad : Нажми чтобы узнать сколько раз срабатывал датчик движения";
bot.sendMessage(chat_id, welcome, "Markdown");
}
}
}
void setup()
{
Serial.begin(115200);
Serial.println();
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
Serial.print("Connecting to Wifi SSID ");
Serial.print(WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.print("\nWiFi connected. IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Retrieving time: ");
configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
time_t now = time(nullptr);
while (now < 24 * 3600)
{
Serial.print(".");
delay(100);
now = time(nullptr);
}
Serial.println(now);
}
void loop()
{
if (millis() - bot_lasttime > BOT_MTBS)
{
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while (numNewMessages)
{
Serial.println("got response");
handleNewMessages(numNewMessages);
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
bot_lasttime = millis();
}
fill_solid(leds, NUM_LEDS, CRGB(255, 100, 20));
FastLED.show();
}Board not found
wokwi-custom-board
wokwi-custom-board