putting output config into json
i could not apply the structure of configSystemOutputs into json, so i had to switch to use arrays instead. it works, but looks not that nice as a struct.
This commit is contained in:
parent
4c9c280d45
commit
d68d0fbf79
3 changed files with 94 additions and 48 deletions
|
@ -151,6 +151,39 @@ void loop() {
|
|||
if((digitalRead(PinWIPE) != PinWIPE_default) && (alrdySaved == false)) {
|
||||
Serial.println(":: [LOOP] PinWIPE is triggered, saving config.json and set config.system.httpLogSerial to true");
|
||||
config.system.httpLogSerial = true;
|
||||
|
||||
// testing output save stuff
|
||||
|
||||
Serial.println(":: [LOOP] save output 0");
|
||||
byte i = 0;
|
||||
config.system.output_type[i] = 1;
|
||||
strlcpy(config.system.output_name[i], "bla", sizeof("bla"));
|
||||
config.system.output_gpio[i] = 3;
|
||||
config.system.output_gpio_invert[i] = false;
|
||||
config.system.output_gpio_pwm[i] = false;
|
||||
strlcpy(config.system.output_i2c[i], "0x3", sizeof("0x3"));
|
||||
|
||||
for(byte j=0; j < 4 ; j++) {
|
||||
config.system.output_ip[i][j] = j + 3;
|
||||
}
|
||||
strlcpy(config.system.output_ip_path[i], "/asd?foo=lol", sizeof("/asd?foo=lol"));
|
||||
config.system.output_enabled[i] = true;
|
||||
|
||||
Serial.println(":: [LOOP] save output 1");
|
||||
i = 1;
|
||||
config.system.output_type[i] = 2;
|
||||
strlcpy(config.system.output_name[i], "lol", sizeof("lol"));
|
||||
config.system.output_gpio[i] = 5;
|
||||
config.system.output_gpio_invert[i] = true;
|
||||
config.system.output_gpio_pwm[i] = true;
|
||||
strlcpy(config.system.output_i2c[i], "0x69", sizeof("0x69"));
|
||||
|
||||
for(byte j=0; j < 4 ; j++) {
|
||||
config.system.output_ip[i][j] = j + 23;
|
||||
}
|
||||
strlcpy(config.system.output_ip_path[i], "/asd?foo=lol", sizeof("/asd?foo=lol"));
|
||||
config.system.output_enabled[i] = true;
|
||||
|
||||
// save config to littlefs as json
|
||||
SaveConfig();
|
||||
// only print json to serial
|
||||
|
|
|
@ -100,33 +100,17 @@ struct Config_WiFi {
|
|||
* Config System
|
||||
*/
|
||||
|
||||
/*
|
||||
* Config System Outputs
|
||||
*
|
||||
* - type: output type like GPIO, I2C, URL
|
||||
* 1 - GPIO
|
||||
* 2 - I2C
|
||||
* 3 - URL
|
||||
* - gpio: which gpio is used
|
||||
* - gpio_invert: invert gpio output
|
||||
* - gpio_pwm: enable pwm for output
|
||||
* - i2c:
|
||||
* - ip: ip to smart plug (tasmota e.g.)
|
||||
* - ip_path: uri path
|
||||
* - enabled: enable output
|
||||
*
|
||||
*/
|
||||
struct Config_System_Outputs {
|
||||
byte type;
|
||||
char name[32];
|
||||
byte gpio;
|
||||
bool gpio_invert;
|
||||
bool gpio_pwm;
|
||||
char i2c[8];
|
||||
byte ip[4];
|
||||
char ip_path[32];
|
||||
bool enabled;
|
||||
};
|
||||
//struct Config_System_Outputs {
|
||||
//byte type;
|
||||
//char name[32] = "lol";
|
||||
//byte gpio = 15;
|
||||
//bool gpio_invert;
|
||||
//bool gpio_pwm;
|
||||
//char i2c[8];
|
||||
//byte ip[4];
|
||||
//char ip_path[32];
|
||||
//bool enabled;
|
||||
//};
|
||||
|
||||
/* main System struct */
|
||||
struct Config_System {
|
||||
|
@ -137,7 +121,33 @@ struct Config_System {
|
|||
char httpPass[32];
|
||||
bool httpLogSerial;
|
||||
unsigned short schedulerInterval = 1000;
|
||||
Config_System_Outputs outputs[Max_Outputs];
|
||||
|
||||
/*
|
||||
* Config System Outputs
|
||||
*
|
||||
* - output_type: output type like GPIO, I2C, URL
|
||||
* 1 - GPIO
|
||||
* 2 - I2C
|
||||
* 3 - URL
|
||||
* - output_gpio: which gpio is used
|
||||
* - output_gpio_invert: invert gpio output
|
||||
* - output_gpio_pwm: enable pwm for output
|
||||
* - output_i2c:
|
||||
* - output_ip: ip to smart plug (tasmota e.g.)
|
||||
* - output_ip_path: uri path
|
||||
* - output_enabled: enable output
|
||||
*
|
||||
*/
|
||||
byte output_type[Max_Outputs];
|
||||
char output_name[Max_Outputs][32];
|
||||
byte output_gpio[Max_Outputs];
|
||||
bool output_gpio_invert[Max_Outputs];
|
||||
bool output_gpio_pwm[Max_Outputs];
|
||||
char output_i2c[Max_Outputs][8];
|
||||
byte output_ip[Max_Outputs][4];
|
||||
char output_ip_path[Max_Outputs][32];
|
||||
bool output_enabled[Max_Outputs];
|
||||
//Config_System_Outputs outputs[Max_Outputs];
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -207,17 +207,17 @@ bool LoadConfig() {
|
|||
|
||||
/* System Outputs */
|
||||
for(byte i=0; i < Max_Outputs; i++) {
|
||||
JsonObject objSystemOutputs = doc["system"]["outputs"][i];
|
||||
config.system.outputs[i].type = objSystemOutputs["type"];
|
||||
strlcpy(config.system.outputs[i].name, objSystemOutputs["name"], sizeof(config.system.outputs[i].name));
|
||||
config.system.outputs[i].gpio = objSystemOutputs["gpio"];
|
||||
config.system.outputs[i].gpio_invert = objSystemOutputs["gpio_invert"];
|
||||
config.system.outputs[i].gpio_pwm = objSystemOutputs["gpio_pwm"];
|
||||
strlcpy(config.system.outputs[i].name, objSystemOutputs["name"], sizeof(config.system.outputs[i].i2c));
|
||||
config.system.output_type[i] = objSystem["output_type"][i];
|
||||
strlcpy(config.system.output_name[i], objSystem["output_name"][i], sizeof(config.system.output_name[i]));
|
||||
config.system.output_gpio[i] = objSystem["output_gpio"][i];
|
||||
config.system.output_gpio_invert[i] = objSystem["output_gpio_invert"][i];
|
||||
config.system.output_gpio_pwm[i] = objSystem["output_gpio_pwm"][i];
|
||||
strlcpy(config.system.output_i2c[i], objSystem["output_i2c"][i], sizeof(config.system.output_i2c[i]));
|
||||
for(byte j=0; j < 4 ; j++) {
|
||||
config.system.outputs[i].ip[j] = objSystemOutputs["ip"][j];
|
||||
config.system.output_ip[i][j] = objSystem["output_ip"][i][j];
|
||||
}
|
||||
config.system.outputs[i].enabled = objSystemOutputs["enabled"];
|
||||
strlcpy(config.system.output_ip_path[i], objSystem["output_ip_path"][i], sizeof(config.system.output_ip_path[i]));
|
||||
config.system.output_enabled[i] = objSystem["output_enabled"][i];
|
||||
}
|
||||
|
||||
/* Grow */
|
||||
|
@ -280,19 +280,22 @@ bool SaveConfig(bool writeToSerial = false) {
|
|||
objSystem["schedulerInterval"] = config.system.schedulerInterval;
|
||||
|
||||
/* System Outputs */
|
||||
JsonObject objSystemOutputs = doc["system"]["outputs"].add<JsonObject>();
|
||||
|
||||
|
||||
for(byte i=0; i < Max_Outputs; i++) {
|
||||
objSystemOutputs["type"] = config.system.outputs[i].type;
|
||||
objSystemOutputs["name"] = config.system.outputs[i].name;
|
||||
objSystemOutputs["gpio"] = config.system.outputs[i].gpio;
|
||||
objSystemOutputs["gpio_invert"] = config.system.outputs[i].gpio_invert;
|
||||
objSystemOutputs["gpio_pwm"] = config.system.outputs[i].gpio_pwm;
|
||||
objSystemOutputs["i2c"] = config.system.outputs[i].i2c;
|
||||
|
||||
|
||||
objSystem["output_type"][i] = config.system.output_type[i];
|
||||
objSystem["output_name"][i] = config.system.output_name[i];
|
||||
objSystem["output_gpio"][i] = config.system.output_gpio[i];
|
||||
objSystem["output_gpio_invert"][i] = config.system.output_gpio_invert[i];
|
||||
objSystem["output_gpio_pwm"][i] = config.system.output_gpio_pwm[i];
|
||||
objSystem["output_i2c"][i] = config.system.output_i2c[i];
|
||||
for(byte j=0; j < 4 ; j++) {
|
||||
objSystemOutputs["ip"][j] = config.system.outputs[i].ip[j];
|
||||
objSystem["output_ip"][j] = config.system.output_ip[j];
|
||||
}
|
||||
objSystemOutputs["ip_path"] = config.system.outputs[i].ip_path;
|
||||
objSystemOutputs["enabled"] = config.system.outputs[i].enabled;
|
||||
objSystem["output_ip_path"][i] = config.system.output_ip_path[i];
|
||||
objSystem["output_enabled"][i] = config.system.output_enabled[i];
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue