Working version

This commit is contained in:
Dmitry Borisenko
2020-11-15 02:46:27 +03:00
parent d6aab0cf94
commit 94d93d3be6
14 changed files with 58 additions and 111 deletions

View File

@@ -154,6 +154,12 @@
{ {
"type": "hr" "type": "hr"
}, },
{
"type": "button",
"title": "Очистить графики и сбросить введенные данные",
"action": "/set?cleanlog",
"class": "btn btn-block btn-default"
},
{ {
"type": "link", "type": "link",
"title": "Ручная настройка", "title": "Ручная настройка",
@@ -166,12 +172,6 @@
"action": "https://github.com/IoTManagerProject/IoTManager/wiki", "action": "https://github.com/IoTManagerProject/IoTManager/wiki",
"class": "btn btn-block btn-default" "class": "btn btn-block btn-default"
}, },
{
"type": "button",
"title": "Очистить графики и сбросить введенные данные",
"action": "/set?cleanlog",
"class": "btn btn-block btn-default"
},
{ {
"type": "hr" "type": "hr"
}, },

View File

@@ -114,3 +114,7 @@ enum ConfigType_t {
//13.11.2020 (SSDP OFF, UDP OFF) //13.11.2020 (SSDP OFF, UDP OFF)
//RAM: [===== ] 46.6% (used 38208 bytes from 81920 bytes) //RAM: [===== ] 46.6% (used 38208 bytes from 81920 bytes)
//Flash: [===== ] 54.2% (used 566388 bytes from 1044464 bytes) //Flash: [===== ] 54.2% (used 566388 bytes from 1044464 bytes)
//15.11.2020 (SSDP OFF, UDP OFF)
//RAM: [===== ] 46.1% (used 37780 bytes from 81920 bytes)
//Flash: [===== ] 54.3% (used 566656 bytes from 1044464 bytes)

View File

@@ -49,3 +49,5 @@ int getOffsetInMinutes(int timezone);
* Разбивает время на составляющие * Разбивает время на составляющие
*/ */
void breakEpochToTime(unsigned long epoch, Time_t& tm); void breakEpochToTime(unsigned long epoch, Time_t& tm);
void handle_time_init();

View File

@@ -1,31 +0,0 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
//class InputClass : public LineParsing {
// public:
// InputClass() : LineParsing(){};
//
// void inputSetDefaultFloat() {
// inputSetFloat(_key, _state);
// }
//
// void inputSetDefaultStr() {
// inputSetStr(_key, _state);
// }
//
// void inputSetFloat(String key, String state) {
// eventGen2(key, state);
// jsonWriteFloat(configLiveJson, key, state.toFloat());
// publishStatus(key, state);
// }
//
// void inputSetStr(String key, String state) {
// eventGen2(key, state);
// jsonWriteStr(configLiveJson, key, state);
// publishStatus(key, state);
// }
//};
//
//extern InputClass myInput;

View File

@@ -10,17 +10,15 @@ typedef std::vector<Input> MyInputVector;
class Input { class Input {
public: public:
Input(String key); Input(String key, String widget);
~Input(); ~Input();
void execute(String state); void execute(String value);
private: private:
String _key; String _key;
void addNewDelOldData(const String filename, size_t maxPoints, String payload);
}; };
extern MyInputVector* myInput; extern MyInputVector* myInput;

View File

@@ -31,4 +31,4 @@ extern MyLoggingVector* myLogging;
extern void choose_log_date_and_send(); extern void choose_log_date_and_send();
extern void sendLogData(String file, String topic); extern void sendLogData(String file, String topic);
extern void clean_log_date(); extern void cleanLogAndData();

View File

@@ -45,12 +45,9 @@ void csvCmdExecute(String& cmdStr) {
else if (order == F("button-in")) { else if (order == F("button-in")) {
sCmd.addCommand(order.c_str(), buttonIn); sCmd.addCommand(order.c_str(), buttonIn);
} }
else if (order == F("input-digit")) { else if (order == F("input")) {
sCmd.addCommand(order.c_str(), input); sCmd.addCommand(order.c_str(), input);
} }
else if (order == F("input-time")) {
//sCmd.addCommand(order.c_str(), inputTime);
}
else if (order == F("output-text")) { else if (order == F("output-text")) {
sCmd.addCommand(order.c_str(), textOut); sCmd.addCommand(order.c_str(), textOut);
} }

View File

@@ -68,6 +68,8 @@ void addPreset(String name) {
void delAllItems() { void delAllItems() {
removeFile(DEVICE_CONFIG_FILE); removeFile(DEVICE_CONFIG_FILE);
addFile(DEVICE_CONFIG_FILE, String(firstLine)); addFile(DEVICE_CONFIG_FILE, String(firstLine));
removeFile(DEVICE_SCENARIO_FILE);
addFile(DEVICE_SCENARIO_FILE, "//");
removeFile("id.txt"); removeFile("id.txt");
removeFile("order.txt"); removeFile("order.txt");
removeFile("pins.txt"); removeFile("pins.txt");

View File

@@ -1,5 +1,5 @@
#include "Utils/TimeUtils.h" #include "Utils/TimeUtils.h"
#include "Global.h"
#include "Utils/StringUtils.h" #include "Utils/StringUtils.h"
static const uint8_t days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; static const uint8_t days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
@@ -211,3 +211,17 @@ void breakEpochToTime(unsigned long epoch, Time_t& tm) {
tm.day_of_month = time + 1; // day of month tm.day_of_month = time + 1; // day of month
tm.valid = (epoch > MIN_DATETIME); tm.valid = (epoch > MIN_DATETIME);
} }
void handle_time_init() {
ts.add(
TIME, 1000, [&](void*) {
String timenow = timeNow->getTimeWOsec();
static String prevTime;
if (prevTime != timenow) {
prevTime = timenow;
jsonWriteStr(configLiveJson, "timenow", timenow);
eventGen2("timenow", timenow);
}
},
nullptr, true);
}

View File

@@ -59,7 +59,7 @@ void web_init() {
#ifdef LOGGING_ENABLED #ifdef LOGGING_ENABLED
if (request->hasArg("cleanlog")) { if (request->hasArg("cleanlog")) {
clean_log_date(); cleanLogAndData();
request->send(200); request->send(200);
} }
#endif #endif

View File

@@ -1,19 +0,0 @@
//#include "BufferExecute.h"
//#include "items/InputClass.h"
////==========================================Модуль ввода цифровых значений==================================
////input-digit digit1 inputDigit Ввод Введите.цифру 4 st[60]
////==========================================================================================================
//InputClass myInputDigit;
//void inputDigit() {
// myInputDigit.update();
// String key = myInputDigit.gkey();
// sCmd.addCommand(key.c_str(), inputDigitSet);
// myInputDigit.inputSetDefaultFloat();
// myInputDigit.clear();
//}
//
//void inputDigitSet() {
// String key = sCmd.order();
// String state = sCmd.next();
// myInputDigit.inputSetFloat(key, state);
//}

View File

@@ -1,32 +0,0 @@
#include "BufferExecute.h"
#include "items/InputClass.h"
//==========================================Модуль ввода времени============================================
//==========================================================================================================
//InputClass myInputTime;
//void inputTime() {
// myInputTime.update();
// String key = myInputTime.gkey();
// sCmd.addCommand(key.c_str(), inputTimeSet);
// myInputTime.inputSetDefaultStr();
// myInputTime.clear();
//}
//
//void inputTimeSet() {
// String key = sCmd.order();
// String state = sCmd.next();
// myInputTime.inputSetStr(key, state);
//}
void handle_time_init() {
ts.add(
TIME, 1000, [&](void*) {
String timenow = timeNow->getTimeWOsec();
static String prevTime;
if (prevTime != timenow) {
prevTime = timenow;
jsonWriteStr(configLiveJson, "timenow", timenow);
eventGen2("timenow", timenow);
}
},
nullptr, true);
}

View File

@@ -6,24 +6,35 @@
#include "Global.h" #include "Global.h"
#include "BufferExecute.h" #include "BufferExecute.h"
Input::Input(String key) { Input::Input(String key, String widget) {
_key = key; _key = key;
String value = jsonReadStr(configLiveJson, key); String value = jsonReadStr(configLiveJson, key);
if (value == "") {
if (widget.indexOf("Digit") != -1) {
value = "52";
}
if (widget.indexOf("Time") != -1) {
value = "12:00";
}
}
this->execute(value); this->execute(value);
} }
Input::~Input() {} Input::~Input() {}
void Input::execute(String state) { void Input::execute(String value) {
eventGen2(_key, state); eventGen2(_key, value);
jsonWriteInt(configLiveJson, _key, state.toInt()); jsonWriteStr(configLiveJson, _key, value);
saveLive(); saveLive();
publishStatus(_key, state); publishStatus(_key, value);
} }
MyInputVector* myInput = nullptr; MyInputVector* myInput = nullptr;
void input() { void input() {
myLineParsing.update(); myLineParsing.update();
String widget = myLineParsing.gfile();
String key = myLineParsing.gkey(); String key = myLineParsing.gkey();
myLineParsing.clear(); myLineParsing.clear();
@@ -33,20 +44,20 @@ void input() {
static bool firstTime = true; static bool firstTime = true;
if (firstTime) myInput = new MyInputVector(); if (firstTime) myInput = new MyInputVector();
firstTime = false; firstTime = false;
myInput->push_back(Input(key)); myInput->push_back(Input(key, widget));
sCmd.addCommand(key.c_str(), inputExecute); sCmd.addCommand(key.c_str(), inputExecute);
} }
void inputExecute() { void inputExecute() {
String key = sCmd.order(); String key = sCmd.order();
String state = sCmd.next(); String value = sCmd.next();
int number = getKeyNum(key, input_KeyList); int number = getKeyNum(key, input_KeyList);
if (myInput != nullptr) { if (myInput != nullptr) {
if (number != -1) { if (number != -1) {
myInput->at(number).execute(state); myInput->at(number).execute(value);
} }
} }
} }

View File

@@ -112,7 +112,7 @@ void sendLogData(String file, String topic) {
} }
} }
void clean_log_date() { void cleanLogAndData() {
#ifdef ESP8266 #ifdef ESP8266
auto dir = LittleFS.openDir("logs"); auto dir = LittleFS.openDir("logs");
while (dir.next()) { while (dir.next()) {
@@ -121,5 +121,6 @@ void clean_log_date() {
removeFile("logs/" + fname); removeFile("logs/" + fname);
} }
removeFile("live.json"); removeFile("live.json");
configLiveJson = "";
#endif #endif
} }