Optimize logging, fix graph title
This commit is contained in:
parent
a4675cccc8
commit
c2e715f1cf
|
@ -249,15 +249,15 @@ void display_screen_grid(float grid_power, float consum, float inv_power, float
|
||||||
//Graph last 100 values
|
//Graph last 100 values
|
||||||
void display_screen_graph(float *values, char* key, int type, int buffersize)
|
void display_screen_graph(float *values, char* key, int type, int buffersize)
|
||||||
{
|
{
|
||||||
logPrintD("Display graph...");
|
logPrintlnD("Display graph...");
|
||||||
display.firstPage();
|
display.firstPage();
|
||||||
do {
|
do {
|
||||||
display_header(title_graph);
|
display_header(title_graph);
|
||||||
if (type = 0)
|
if (type == 0)
|
||||||
{
|
{
|
||||||
display.drawStr(58,17, title_graph_load);
|
display.drawStr(58,17, title_graph_load);
|
||||||
}
|
}
|
||||||
else if (type = 1)
|
else if (type == 1)
|
||||||
{
|
{
|
||||||
display.drawStr(58,17, title_graph_pv);
|
display.drawStr(58,17, title_graph_pv);
|
||||||
}
|
}
|
||||||
|
|
62
src/main.cpp
62
src/main.cpp
|
@ -107,7 +107,7 @@ bool shouldSaveConfig = false;
|
||||||
|
|
||||||
//WiFiManager callback notifying us of the need to save config
|
//WiFiManager callback notifying us of the need to save config
|
||||||
void saveConfigCallback () {
|
void saveConfigCallback () {
|
||||||
Serial.println("Should save config");
|
logPrintlnI("Should save config");
|
||||||
shouldSaveConfig = true;
|
shouldSaveConfig = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,26 +316,26 @@ void reconnect() {
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Booting...");
|
logPrintlnI("Booting...");
|
||||||
pinMode(BUTTON_ROTATION, INPUT_PULLUP);
|
pinMode(BUTTON_ROTATION, INPUT_PULLUP);
|
||||||
pinMode(BUTTON_SETUP, INPUT_PULLUP);
|
pinMode(BUTTON_SETUP, INPUT_PULLUP);
|
||||||
pinMode(STATUS_LED, OUTPUT);
|
pinMode(STATUS_LED, OUTPUT);
|
||||||
display_begin();
|
display_begin();
|
||||||
Serial.println("Display init...");
|
logPrintlnI("Display init...");
|
||||||
display_init(VERSION);
|
display_init(VERSION);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
|
||||||
//read configuration from Flash json
|
//read configuration from Flash json
|
||||||
Serial.println("mounting Flash...");
|
logPrintlnI("mounting Flash...");
|
||||||
|
|
||||||
if (Flash.begin()) {
|
if (Flash.begin()) {
|
||||||
Serial.println("mounted file system");
|
logPrintlnI("mounted file system");
|
||||||
if (Flash.exists("/config.json")) {
|
if (Flash.exists("/config.json")) {
|
||||||
//file exists, reading and loading
|
//file exists, reading and loading
|
||||||
Serial.println("reading config file");
|
logPrintlnI("reading config file");
|
||||||
File configFile = Flash.open("/config.json", "r");
|
File configFile = Flash.open("/config.json", "r");
|
||||||
if (configFile) {
|
if (configFile) {
|
||||||
Serial.println("opened config file");
|
logPrintlnI("opened config file");
|
||||||
size_t size = configFile.size();
|
size_t size = configFile.size();
|
||||||
// Allocate a buffer to store contents of the file.
|
// Allocate a buffer to store contents of the file.
|
||||||
std::unique_ptr<char[]> buf(new char[size]);
|
std::unique_ptr<char[]> buf(new char[size]);
|
||||||
|
@ -353,7 +353,7 @@ void setup() {
|
||||||
json.printTo(Serial);
|
json.printTo(Serial);
|
||||||
if (json.success()) {
|
if (json.success()) {
|
||||||
#endif
|
#endif
|
||||||
Serial.println("\nparsed json");
|
logPrintlnI("\nparsed json");
|
||||||
strcpy(mqtt_server, json["mqtt_server"]);
|
strcpy(mqtt_server, json["mqtt_server"]);
|
||||||
strcpy(gx_vrm_id, json["gx_vrm_id"]);
|
strcpy(gx_vrm_id, json["gx_vrm_id"]);
|
||||||
strcpy(disp_refresh_interval, json["disp_refresh_interval"]);
|
strcpy(disp_refresh_interval, json["disp_refresh_interval"]);
|
||||||
|
@ -369,13 +369,13 @@ void setup() {
|
||||||
strcpy(show_graph, json["show_graph"]);
|
strcpy(show_graph, json["show_graph"]);
|
||||||
strcpy(show_statistics, json["show_statistics"]);
|
strcpy(show_statistics, json["show_statistics"]);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("failed to load json config");
|
logPrintlnI("failed to load json config");
|
||||||
}
|
}
|
||||||
configFile.close();
|
configFile.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.println("failed to mount Flash");
|
logPrintlnI("failed to mount Flash");
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
@ -508,7 +508,7 @@ void setup() {
|
||||||
display_text((char*)" Connected. IP:", ip_address);
|
display_text((char*)" Connected. IP:", ip_address);
|
||||||
//save the custom parameters to Flash
|
//save the custom parameters to Flash
|
||||||
if (shouldSaveConfig) {
|
if (shouldSaveConfig) {
|
||||||
Serial.println("saving config");
|
logPrintlnI("saving config");
|
||||||
#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
|
#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
|
||||||
DynamicJsonDocument json(1024);
|
DynamicJsonDocument json(1024);
|
||||||
#else
|
#else
|
||||||
|
@ -532,7 +532,7 @@ void setup() {
|
||||||
|
|
||||||
File configFile = Flash.open("/config.json", "w");
|
File configFile = Flash.open("/config.json", "w");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
Serial.println("failed to open config file for writing");
|
logPrintlnI("failed to open config file for writing");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
|
#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
|
||||||
|
@ -563,42 +563,42 @@ void setup() {
|
||||||
delay(1000); //for screen display
|
delay(1000); //for screen display
|
||||||
|
|
||||||
//Generate mqtt topics from id and address
|
//Generate mqtt topics from id and address
|
||||||
Serial.println();
|
logPrintlnI("-------------- MQTT topic list --------------");
|
||||||
Serial.println("-------------- MQTT topic list --------------");
|
|
||||||
sprintf(mqtt_pv_voltage, "N/%s/solarcharger/%s/Pv/V", gx_vrm_id, address_pv_charger);
|
sprintf(mqtt_pv_voltage, "N/%s/solarcharger/%s/Pv/V", gx_vrm_id, address_pv_charger);
|
||||||
Serial.println(mqtt_pv_voltage);
|
logPrintlnI(mqtt_pv_voltage);
|
||||||
sprintf(mqtt_pv_power, "N/%s/solarcharger/%s/Yield/Power", gx_vrm_id, address_pv_charger);
|
sprintf(mqtt_pv_power, "N/%s/solarcharger/%s/Yield/Power", gx_vrm_id, address_pv_charger);
|
||||||
Serial.println(mqtt_pv_power);
|
logPrintlnI(mqtt_pv_power);
|
||||||
sprintf(mqtt_pv_yield, "N/%s/solarcharger/%s/History/Daily/0/Yield", gx_vrm_id, address_pv_charger);
|
sprintf(mqtt_pv_yield, "N/%s/solarcharger/%s/History/Daily/0/Yield", gx_vrm_id, address_pv_charger);
|
||||||
Serial.println(mqtt_pv_yield);
|
logPrintlnI(mqtt_pv_yield);
|
||||||
sprintf(mqtt_pv_bat_current, "N/%s/solarcharger/%s/Dc/0/Current", gx_vrm_id, address_pv_charger);
|
sprintf(mqtt_pv_bat_current, "N/%s/solarcharger/%s/Dc/0/Current", gx_vrm_id, address_pv_charger);
|
||||||
Serial.println(mqtt_pv_bat_current);
|
logPrintlnI(mqtt_pv_bat_current);
|
||||||
sprintf(mqtt_grid_power, "N/%s/grid/%s/Ac/Power", gx_vrm_id, address_grid_meter);
|
sprintf(mqtt_grid_power, "N/%s/grid/%s/Ac/Power", gx_vrm_id, address_grid_meter);
|
||||||
Serial.println(mqtt_grid_power);
|
logPrintlnI(mqtt_grid_power);
|
||||||
sprintf(mqtt_inv_power, "N/%s/vebus/%s/Ac/ActiveIn/L1/P", gx_vrm_id, address_inverter);
|
sprintf(mqtt_inv_power, "N/%s/vebus/%s/Ac/ActiveIn/L1/P", gx_vrm_id, address_inverter);
|
||||||
Serial.println(mqtt_inv_power);
|
logPrintlnI(mqtt_inv_power);
|
||||||
sprintf(mqtt_inv_current, "N/%s/vebus/%s/Dc/0/Current", gx_vrm_id, address_inverter);
|
sprintf(mqtt_inv_current, "N/%s/vebus/%s/Dc/0/Current", gx_vrm_id, address_inverter);
|
||||||
Serial.println(mqtt_inv_current);
|
logPrintlnI(mqtt_inv_current);
|
||||||
sprintf(mqtt_bat_soc, "N/%s/battery/%s/Soc", gx_vrm_id, address_battery);
|
sprintf(mqtt_bat_soc, "N/%s/battery/%s/Soc", gx_vrm_id, address_battery);
|
||||||
Serial.println(mqtt_bat_soc);
|
logPrintlnI(mqtt_bat_soc);
|
||||||
sprintf(mqtt_bat_voltage, "N/%s/battery/%s/Dc/0/Voltage", gx_vrm_id, address_battery);
|
sprintf(mqtt_bat_voltage, "N/%s/battery/%s/Dc/0/Voltage", gx_vrm_id, address_battery);
|
||||||
Serial.println(mqtt_bat_voltage);
|
logPrintlnI(mqtt_bat_voltage);
|
||||||
sprintf(mqtt_bat_current, "N/%s/battery/%s/Dc/0/Current", gx_vrm_id, address_battery);
|
sprintf(mqtt_bat_current, "N/%s/battery/%s/Dc/0/Current", gx_vrm_id, address_battery);
|
||||||
Serial.println(mqtt_bat_current);
|
logPrintlnI(mqtt_bat_current);
|
||||||
sprintf(mqtt_bat_power, "N/%s/battery/%s/Dc/0/Power", gx_vrm_id, address_battery);
|
sprintf(mqtt_bat_power, "N/%s/battery/%s/Dc/0/Power", gx_vrm_id, address_battery);
|
||||||
Serial.println(mqtt_bat_power);
|
logPrintlnI(mqtt_bat_power);
|
||||||
sprintf(mqtt_bat_max_cell_volt, "N/%s/battery/%s/System/MaxCellVoltage", gx_vrm_id, address_battery);
|
sprintf(mqtt_bat_max_cell_volt, "N/%s/battery/%s/System/MaxCellVoltage", gx_vrm_id, address_battery);
|
||||||
Serial.println(mqtt_bat_max_cell_volt);
|
logPrintlnI(mqtt_bat_max_cell_volt);
|
||||||
sprintf(mqtt_bat_min_cell_volt, "N/%s/battery/%s/System/MinCellVoltage", gx_vrm_id, address_battery);
|
sprintf(mqtt_bat_min_cell_volt, "N/%s/battery/%s/System/MinCellVoltage", gx_vrm_id, address_battery);
|
||||||
Serial.println(mqtt_bat_min_cell_volt);
|
logPrintlnI(mqtt_bat_min_cell_volt);
|
||||||
sprintf(mqtt_temp_outside, "N/%s/temperature/%s/Temperature", gx_vrm_id, address_outside_temperature);
|
sprintf(mqtt_temp_outside, "N/%s/temperature/%s/Temperature", gx_vrm_id, address_outside_temperature);
|
||||||
Serial.println(mqtt_temp_outside);
|
logPrintlnI(mqtt_temp_outside);
|
||||||
sprintf(mqtt_grid_power_l1, "N/%s/system/0/Ac/ConsumptionOnInput/L1/Power", gx_vrm_id);
|
sprintf(mqtt_grid_power_l1, "N/%s/system/0/Ac/ConsumptionOnInput/L1/Power", gx_vrm_id);
|
||||||
Serial.println(mqtt_grid_power_l1);
|
logPrintlnI(mqtt_grid_power_l1);
|
||||||
sprintf(mqtt_grid_power_l2, "N/%s/system/0/Ac/ConsumptionOnInput/L2/Power", gx_vrm_id);
|
sprintf(mqtt_grid_power_l2, "N/%s/system/0/Ac/ConsumptionOnInput/L2/Power", gx_vrm_id);
|
||||||
Serial.println(mqtt_grid_power_l2);
|
logPrintlnI(mqtt_grid_power_l2);
|
||||||
sprintf(mqtt_grid_power_l3, "N/%s/system/0/Ac/ConsumptionOnInput/L3/Power", gx_vrm_id);
|
sprintf(mqtt_grid_power_l3, "N/%s/system/0/Ac/ConsumptionOnInput/L3/Power", gx_vrm_id);
|
||||||
Serial.println(mqtt_grid_power_l3);
|
logPrintlnI(mqtt_grid_power_l3);
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("-------------- Settings --------------");
|
Serial.println("-------------- Settings --------------");
|
||||||
Serial.print("mqtt server: "); Serial.println(mqtt_server);
|
Serial.print("mqtt server: "); Serial.println(mqtt_server);
|
||||||
|
|
Loading…
Reference in a new issue