mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
telegram bot added (working version)
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
"mqttUser": "rise",
|
"mqttUser": "rise",
|
||||||
"mqttPass": "23ri22se32",
|
"mqttPass": "23ri22se32",
|
||||||
"scen": "1",
|
"scen": "1",
|
||||||
"pushingboxid": "v7C133E426B0C69E",
|
"telegramApi": "1425283609:AAFf3YO8ouCJF23kU8CMiU7XXy21MFhbn9w",
|
||||||
"weblogin": "admin",
|
"weblogin": "admin",
|
||||||
"webpass": "admin",
|
"webpass": "admin",
|
||||||
"udponoff": "1",
|
"udponoff": "1",
|
||||||
|
|||||||
@@ -37,8 +37,8 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "link",
|
"type": "link",
|
||||||
"title": "Конфигурация push",
|
"title": "Конфигурация telegram",
|
||||||
"action": "/?set.push",
|
"action": "/?set.telegram",
|
||||||
"class": "btn btn-block btn-default"
|
"class": "btn btn-block btn-default"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,30 +22,24 @@
|
|||||||
{
|
{
|
||||||
"type": "h4",
|
"type": "h4",
|
||||||
"style": "width:60%;float:left;",
|
"style": "width:60%;float:left;",
|
||||||
"title": "Device id:"
|
"title": "Telegram API token:"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"title": "",
|
"title": "",
|
||||||
"name": "push-arg",
|
"name": "telegramApi-arg",
|
||||||
"style": "width:40%;float:right",
|
"style": "width:40%;float:right",
|
||||||
"state": "{{pushingboxid}}"
|
"state": "{{telegramApi}}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "button",
|
"type": "button",
|
||||||
"title": "{{ButSave}}",
|
"title": "{{ButSave}}",
|
||||||
"action": "set?pushingboxid=[[push-arg]]",
|
"action": "set?telegramApi=[[telegramApi-arg]]",
|
||||||
"class": "btn btn-block btn-default",
|
"class": "btn btn-block btn-default",
|
||||||
"style": "width:100%;display:inline"
|
"style": "width:100%;display:inline"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "hr"
|
"type": "hr"
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "link",
|
|
||||||
"title": "Перезагрузить устройство",
|
|
||||||
"action": "javascript:if(confirm(renameBlock(jsonResponse,'Перезагрузить?'))){send_request(this,'/restart?device=ok');}",
|
|
||||||
"class": "btn btn-block btn-danger"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -8,3 +8,57 @@ extern void spaceCmdExecute(String& cmdStr);
|
|||||||
extern void loopCmdExecute();
|
extern void loopCmdExecute();
|
||||||
extern void addKey(String& key, String& keyNumberTable, int number);
|
extern void addKey(String& key, String& keyNumberTable, int number);
|
||||||
extern int getKeyNum(String& key, String& keyNumberTable);
|
extern int getKeyNum(String& key, String& keyNumberTable);
|
||||||
|
|
||||||
|
extern void buttonOut();
|
||||||
|
extern void buttonOutSet();
|
||||||
|
|
||||||
|
extern void pwmOut();
|
||||||
|
extern void pwmOutSet();
|
||||||
|
|
||||||
|
extern void buttonIn();
|
||||||
|
extern void buttonInSet();
|
||||||
|
|
||||||
|
extern void inputDigit();
|
||||||
|
extern void inputDigitSet();
|
||||||
|
|
||||||
|
extern void inputTime();
|
||||||
|
extern void inputTimeSet();
|
||||||
|
|
||||||
|
extern void textOut();
|
||||||
|
extern void textOutSet();
|
||||||
|
|
||||||
|
extern void analogAdc();
|
||||||
|
extern void analogReading();
|
||||||
|
|
||||||
|
extern void ultrasonicCm();
|
||||||
|
extern void ultrasonicReading();
|
||||||
|
|
||||||
|
extern void dallasTemp();
|
||||||
|
extern void dallasReading();
|
||||||
|
|
||||||
|
extern void dhtTemp();
|
||||||
|
extern void dhtReadingTemp();
|
||||||
|
extern void dhtHum();
|
||||||
|
extern void dhtReadingHum();
|
||||||
|
|
||||||
|
extern void bme280Temp();
|
||||||
|
extern void bme280ReadingTemp();
|
||||||
|
extern void bme280Hum();
|
||||||
|
extern void bme280ReadingHum();
|
||||||
|
extern void bme280Press();
|
||||||
|
extern void bme280ReadingPress();
|
||||||
|
|
||||||
|
extern void bmp280Temp();
|
||||||
|
extern void bmp280ReadingTemp();
|
||||||
|
extern void bmp280Press();
|
||||||
|
extern void bmp280ReadingPress();
|
||||||
|
|
||||||
|
//extern void modbus();
|
||||||
|
//extern void modbusReading();
|
||||||
|
|
||||||
|
extern void sysUptime();
|
||||||
|
extern void uptimeReading();
|
||||||
|
|
||||||
|
extern void logging();
|
||||||
|
|
||||||
|
extern void impuls();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <Adafruit_BME280.h>
|
#include <Adafruit_BME280.h>
|
||||||
#include <Adafruit_BMP280.h>
|
#include <Adafruit_BMP280.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include "CTBot.h"
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <Bounce2.h>
|
#include <Bounce2.h>
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
extern void buttonOut();
|
|
||||||
extern void buttonOutSet();
|
|
||||||
|
|
||||||
extern void pwmOut();
|
|
||||||
extern void pwmOutSet();
|
|
||||||
|
|
||||||
extern void buttonIn();
|
|
||||||
extern void buttonInSet();
|
|
||||||
|
|
||||||
extern void inputDigit();
|
|
||||||
extern void inputDigitSet();
|
|
||||||
|
|
||||||
extern void inputTime();
|
|
||||||
extern void inputTimeSet();
|
|
||||||
|
|
||||||
extern void textOut();
|
|
||||||
extern void textOutSet();
|
|
||||||
|
|
||||||
extern void analogAdc();
|
|
||||||
extern void analogReading();
|
|
||||||
|
|
||||||
extern void ultrasonicCm();
|
|
||||||
extern void ultrasonicReading();
|
|
||||||
|
|
||||||
extern void dallasTemp();
|
|
||||||
extern void dallasReading();
|
|
||||||
|
|
||||||
extern void dhtTemp();
|
|
||||||
extern void dhtReadingTemp();
|
|
||||||
extern void dhtHum();
|
|
||||||
extern void dhtReadingHum();
|
|
||||||
|
|
||||||
extern void bme280Temp();
|
|
||||||
extern void bme280ReadingTemp();
|
|
||||||
extern void bme280Hum();
|
|
||||||
extern void bme280ReadingHum();
|
|
||||||
extern void bme280Press();
|
|
||||||
extern void bme280ReadingPress();
|
|
||||||
|
|
||||||
extern void bmp280Temp();
|
|
||||||
extern void bmp280ReadingTemp();
|
|
||||||
extern void bmp280Press();
|
|
||||||
extern void bmp280ReadingPress();
|
|
||||||
|
|
||||||
//extern void modbus();
|
|
||||||
//extern void modbusReading();
|
|
||||||
|
|
||||||
extern void sysUptime();
|
|
||||||
extern void uptimeReading();
|
|
||||||
|
|
||||||
extern void logging();
|
|
||||||
|
|
||||||
extern void impuls();
|
|
||||||
6
include/Telegram.h
Normal file
6
include/Telegram.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern void telegramInit();
|
||||||
|
extern void handleTelegram();
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ButtonInClass : public LineParsing {
|
class ButtonInClass : public LineParsing {
|
||||||
protected:
|
protected:
|
||||||
int numberEntering = 0;
|
int numberEntering = 0;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
default_envs = esp32
|
default_envs = esp8266
|
||||||
;=============================================================================================================================================
|
;=============================================================================================================================================
|
||||||
[common_env_data]
|
[common_env_data]
|
||||||
lib_deps_external =
|
lib_deps_external =
|
||||||
@@ -26,6 +26,7 @@ lib_deps =
|
|||||||
AsyncTCP
|
AsyncTCP
|
||||||
madhephaestus/ESP32Servo
|
madhephaestus/ESP32Servo
|
||||||
luc-github/ESP32SSDP
|
luc-github/ESP32SSDP
|
||||||
|
CTBot
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -43,6 +44,7 @@ lib_deps =
|
|||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
ESPAsyncUDP
|
ESPAsyncUDP
|
||||||
EspSoftwareSerial
|
EspSoftwareSerial
|
||||||
|
CTBot
|
||||||
monitor_filters = esp8266_exception_decoder
|
monitor_filters = esp8266_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -58,6 +60,7 @@ lib_deps =
|
|||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
ESPAsyncUDP
|
ESPAsyncUDP
|
||||||
EspSoftwareSerial
|
EspSoftwareSerial
|
||||||
|
CTBot
|
||||||
monitor_filters = esp8266_exception_decoder
|
monitor_filters = esp8266_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
|
#include "items/SensorDallas.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Module/Terminal.h"
|
#include "Module/Terminal.h"
|
||||||
|
|
||||||
@@ -23,9 +23,80 @@ void csvCmdExecute(String& cmdStr) {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
while (cmdStr.length()) {
|
while (cmdStr.length()) {
|
||||||
String buf = selectToMarker(cmdStr, "\n");
|
String buf = selectToMarker(cmdStr, "\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
buf = deleteBeforeDelimiter(buf, " "); //отсечка чекбокса
|
buf = deleteBeforeDelimiter(buf, " "); //отсечка чекбокса
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
if (count > 1) sCmd.readStr(buf);
|
if (count > 1) {
|
||||||
|
SerialPrint("I", "Items", buf);
|
||||||
|
String order = selectToMarker(buf, " "); //отсечка самой команды
|
||||||
|
|
||||||
|
if (order == F("button-out")) {
|
||||||
|
sCmd.addCommand(order.c_str(), buttonOut);
|
||||||
|
}
|
||||||
|
else if (order == F("pwm-out")) {
|
||||||
|
sCmd.addCommand(order.c_str(), pwmOut);
|
||||||
|
}
|
||||||
|
else if (order == F("button-in")) {
|
||||||
|
sCmd.addCommand(order.c_str(), buttonIn);
|
||||||
|
}
|
||||||
|
else if (order == F("input-digit")) {
|
||||||
|
sCmd.addCommand(order.c_str(), inputDigit);
|
||||||
|
}
|
||||||
|
else if (order == F("input-time")) {
|
||||||
|
sCmd.addCommand(order.c_str(), inputTime);
|
||||||
|
}
|
||||||
|
else if (order == F("output-text")) {
|
||||||
|
sCmd.addCommand(order.c_str(), textOut);
|
||||||
|
}
|
||||||
|
else if (order == F("analog-adc")) {
|
||||||
|
sCmd.addCommand(order.c_str(), analogAdc);
|
||||||
|
}
|
||||||
|
else if (order == F("ultrasonic-cm")) {
|
||||||
|
sCmd.addCommand(order.c_str(), ultrasonicCm);
|
||||||
|
}
|
||||||
|
else if (order == F("dallas-temp")) {
|
||||||
|
sCmd.addCommand(order.c_str(), dallas);
|
||||||
|
}
|
||||||
|
else if (order == F("dht-temp")) {
|
||||||
|
sCmd.addCommand(order.c_str(), dhtTemp);
|
||||||
|
}
|
||||||
|
else if (order == F("dht-hum")) {
|
||||||
|
sCmd.addCommand(order.c_str(), dhtHum);
|
||||||
|
}
|
||||||
|
else if (order == F("bme280-temp")) {
|
||||||
|
sCmd.addCommand(order.c_str(), bme280Temp);
|
||||||
|
}
|
||||||
|
else if (order == F("bme280-hum")) {
|
||||||
|
sCmd.addCommand(order.c_str(), bme280Hum);
|
||||||
|
}
|
||||||
|
else if (order == F("bme280-press")) {
|
||||||
|
sCmd.addCommand(order.c_str(), bme280Press);
|
||||||
|
}
|
||||||
|
else if (order == F("bmp280-temp")) {
|
||||||
|
sCmd.addCommand(order.c_str(), bmp280Temp);
|
||||||
|
}
|
||||||
|
else if (order == F("bmp280-press")) {
|
||||||
|
sCmd.addCommand(order.c_str(), bmp280Press);
|
||||||
|
}
|
||||||
|
else if (order == F("modbus")) {
|
||||||
|
//sCmd.addCommand(order.c_str(), modbus);
|
||||||
|
}
|
||||||
|
else if (order == F("uptime")) {
|
||||||
|
sCmd.addCommand(order.c_str(), sysUptime);
|
||||||
|
}
|
||||||
|
else if (order == F("logging")) {
|
||||||
|
sCmd.addCommand(order.c_str(), logging);
|
||||||
|
}
|
||||||
|
else if (order == F("impuls-out")) {
|
||||||
|
sCmd.addCommand(order.c_str(), impuls);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sCmd.readStr(buf);
|
||||||
|
}
|
||||||
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
|
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,7 +151,7 @@ void addKey(String& key, String& keyNumberTable, int number) {
|
|||||||
|
|
||||||
int getKeyNum(String& key, String& keyNumberTable) {
|
int getKeyNum(String& key, String& keyNumberTable) {
|
||||||
String keyNumberTableBuf = keyNumberTable;
|
String keyNumberTableBuf = keyNumberTable;
|
||||||
//SerialPrint("","",keyNumberTable);
|
|
||||||
int number = -1;
|
int number = -1;
|
||||||
while (keyNumberTableBuf.length()) {
|
while (keyNumberTableBuf.length()) {
|
||||||
String tmp = selectToMarker(keyNumberTableBuf, ",");
|
String tmp = selectToMarker(keyNumberTableBuf, ",");
|
||||||
|
|||||||
@@ -35,19 +35,18 @@ void Device_init() {
|
|||||||
if (mySensorDallas2 != nullptr) {
|
if (mySensorDallas2 != nullptr) {
|
||||||
mySensorDallas2->clear();
|
mySensorDallas2->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//======clear logging params======
|
//======clear logging params======
|
||||||
if (myLogging != nullptr) {
|
if (myLogging != nullptr) {
|
||||||
myLogging->clear();
|
myLogging->clear();
|
||||||
}
|
}
|
||||||
loggingKeyList = "";
|
loggingKeyList = "";
|
||||||
|
|
||||||
//======clear impuls params=======
|
//======clear impuls params=======
|
||||||
if (myImpulsOut != nullptr) {
|
if (myImpulsOut != nullptr) {
|
||||||
myImpulsOut->clear();
|
myImpulsOut->clear();
|
||||||
}
|
}
|
||||||
impulsKeyList = "";
|
impulsKeyList = "";
|
||||||
impulsEnterCounter = -1;
|
impulsEnterCounter = -1;
|
||||||
|
//================================
|
||||||
|
|
||||||
|
|
||||||
#ifdef LAYOUT_IN_RAM
|
#ifdef LAYOUT_IN_RAM
|
||||||
|
|||||||
@@ -1,60 +1,60 @@
|
|||||||
#include "ItemsCmd.h"
|
//#include "BufferExecute.h"
|
||||||
|
//
|
||||||
|
//#include "BufferExecute.h"
|
||||||
|
//#include "Class/NotAsync.h"
|
||||||
|
//#include "Cmd.h"
|
||||||
|
//#include "Global.h"
|
||||||
|
//#include "Module/Terminal.h"
|
||||||
|
//#include "Servo/Servos.h"
|
||||||
|
//
|
||||||
|
//#include "items/SensorDallas.h"
|
||||||
|
//
|
||||||
|
//Terminal *term = nullptr;
|
||||||
|
//
|
||||||
|
//boolean but[NUM_BUTTONS];
|
||||||
|
//Bounce *buttons = new Bounce[NUM_BUTTONS];
|
||||||
|
//
|
||||||
|
//#ifdef ESP8266
|
||||||
|
//SoftwareSerial *mySerial = nullptr;
|
||||||
|
//#else
|
||||||
|
//HardwareSerial *mySerial = nullptr;
|
||||||
|
//#endif
|
||||||
|
//
|
||||||
|
//void getData();
|
||||||
|
//
|
||||||
|
//void cmd_init() {
|
||||||
|
//sCmd.addCommand("button-out", buttonOut);
|
||||||
|
//sCmd.addCommand("pwm-out", pwmOut);
|
||||||
|
//sCmd.addCommand("button-in", buttonIn);
|
||||||
|
|
||||||
#include "BufferExecute.h"
|
//sCmd.addCommand("input-digit", inputDigit);
|
||||||
#include "Class/NotAsync.h"
|
//sCmd.addCommand("input-time", inputTime);
|
||||||
#include "Cmd.h"
|
//sCmd.addCommand("output-text", textOut);
|
||||||
#include "Global.h"
|
|
||||||
#include "Module/Terminal.h"
|
|
||||||
#include "Servo/Servos.h"
|
|
||||||
|
|
||||||
#include "items/SensorDallas.h"
|
//sCmd.addCommand("analog-adc", analogAdc);
|
||||||
|
//sCmd.addCommand("ultrasonic-cm", ultrasonicCm);
|
||||||
|
//sCmd.addCommand("dallas-temp", dallas);
|
||||||
|
|
||||||
Terminal *term = nullptr;
|
//sCmd.addCommand("dht-temp", dhtTemp);
|
||||||
|
//sCmd.addCommand("dht-hum", dhtHum);
|
||||||
|
|
||||||
boolean but[NUM_BUTTONS];
|
//sCmd.addCommand("bme280-temp", bme280Temp);
|
||||||
Bounce *buttons = new Bounce[NUM_BUTTONS];
|
//sCmd.addCommand("bme280-hum", bme280Hum);
|
||||||
|
//sCmd.addCommand("bme280-press", bme280Press);
|
||||||
|
|
||||||
#ifdef ESP8266
|
//sCmd.addCommand("bmp280-temp", bmp280Temp);
|
||||||
SoftwareSerial *mySerial = nullptr;
|
//sCmd.addCommand("bmp280-press", bmp280Press);
|
||||||
#else
|
|
||||||
HardwareSerial *mySerial = nullptr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void getData();
|
|
||||||
|
|
||||||
void cmd_init() {
|
|
||||||
sCmd.addCommand("button-out", buttonOut);
|
|
||||||
sCmd.addCommand("pwm-out", pwmOut);
|
|
||||||
sCmd.addCommand("button-in", buttonIn);
|
|
||||||
|
|
||||||
sCmd.addCommand("input-digit", inputDigit);
|
|
||||||
sCmd.addCommand("input-time", inputTime);
|
|
||||||
sCmd.addCommand("output-text", textOut);
|
|
||||||
|
|
||||||
sCmd.addCommand("analog-adc", analogAdc);
|
|
||||||
sCmd.addCommand("ultrasonic-cm", ultrasonicCm);
|
|
||||||
sCmd.addCommand("dallas-temp", dallas);
|
|
||||||
|
|
||||||
sCmd.addCommand("dht-temp", dhtTemp);
|
|
||||||
sCmd.addCommand("dht-hum", dhtHum);
|
|
||||||
|
|
||||||
sCmd.addCommand("bme280-temp", bme280Temp);
|
|
||||||
sCmd.addCommand("bme280-hum", bme280Hum);
|
|
||||||
sCmd.addCommand("bme280-press", bme280Press);
|
|
||||||
|
|
||||||
sCmd.addCommand("bmp280-temp", bmp280Temp);
|
|
||||||
sCmd.addCommand("bmp280-press", bmp280Press);
|
|
||||||
|
|
||||||
//sCmd.addCommand("modbus", modbus);
|
//sCmd.addCommand("modbus", modbus);
|
||||||
|
|
||||||
sCmd.addCommand("uptime", sysUptime);
|
//sCmd.addCommand("uptime", sysUptime);
|
||||||
|
|
||||||
sCmd.addCommand("logging", logging);
|
//sCmd.addCommand("logging", logging);
|
||||||
|
|
||||||
sCmd.addCommand("impuls-out", impuls);
|
//sCmd.addCommand("impuls-out", impuls);
|
||||||
|
|
||||||
handle_time_init();
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
// sCmd.addCommand("timerStart", timerStart_);
|
// sCmd.addCommand("timerStart", timerStart_);
|
||||||
// sCmd.addCommand("timerStop", timerStop_);
|
// sCmd.addCommand("timerStop", timerStop_);
|
||||||
|
|||||||
35
src/Telegram.cpp
Normal file
35
src/Telegram.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include "Telegram.h"
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
|
||||||
|
CTBot* myBot{ nullptr };
|
||||||
|
|
||||||
|
void telegramInit() {
|
||||||
|
String token = jsonReadStr(configSetupJson, "telegramApi");
|
||||||
|
if (!myBot) {
|
||||||
|
myBot = new CTBot();
|
||||||
|
}
|
||||||
|
myBot->setTelegramToken(token);
|
||||||
|
if (myBot->testConnection()) {
|
||||||
|
SerialPrint("I", "Telegram", "Connected");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SerialPrint("E", "Telegram", "Not connected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleTelegram() {
|
||||||
|
|
||||||
|
TBMessage msg;
|
||||||
|
|
||||||
|
static unsigned long prevMillis;
|
||||||
|
unsigned long currentMillis = millis();
|
||||||
|
unsigned long difference = currentMillis - prevMillis;
|
||||||
|
if (difference >= 1000) {
|
||||||
|
prevMillis = millis();
|
||||||
|
if (myBot->getNewMessage(msg)) {
|
||||||
|
Serial.println(msg.text);
|
||||||
|
myBot->sendMessage(msg.sender.id, msg.text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
|
||||||
|
|
||||||
String jsonReadStr(String& json, String name) {
|
String jsonReadStr(String& json, String name) {
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
JsonObject& root = jsonBuffer.parseObject(json);
|
JsonObject& root = jsonBuffer.parseObject(json);
|
||||||
|
|||||||
33
src/Web.cpp
33
src/Web.cpp
@@ -193,14 +193,13 @@ void web_init() {
|
|||||||
request->send(200, "text/html", payload);
|
request->send(200, "text/html", payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
// //==============================push settings=============================================
|
//==============================push settings=============================================
|
||||||
//#ifdef PUSH_ENABLED
|
if (request->hasArg("telegramApi")) {
|
||||||
// if (request->hasArg("pushingboxid")) {
|
jsonWriteStr(configSetupJson, "telegramApi", request->getParam("telegramApi")->value());
|
||||||
// jsonWriteStr(configSetupJson, "pushingboxid", request->getParam("pushingboxid")->value());
|
|
||||||
// saveConfig();
|
saveConfig();
|
||||||
// request->send(200);
|
request->send(200);
|
||||||
// }
|
}
|
||||||
//#endif
|
|
||||||
|
|
||||||
//==============================utilities settings=============================================
|
//==============================utilities settings=============================================
|
||||||
if (request->hasArg("i2c")) {
|
if (request->hasArg("i2c")) {
|
||||||
@@ -215,7 +214,7 @@ void web_init() {
|
|||||||
serverIP = jsonReadStr(configSetupJson, "serverip");
|
serverIP = jsonReadStr(configSetupJson, "serverip");
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//==============================list of items=====================================================
|
//==============================list of items=====================================================
|
||||||
//server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) {
|
//server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
@@ -240,13 +239,17 @@ void web_init() {
|
|||||||
String msg = "";
|
String msg = "";
|
||||||
if (lastVersion == FIRMWARE_VERSION) {
|
if (lastVersion == FIRMWARE_VERSION) {
|
||||||
msg = F("Актуальная версия прошивки уже установлена.");
|
msg = F("Актуальная версия прошивки уже установлена.");
|
||||||
} else if (lastVersion > FIRMWARE_VERSION) {
|
}
|
||||||
|
else if (lastVersion > FIRMWARE_VERSION) {
|
||||||
msg = F("Новая версия прошивки<a href=\"#\" class=\"btn btn-block btn-danger\" onclick=\"send_request(this, '/upgrade');setTimeout(function(){ location.href='/?set.device'; }, 90000);html('my-block','<span class=loader></span>Идет обновление прошивки, после обновления страница перезагрузится автоматически...')\">Установить</a>");
|
msg = F("Новая версия прошивки<a href=\"#\" class=\"btn btn-block btn-danger\" onclick=\"send_request(this, '/upgrade');setTimeout(function(){ location.href='/?set.device'; }, 90000);html('my-block','<span class=loader></span>Идет обновление прошивки, после обновления страница перезагрузится автоматически...')\">Установить</a>");
|
||||||
} else if (lastVersion == -1) {
|
}
|
||||||
|
else if (lastVersion == -1) {
|
||||||
msg = F("Cервер не найден. Попробуйте повторить позже...");
|
msg = F("Cервер не найден. Попробуйте повторить позже...");
|
||||||
} else if (lastVersion == -2) {
|
}
|
||||||
|
else if (lastVersion == -2) {
|
||||||
msg = F("Устройство не подключено к роутеру!");
|
msg = F("Устройство не подключено к роутеру!");
|
||||||
} else if (lastVersion < FIRMWARE_VERSION) {
|
}
|
||||||
|
else if (lastVersion < FIRMWARE_VERSION) {
|
||||||
msg = F("Ошибка версии. Попробуйте повторить позже...");
|
msg = F("Ошибка версии. Попробуйте повторить позже...");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +265,7 @@ void web_init() {
|
|||||||
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>" + msg);
|
jsonWriteStr(tmp, "title", "<button class=\"close\" onclick=\"toggle('my-block')\">×</button>" + msg);
|
||||||
jsonWriteStr(tmp, "class", "pop-up");
|
jsonWriteStr(tmp, "class", "pop-up");
|
||||||
request->send(200, "text/html", tmp);
|
request->send(200, "text/html", tmp);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Upgrade
|
* Upgrade
|
||||||
@@ -270,7 +273,7 @@ void web_init() {
|
|||||||
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
myNotAsyncActions->make(do_UPGRADE);
|
myNotAsyncActions->make(do_UPGRADE);
|
||||||
request->send(200, "text/html");
|
request->send(200, "text/html");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void setConfigParam(const char* param, const String& value) {
|
void setConfigParam(const char* param, const String& value) {
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
#include "items/ButtonInClass.h"
|
#include "items/ButtonInClass.h"
|
||||||
//==========================================Модуль физических кнопок========================================
|
//==========================================Модуль физических кнопок========================================
|
||||||
//button-in switch1 toggle Кнопки Свет 1 pin[2] db[20]
|
//button-in switch1 toggle Кнопки Свет 1 pin[2] db[20]
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
|
|
||||||
|
boolean but[NUM_BUTTONS];
|
||||||
|
Bounce *buttons = new Bounce[NUM_BUTTONS];
|
||||||
|
|
||||||
ButtonInClass myButtonIn;
|
ButtonInClass myButtonIn;
|
||||||
void buttonIn() {
|
void buttonIn() {
|
||||||
myButtonIn.update();
|
myButtonIn.update();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "items/ButtonOutClass.h"
|
#include "items/ButtonOutClass.h"
|
||||||
|
|
||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
//==========================================Модуль кнопок===================================================
|
//==========================================Модуль кнопок===================================================
|
||||||
//button-out light toggle Кнопки Свет 1 pin[12] inv[1] st[1]
|
//button-out light toggle Кнопки Свет 1 pin[12] inv[1] st[1]
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "BufferExecute.h"
|
#include "BufferExecute.h"
|
||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
|
|
||||||
ImpulsOutClass::ImpulsOutClass(unsigned int impulsPin) {
|
ImpulsOutClass::ImpulsOutClass(unsigned int impulsPin) {
|
||||||
_impulsPin = impulsPin;
|
_impulsPin = impulsPin;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
#include "items/InputClass.h"
|
#include "items/InputClass.h"
|
||||||
//==========================================Модуль ввода цифровых значений==================================
|
//==========================================Модуль ввода цифровых значений==================================
|
||||||
//input-digit digit1 inputDigit Ввод Введите.цифру 4 st[60]
|
//input-digit digit1 inputDigit Ввод Введите.цифру 4 st[60]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
#include "items/InputClass.h"
|
#include "items/InputClass.h"
|
||||||
//==========================================Модуль ввода времени============================================
|
//==========================================Модуль ввода времени============================================
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
|
|
||||||
LoggingClass::LoggingClass(unsigned long period, unsigned int maxPoints, String loggingValueKey, String key) {
|
LoggingClass::LoggingClass(unsigned long period, unsigned int maxPoints, String loggingValueKey, String key) {
|
||||||
_period = period * 1000;
|
_period = period * 1000;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
#include "items/OutputTextClass.h"
|
#include "items/OutputTextClass.h"
|
||||||
//===============================================Модуль вывода текста============================================
|
//===============================================Модуль вывода текста============================================
|
||||||
//output-text;id;anydata;Вывод;Сигнализация;order;st[Обнаружено.движение]
|
//output-text;id;anydata;Вывод;Сигнализация;order;st[Обнаружено.движение]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
#include "items/PwmOutClass.h"
|
#include "items/PwmOutClass.h"
|
||||||
//==========================================Модуль управления ШИМ===================================================
|
//==========================================Модуль управления ШИМ===================================================
|
||||||
//pwm-out volume range Кнопки Свет 1 pin[12] st[500]
|
//pwm-out volume range Кнопки Свет 1 pin[12] st[500]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
#include "items/SensorAnalogClass.h"
|
#include "items/SensorAnalogClass.h"
|
||||||
#ifdef ANALOG_ENABLED
|
#ifdef ANALOG_ENABLED
|
||||||
//==============================================Модуль аналогового сенсора===========================================================================================
|
//==============================================Модуль аналогового сенсора===========================================================================================
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "items/SensorBme280Class.h"
|
#include "items/SensorBme280Class.h"
|
||||||
|
|
||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
//#ifdef SensorBme280Enabled
|
//#ifdef SensorBme280Enabled
|
||||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||||
//bme280-temp;id;anydata;Сенсоры;Температура;order;c[1]
|
//bme280-temp;id;anydata;Сенсоры;Температура;order;c[1]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "items/SensorBmp280Class.h"
|
#include "items/SensorBmp280Class.h"
|
||||||
|
|
||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
//#ifdef SensorBmp280Enabled
|
//#ifdef SensorBmp280Enabled
|
||||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||||
//bmp280-temp;id;anydata;Сенсоры;Температура;order;c[1]
|
//bmp280-temp;id;anydata;Сенсоры;Температура;order;c[1]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "items/SensorDallas.h"
|
#include "items/SensorDallas.h"
|
||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
SensorDallas::SensorDallas(unsigned long interval, unsigned int pin, unsigned int index, String key) {
|
SensorDallas::SensorDallas(unsigned long interval, unsigned int pin, unsigned int index, String key) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "items/SensorDhtClass.h"
|
#include "items/SensorDhtClass.h"
|
||||||
|
|
||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
//#ifdef SensorDhtEnabled
|
//#ifdef SensorDhtEnabled
|
||||||
//=========================================DHT Sensor==================================================================
|
//=========================================DHT Sensor==================================================================
|
||||||
//dht-temp;id;anydata;Сенсоры;Температура;order;pin;type[dht11];c[1]
|
//dht-temp;id;anydata;Сенсоры;Температура;order;pin;type[dht11];c[1]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//#include "items/SensorModbusClass.h"
|
//#include "items/SensorModbusClass.h"
|
||||||
//
|
//
|
||||||
//#include "ItemsCmd.h"
|
//#include "BufferExecute.h"
|
||||||
////#ifdef SensorModbusEnabled
|
////#ifdef SensorModbusEnabled
|
||||||
////=========================================Модуль modbus===================================================================================
|
////=========================================Модуль modbus===================================================================================
|
||||||
////modbus;id;anydata;Сенсоры;Температура;order;addr[1];regaddr[0];c[1]
|
////modbus;id;anydata;Сенсоры;Температура;order;addr[1];regaddr[0];c[1]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
#include "items/SensorUltrasonicClass.h"
|
#include "items/SensorUltrasonicClass.h"
|
||||||
//#ifdef SensorUltrasonicEnabled
|
//#ifdef SensorUltrasonicEnabled
|
||||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "ItemsCmd.h"
|
#include "BufferExecute.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
|||||||
40
src/main.cpp
40
src/main.cpp
@@ -18,6 +18,7 @@
|
|||||||
#include "items/LoggingClass.h"
|
#include "items/LoggingClass.h"
|
||||||
#include "items/ImpulsOutClass.h"
|
#include "items/ImpulsOutClass.h"
|
||||||
#include "items/SensorDallas.h"
|
#include "items/SensorDallas.h"
|
||||||
|
#include "Telegram.h"
|
||||||
|
|
||||||
void not_async_actions();
|
void not_async_actions();
|
||||||
|
|
||||||
@@ -38,44 +39,47 @@ void setup() {
|
|||||||
myNotAsyncActions = new NotAsync(do_LAST);
|
myNotAsyncActions = new NotAsync(do_LAST);
|
||||||
myScenario = new Scenario();
|
myScenario = new Scenario();
|
||||||
|
|
||||||
SerialPrint("I", "FS", "FS Init");
|
|
||||||
fileSystemInit();
|
fileSystemInit();
|
||||||
|
SerialPrint("I", "FS", "FS Init");
|
||||||
|
|
||||||
SerialPrint("I", "Conf", "Config Init");
|
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
SerialPrint("I", "Conf", "Config Init");
|
||||||
|
|
||||||
SerialPrint("I", "Time", "Clock Init");
|
|
||||||
clock_init();
|
clock_init();
|
||||||
|
SerialPrint("I", "Time", "Clock Init");
|
||||||
|
|
||||||
SerialPrint("I", "CMD", "Commands Init");
|
handle_time_init();
|
||||||
cmd_init();
|
SerialPrint("I", "Time", "Handle time init(");
|
||||||
|
|
||||||
SerialPrint("I", "Sensors", "Sensors Init");
|
|
||||||
sensorsInit();
|
sensorsInit();
|
||||||
|
SerialPrint("I", "Sensors", "Sensors Init");
|
||||||
|
|
||||||
SerialPrint("I", "Items", "Items Init");
|
|
||||||
itemsListInit();
|
itemsListInit();
|
||||||
|
SerialPrint("I", "Items", "Items Init");
|
||||||
|
|
||||||
SerialPrint("I", "Init", "Init Init");
|
|
||||||
all_init();
|
all_init();
|
||||||
|
SerialPrint("I", "Init", "Init Init");
|
||||||
|
|
||||||
SerialPrint("I", "WIFI", "Network Init");
|
|
||||||
routerConnect();
|
routerConnect();
|
||||||
|
SerialPrint("I", "WIFI", "Network Init");
|
||||||
|
|
||||||
|
telegramInit();
|
||||||
|
SerialPrint("I", "Telegram", "Telegram Init");
|
||||||
|
|
||||||
SerialPrint("I", "Uptime", "Uptime Init");
|
|
||||||
uptime_init();
|
uptime_init();
|
||||||
|
SerialPrint("I", "Uptime", "Uptime Init");
|
||||||
|
|
||||||
SerialPrint("I", "Update", "Updater Init");
|
|
||||||
upgradeInit();
|
upgradeInit();
|
||||||
|
SerialPrint("I", "Update", "Updater Init");
|
||||||
|
|
||||||
SerialPrint("I", "HTTP", "HttpServer Init");
|
|
||||||
HttpServer::init();
|
HttpServer::init();
|
||||||
|
SerialPrint("I", "HTTP", "HttpServer Init");
|
||||||
|
|
||||||
SerialPrint("I", "Web", "WebAdmin Init");
|
|
||||||
web_init();
|
web_init();
|
||||||
|
SerialPrint("I", "Web", "WebAdmin Init");
|
||||||
|
|
||||||
SerialPrint("I", "Stat", "Stat Init");
|
|
||||||
initSt();
|
initSt();
|
||||||
|
SerialPrint("I", "Stat", "Stat Init");
|
||||||
|
|
||||||
#ifdef UDP_ENABLED
|
#ifdef UDP_ENABLED
|
||||||
SerialPrint("I", "UDP", "Udp Init");
|
SerialPrint("I", "UDP", "Udp Init");
|
||||||
@@ -90,6 +94,8 @@ void setup() {
|
|||||||
SsdpInit();
|
SsdpInit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//esp_log_level_set("esp_littlefs", ESP_LOG_NONE);
|
//esp_log_level_set("esp_littlefs", ESP_LOG_NONE);
|
||||||
|
|
||||||
ts.add(
|
ts.add(
|
||||||
@@ -99,9 +105,7 @@ void setup() {
|
|||||||
nullptr, true);
|
nullptr, true);
|
||||||
|
|
||||||
just_load = false;
|
just_load = false;
|
||||||
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
initialized = true;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -124,6 +128,8 @@ void loop() {
|
|||||||
myNotAsyncActions->loop();
|
myNotAsyncActions->loop();
|
||||||
ts.update();
|
ts.update();
|
||||||
|
|
||||||
|
handleTelegram();
|
||||||
|
|
||||||
if (myLogging != nullptr) {
|
if (myLogging != nullptr) {
|
||||||
for (unsigned int i = 0; i < myLogging->size(); i++) {
|
for (unsigned int i = 0; i < myLogging->size(); i++) {
|
||||||
myLogging->at(i).loop();
|
myLogging->at(i).loop();
|
||||||
|
|||||||
Reference in New Issue
Block a user