mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
arduino json 6
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
#define MYSENSORS
|
||||
#endif
|
||||
|
||||
#define JSON_BUFFER_SIZE 1024
|
||||
#define NUM_BUTTONS 6
|
||||
#define MQTT_RECONNECT_INTERVAL 20000
|
||||
#define CHANGE_BROKER_AFTER 5
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
;To choose firmware please use one of definition:
|
||||
;esp8266_1mb , esp8266_4mb , esp32_4mb , esp8266_mysensors_4mb , esp32_mysensors_4mb
|
||||
[platformio]
|
||||
default_envs = esp32_4mb
|
||||
default_envs = esp8266_4mb
|
||||
|
||||
|
||||
;data_esp => esp8266_1mb , esp8266_4mb , esp32_4mb
|
||||
@@ -25,7 +25,7 @@ data_dir = data_esp
|
||||
|
||||
[common_env_data]
|
||||
lib_deps_external =
|
||||
bblanchon/ArduinoJson @5.*
|
||||
bblanchon/ArduinoJson @6.18.0
|
||||
knolleary/PubSubClient
|
||||
|
||||
|
||||
|
||||
@@ -1,53 +1,110 @@
|
||||
#include "Utils/JsonUtils.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include "Global.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
|
||||
//String jsonReadStr(String& json, String name) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// return root[name].as<String>();
|
||||
//}
|
||||
//
|
||||
//boolean jsonReadBool(String& json, String name) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// return root[name].as<boolean>();
|
||||
//}
|
||||
//
|
||||
//int jsonReadInt(String& json, String name) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// return root[name];
|
||||
//}
|
||||
//
|
||||
//String jsonWriteStr(String& json, String name, String value) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// root[name] = value;
|
||||
// json = "";
|
||||
// root.printTo(json);
|
||||
// return json;
|
||||
//}
|
||||
//
|
||||
//String jsonWriteBool(String& json, String name, boolean value) {
|
||||
// return jsonWriteStr(json, name, value ? "1" : "0");
|
||||
//}
|
||||
//
|
||||
//String jsonWriteInt(String& json, String name, int value) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// root[name] = value;
|
||||
// json = "";
|
||||
// root.printTo(json);
|
||||
// return json;
|
||||
//}
|
||||
//
|
||||
//String jsonWriteFloat(String& json, String name, float value) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// root[name] = value;
|
||||
// json = "";
|
||||
// root.printTo(json);
|
||||
// return json;
|
||||
//}
|
||||
//
|
||||
//void saveConfig() {
|
||||
// writeFile(String("config.json"), configSetupJson);
|
||||
//}
|
||||
//
|
||||
//void saveStore() {
|
||||
// writeFile(String("store.json"), configStoreJson);
|
||||
//}
|
||||
|
||||
String jsonReadStr(String& json, String name) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
return root[name].as<String>();
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
return doc[name].as<String>();
|
||||
}
|
||||
|
||||
boolean jsonReadBool(String& json, String name) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
return root[name].as<boolean>();
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
return doc[name].as<bool>();
|
||||
}
|
||||
|
||||
int jsonReadInt(String& json, String name) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
return root[name];
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
return doc[name].as<int>();
|
||||
}
|
||||
|
||||
String jsonWriteStr(String& json, String name, String value) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
root[name] = value;
|
||||
json = "";
|
||||
root.printTo(json);
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
doc[name] = value;
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteBool(String& json, String name, boolean value) {
|
||||
return jsonWriteStr(json, name, value ? "1" : "0");
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
doc[name] = value;
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteInt(String& json, String name, int value) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
root[name] = value;
|
||||
json = "";
|
||||
root.printTo(json);
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
doc[name] = value;
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteFloat(String& json, String name, float value) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
root[name] = value;
|
||||
json = "";
|
||||
root.printTo(json);
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
doc[name] = value;
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user