mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
New method of sending date - direct from SPIFFS to MQTT!!!!
This commit is contained in:
2
Init.ino
2
Init.ino
@@ -41,7 +41,7 @@ void Device_init() {
|
|||||||
ts.remove(STEPPER1);
|
ts.remove(STEPPER1);
|
||||||
ts.remove(STEPPER2);
|
ts.remove(STEPPER2);
|
||||||
|
|
||||||
#ifdef layout_in_rom
|
#ifdef layout_in_ram
|
||||||
all_widgets = "";
|
all_widgets = "";
|
||||||
#else
|
#else
|
||||||
SPIFFS.remove("/layout.txt");
|
SPIFFS.remove("/layout.txt");
|
||||||
|
|||||||
19
Logging.ino
19
Logging.ino
@@ -103,7 +103,25 @@ void choose_log_date_and_send() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//=========================================Отправка данных===================================================================================
|
//=========================================Отправка данных===================================================================================
|
||||||
|
//прямое выкидывание данных из файла в файловой системе в mqtt, без загрузки оперативной памяти
|
||||||
void sendLogData(String file, String topic) {
|
void sendLogData(String file, String topic) {
|
||||||
|
File configFile = SPIFFS.open("/" + file, "r");
|
||||||
|
if (!configFile) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
configFile.seek(0, SeekSet); //поставим курсор в начало файла
|
||||||
|
while (configFile.position() != configFile.size()) {
|
||||||
|
String tmp = configFile.readStringUntil('\r\n');
|
||||||
|
String unix_time = selectToMarker (tmp, " ");
|
||||||
|
String value = deleteBeforeDelimiter(tmp, " ");
|
||||||
|
String final_line = "{\"status\":{\"x\":" + unix_time + ",\"y1\":" + value + "}}";
|
||||||
|
//Serial.println(final_line);
|
||||||
|
sendCHART(topic, final_line);
|
||||||
|
}
|
||||||
|
getMemoryLoad("[i] after send log date");
|
||||||
|
}
|
||||||
|
//старый метод выкидывания данных с использованием оперативной памяти
|
||||||
|
void sendLogData2(String file, String topic) {
|
||||||
String log_date = readFile(file, 5000);
|
String log_date = readFile(file, 5000);
|
||||||
log_date.replace("\r\n", "\n");
|
log_date.replace("\r\n", "\n");
|
||||||
log_date.replace("\r", "\n");
|
log_date.replace("\r", "\n");
|
||||||
@@ -134,7 +152,6 @@ void sendLogData(String file, String topic) {
|
|||||||
json_array = "";
|
json_array = "";
|
||||||
getMemoryLoad("[i] after send log date");
|
getMemoryLoad("[i] after send log date");
|
||||||
}
|
}
|
||||||
|
|
||||||
//=========================================Очистка данных===================================================================================
|
//=========================================Очистка данных===================================================================================
|
||||||
void clean_log_date() {
|
void clean_log_date() {
|
||||||
SPIFFS.remove("/log.analog.txt");
|
SPIFFS.remove("/log.analog.txt");
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ void createWidget (String widget_name, String page_name, String page_number, St
|
|||||||
jsonWriteStr(widget, "order", page_number);
|
jsonWriteStr(widget, "order", page_number);
|
||||||
jsonWriteStr(widget, "descr", widget_name);
|
jsonWriteStr(widget, "descr", widget_name);
|
||||||
jsonWriteStr(widget, "topic", prex + "/" + topic);
|
jsonWriteStr(widget, "topic", prex + "/" + topic);
|
||||||
#ifdef layout_in_rom
|
#ifdef layout_in_ram
|
||||||
all_widgets += widget + "\r\n";
|
all_widgets += widget + "\r\n";
|
||||||
#else
|
#else
|
||||||
addFile("layout.txt", widget);
|
addFile("layout.txt", widget);
|
||||||
@@ -40,7 +40,7 @@ void createChart (String widget_name, String page_name, String page_number, Str
|
|||||||
jsonWriteStr(widget, "series", widget_name);
|
jsonWriteStr(widget, "series", widget_name);
|
||||||
jsonWriteStr(widget, "maxCount", maxCount);
|
jsonWriteStr(widget, "maxCount", maxCount);
|
||||||
jsonWriteStr(widget, "topic", prex + "/" + topic);
|
jsonWriteStr(widget, "topic", prex + "/" + topic);
|
||||||
#ifdef layout_in_rom
|
#ifdef layout_in_ram
|
||||||
all_widgets += widget + "\r\n";
|
all_widgets += widget + "\r\n";
|
||||||
#else
|
#else
|
||||||
addFile("layout.txt", widget);
|
addFile("layout.txt", widget);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ dhtH DHT22 2 Влажность#DHT,#% Датчики any-data 2
|
|||||||
dhtComfort Степень#комфорта: Датчики 3
|
dhtComfort Степень#комфорта: Датчики 3
|
||||||
dhtPerception Восприятие: Датчики 4
|
dhtPerception Восприятие: Датчики 4
|
||||||
dhtDewpoint Точка#росы: Датчики 5
|
dhtDewpoint Точка#росы: Датчики 5
|
||||||
|
logging dhtT 1 10 Температура Датчики 6
|
||||||
|
logging dhtH 1 10 Влажность Датчики 7
|
||||||
|
|
||||||
//2 - номер пина датчика
|
//2 - номер пина датчика
|
||||||
//варианты отображения: any-data, progress-round, progress-line, fill-gauge
|
//варианты отображения: any-data, progress-round, progress-line, fill-gauge
|
||||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"widget": "chart",
|
"widget": "chart",
|
||||||
"series": "Temperature, °C",
|
"series": "Temperature, °C",
|
||||||
"dateFormat": "HH:mm:ss"
|
"dateFormat": "HH:mm"
|
||||||
}
|
}
|
||||||
@@ -35,18 +35,21 @@ void setup() {
|
|||||||
SSDP_init();
|
SSDP_init();
|
||||||
Serial.println("[V] SSDP_init");
|
Serial.println("[V] SSDP_init");
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
ts.add(TEST, 3000, [&](void*) {
|
|
||||||
|
|
||||||
String json = "{}";
|
|
||||||
jsonWriteStr(json, "test", GetTime());
|
|
||||||
ws.textAll(json);
|
|
||||||
|
|
||||||
getMemoryLoad("[i] After loading");
|
ts.add(TEST, 10000, [&](void*) {
|
||||||
|
|
||||||
|
//String json = "{}";
|
||||||
|
//jsonWriteStr(json, "test", GetTime());
|
||||||
|
//ws.textAll(json);
|
||||||
|
|
||||||
|
//getMemoryLoad("[i] After loading");
|
||||||
//Serial.print(GetDataDigital());
|
//Serial.print(GetDataDigital());
|
||||||
//Serial.print(" ");
|
//Serial.print(" ");
|
||||||
//Serial.println(GetTime());
|
//Serial.println(GetTime());
|
||||||
|
|
||||||
}, nullptr, true);
|
|
||||||
|
}, nullptr, false);
|
||||||
|
|
||||||
just_load = false;
|
just_load = false;
|
||||||
}
|
}
|
||||||
|
|||||||
36
main.ino
36
main.ino
@@ -12,7 +12,21 @@ int jsonReadtoInt(String &json, String name) {
|
|||||||
JsonObject& root = jsonBuffer.parseObject(json);
|
JsonObject& root = jsonBuffer.parseObject(json);
|
||||||
return root[name];
|
return root[name];
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
DynamicJsonBuffer jsonBuffer;
|
||||||
|
JsonObject& root = jsonBuffer.parseObject(json);
|
||||||
|
root[name] = volume;
|
||||||
|
json = "";
|
||||||
|
root.printTo(json);
|
||||||
|
return json;
|
||||||
|
|
||||||
|
DynamicJsonDocument jsonBuffer(1024);
|
||||||
|
deserializeJson(jsonBuffer,json);
|
||||||
|
jsonBuffer[name] = volume;
|
||||||
|
json = "";
|
||||||
|
serializeJson(jsonBuffer,json);
|
||||||
|
return json;
|
||||||
|
*/
|
||||||
// ------------- Запись значения json String
|
// ------------- Запись значения json String
|
||||||
String jsonWriteStr(String &json, String name, String volume) {
|
String jsonWriteStr(String &json, String name, String volume) {
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
@@ -43,10 +57,10 @@ String jsonWriteFloat(String &json, String name, float volume) {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
String jsonWriteArray(String &json, String value1, String value2, String value3) {
|
String jsonWriteArray(String &json, String value1, String value2, String value3) {
|
||||||
|
|
||||||
const int capacity = JSON_ARRAY_SIZE(1) + 3 * JSON_OBJECT_SIZE(3);
|
const int capacity = JSON_ARRAY_SIZE(1) + 3 * JSON_OBJECT_SIZE(3);
|
||||||
|
|
||||||
StaticJsonBuffer<capacity> jb;
|
StaticJsonBuffer<capacity> jb;
|
||||||
JsonArray& arr = jb.createArray();
|
JsonArray& arr = jb.createArray();
|
||||||
JsonObject& obj1 = jb.createObject();
|
JsonObject& obj1 = jb.createObject();
|
||||||
@@ -54,13 +68,13 @@ String jsonWriteArray(String &json, String value1, String value2, String value3)
|
|||||||
obj1[value1] = 1;
|
obj1[value1] = 1;
|
||||||
obj1[value2] = 2;
|
obj1[value2] = 2;
|
||||||
obj1[value3] = 3;
|
obj1[value3] = 3;
|
||||||
|
|
||||||
arr.add(obj1);
|
arr.add(obj1);
|
||||||
|
|
||||||
arr.printTo(json);
|
arr.printTo(json);
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
//=============================================CONFIG===========================================================
|
//=============================================CONFIG===========================================================
|
||||||
void saveConfig () {
|
void saveConfig () {
|
||||||
@@ -231,14 +245,14 @@ String addFile(String fileName, String strings ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------- Чтение строки из файла
|
// ------------- Чтение строки из файла
|
||||||
String readFileString(String fileName, String found)
|
//возвращает стоку из файла в которой есть искомое слово found
|
||||||
{
|
String readFileString(String fileName, String found) {
|
||||||
File configFile = SPIFFS.open("/" + fileName, "r");
|
File configFile = SPIFFS.open("/" + fileName, "r");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
return "Failed";
|
return "Failed";
|
||||||
}
|
}
|
||||||
if (configFile.find(found.c_str())) {
|
if (configFile.find(found.c_str())) {
|
||||||
//return configFile.readStringUntil('\r'); //'\r'
|
return configFile.readStringUntil('\n'); //'\r'
|
||||||
}
|
}
|
||||||
configFile.close();
|
configFile.close();
|
||||||
}
|
}
|
||||||
@@ -328,6 +342,12 @@ void getMemoryLoad(String text) {
|
|||||||
*/
|
*/
|
||||||
//===================================================================
|
//===================================================================
|
||||||
/*
|
/*
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"title": "Конфигурация устройства",
|
||||||
|
"socket": "test2",
|
||||||
|
"class": "btn btn-block btn-primary"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "hr"
|
"type": "hr"
|
||||||
},
|
},
|
||||||
|
|||||||
29
mqtt.ino
29
mqtt.ino
@@ -169,12 +169,9 @@ void sendCONTROL(String id, String topik, String state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//=====================================================ОТПРАВЛЯЕМ ВИДЖЕТЫ========================================================
|
//=====================================================ОТПРАВЛЯЕМ ВИДЖЕТЫ========================================================
|
||||||
|
|
||||||
|
#ifdef layout_in_ram
|
||||||
void sendAllWigets() {
|
void sendAllWigets() {
|
||||||
|
|
||||||
#ifndef layout_in_rom
|
|
||||||
all_widgets = readFile("layout.txt", 5000);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (all_widgets != "") {
|
if (all_widgets != "") {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
String line;
|
String line;
|
||||||
@@ -193,23 +190,23 @@ void sendAllWigets() {
|
|||||||
psn_1 = psn_2 + 1;
|
psn_1 = psn_2 + 1;
|
||||||
} while (psn_2 + 2 < all_widgets.length());
|
} while (psn_2 + 2 < all_widgets.length());
|
||||||
getMemoryLoad("[i] after send all widgets");
|
getMemoryLoad("[i] after send all widgets");
|
||||||
#ifndef layout_in_rom
|
|
||||||
all_widgets = "";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
#endif
|
||||||
void sendAllWigets2() {
|
|
||||||
|
//прямое выкидывание данных из файла в файловой системе в mqtt, без загрузки оперативной памяти
|
||||||
|
void sendAllWigets() {
|
||||||
File configFile = SPIFFS.open("/layout.txt", "r");
|
File configFile = SPIFFS.open("/layout.txt", "r");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// while (str.length() != 0) {
|
configFile.seek(0, SeekSet); //поставим курсор в начало файла
|
||||||
|
while (configFile.position() != configFile.size()) {
|
||||||
// configFile.readStringUntil("\r\n");
|
String widget_to_send = configFile.readStringUntil('\r\n');
|
||||||
|
Serial.println("[V] " + widget_to_send);
|
||||||
// }
|
sendMQTT("config", widget_to_send);
|
||||||
}*/
|
}
|
||||||
|
}
|
||||||
//=====================================================ОТПРАВЛЯЕМ ДАННЫЕ В ВИДЖЕТЫ ПРИ ОБНОВЛЕНИИ СТРАНИЦЫ========================================================
|
//=====================================================ОТПРАВЛЯЕМ ДАННЫЕ В ВИДЖЕТЫ ПРИ ОБНОВЛЕНИИ СТРАНИЦЫ========================================================
|
||||||
void sendAllData() { //берет строку json и ключи превращает в топики а значения колючей в них посылает
|
void sendAllData() { //берет строку json и ключи превращает в топики а значения колючей в них посылает
|
||||||
|
|
||||||
|
|||||||
4
set.h
4
set.h
@@ -5,9 +5,9 @@ boolean start_check_version = false;
|
|||||||
|
|
||||||
//#define OTA_enable
|
//#define OTA_enable
|
||||||
//#define MDNS_enable
|
//#define MDNS_enable
|
||||||
#define WS_enable
|
//#define WS_enable
|
||||||
|
|
||||||
//#define layout_in_rom
|
//#define layout_in_ram
|
||||||
|
|
||||||
#define TIME_COMPILING String(__TIME__)
|
#define TIME_COMPILING String(__TIME__)
|
||||||
#define DATE_COMPILING String(__DATE__)
|
#define DATE_COMPILING String(__DATE__)
|
||||||
|
|||||||
Reference in New Issue
Block a user