3131#define FACTORY_OFFSET CONFIG_SIZE
3232#define FACTORY_SIZE 1024
3333
34+ uint32_t config_ver = INITIAL_CONFIG_VERSION;
35+
3436// Wifi Network Strings
3537String esid;
3638String epass;
@@ -251,6 +253,26 @@ ConfigOpt *opts[] =
251253ConfigJson user_config (opts, sizeof (opts) / sizeof(opts[0 ]), EEPROM_SIZE, CONFIG_OFFSET);
252254ConfigJson factory_config (opts, sizeof (opts) / sizeof(opts[0 ]), EEPROM_SIZE, FACTORY_OFFSET);
253255
256+ // -------------------------------------------------------------------
257+ // config version handling
258+ // -------------------------------------------------------------------
259+ uint32_t
260+ config_version () {
261+ return config_ver;
262+ }
263+
264+ void
265+ increment_config () {
266+ config_ver++;
267+ DBUGVAR (config_ver);
268+
269+ #if ENABLE_CONFIG_CHANGE_NOTIFICATION
270+ StaticJsonDocument<128 > event;
271+ event[" config_version" ] = config_ver;
272+ event_send (event);
273+ #endif
274+ }
275+
254276// -------------------------------------------------------------------
255277// Reset EEPROM, wipes all settings
256278// -------------------------------------------------------------------
@@ -368,7 +390,117 @@ bool config_deserialize(const char *json)
368390
369391bool config_deserialize (DynamicJsonDocument &doc)
370392{
371- return user_config.deserialize (doc);
393+ bool config_modified = user_config.deserialize (doc);
394+
395+ #if ENABLE_CONFIG_CHANGE_NOTIFICATION
396+ // Update EVSE config
397+ // Update the EVSE setting flags, a little low level, may move later
398+ if (doc.containsKey (" diode_check" ))
399+ {
400+ bool enable = doc[" diode_check" ];
401+ if (enable != evse.isDiodeCheckEnabled ()) {
402+ evse.enableDiodeCheck (enable);
403+ config_modified = true ;
404+ DBUGLN (" diode_check changed" );
405+ }
406+ }
407+
408+ if (doc.containsKey (" gfci_check" ))
409+ {
410+ bool enable = doc[" gfci_check" ];
411+ if (enable != evse.isGfiTestEnabled ()) {
412+ evse.enableGfiTestCheck (enable);
413+ config_modified = true ;
414+ DBUGLN (" gfci_check changed" );
415+ }
416+ }
417+
418+ if (doc.containsKey (" ground_check" ))
419+ {
420+ bool enable = doc[" ground_check" ];
421+ if (enable != evse.isGroundCheckEnabled ()) {
422+ evse.enableGroundCheck (enable);
423+ config_modified = true ;
424+ DBUGLN (" ground_check changed" );
425+ }
426+ }
427+
428+ if (doc.containsKey (" relay_check" ))
429+ {
430+ bool enable = doc[" relay_check" ];
431+ if (enable != evse.isStuckRelayCheckEnabled ()) {
432+ evse.enableStuckRelayCheck (enable);
433+ config_modified = true ;
434+ DBUGLN (" relay_check changed" );
435+ }
436+ }
437+
438+ if (doc.containsKey (" vent_check" ))
439+ {
440+ bool enable = doc[" vent_check" ];
441+ if (enable != evse.isVentRequiredEnabled ()) {
442+ evse.enableVentRequired (enable);
443+ config_modified = true ;
444+ DBUGLN (" vent_check changed" );
445+ }
446+ }
447+
448+ if (doc.containsKey (" temp_check" ))
449+ {
450+ bool enable = doc[" temp_check" ];
451+ if (enable != evse.isTemperatureCheckEnabled ()) {
452+ evse.enableTemperatureCheck (enable);
453+ config_modified = true ;
454+ DBUGLN (" temp_check changed" );
455+ }
456+ }
457+
458+ if (doc.containsKey (" service" ))
459+ {
460+ EvseMonitor::ServiceLevel service = static_cast <EvseMonitor::ServiceLevel>(doc[" service" ].as <uint8_t >());
461+ if (service != evse.getServiceLevel ()) {
462+ evse.setServiceLevel (service);
463+ config_modified = true ;
464+ DBUGLN (" service changed" );
465+ }
466+ }
467+
468+ if (doc.containsKey (" max_current_soft" ))
469+ {
470+ long current = doc[" max_current_soft" ];
471+ if (current != evse.getMaxConfiguredCurrent ()) {
472+ evse.setMaxConfiguredCurrent (current);
473+ config_modified = true ;
474+ DBUGLN (" max_current_soft changed" );
475+ }
476+ }
477+
478+ if (doc.containsKey (" scale" ) && doc.containsKey (" offset" ))
479+ {
480+ long scale = doc[" scale" ];
481+ long offset = doc[" offset" ];
482+ if (scale != evse.getCurrentSensorScale () || offset != evse.getCurrentSensorOffset ()) {
483+ evse.configureCurrentSensorScale (doc[" scale" ], doc[" offset" ]);
484+ config_modified = true ;
485+ DBUGLN (" scale changed" );
486+ }
487+ }
488+ #endif
489+
490+ if (config_modified)
491+ {
492+ #if ENABLE_CONFIG_CHANGE_NOTIFICATION
493+ // HACK: force a flush of the RAPI command queue to make sure the config
494+ // is updated before we send the response
495+ DBUG (" Flushing RAPI command queue ..." );
496+ rapiSender.flush ();
497+ DBUGLN (" Done" );
498+ #endif
499+
500+ increment_config ();
501+ }
502+
503+ return config_modified;
372504}
373505
374506bool config_serialize (String& json, bool longNames, bool compactOutput, bool hideSecrets)
@@ -378,6 +510,43 @@ bool config_serialize(String& json, bool longNames, bool compactOutput, bool hid
378510
379511bool config_serialize (DynamicJsonDocument &doc, bool longNames, bool compactOutput, bool hideSecrets)
380512{
513+ // Static supported protocols
514+ JsonArray mqtt_supported_protocols = doc.createNestedArray (" mqtt_supported_protocols" );
515+ mqtt_supported_protocols.add (" mqtt" );
516+ mqtt_supported_protocols.add (" mqtts" );
517+ JsonArray http_supported_protocols = doc.createNestedArray (" http_supported_protocols" );
518+ http_supported_protocols.add (" http" );
519+
520+ #if ENABLE_CONFIG_CHANGE_NOTIFICATION
521+ doc[" buildenv" ] = buildenv;
522+ doc[" version" ] = currentfirmware;
523+ doc[" wifi_serial" ] = serial;
524+ doc[" protocol" ] = " -" ;
525+ doc[" espinfo" ] = ESPAL.getChipInfo ();
526+ doc[" espflash" ] = ESPAL.getFlashChipSize ();
527+
528+ // EVSE information are only evailable when config_version is incremented
529+ if (config_ver > 0 ) {
530+ // Read only information
531+ doc[" firmware" ] = evse.getFirmwareVersion ();
532+ doc[" evse_serial" ] = evse.getSerial ();
533+ // OpenEVSE module config
534+ doc[" diode_check" ] = evse.isDiodeCheckEnabled ();
535+ doc[" gfci_check" ] = evse.isGfiTestEnabled ();
536+ doc[" ground_check" ] = evse.isGroundCheckEnabled ();
537+ doc[" relay_check" ] = evse.isStuckRelayCheckEnabled ();
538+ doc[" vent_check" ] = evse.isVentRequiredEnabled ();
539+ doc[" temp_check" ] = evse.isTemperatureCheckEnabled ();
540+ doc[" max_current_soft" ] = evse.getMaxConfiguredCurrent ();
541+ // OpenEVSE Read only information
542+ doc[" service" ] = static_cast <uint8_t >(evse.getServiceLevel ());
543+ doc[" scale" ] = evse.getCurrentSensorScale ();
544+ doc[" offset" ] = evse.getCurrentSensorOffset ();
545+ doc[" min_current_hard" ] = evse.getMinCurrent ();
546+ doc[" max_current_hard" ] = evse.getMaxHardwareCurrent ();
547+ }
548+ #endif
549+
381550 return user_config.serialize (doc, longNames, compactOutput, hideSecrets);
382551}
383552
0 commit comments