mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
uart
This commit is contained in:
1
data/items/uart-button.txt
Normal file
1
data/items/uart-button.txt
Normal file
@@ -0,0 +1 @@
|
||||
0;button-out;id;toggle;Кнопки;Освещение;order;type[UART]
|
||||
1
data/items/uart-widget.txt
Normal file
1
data/items/uart-widget.txt
Normal file
@@ -0,0 +1 @@
|
||||
0;inoutput;id;anydata;Вывод;Вывод#uart;order
|
||||
4
data/presets/7.c.txt
Normal file
4
data/presets/7.c.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
0;inoutput;text;anydataAlarm;Сигнализация;Движение:;1
|
||||
0;inoutput;time;anydataTime;Сигнализация;Время:;2
|
||||
0;button-in;sensor;na;na;na;3;pin[0];db[20]
|
||||
0;button-out;reset;toggle;Сигнализация;Сбросить;4
|
||||
10
data/presets/7.s.txt
Normal file
10
data/presets/7.s.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
sensor = 1
|
||||
text обнаружено
|
||||
time %date%
|
||||
telegram text обнаружено#движение 1
|
||||
end
|
||||
reset = 1
|
||||
text не#обнаружено
|
||||
time %date%
|
||||
reset 0
|
||||
end
|
||||
4
data/presets/8.c.txt
Normal file
4
data/presets/8.c.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
0;button-in;sensor;na;na;na;1;pin[0];db[20]
|
||||
0;button-out;light;toggle;Освещение;Освещение;2;pin[13]
|
||||
0;count-down;count;anydata;Освещение;Обратный#отчет;3
|
||||
0;inoutput;period;inputDigit;Освещение;Период#включения;4
|
||||
7
data/presets/8.s.txt
Normal file
7
data/presets/8.s.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
sensor = 1
|
||||
light 1
|
||||
count period
|
||||
end
|
||||
count = 0
|
||||
light 0
|
||||
end
|
||||
2
data/presets/9.c.txt
Normal file
2
data/presets/9.c.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
0;button-out;light;toggle;Кнопки;Освещение;1;pin[13]
|
||||
0;button-in;switch;na;na;na;2;pin[0];db[20]
|
||||
3
data/presets/9.s.txt
Normal file
3
data/presets/9.s.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
switch = 1
|
||||
light change
|
||||
end
|
||||
@@ -93,6 +93,8 @@
|
||||
"/set?addItem=impuls-out": "20.Создать импульсы через заданный промежуток времени (управление шд)",
|
||||
"/set?addItem=count-down": "21.Таймер обратного отчета",
|
||||
"/set?addItem=modbus": "22.Прочитать регистр modbus устройства",
|
||||
"/set?addItem=uart-button": "23.UART кнопка (шлет свое состояние в UART)",
|
||||
"/set?addItem=uart-widget": "24.UART виджет (позволяет вывести полученные данные в любой виджет)",
|
||||
"/set?addItem=logging": "a.Логгирование и вывод в график любой величины",
|
||||
"/set?addItem=uptime": "b.Отобразить время работы устройства"
|
||||
}
|
||||
@@ -111,7 +113,8 @@
|
||||
"/set?addPreset=5.c": "5.Выключить все (пример работы сценариев)",
|
||||
"/set?addPreset=6.c": "6.Включить кнопку на определенное время (пример работы таймера обратного отчета)",
|
||||
"/set?addPreset=7.c": "7.Охранный датчик движения",
|
||||
"/set?addPreset=8.c": "8.Датчик движения включающий свет"
|
||||
"/set?addPreset=8.c": "8.Датчик движения включающий свет с настраиваемой задержкой",
|
||||
"/set?addPreset=9.c": "9.Управление светом с помощью выключателя и приложения"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
6
data/widgets/anydataAlarm.json
Normal file
6
data/widgets/anydataAlarm.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"widget": "anydata",
|
||||
"after": "",
|
||||
"color":"red",
|
||||
"icon": "walk"
|
||||
}
|
||||
@@ -2,5 +2,6 @@
|
||||
"widget" : "input",
|
||||
"color" : "green",
|
||||
"type" : "number",
|
||||
"size" : "small",
|
||||
"icon": "thermometer"
|
||||
}
|
||||
@@ -2,5 +2,6 @@
|
||||
"widget" : "input",
|
||||
"color" : "orange",
|
||||
"type" : "time",
|
||||
"size" : "small",
|
||||
"icon": "alarm-outline"
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "SoftwareSerial.h"
|
||||
|
||||
extern SoftwareSerial* myUART;
|
||||
|
||||
extern void uartInit();
|
||||
extern void uartHandle();
|
||||
extern void parse(String& incStr);
|
||||
@@ -10,7 +10,7 @@ typedef std::vector<ButtonOut> MyButtonOutVector;
|
||||
class ButtonOut {
|
||||
public:
|
||||
|
||||
ButtonOut(String pin, boolean inv, String key);
|
||||
ButtonOut(String pin, boolean inv, String key, String type);
|
||||
|
||||
~ButtonOut();
|
||||
|
||||
@@ -21,6 +21,7 @@ class ButtonOut {
|
||||
String _pin;
|
||||
boolean _inv;
|
||||
String _key;
|
||||
String _type;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -23,26 +23,28 @@ void uartInit() {
|
||||
}
|
||||
|
||||
void uartHandle() {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
return;
|
||||
}
|
||||
static String incStr;
|
||||
if (myUART->available()) {
|
||||
char inc;
|
||||
inc = myUART->read();
|
||||
incStr += inc;
|
||||
if (inc == '\n') {
|
||||
parse(incStr);
|
||||
incStr = "";
|
||||
if (myUART != nullptr) {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
return;
|
||||
}
|
||||
static String incStr;
|
||||
if (myUART->available()) {
|
||||
char inc;
|
||||
inc = myUART->read();
|
||||
incStr += inc;
|
||||
if (inc == '\n') {
|
||||
parse(incStr);
|
||||
incStr = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parse(String& incStr) {
|
||||
incStr.replace("\r\n", "");
|
||||
incStr.replace("\r", "");
|
||||
incStr.replace("\n", "");
|
||||
if (incStr.indexOf("set") != -1) {
|
||||
incStr.replace("\r\n", "");
|
||||
incStr.replace("\r", "");
|
||||
incStr.replace("\n", "");
|
||||
incStr = deleteBeforeDelimiter(incStr, " ");
|
||||
SerialPrint("I", "UART", incStr);
|
||||
orderBuf += incStr;
|
||||
|
||||
@@ -38,6 +38,7 @@ void web_init() {
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
addPreset(request->getParam("addPreset")->value());
|
||||
#endif
|
||||
jsonWriteStr(configSetupJson, "warning1", F("<div style='margin-top:10px;margin-bottom:10px;'><font color='black'><p style='border: 1px solid #DCDCDC; border-radius: 3px; background-color: #ffc7c7; padding: 10px;'>Требуется перезагрузка</p></font></div>"));
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "SoftUART.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
//this class save data to flash
|
||||
ButtonOut::ButtonOut(String pin, boolean inv, String key) {
|
||||
ButtonOut::ButtonOut(String pin, boolean inv, String key, String type) {
|
||||
_pin = pin;
|
||||
_inv = inv;
|
||||
_key = key;
|
||||
_type = type;
|
||||
if (_pin != "") {
|
||||
pinMode(_pin.toInt(), OUTPUT);
|
||||
}
|
||||
@@ -18,6 +20,13 @@ ButtonOut::ButtonOut(String pin, boolean inv, String key) {
|
||||
ButtonOut::~ButtonOut() {}
|
||||
|
||||
void ButtonOut::execute(String state) {
|
||||
if (_type == "UART") {
|
||||
if (jsonReadBool(configSetupJson, "uart")) {
|
||||
if (myUART != nullptr) {
|
||||
myUART->print(_key + " " + state);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state != "" && _pin != "") {
|
||||
if (state == "change") {
|
||||
state = String(!digitalRead(_pin.toInt()));
|
||||
@@ -45,6 +54,7 @@ void buttonOut() {
|
||||
String key = myLineParsing.gkey();
|
||||
String pin = myLineParsing.gpin();
|
||||
String inv = myLineParsing.ginv();
|
||||
String type = myLineParsing.gtype();
|
||||
|
||||
bool invb = false;
|
||||
if (inv.toInt() == 1) invb = true;
|
||||
@@ -57,7 +67,7 @@ void buttonOut() {
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myButtonOut = new MyButtonOutVector();
|
||||
firstTime = false;
|
||||
myButtonOut->push_back(ButtonOut(pin, invb, key));
|
||||
myButtonOut->push_back(ButtonOut(pin, invb, key, type));
|
||||
|
||||
sCmd.addCommand(key.c_str(), buttonOutExecute);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "items/vInOutput.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "Clock.h"
|
||||
|
||||
//this class save date to flash
|
||||
InOutput::InOutput(String key, String widget) {
|
||||
_key = key;
|
||||
@@ -12,7 +12,7 @@ InOutput::InOutput(String key, String widget) {
|
||||
|
||||
if (value == "") {
|
||||
if (widget.indexOf("Digit") != -1) {
|
||||
value = "52";
|
||||
value = "25";
|
||||
}
|
||||
if (widget.indexOf("Time") != -1) {
|
||||
value = "12:00";
|
||||
@@ -52,13 +52,18 @@ void inOutput() {
|
||||
void inOutputExecute() {
|
||||
String key = sCmd.order();
|
||||
String value = sCmd.next();
|
||||
//String type = sCmd.next();
|
||||
|
||||
|
||||
if (!isDigitStr(value)) { //если значение - текст
|
||||
if (value.indexOf(":") == -1) { //если этот текст не время
|
||||
String tmp = getValue(value);
|
||||
if(tmp != "no value") {
|
||||
value = tmp;
|
||||
value.replace("#"," ");
|
||||
String valueJson = getValue(value);
|
||||
if (valueJson != "no value") { //если это ключ переменной
|
||||
value = valueJson;
|
||||
}
|
||||
else { //если это просто текст
|
||||
value.replace("#", " ");
|
||||
value.replace("%date%", timeNow->getDateTimeDotFormated());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ void setup() {
|
||||
fileSystemInit();
|
||||
SerialPrint("I", F("FS"), F("FS Init"));
|
||||
|
||||
SerialPrint("I", F("UART"), F("UART Init"));
|
||||
uartInit();
|
||||
|
||||
loadConfig();
|
||||
SerialPrint("I", F("Conf"), F("Config Init"));
|
||||
|
||||
@@ -92,8 +95,7 @@ void setup() {
|
||||
SerialPrint("I", F("Bus"), F("Bus Init"));
|
||||
busInit();
|
||||
|
||||
SerialPrint("I", F("UART"), F("UART Init"));
|
||||
uartInit();
|
||||
|
||||
|
||||
#ifdef SSDP_ENABLED
|
||||
SerialPrint("I", F("SSDP"), F("Ssdp Init"));
|
||||
|
||||
Reference in New Issue
Block a user