Skip to content

Commit 8a4fadd

Browse files
committed
Autostart: added init option "minimal" to boot with just basic networking as configured; this is
now the first fallback in case of repeated early crashes, aiming at keeping the module reachable in case of a bug in a higher level module / configuration. Auto init will be disabled only if early crashes continue in minimal mode. Config extension: [auto] init -- "no" / "yes" / "minimal" (default "yes") Web UI: optimize autostart configuration
1 parent 76c7dc4 commit 8a4fadd

8 files changed

Lines changed: 173 additions & 38 deletions

File tree

vehicle/OVMS.V3/changes.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Open Vehicle Monitor System v3 - Change log
22

33
????-??-?? ??? ??????? OTA release
4+
- Autostart: added init option "minimal" to boot with just basic networking as configured; this is
5+
now the first fallback in case of repeated early crashes, aiming at keeping the module reachable
6+
in case of a bug in a higher level module / configuration. Auto init will be disabled only if
7+
early crashes continue in minimal mode.
8+
Config extension:
9+
[auto] init -- "no" / "yes" / "minimal" (default "yes")
410
- Server V3: the MQTT client ID to use can now be configured. While not normally necessary, changing the
511
client ID may be necessary to discard an existing MQTT server session when changing the username.
612
New configs:

vehicle/OVMS.V3/components/dbc/src/dbc_app.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void dbc_autoload(int verbosity, OvmsWriter* writer, OvmsCommand* cmd, int argc,
320320

321321
void dbc_sdmounted(std::string event, void* data)
322322
{
323-
if (MyConfig.GetParamValueBool("auto", "dbc", false))
323+
if (MyDBC.m_autoload)
324324
MyDBC.LoadAutoExtras(true);
325325
}
326326

@@ -955,5 +955,12 @@ dbcfile* dbc::SelectedFile()
955955
void dbc::AutoInit()
956956
{
957957
if (MyConfig.GetParamValueBool("auto", "dbc", false))
958+
{
958959
LoadDirectory("/store/dbc", true);
960+
m_autoload = true;
961+
}
962+
else
963+
{
964+
m_autoload = false;
965+
}
959966
}

vehicle/OVMS.V3/components/dbc/src/dbc_app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class dbc
7777
OvmsMutex m_mutex;
7878
dbcLoadedFiles_t m_dbclist;
7979
dbcfile* m_selected;
80+
bool m_autoload = false;
8081
};
8182

8283
extern dbc MyDBC;

vehicle/OVMS.V3/components/ovms_webserver/src/web_cfg_autostart.cpp

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ void OvmsWebServer::HandleCfgAutoInit(PageEntry_t& p, PageContext_t& c)
3333
{
3434
auto lock = MyConfig.Lock();
3535
std::string error, warn;
36-
bool init, ext12v, modem, server_v2, server_v3;
36+
std::string init;
37+
bool ext12v, modem, server_v2, server_v3;
3738
#ifdef CONFIG_OVMS_SC_JAVASCRIPT_DUKTAPE
3839
bool scripting;
3940
#endif
@@ -46,7 +47,7 @@ void OvmsWebServer::HandleCfgAutoInit(PageEntry_t& p, PageContext_t& c)
4647

4748
if (c.method == "POST") {
4849
// process form submission:
49-
init = (c.getvar("init") == "yes");
50+
init = c.getvar("init");
5051
dbc = (c.getvar("dbc") == "yes");
5152
ext12v = (c.getvar("ext12v") == "yes");
5253
#ifdef CONFIG_OVMS_COMP_MAX7317
@@ -96,7 +97,7 @@ void OvmsWebServer::HandleCfgAutoInit(PageEntry_t& p, PageContext_t& c)
9697

9798
if (error == "") {
9899
// success:
99-
MyConfig.SetParamValueBool("auto", "init", init);
100+
MyConfig.SetParamValue("auto", "init", init);
100101
MyConfig.SetParamValueBool("auto", "dbc", dbc);
101102
MyConfig.SetParamValueBool("auto", "ext12v", ext12v);
102103
#ifdef CONFIG_OVMS_COMP_MAX7317
@@ -136,7 +137,7 @@ void OvmsWebServer::HandleCfgAutoInit(PageEntry_t& p, PageContext_t& c)
136137
}
137138
else {
138139
// read configuration:
139-
init = MyConfig.GetParamValueBool("auto", "init", true);
140+
init = MyConfig.GetParamValue("auto", "init", "yes");
140141
dbc = MyConfig.GetParamValueBool("auto", "dbc", false);
141142
ext12v = MyConfig.GetParamValueBool("auto", "ext12v", false);
142143
#ifdef CONFIG_OVMS_COMP_MAX7317
@@ -164,27 +165,16 @@ void OvmsWebServer::HandleCfgAutoInit(PageEntry_t& p, PageContext_t& c)
164165
c.panel_start("primary", "Auto start configuration");
165166
c.form_start(p.uri);
166167

167-
c.input_checkbox("Enable auto start", "init", init,
168-
"<p>Note: if a crash occurs within 10 seconds after powering the module, autostart will be temporarily"
169-
" disabled. You may need to use the USB shell to access the module and fix the config.</p>");
170-
171-
#ifdef CONFIG_OVMS_SC_JAVASCRIPT_DUKTAPE
172-
c.input_checkbox("Enable Javascript engine (Duktape)", "scripting", scripting,
173-
"<p>Enable execution of Javascript on the module (plugins, commands, event handlers).</p>");
174-
#endif
175-
176-
c.input_checkbox("Autoload DBC files", "dbc", dbc,
177-
"<p>Enable to autoload DBC files (for reverse engineering).</p>");
178-
179-
#ifdef CONFIG_OVMS_COMP_MAX7317
180-
c.input_checkbox("Start EGPIO monitor", "egpio", egpio,
181-
"<p>Enable to monitor EGPIO input ports and generate metrics and events from changes.</p>");
182-
c.input_text("EGPIO ports", "egpio_ports", egpio_ports.c_str(), "Ports to monitor",
183-
"<p>Enter list of port numbers (0…9) to monitor, separated by spaces.</p>");
184-
#endif //CONFIG_OVMS_COMP_MAX7317
168+
c.input_select_start("Auto init level", "init");
169+
c.input_select_option("Full (as configured below)", "yes", (init == "yes"));
170+
c.input_select_option("Minimal (just basic networking as configured)", "minimal", (init == "minimal"));
171+
c.input_select_option("Disabled (only USB access)", "no", (init == "no"));
172+
c.input_select_end(
173+
"<p>Note: on successive early crashes after powering on, the level will be reduced to 'minimal',"
174+
" then 'disabled'. You may need to use the USB shell to access the module and fix the config.</p>");
185175

186-
c.input_checkbox("Power on external 12V", "ext12v", ext12v,
187-
"<p>Enable to provide 12V to external devices connected to the module (i.e. ECU displays).</p>");
176+
// Networking:
177+
c.fieldset_start("Networking");
188178

189179
c.input_select_start("Wifi mode", "wifi_mode");
190180
c.input_select_option("Access point", "ap", (wifi_mode == "ap"));
@@ -208,8 +198,14 @@ void OvmsWebServer::HandleCfgAutoInit(PageEntry_t& p, PageContext_t& c)
208198
c.input_select_option(kv.first.c_str(), kv.first.c_str(), (kv.first == wifi_ssid_client));
209199
c.input_select_end();
210200

201+
c.print("<hr>");
211202
c.input_checkbox("Start modem", "modem", modem);
212203

204+
c.fieldset_end();
205+
206+
// Vehicle:
207+
c.fieldset_start("Vehicle");
208+
213209
c.input_select_start("Vehicle type", "vehicle_type");
214210
c.input_select_option("&mdash;", "", vehicle_type.empty());
215211
// sort vehicle options by name:
@@ -220,6 +216,38 @@ void OvmsWebServer::HandleCfgAutoInit(PageEntry_t& p, PageContext_t& c)
220216
c.input_select_option(entry.first, entry.second, (vehicle_type == entry.second));
221217
c.input_select_end();
222218

219+
c.input_checkbox("Autoload DBC files", "dbc", dbc,
220+
"<p>Enable to autoload DBC files (for reverse engineering).</p>");
221+
222+
c.fieldset_end();
223+
224+
#ifdef CONFIG_OVMS_SC_JAVASCRIPT_DUKTAPE
225+
// Scripting:
226+
c.fieldset_start("Scripting");
227+
c.input_checkbox("Enable Javascript engine (Duktape)", "scripting", scripting,
228+
"<p>Enable execution of Javascript on the module (plugins, commands, event handlers).</p>");
229+
c.fieldset_end();
230+
#endif
231+
232+
// Connections:
233+
c.fieldset_start("Connections");
234+
c.input_checkbox("Start server V2", "server_v2", server_v2);
235+
c.input_checkbox("Start server V3", "server_v3", server_v3);
236+
c.fieldset_end();
237+
238+
// Peripherals:
239+
c.fieldset_start("Peripherals");
240+
241+
#ifdef CONFIG_OVMS_COMP_MAX7317
242+
c.input_checkbox("Start EGPIO monitor", "egpio", egpio,
243+
"<p>Enable to monitor EGPIO input ports and generate metrics and events from changes.</p>");
244+
c.input_text("EGPIO ports", "egpio_ports", egpio_ports.c_str(), "Ports to monitor",
245+
"<p>Enter list of port numbers (0…9) to monitor, separated by spaces.</p>");
246+
#endif //CONFIG_OVMS_COMP_MAX7317
247+
248+
c.input_checkbox("Power on external 12V", "ext12v", ext12v,
249+
"<p>Enable to provide 12V to external devices connected to the module (i.e. ECU displays).</p>");
250+
223251
c.input_select_start("Start OBD2ECU", "obd2ecu");
224252
c.input_select_option("&mdash;", "", obd2ecu.empty());
225253
c.input_select_option("can1", "can1", obd2ecu == "can1");
@@ -229,10 +257,10 @@ void OvmsWebServer::HandleCfgAutoInit(PageEntry_t& p, PageContext_t& c)
229257
c.input_select_end(
230258
"<p>OBD2ECU translates OVMS to OBD2 metrics, i.e. to drive standard ECU displays</p>");
231259

232-
c.input_checkbox("Start server V2", "server_v2", server_v2);
233-
c.input_checkbox("Start server V3", "server_v3", server_v3);
260+
c.fieldset_end();
234261

235262
c.print(
263+
"<hr>"
236264
"<div class=\"form-group\">"
237265
"<div class=\"col-sm-offset-3 col-sm-9\">"
238266
"<button type=\"submit\" class=\"btn btn-default\" name=\"action\" value=\"save\">Save</button> "

vehicle/OVMS.V3/components/ovms_webserver/src/web_framework.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828

2929
#include "ovms_webserver.h"
30+
#include "ovms_housekeeping.h"
3031
#include "buffered_shell.h"
3132

3233
/**
@@ -492,6 +493,7 @@ std::string OvmsWebServer::CreateMenu(PageContext_t& c)
492493

493494
if (vehicle != "") {
494495
std::string vehiclename = MyVehicleFactory.ActiveVehicleShortName();
496+
if (vehiclename.empty()) vehiclename = "Vehicle";
495497
menu +=
496498
"<li class=\"dropdown\" id=\"menu-vehicle\">"
497499
"<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\" role=\"button\" aria-haspopup=\"true\" aria-expanded=\"false\">"
@@ -572,12 +574,13 @@ void OvmsWebServer::OutputHome(PageEntry_t& p, PageContext_t& c)
572574
, tools.c_str());
573575

574576
if (vehicle != "") {
575-
const char* vehiclename = MyVehicleFactory.ActiveVehicleName();
577+
std::string vehiclename = MyVehicleFactory.ActiveVehicleName();
578+
if (vehiclename.empty()) vehiclename = "Vehicle";
576579
mg_printf_http_chunk(c.nc,
577580
"<fieldset class=\"menu\" id=\"fieldset-menu-vehicle\"><legend>%s</legend>"
578581
"<ul class=\"list-inline\">%s</ul>"
579582
"</fieldset>"
580-
, vehiclename, vehicle.c_str());
583+
, vehiclename.c_str(), vehicle.c_str());
581584
}
582585

583586
c.printf(
@@ -589,8 +592,8 @@ void OvmsWebServer::OutputHome(PageEntry_t& p, PageContext_t& c)
589592
c.panel_end();
590593

591594
// check auto init, show warning if disabled:
592-
if (!MyConfig.GetParamValueBool("auto", "init", true)) {
593-
c.alert("warning", "<p><strong>Warning:</strong> auto start disabled. Check auto start configuration.</p>");
595+
if (MyHousekeeping->GetInitLevel() != INIT_Full) {
596+
c.alert("warning", "<p><strong>Warning:</strong> auto start reduced or disabled. Check auto start configuration.</p>");
594597
}
595598
}
596599

vehicle/OVMS.V3/main/ovms_boot.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static const char *TAG = "boot";
5353

5454
#include "ovms.h"
5555
#include "ovms_boot.h"
56+
#include "ovms_housekeeping.h"
5657
#include "ovms_command.h"
5758
#include "ovms_metrics.h"
5859
#include "ovms_notify.h"
@@ -165,6 +166,7 @@ void boot_status(int verbosity, OvmsWriter* writer, OvmsCommand* cmd, int argc,
165166
writer->printf(" Detected boot reason: %s (%d/%d)\n",MyBoot.GetBootReasonName(),boot_data.bootreason_cpu0,boot_data.bootreason_cpu1);
166167
writer->printf(" Reset reason: %s (%d)\n",MyBoot.GetResetReasonName(),MyBoot.GetResetReason());
167168
writer->printf(" Crash counters: %d total, %d early\n",MyBoot.GetCrashCount(),MyBoot.GetEarlyCrashCount());
169+
writer->printf(" Auto init level: %s\n",MyHousekeeping->GetInitLevelName());
168170

169171
if (MyBoot.m_shutdown_timer>0)
170172
{

0 commit comments

Comments
 (0)