move plugins to sprocket

This commit is contained in:
2018-08-24 17:42:35 +02:00
parent 426d495fd9
commit 5334d58433
11 changed files with 182 additions and 45 deletions

43
src/JsonStruct.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef __JSON_STRUCT__
#define __JSON_STRUCT__
#include <ArduinoJson.h>
#include <FS.h>
struct JsonStruct {
SprocketConfig soricketConfig;
MeshConfig meshConfig;
int valid = 0;
// ------------------------------------------------------------------------------------------
virtual int verifyJsonObject(JsonObject& json){
return json.success();
//&& json.containsKey(JSON_DOMAIN)
};
virtual String toJsonString();
String getAttrFromJson(JsonObject& json, const char* attr){
if(json.containsKey(attr)){
return json[attr];
}
return "";
}
int getIntAttrFromJson(JsonObject& json, const char* attr){
if(json.containsKey(attr)){
return json[attr];
}
return 0;
}
// Map a json object to this struct.
virtual int fromJsonObject(JsonObject& json);
// Parse a json string and map parsed object
int fromJsonString(String& str){
//StaticJsonBuffer<200> jsonBuffer;
DynamicJsonBuffer jsonBuffer(JSON_ARRAY_SIZE(300));
JsonObject& json = jsonBuffer.parseObject(str);
return fromJsonObject(json);
};
};
#endif