mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
UART working condition
This commit is contained in:
@@ -22,5 +22,9 @@
|
||||
"snaMqtt": "0",
|
||||
"blink": "1",
|
||||
"oneWirePin": "2",
|
||||
"serverip": "http://206.189.49.244"
|
||||
"serverip": "http://206.189.49.244",
|
||||
"uart": "0",
|
||||
"uartS":"9600",
|
||||
"uartTX":"12",
|
||||
"uartRX":"13"
|
||||
}
|
||||
@@ -84,9 +84,16 @@
|
||||
{
|
||||
"type": "input",
|
||||
"title": "",
|
||||
"name": "uartTX-arg",
|
||||
"name": "uartRX-arg",
|
||||
"state": "{{uartRX}}",
|
||||
"style": "width:40%;float:right"
|
||||
},
|
||||
{
|
||||
"type": "button",
|
||||
"title": "{{ButSave}}",
|
||||
"style": "width:100%;float:left;",
|
||||
"action": "set?uartS=[[uartS-arg]]&uartTX=[[uartTX-arg]]&uartRX=[[uartRX-arg]]",
|
||||
"class": "btn btn-block btn-default"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "SoftUART.h"
|
||||
#include "Global.h"
|
||||
|
||||
#ifdef ESP8266
|
||||
SoftwareSerial* myUART = nullptr;
|
||||
@@ -7,10 +8,13 @@ HardwareSerial* myUART = nullptr;
|
||||
#endif
|
||||
|
||||
void uartInit() {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
return;
|
||||
}
|
||||
if (!myUART) {
|
||||
#ifdef ESP8266
|
||||
myUART = new SoftwareSerial(4, 5);
|
||||
myUART->begin(9600);
|
||||
myUART = new SoftwareSerial(jsonReadInt(configSetupJson, "uartTX"), jsonReadInt(configSetupJson, "uartRX"));
|
||||
myUART->begin(jsonReadInt(configSetupJson, "uartS"));
|
||||
#else
|
||||
myUART = new HardwareSerial(2);
|
||||
myUART->begin(4, 5);
|
||||
@@ -19,19 +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 = "";
|
||||
parse(incStr);
|
||||
incStr = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parse(String& incStr) {
|
||||
|
||||
|
||||
if (incStr.indexOf("set") != -1) {
|
||||
incStr.replace("\r\n", "");
|
||||
incStr.replace("\r", "");
|
||||
incStr.replace("\n", "");
|
||||
incStr = deleteBeforeDelimiter(incStr, " ");
|
||||
SerialPrint("I", "UART", incStr);
|
||||
orderBuf += incStr;
|
||||
}
|
||||
}
|
||||
26
src/Web.cpp
26
src/Web.cpp
@@ -6,6 +6,7 @@
|
||||
#include "items/vLogging.h"
|
||||
#include "Telegram.h"
|
||||
#include "RemoteOrdersUdp.h"
|
||||
#include "SoftUART.h"
|
||||
|
||||
bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
||||
if (request->hasArg("preset")) {
|
||||
@@ -255,6 +256,31 @@ void web_init() {
|
||||
myNotAsyncActions->make(do_BUSSCAN);
|
||||
request->redirect("/?set.utilities");
|
||||
}
|
||||
if (request->hasArg("uart")) {
|
||||
bool value = request->getParam("uart")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "uart", value);
|
||||
saveConfig();
|
||||
uartInit();
|
||||
request->send(200);
|
||||
}
|
||||
if (request->hasArg("uartS")) {
|
||||
jsonWriteStr(configSetupJson, "uartS", request->getParam("uartS")->value());
|
||||
saveConfig();
|
||||
uartInit();
|
||||
request->send(200);
|
||||
}
|
||||
if (request->hasArg("uartTX")) {
|
||||
jsonWriteStr(configSetupJson, "uartTX", request->getParam("uartTX")->value());
|
||||
saveConfig();
|
||||
uartInit();
|
||||
request->send(200);
|
||||
}
|
||||
if (request->hasArg("uartRX")) {
|
||||
jsonWriteStr(configSetupJson, "uartRX", request->getParam("uartRX")->value());
|
||||
saveConfig();
|
||||
uartInit();
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
//==============================developer settings=============================================
|
||||
if (request->hasArg("serverip")) {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "items/vCountDown.h"
|
||||
#include "items/vSensorUltrasonic.h"
|
||||
#include "Telegram.h"
|
||||
#include "SoftUART.h"
|
||||
|
||||
void not_async_actions();
|
||||
|
||||
@@ -91,6 +92,9 @@ 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"));
|
||||
SsdpInit();
|
||||
@@ -155,6 +159,8 @@ void loop() {
|
||||
|
||||
handleTelegram();
|
||||
|
||||
uartHandle();
|
||||
|
||||
if (myLogging != nullptr) {
|
||||
for (unsigned int i = 0; i < myLogging->size(); i++) {
|
||||
myLogging->at(i).loop();
|
||||
|
||||
Reference in New Issue
Block a user