mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
read config from json on SPIFFS
This commit is contained in:
@@ -17,52 +17,39 @@
|
||||
#define JSON_stationPassword "stationPassword"
|
||||
#define JSON_hostname "hostname"
|
||||
|
||||
#define JSON_startupDelay "startupDelay"
|
||||
#define JSON_serialBaudRate "serialBaudRate"
|
||||
|
||||
struct MeshSprocketConfig : public JsonStruct {
|
||||
SprocketConfig sprocket;
|
||||
MeshConfig mesh;
|
||||
int valid = 0;
|
||||
int stationMode;
|
||||
int channel;
|
||||
int meshPort;
|
||||
String meshSSID;
|
||||
String meshPassword;
|
||||
String stationSSID;
|
||||
String stationPassword;
|
||||
String hostname;
|
||||
uint16_t debugTypes;
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
String toJsonString(){
|
||||
//StaticJsonBuffer<200> jsonBuffer;
|
||||
DynamicJsonBuffer jsonBuffer(JSON_ARRAY_SIZE(300));
|
||||
JsonObject& root = jsonBuffer.createObject();
|
||||
root[JSON_stationMode] = mesh.stationMode;
|
||||
root[JSON_channel] = mesh.channel;
|
||||
root[JSON_meshPort] = mesh.meshPort;
|
||||
root[JSON_meshSSID] = mesh.meshSSID;
|
||||
root[JSON_meshPassword] = mesh.meshPassword;
|
||||
root[JSON_stationSSID] = mesh.stationSSID;
|
||||
root[JSON_stationPassword] = mesh.stationPassword;
|
||||
root[JSON_hostname] = mesh.hostname;
|
||||
root[JSON_startupDelay] = sprocket.startupDelay;
|
||||
root[JSON_serialBaudRate] = sprocket.serialBaudRate;
|
||||
String jsonString;
|
||||
root.printTo(jsonString);
|
||||
return jsonString;
|
||||
void mapJsonObject(JsonObject& root) {
|
||||
root[JSON_stationMode] = stationMode;
|
||||
root[JSON_channel] = channel;
|
||||
root[JSON_meshPort] = meshPort;
|
||||
root[JSON_meshSSID] = meshSSID;
|
||||
root[JSON_meshPassword] = meshPassword;
|
||||
root[JSON_stationSSID] = stationSSID;
|
||||
root[JSON_stationPassword] = stationPassword;
|
||||
root[JSON_hostname] = hostname;
|
||||
}
|
||||
|
||||
// Map a json object to this struct.
|
||||
int fromJsonObject(JsonObject& json){
|
||||
if(!verifyJsonObject(json)){
|
||||
Serial.println("ERROR: cannot parse JSON object");
|
||||
valid = 0;
|
||||
return valid;
|
||||
}
|
||||
mesh.stationMode = getIntAttrFromJson(json, JSON_stationMode);
|
||||
mesh.channel = getIntAttrFromJson(json, JSON_channel);
|
||||
mesh.meshPort = getIntAttrFromJson(json, JSON_meshPort);
|
||||
mesh.meshSSID = getAttrFromJson(json, JSON_meshSSID).c_str();
|
||||
mesh.meshPassword = getAttrFromJson(json, JSON_meshPassword).c_str();
|
||||
mesh.stationSSID = getAttrFromJson(json, JSON_stationSSID).c_str();
|
||||
mesh.stationPassword = getAttrFromJson(json, JSON_stationPassword).c_str();
|
||||
mesh.hostname = getAttrFromJson(json, JSON_hostname).c_str();
|
||||
sprocket.startupDelay = getIntAttrFromJson(json, JSON_startupDelay);
|
||||
sprocket.serialBaudRate = getIntAttrFromJson(json, JSON_serialBaudRate);
|
||||
valid = 1;
|
||||
return valid;
|
||||
void fromJsonObject(JsonObject& json) {
|
||||
stationMode = getIntAttrFromJson(json, JSON_stationMode);
|
||||
channel = getIntAttrFromJson(json, JSON_channel);
|
||||
meshPort = getIntAttrFromJson(json, JSON_meshPort);
|
||||
meshSSID = getAttrFromJson(json, JSON_meshSSID);
|
||||
meshPassword = getAttrFromJson(json, JSON_meshPassword);
|
||||
stationSSID = getAttrFromJson(json, JSON_stationSSID);
|
||||
stationPassword = getAttrFromJson(json, JSON_stationPassword);
|
||||
hostname = getAttrFromJson(json, JSON_hostname);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user