New method of sending date - direct from SPIFFS to MQTT!!!!

This commit is contained in:
Dmitry Borisenko
2020-03-28 00:29:50 +01:00
parent 7d1c0268f5
commit abfc847793
10 changed files with 76 additions and 37 deletions

View File

@@ -41,7 +41,7 @@ void Device_init() {
ts.remove(STEPPER1);
ts.remove(STEPPER2);
#ifdef layout_in_rom
#ifdef layout_in_ram
all_widgets = "";
#else
SPIFFS.remove("/layout.txt");

View File

@@ -103,7 +103,25 @@ void choose_log_date_and_send() {
}
//=========================================Отправка данных===================================================================================
//прямое выкидывание данных из файла в файловой системе в mqtt, без загрузки оперативной памяти
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);
log_date.replace("\r\n", "\n");
log_date.replace("\r", "\n");
@@ -134,7 +152,6 @@ void sendLogData(String file, String topic) {
json_array = "";
getMemoryLoad("[i] after send log date");
}
//=========================================Очистка данных===================================================================================
void clean_log_date() {
SPIFFS.remove("/log.analog.txt");

View File

@@ -15,7 +15,7 @@ void createWidget (String widget_name, String page_name, String page_number, St
jsonWriteStr(widget, "order", page_number);
jsonWriteStr(widget, "descr", widget_name);
jsonWriteStr(widget, "topic", prex + "/" + topic);
#ifdef layout_in_rom
#ifdef layout_in_ram
all_widgets += widget + "\r\n";
#else
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, "maxCount", maxCount);
jsonWriteStr(widget, "topic", prex + "/" + topic);
#ifdef layout_in_rom
#ifdef layout_in_ram
all_widgets += widget + "\r\n";
#else
addFile("layout.txt", widget);

View File

@@ -3,6 +3,8 @@ dhtH DHT22 2 Влажность#DHT,#% Датчики any-data 2
dhtComfort Степень#комфорта: Датчики 3
dhtPerception Восприятие: Датчики 4
dhtDewpoint Точка#росы: Датчики 5
logging dhtT 1 10 Температура Датчики 6
logging dhtH 1 10 Влажность Датчики 7
//2 - номер пина датчика
//варианты отображения: any-data, progress-round, progress-line, fill-gauge

Binary file not shown.

View File

@@ -1,5 +1,5 @@
{
"widget": "chart",
"series": "Temperature, °C",
"dateFormat": "HH:mm:ss"
"dateFormat": "HH:mm"
}

View File

@@ -35,18 +35,21 @@ void setup() {
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(" ");
//Serial.println(GetTime());
}, nullptr, true);
}, nullptr, false);
just_load = false;
}

View File

@@ -12,7 +12,21 @@ int jsonReadtoInt(String &json, String name) {
JsonObject& root = jsonBuffer.parseObject(json);
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
String jsonWriteStr(String &json, String name, String volume) {
DynamicJsonBuffer jsonBuffer;
@@ -43,10 +57,10 @@ String jsonWriteFloat(String &json, String name, float volume) {
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);
StaticJsonBuffer<capacity> jb;
JsonArray& arr = jb.createArray();
JsonObject& obj1 = jb.createObject();
@@ -54,13 +68,13 @@ String jsonWriteArray(String &json, String value1, String value2, String value3)
obj1[value1] = 1;
obj1[value2] = 2;
obj1[value3] = 3;
arr.add(obj1);
arr.printTo(json);
return json;
}
}
*/
//=============================================CONFIG===========================================================
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");
if (!configFile) {
return "Failed";
}
if (configFile.find(found.c_str())) {
//return configFile.readStringUntil('\r'); //'\r'
return configFile.readStringUntil('\n'); //'\r'
}
configFile.close();
}
@@ -328,6 +342,12 @@ void getMemoryLoad(String text) {
*/
//===================================================================
/*
{
"type": "button",
"title": "Конфигурация устройства",
"socket": "test2",
"class": "btn btn-block btn-primary"
},
{
"type": "hr"
},

View File

@@ -169,12 +169,9 @@ void sendCONTROL(String id, String topik, String state) {
}
//=====================================================ОТПРАВЛЯЕМ ВИДЖЕТЫ========================================================
#ifdef layout_in_ram
void sendAllWigets() {
#ifndef layout_in_rom
all_widgets = readFile("layout.txt", 5000);
#endif
if (all_widgets != "") {
int counter = 0;
String line;
@@ -193,23 +190,23 @@ void sendAllWigets() {
psn_1 = psn_2 + 1;
} while (psn_2 + 2 < all_widgets.length());
getMemoryLoad("[i] after send all widgets");
#ifndef layout_in_rom
all_widgets = "";
#endif
}
}
/*
void sendAllWigets2() {
#endif
//прямое выкидывание данных из файла в файловой системе в mqtt, без загрузки оперативной памяти
void sendAllWigets() {
File configFile = SPIFFS.open("/layout.txt", "r");
if (!configFile) {
return;
}
// while (str.length() != 0) {
// configFile.readStringUntil("\r\n");
// }
}*/
configFile.seek(0, SeekSet); //поставим курсор в начало файла
while (configFile.position() != configFile.size()) {
String widget_to_send = configFile.readStringUntil('\r\n');
Serial.println("[V] " + widget_to_send);
sendMQTT("config", widget_to_send);
}
}
//=====================================================ОТПРАВЛЯЕМ ДАННЫЕ В ВИДЖЕТЫ ПРИ ОБНОВЛЕНИИ СТРАНИЦЫ========================================================
void sendAllData() { //берет строку json и ключи превращает в топики а значения колючей в них посылает

4
set.h
View File

@@ -5,9 +5,9 @@ boolean start_check_version = false;
//#define OTA_enable
//#define MDNS_enable
#define WS_enable
//#define WS_enable
//#define layout_in_rom
//#define layout_in_ram
#define TIME_COMPILING String(__TIME__)
#define DATE_COMPILING String(__DATE__)