add meteo-out
This commit is contained in:
107
Devices/dev-test/src/main.cpp
Normal file
107
Devices/dev-test/src/main.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ArduinoNATS.h>
|
||||
#include <FastBot2.h>
|
||||
|
||||
FastBot2 bot;
|
||||
|
||||
#define WIFI_SSID "paranetm"
|
||||
#define WIFI_PASS "78515169"
|
||||
#define BOT_TOKEN "5363807811:AAHRz_rDIY5AV2NpEzS9jy0xXwjScAJyUOs"
|
||||
#define CHAT_ID "317081354"
|
||||
|
||||
WiFiClient clientNats;
|
||||
NATS nats(
|
||||
&clientNats,
|
||||
"nats.paranet.ru", NATS_DEFAULT_PORT);
|
||||
|
||||
void updateh(fb::Update &u)
|
||||
{
|
||||
Serial.println("NEW MESSAGE");
|
||||
Serial.println(u.message().from().username());
|
||||
Serial.println(u.message().text());
|
||||
|
||||
// #1
|
||||
// отправить обратно в чат (эхо)
|
||||
bot.sendMessage(fb::Message(u.message().text(), u.message().chat().id()));
|
||||
|
||||
// #2
|
||||
// String text = u.message().text();
|
||||
// text += " - ответ";
|
||||
// bot.sendMessage(fb::Message(text, u.message().chat().id()));
|
||||
|
||||
// #3
|
||||
// fb::Message msg;
|
||||
// msg.text = u.message().text();
|
||||
// msg.text += " - ответ";
|
||||
// msg.chatID = u.message().chat().id();
|
||||
// bot.sendMessage(msg);
|
||||
}
|
||||
|
||||
void nats_blink_handler(NATS::msg msg)
|
||||
{
|
||||
// nats.publish(msg.reply, msg.data);
|
||||
String str = F("reply\n");
|
||||
str += msg.reply;
|
||||
str += F("\ndata\n");
|
||||
str += msg.data;
|
||||
Serial.println(str);
|
||||
// _telegram.send(str, _config.CHAT_ID);
|
||||
|
||||
// int count = atoi(msg.data);
|
||||
// while (count-- > 0)
|
||||
// {
|
||||
// digitalWrite(LED_BUILTIN, LOW);
|
||||
// delay(100);
|
||||
// digitalWrite(LED_BUILTIN, HIGH);
|
||||
// delay(100);
|
||||
// }
|
||||
}
|
||||
|
||||
void nats_on_connect()
|
||||
{
|
||||
nats.subscribe("switches/k1", nats_blink_handler);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println(F("SYSTEM: HAL9000"));
|
||||
Serial.println(F("Module: test"));
|
||||
|
||||
Serial.println("Connected");
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("Connected");
|
||||
|
||||
// ============
|
||||
bot.attachUpdate(updateh); // подключить обработчик обновлений
|
||||
bot.setToken(F(BOT_TOKEN)); // установить токен
|
||||
|
||||
// режим опроса обновлений. Самый быстрый - Long
|
||||
// особенности читай тут в самом низу
|
||||
// https://github.com/GyverLibs/FastBot2/blob/main/docs/3.start.md
|
||||
|
||||
// bot.setPollMode(fb::Poll::Sync, 4000); // умолч
|
||||
// bot.setPollMode(fb::Poll::Async, 4000);
|
||||
bot.setPollMode(fb::Poll::Long, 60000);
|
||||
|
||||
// поприветствуем админа
|
||||
bot.sendMessage(fb::Message("Hello!", CHAT_ID));
|
||||
|
||||
Serial.print("connect NATS...");
|
||||
nats.on_connect = nats_on_connect;
|
||||
nats.connect();
|
||||
Serial.println(" OK");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
bot.tick();
|
||||
}
|
||||
Reference in New Issue
Block a user