mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 05:24:30 +01:00
move plugins to sprocket
This commit is contained in:
43
src/JsonStruct.h
Normal file
43
src/JsonStruct.h
Normal 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
|
||||
Reference in New Issue
Block a user