mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
1 mb compiling version
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "items/vLogging.h"
|
||||
#include "items/vImpulsOut.h"
|
||||
#include "items/vCountDown.h"
|
||||
#include "items/SensorModbusClass.h"
|
||||
|
||||
void loopCmdAdd(const String& cmdStr) {
|
||||
orderBuf += cmdStr;
|
||||
@@ -41,9 +42,11 @@ void csvCmdExecute(String& cmdStr) {
|
||||
if (order == F("button-out")) {
|
||||
sCmd.addCommand(order.c_str(), buttonOut);
|
||||
}
|
||||
#ifdef PwmOutEnable
|
||||
else if (order == F("pwm-out")) {
|
||||
sCmd.addCommand(order.c_str(), pwmOut);
|
||||
}
|
||||
#endif
|
||||
else if (order == F("button-in")) {
|
||||
sCmd.addCommand(order.c_str(), buttonIn);
|
||||
}
|
||||
@@ -59,12 +62,15 @@ void csvCmdExecute(String& cmdStr) {
|
||||
else if (order == F("dallas-temp")) {
|
||||
sCmd.addCommand(order.c_str(), dallas);
|
||||
}
|
||||
#ifdef SensorDhtEnabled
|
||||
else if (order == F("dht-temp")) {
|
||||
sCmd.addCommand(order.c_str(), dhtTemp);
|
||||
}
|
||||
else if (order == F("dht-hum")) {
|
||||
sCmd.addCommand(order.c_str(), dhtHum);
|
||||
}
|
||||
#endif
|
||||
#ifdef SensorBme280Enabled
|
||||
else if (order == F("bme280-temp")) {
|
||||
sCmd.addCommand(order.c_str(), bme280Temp);
|
||||
}
|
||||
@@ -74,15 +80,20 @@ void csvCmdExecute(String& cmdStr) {
|
||||
else if (order == F("bme280-press")) {
|
||||
sCmd.addCommand(order.c_str(), bme280Press);
|
||||
}
|
||||
#endif
|
||||
#ifdef SensorBmp280Enabled
|
||||
else if (order == F("bmp280-temp")) {
|
||||
sCmd.addCommand(order.c_str(), bmp280Temp);
|
||||
}
|
||||
else if (order == F("bmp280-press")) {
|
||||
sCmd.addCommand(order.c_str(), bmp280Press);
|
||||
}
|
||||
#endif
|
||||
#ifdef SensorModbusEnabled
|
||||
else if (order == F("modbus")) {
|
||||
//sCmd.addCommand(order.c_str(), modbus);
|
||||
sCmd.addCommand(order.c_str(), modbus);
|
||||
}
|
||||
#endif
|
||||
else if (order == F("uptime")) {
|
||||
sCmd.addCommand(order.c_str(), sysUptime);
|
||||
}
|
||||
|
||||
@@ -76,11 +76,13 @@ void deviceInit() {
|
||||
inOutput_KeyList = "";
|
||||
inOutput_EnterCounter = -1;
|
||||
//======clear pwm params=======
|
||||
#ifdef PwmOutEnable
|
||||
if (myPwmOut != nullptr) {
|
||||
myPwmOut->clear();
|
||||
}
|
||||
pwmOut_KeyList = "";
|
||||
pwmOut_EnterCounter = -1;
|
||||
#endif
|
||||
//===================================
|
||||
if (myCountDown != nullptr) {
|
||||
myCountDown->clear();
|
||||
|
||||
@@ -19,34 +19,13 @@ void itemsListInit() {
|
||||
},
|
||||
nullptr);
|
||||
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
myNotAsyncActions->add(
|
||||
do_addItem, [&](void*) {
|
||||
addItem(itemName);
|
||||
itemName = "";
|
||||
},
|
||||
nullptr);
|
||||
|
||||
myNotAsyncActions->add(
|
||||
do_addPreset, [&](void*) {
|
||||
addPreset(presetName);
|
||||
presetName = "";
|
||||
},
|
||||
nullptr);
|
||||
#endif
|
||||
SerialPrint("I", F("Items"), F("Items Init"));
|
||||
}
|
||||
|
||||
void addItem(String name) {
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
String url = serverIP + F("/projects/iotmanager/config/items/") + name + ".txt";
|
||||
String item = getURL(url);
|
||||
Serial.println(url);
|
||||
if (item == "error") return;
|
||||
#endif
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
|
||||
String item = readFile("items/" + name + ".txt", 1024);
|
||||
#endif
|
||||
|
||||
name = selectToMarker(name, "-");
|
||||
|
||||
@@ -81,34 +60,16 @@ void addItem(String name) {
|
||||
}
|
||||
|
||||
void addPreset(String name) {
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
String url = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
|
||||
String preset = getURL(url);
|
||||
Serial.println(url);
|
||||
if (preset == "error") return;
|
||||
#endif
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
String preset = readFile("presets/" + name + ".txt", 4048);
|
||||
#endif
|
||||
|
||||
addFile(DEVICE_CONFIG_FILE, "\n" + preset);
|
||||
Serial.println(preset);
|
||||
|
||||
name.replace(".c", ".s");
|
||||
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
url = serverIP + F("/projects/iotmanager/config/presets/") + name + ".txt";
|
||||
String scenario = getURL(url);
|
||||
Serial.println(url);
|
||||
if (scenario == "error") return;
|
||||
#endif
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
String scenario = readFile("presets/" + name + ".txt", 4048);
|
||||
#endif
|
||||
|
||||
removeFile(DEVICE_SCENARIO_FILE);
|
||||
|
||||
|
||||
addFile(DEVICE_SCENARIO_FILE, scenario);
|
||||
loadScenario();
|
||||
Serial.println(scenario);
|
||||
|
||||
@@ -124,10 +124,8 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length) {
|
||||
SerialPrint("I", "MQTT", "Full update");
|
||||
publishWidgets();
|
||||
publishState();
|
||||
#ifdef LOGGING_ENABLED
|
||||
choose_log_date_and_send();
|
||||
#endif
|
||||
|
||||
choose_log_date_and_send();
|
||||
}
|
||||
|
||||
else if (topicStr.indexOf("control") != -1) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#ifdef uartEnable
|
||||
#include "SoftUART.h"
|
||||
#include "Global.h"
|
||||
|
||||
@@ -8,7 +9,7 @@ HardwareSerial* myUART = nullptr;
|
||||
#endif
|
||||
|
||||
void uartInit() {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
if (!jsonReadBool(configSetupJson, "uartEnable")) {
|
||||
return;
|
||||
}
|
||||
if (!myUART) {
|
||||
@@ -25,7 +26,7 @@ void uartInit() {
|
||||
|
||||
void uartHandle() {
|
||||
if (myUART) {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
if (!jsonReadBool(configSetupJson, "uartEnable")) {
|
||||
return;
|
||||
}
|
||||
static String incStr;
|
||||
@@ -50,4 +51,5 @@ void parse(String& incStr) {
|
||||
orderBuf += incStr;
|
||||
SerialPrint("I", "=>UART", incStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,6 +1,5 @@
|
||||
#ifdef telegram
|
||||
#include "Telegram.h"
|
||||
|
||||
|
||||
CTBot* myBot{ nullptr };
|
||||
|
||||
void telegramInit() {
|
||||
@@ -119,4 +118,5 @@ String returnListOfParams() {
|
||||
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
70
src/Web.cpp
70
src/Web.cpp
@@ -20,24 +20,12 @@ void web_init() {
|
||||
server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
//==============================set.device.json====================================================================================================
|
||||
if (request->hasArg("addItem")) {
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
itemName = request->getParam("addItem")->value();
|
||||
myNotAsyncActions->make(do_addItem);
|
||||
#endif
|
||||
#ifndef FLASH_SIZE_1MB
|
||||
addItem(request->getParam("addItem")->value());
|
||||
#endif
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("addPreset")) {
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
presetName = request->getParam("addPreset")->value();
|
||||
myNotAsyncActions->make(do_addPreset);
|
||||
#endif
|
||||
#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");
|
||||
}
|
||||
@@ -109,12 +97,11 @@ void web_init() {
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
#ifdef LOGGING_ENABLED
|
||||
|
||||
if (request->hasArg("cleanlog")) {
|
||||
cleanLogAndData();
|
||||
request->send(200);
|
||||
}
|
||||
#endif
|
||||
|
||||
//==============================wifi settings=============================================
|
||||
if (request->hasArg("devname")) {
|
||||
@@ -279,29 +266,37 @@ 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);
|
||||
if (request->hasArg("uartEnable")) {
|
||||
bool value = request->getParam("uartEnable")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "uartEnable", value);
|
||||
saveConfig();
|
||||
#ifdef uartEnable
|
||||
uartInit();
|
||||
#endif
|
||||
request->send(200);
|
||||
}
|
||||
if (request->hasArg("uartS")) {
|
||||
jsonWriteStr(configSetupJson, "uartS", request->getParam("uartS")->value());
|
||||
saveConfig();
|
||||
#ifdef uartEnable
|
||||
uartInit();
|
||||
#endif
|
||||
request->send(200);
|
||||
}
|
||||
if (request->hasArg("uartTX")) {
|
||||
jsonWriteStr(configSetupJson, "uartTX", request->getParam("uartTX")->value());
|
||||
saveConfig();
|
||||
#ifdef uartEnable
|
||||
uartInit();
|
||||
#endif
|
||||
request->send(200);
|
||||
}
|
||||
if (request->hasArg("uartRX")) {
|
||||
jsonWriteStr(configSetupJson, "uartRX", request->getParam("uartRX")->value());
|
||||
saveConfig();
|
||||
#ifdef uartEnable
|
||||
uartInit();
|
||||
#endif
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
@@ -335,26 +330,31 @@ void web_init() {
|
||||
SerialPrint("I", "Update", "firmware version: " + String(lastVersion));
|
||||
|
||||
String msg = "";
|
||||
//if (FLASH_SIZE_1MB) {
|
||||
// msg = F("Обновление невозможно, память устройства 1 мб");
|
||||
//}
|
||||
//else {
|
||||
if (lastVersion == FIRMWARE_VERSION) {
|
||||
msg = F("Актуальная версия прошивки уже установлена.");
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
if (FLASH_SIZE_1MB) {
|
||||
msg = F("Обновление невозможно, память устройства 1 мб");
|
||||
}
|
||||
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>");
|
||||
else {
|
||||
#endif
|
||||
|
||||
if (lastVersion == FIRMWARE_VERSION) {
|
||||
msg = F("Актуальная версия прошивки уже установлена.");
|
||||
}
|
||||
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>");
|
||||
}
|
||||
else if (lastVersion == -1) {
|
||||
msg = F("Cервер не найден. Попробуйте повторить позже...");
|
||||
}
|
||||
else if (lastVersion == -2) {
|
||||
msg = F("Устройство не подключено к роутеру!");
|
||||
}
|
||||
else if (lastVersion < FIRMWARE_VERSION) {
|
||||
msg = F("Ошибка версии. Попробуйте повторить позже...");
|
||||
}
|
||||
#ifdef FLASH_SIZE_1MB
|
||||
}
|
||||
else if (lastVersion == -1) {
|
||||
msg = F("Cервер не найден. Попробуйте повторить позже...");
|
||||
}
|
||||
else if (lastVersion == -2) {
|
||||
msg = F("Устройство не подключено к роутеру!");
|
||||
}
|
||||
else if (lastVersion < FIRMWARE_VERSION) {
|
||||
msg = F("Ошибка версии. Попробуйте повторить позже...");
|
||||
}
|
||||
//}
|
||||
#endif
|
||||
|
||||
// else if (lastVersion == "") {
|
||||
//msg = F("Нажмите на кнопку \"обновить прошивку\" повторно...");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Consts.h"
|
||||
#ifdef SensorBme280Enabled
|
||||
#include "items/SensorBme280Class.h"
|
||||
|
||||
#include "BufferExecute.h"
|
||||
//#ifdef SensorBme280Enabled
|
||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||
//bme280-temp;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
//bme280-hum;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
@@ -44,4 +44,4 @@ void bme280ReadingPress() {
|
||||
String key = sCmd.order();
|
||||
mySensorBme280.SensorBme280ReadPress(key);
|
||||
}
|
||||
//#endif
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Consts.h"
|
||||
#ifdef SensorBmp280Enabled
|
||||
#include "items/SensorBmp280Class.h"
|
||||
|
||||
#include "BufferExecute.h"
|
||||
//#ifdef SensorBmp280Enabled
|
||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||
//bmp280-temp;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
//bmp280-hum;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
@@ -32,4 +32,4 @@ void bmp280ReadingPress() {
|
||||
String key = sCmd.order();
|
||||
mySensorBmp280.SensorBmp280ReadPress(key);
|
||||
}
|
||||
//#endif
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Consts.h"
|
||||
#ifdef SensorDhtEnabled
|
||||
#include "items/SensorDhtClass.h"
|
||||
|
||||
#include "BufferExecute.h"
|
||||
//#ifdef SensorDhtEnabled
|
||||
//=========================================DHT Sensor==================================================================
|
||||
//dht-temp;id;anydata;Сенсоры;Температура;order;pin;type[dht11];c[1]
|
||||
//dht-hum;id;anydata;Сенсоры;Влажность;order;pin;type[dht11];c[1]
|
||||
@@ -32,4 +32,4 @@ void dhtReadingHum() {
|
||||
String key = sCmd.order();
|
||||
mySensorDht.SensorDhtReadHum(key);
|
||||
}
|
||||
//#endif
|
||||
#endif
|
||||
@@ -1,23 +1,23 @@
|
||||
//#include "items/SensorModbusClass.h"
|
||||
//
|
||||
//#include "BufferExecute.h"
|
||||
////#ifdef SensorModbusEnabled
|
||||
////=========================================Модуль modbus===================================================================================
|
||||
////modbus;id;anydata;Сенсоры;Температура;order;addr[1];regaddr[0];c[1]
|
||||
////=========================================================================================================================================
|
||||
//SensorModbusClass mySensorModbus;
|
||||
//
|
||||
//void modbus() {
|
||||
// mySensorModbus.update();
|
||||
// String key = mySensorModbus.gkey();
|
||||
// sCmd.addCommand(key.c_str(), modbusReading);
|
||||
// mySensorModbus.SensorModbusInit();
|
||||
// mySensorModbus.clear();
|
||||
//}
|
||||
//void modbusReading() {
|
||||
// String key = sCmd.order();
|
||||
// String addr = sCmd.next();
|
||||
// String regaddr = sCmd.next();
|
||||
// mySensorModbus.SensorModbusRead(key, addr.toInt(), regaddr.toInt());
|
||||
//}
|
||||
////#endif
|
||||
#include "Consts.h"
|
||||
#ifdef SensorModbusEnabled
|
||||
#include "items/SensorModbusClass.h"
|
||||
#include "BufferExecute.h"
|
||||
//=========================================Модуль modbus===================================================================================
|
||||
//modbus;id;anydata;Сенсоры;Температура;order;addr[1];regaddr[0];c[1]
|
||||
//=========================================================================================================================================
|
||||
SensorModbusClass mySensorModbus;
|
||||
|
||||
void modbus() {
|
||||
mySensorModbus.update();
|
||||
String key = mySensorModbus.gkey();
|
||||
sCmd.addCommand(key.c_str(), modbusReading);
|
||||
mySensorModbus.SensorModbusInit();
|
||||
mySensorModbus.clear();
|
||||
}
|
||||
void modbusReading() {
|
||||
String key = sCmd.order();
|
||||
String addr = sCmd.next();
|
||||
String regaddr = sCmd.next();
|
||||
mySensorModbus.SensorModbusRead(key, addr.toInt(), regaddr.toInt());
|
||||
}
|
||||
#endif
|
||||
@@ -21,12 +21,14 @@ ButtonOut::~ButtonOut() {}
|
||||
|
||||
void ButtonOut::execute(String state) {
|
||||
if (_type == "UART") {
|
||||
if (jsonReadBool(configSetupJson, "uart")) {
|
||||
if (jsonReadBool(configSetupJson, "uartEnable")) {
|
||||
#ifdef uartEnable
|
||||
if (myUART) {
|
||||
String msg = _key + " " + state;
|
||||
myUART->print(msg);
|
||||
SerialPrint("I", "<=UART", msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (state != "" && _pin != "") {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
|
||||
#include "Consts.h"
|
||||
#ifdef PwmOutEnable
|
||||
#include "items/vPwmOut.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
//this class save data to flash
|
||||
PwmOut::PwmOut(unsigned int pin, String key) {
|
||||
_pin = pin;
|
||||
@@ -52,4 +56,5 @@ void pwmOutExecute() {
|
||||
myPwmOut->at(number).execute(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -41,14 +41,18 @@ void setup() {
|
||||
setChipId();
|
||||
fileSystemInit();
|
||||
loadConfig();
|
||||
#ifdef uartEnable
|
||||
uartInit();
|
||||
#endif
|
||||
clockInit();
|
||||
timeInit();
|
||||
sensorsInit(); //Will be remooved
|
||||
itemsListInit();
|
||||
espInit();
|
||||
routerConnect();
|
||||
#ifdef telegram
|
||||
telegramInit();
|
||||
#endif
|
||||
uptime_init();
|
||||
upgradeInit();
|
||||
HttpServer::init();
|
||||
@@ -91,9 +95,13 @@ void loop() {
|
||||
myNotAsyncActions->loop();
|
||||
ts.update();
|
||||
|
||||
#ifdef telegram
|
||||
handleTelegram();
|
||||
#endif
|
||||
|
||||
#ifdef uartEnable
|
||||
uartHandle();
|
||||
#endif
|
||||
|
||||
if (myLogging != nullptr) {
|
||||
for (unsigned int i = 0; i < myLogging->size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user