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