mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
move plugins to sprocket
This commit is contained in:
69
src/base/MeshSprocketConfig.h
Normal file
69
src/base/MeshSprocketConfig.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef __MESH_SPROCKET_CONFIG__
|
||||
#define __MESH_SPROCKET_CONFIG__
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <FS.h>
|
||||
#include "MeshConfig.h"
|
||||
#include "SprocketConfig.h"
|
||||
#include "JsonStruct.h"
|
||||
|
||||
#define JSON_stationMode "stationMode"
|
||||
#define JSON_channel "channel"
|
||||
#define JSON_meshPort "meshPort"
|
||||
#define JSON_meshSSID "meshSSID"
|
||||
#define JSON_meshPassword "meshPassword"
|
||||
#define JSON_stationSSID "stationSSID"
|
||||
#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;
|
||||
|
||||
// ------------------------------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user