Skip to content

Commit 5cffb59

Browse files
Merge branch 'master' into AWS_IoT_Core_support
2 parents 1f194bb + edb29d1 commit 5cffb59

21 files changed

Lines changed: 615 additions & 326 deletions

plugins/abrp/README.rst

Lines changed: 0 additions & 19 deletions
This file was deleted.

vehicle/OVMS.V3/changes.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Open Vehicle Monitor System v3 - Change log
77
- Fixed MQTT CONNECT to omit empty username/password for certificate-only auth.
88
- New option "retain.depth.limit": disables RETAIN on deep topics (>8 segments)
99
for brokers like AWS IoT Core that reject them.
10+
- Autostart: added init option "minimal" to boot with just basic networking as configured; this is
11+
now the first fallback in case of repeated early crashes, aiming at keeping the module reachable
12+
in case of a bug in a higher level module / configuration. Auto init will be disabled only if
13+
early crashes continue in minimal mode.
14+
Config extension:
15+
[auto] init -- "no" / "yes" / "minimal" (default "yes")
1016
- Server V3: the MQTT client ID to use can now be configured. While not normally necessary, changing the
1117
client ID may be necessary to discard an existing MQTT server session when changing the username.
1218
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_ota/src/ovms_ota.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ void ota_flash_vfs(int verbosity, OvmsWriter* writer, OvmsCommand* cmd, int argc
191191
}
192192
writer->printf("Source image is %ld bytes in size\n",ds.st_size);
193193

194+
if (ds.st_size > target->size)
195+
{
196+
writer->printf("Error: target partition too small (%u bytes capacity) - aborting\n", target->size);
197+
if (target->size < 0x700000)
198+
writer->puts("Consider upgrading your partitioning scheme to v3-35.");
199+
return;
200+
}
201+
194202
FILE* f = fopen(argv[0], "r");
195203
if (f == NULL)
196204
{
@@ -325,14 +333,22 @@ void ota_flash_http(int verbosity, OvmsWriter* writer, OvmsCommand* cmd, int arg
325333
}
326334

327335
size_t expected = http.BodySize();
328-
if (expected < 32)
336+
if (expected < 1024) // empty / HTML error page?
329337
{
330338
writer->printf("Error: Expected download file size (%d) is invalid\n",expected);
331339
return;
332340
}
333341

334342
writer->printf("Expected file size is %d\n",expected);
335343

344+
if (expected > target->size)
345+
{
346+
writer->printf("Error: target partition too small (%u bytes capacity) - aborting\n", target->size);
347+
if (target->size < 0x700000)
348+
writer->puts("Consider upgrading your partitioning scheme to v3-35.");
349+
return;
350+
}
351+
336352
MyOTA.SetFlashStatus("OTA Flash HTTP: Preparing flash partition...");
337353
writer->puts(MyOTA.GetFlashStatus());
338354
esp_ota_handle_t otah;
@@ -1018,6 +1034,16 @@ bool OvmsOTA::AutoFlashSD()
10181034
}
10191035
ESP_LOGW(TAG, "AutoFlashSD Source image is %d bytes in size",(int)ds.st_size);
10201036

1037+
if (ds.st_size > target->size)
1038+
{
1039+
ESP_LOGE(TAG, "Error: target partition too small (%u bytes capacity) - aborting\n", target->size);
1040+
if (target->size < 0x700000)
1041+
{
1042+
ESP_LOGE(TAG, "Consider upgrading your partitioning scheme to v3-35.");
1043+
}
1044+
return false;
1045+
}
1046+
10211047
SetFlashStatus("OTA Auto Flash SD: Preparing flash partition...",0,true);
10221048
esp_ota_handle_t otah;
10231049
esp_err_t err = esp_ota_begin(target, ds.st_size, &otah);
@@ -1422,13 +1448,23 @@ bool OvmsOTA::AutoFlash(bool force)
14221448
}
14231449

14241450
size_t expected = http.BodySize();
1425-
if (expected < 32)
1451+
if (expected < 1024) // empty / HTML error page?
14261452
{
14271453
ESP_LOGE(TAG, "AutoFlash: Expected download file size (%d) is invalid", expected);
14281454
m_lastcheckday = -1; // Allow to try again within the same day
14291455
return false;
14301456
}
14311457

1458+
if (expected > target->size)
1459+
{
1460+
ESP_LOGE(TAG, "Error: target partition too small (%u bytes capacity) - aborting\n", target->size);
1461+
if (target->size < 0x700000)
1462+
{
1463+
ESP_LOGE(TAG, "Consider upgrading your partitioning scheme to v3-35.");
1464+
}
1465+
return false;
1466+
}
1467+
14321468
SetFlashStatus("OTA Auto Flash: Preparing flash partition...",0,true);
14331469
esp_ota_handle_t otah;
14341470
esp_err_t err = esp_ota_begin(target, expected, &otah);

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/components/vehicle_nissanleaf/src/vehicle_nissanleaf.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,42 @@ void OvmsVehicleNissanLeaf::IncomingFrameCan1(CAN_frame_t* p_frame)
10651065
}
10661066
}
10671067

1068+
// --------- Patch ZE1 : detect CHAdeMO charging via battery voltage/current ---------
1069+
if (cfg_ze1)
1070+
{
1071+
bool car_on = StandardMetrics.ms_v_env_on->AsBool();
1072+
1073+
// DC fast charge active if: car off + battery voltage plausible + strong inbound current
1074+
if (!car_on && battery_voltage > 200.0f && battery_current < -25.0f)
1075+
{
1076+
// CHAdeMO detected
1077+
if (StandardMetrics.ms_v_charge_state->AsString() != "charging"
1078+
|| StandardMetrics.ms_v_charge_type->AsString() != "chademo")
1079+
{
1080+
vehicle_nissanleaf_charger_status(CHARGER_STATUS_QUICK_CHARGING);
1081+
}
1082+
// Pilot ON (cable connected, station OK)
1083+
StandardMetrics.ms_v_charge_pilot->SetValue(true);
1084+
// Keep charge metrics up-to-date
1085+
StandardMetrics.ms_v_charge_voltage->SetValue(battery_voltage);
1086+
StandardMetrics.ms_v_charge_current->SetValue(-battery_current);
1087+
StandardMetrics.ms_v_charge_power ->SetValue(-battery_power);
1088+
if (battery_voltage > 0)
1089+
StandardMetrics.ms_v_charge_climit->SetValue(
1090+
m_battery_chargerate_max->AsFloat() * 1000.0f / battery_voltage);
1091+
}
1092+
else if (!car_on
1093+
&& StandardMetrics.ms_v_charge_inprogress->AsBool()
1094+
&& StandardMetrics.ms_v_charge_type->AsString() == "chademo"
1095+
&& battery_current > -5.0f)
1096+
{
1097+
// End of CHAdeMO charging
1098+
StandardMetrics.ms_v_charge_pilot->SetValue(false);
1099+
vehicle_nissanleaf_charger_status(CHARGER_STATUS_FINISHED);
1100+
}
1101+
}
1102+
// --------- End patch ZE1 ---------
1103+
10681104
}
10691105
break;
10701106
case 0x1dc:

0 commit comments

Comments
 (0)