-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ino
108 lines (99 loc) · 3.79 KB
/
main.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// ------------- Чтение значения json
String jsonRead(String &json, String name) {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
return root[name].as<String>();
}
// ------------- Чтение значения json
int jsonReadtoInt(String &json, String name) {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
return root[name];
}
// ------------- Запись значения json String
String jsonWrite(String &json, String name, String volume) {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
root[name] = volume;
json = "";
root.printTo(json);
return json;
}
// ------------- Запись значения json int
String jsonWrite(String &json, String name, int volume) {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
root[name] = volume;
json = "";
root.printTo(json);
return json;
}
void saveConfig (){
writeFile("config.json", configSetup );
}
// ------------- Чтение файла в строку
String readFile(String fileName, size_t len ) {
File configFile = SPIFFS.open("/" + fileName, "r");
if (!configFile) {
return "Failed";
}
size_t size = configFile.size();
if (size > len) {
configFile.close();
return "Large";
}
String temp = configFile.readString();
configFile.close();
return temp;
}
// ------------- Запись строки в файл
String writeFile(String fileName, String strings ) {
File configFile = SPIFFS.open("/" + fileName, "w");
if (!configFile) {
return "Failed to open config file";
}
configFile.print(strings);
//strings.printTo(configFile);
configFile.close();
return "Write sucsses";
}
// Перегрузка функций
// ------------- Создание данных для графика
String graf(int datas, int points, int refresh, String options) {
String root = "{}"; // Формировать строку для отправки в браузер json формат
// {"data":[1],"points":"10","refresh":"1","title":"Analog"}
// Резервируем память для json обекта буфер может рости по мере необходимти, предпочтительно для ESP8266
DynamicJsonBuffer jsonBuffer;
// вызовите парсер JSON через экземпляр jsonBuffer
JsonObject& json = jsonBuffer.parseObject(root);
// Заполняем поля json
JsonArray& data = json.createNestedArray("data");
data.add(datas);
json["points"] = points;
json["refresh"] = refresh;
json["options"] = options;
//"options":"low:0,showLine: false,showArea:true,showPoint:false",
// Помещаем созданный json в переменную root
root = "";
json.printTo(root);
return root;
}
// --------------Создание данных для графика
String graf(int datas, int points, int refresh) {
String root = "{}"; // Формировать строку для отправки в браузер json формат
// {"data":[1],"points":"10","refresh":"1","title":"Analog"}
// Резервируем память для json обекта буфер может рости по мере необходимти, предпочтительно для ESP8266
DynamicJsonBuffer jsonBuffer;
// вызовите парсер JSON через экземпляр jsonBuffer
JsonObject& json = jsonBuffer.parseObject(root);
// Заполняем поля json
JsonArray& data = json.createNestedArray("data");
data.add(datas);
json["points"] = points;
json["refresh"] = refresh;
//"options":"low:0,showLine: false,showArea:true,showPoint:false",
// Помещаем созданный json в переменную root
root = "";
json.printTo(root);
return root;
}