diff --git a/ESP32-Chademo/Chademo.cpp b/ESP32-Chademo/Chademo.cpp index f3bf451..b006ca0 100644 --- a/ESP32-Chademo/Chademo.cpp +++ b/ESP32-Chademo/Chademo.cpp @@ -138,7 +138,9 @@ void CHADEMO::loop() if (!bDoMismatchChecks && chademoState == RUNNING) { - if ((CurrentMillis - mismatchStart) >= mismatchDelay) bDoMismatchChecks = 1; + if (settings.currentMissmatch && (CurrentMillis - mismatchStart) >= mismatchDelay) { + bDoMismatchChecks = 1; + } } if (chademoState == LIMBO && (CurrentMillis - stateMilli) >= stateDelay) @@ -492,12 +494,11 @@ void CHADEMO::sendCANBattSpecs() outFrame.data[3] = 0x00; // Not Used outFrame.data[4] = lowByte(settings.maxChargeVoltage); outFrame.data[5] = highByte(settings.maxChargeVoltage); -// #ifdef SIMPBMS -// outFrame.data[6] = (uint8_t)soc; //charged_rate_reference (change to SoC from BMS) -// #endif -// #ifndef SIMPBMS - outFrame.data[6] = (uint8_t)((settings.capacity - settings.ampHours) / settings.capacity) * 100; //charged_rate_reference ((46 - 30) / 46) * 100) - /// #endif + if(settings.useBms) { + outFrame.data[6] = (uint8_t)soc; //charged_rate_reference (change to SoC from BMS) + } else { + outFrame.data[6] = (uint8_t)((settings.capacity - settings.ampHours) / settings.capacity) * 100; //charged_rate_reference ((46 - 30) / 46) * 100) + } outFrame.data[7] = 0; //not used ACAN_ESP32::can.tryToSend(outFrame); @@ -574,12 +575,11 @@ void CHADEMO::sendCANStatus() outFrame.data[3] = askingAmps; outFrame.data[4] = faults; outFrame.data[5] = status; - #ifdef SIMPBMS - outFrame.data[6] = 100; //charged rate (change to 100 for use with BMS SoC) - #endif - #ifndef SIMPBMS - outFrame.data[6] = (uint8_t)settings.kiloWattHours; //charged rate (change to 100 for use with BMS SoC) - #endif + if(settings.useBms) { + outFrame.data[6] = 100; //charged rate (change to 100 for use with BMS SoC) + } else { + outFrame.data[6] = (uint8_t)settings.kiloWattHours; //charged rate (change to 100 for use with BMS SoC) + } outFrame.data[7] = 0; //not used ACAN_ESP32::can.tryToSend(outFrame); diff --git a/ESP32-Chademo/Chademo.h b/ESP32-Chademo/Chademo.h index 640d473..99c5da7 100644 --- a/ESP32-Chademo/Chademo.h +++ b/ESP32-Chademo/Chademo.h @@ -101,6 +101,7 @@ class CHADEMO void setBattOverTemp(); void setStateOfCharge(uint8_t stateofcharge); + //these need to be accessed quickly in tight spots so they're public in an attempt at efficiency uint8_t bChademoMode; //accessed but not modified in ISR so it should be OK non-volatile uint8_t bChademoSendRequests; //should we be sending periodic status updates? @@ -128,7 +129,6 @@ class CHADEMO uint32_t lastCommTime; const uint16_t lastCommTimeout = 1000; //allow up to 1 second of comm fault before getting angry uint8_t soc; //BMS reported SoC - CHADEMOSTATE chademoState; CHADEMOSTATE stateHolder; EVSE_PARAMS evse_params; diff --git a/ESP32-Chademo/ChademoWebServer.cpp b/ESP32-Chademo/ChademoWebServer.cpp index 8a1135d..3d70745 100644 --- a/ESP32-Chademo/ChademoWebServer.cpp +++ b/ESP32-Chademo/ChademoWebServer.cpp @@ -1,6 +1,8 @@ #include "ChademoWebServer.h" #include #include +#include ; + AsyncWebServer server(80); AsyncWebSocket ws("/ws"); @@ -85,42 +87,12 @@ void ChademoWebServer::setup() } }); - server.on("/edit", - HTTP_POST, - [](AsyncWebServerRequest * request){}, - [&](AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) { - if (!index) { - // open the file on first call and store the file handle in the request object - request->_tempFile = SPIFFS.open("/" + filename, "w"); - - } - - if (len) { - // stream the incoming chunk to the opened file - request->_tempFile.write(data, len); - } - - if (final) { - // close the file handle as the upload is now done - request->_tempFile.close(); - - if (filename.substring(filename.lastIndexOf(".")).equals("bin")) { - Serial.println("Firmware uploaded, restarting"); - request->send(200, "application/json", "restarting"); - ESP.restart(); - } - request->redirect("/"); - } - } - - ); - server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html"); // Start server Serial.println("Starting Web Server"); - + AsyncElegantOTA.begin(&server); server.begin(); } @@ -134,6 +106,8 @@ void ChademoWebServer::toJson(EESettings& settings, DynamicJsonDocument &root) { root["minChargeAmperage"] = settings.minChargeAmperage; root["capacity"] = settings.capacity; root["debuggingLevel"] = settings.debuggingLevel; + root["currentMissmatch"] = settings.currentMissmatch; + } void ChademoWebServer::fromJson(EESettings& settings, JsonObject &doc) { @@ -147,5 +121,6 @@ void ChademoWebServer::fromJson(EESettings& settings, JsonObject &doc) { settings.minChargeAmperage = doc["minChargeAmperage"]; settings.capacity = doc["capacity"]; settings.debuggingLevel = doc["debuggingLevel"]; + settings.currentMissmatch = doc["currentMissmatch"]; } diff --git a/ESP32-Chademo/ESP32-Chademo.ino b/ESP32-Chademo/ESP32-Chademo.ino index 7577ebe..6500127 100644 --- a/ESP32-Chademo/ESP32-Chademo.ino +++ b/ESP32-Chademo/ESP32-Chademo.ino @@ -24,6 +24,7 @@ float Power = 0; float lastSavedAH = 0; int Count = 0; int socketMessage = 0; +uint8_t soc; ISA Sensor; ACAN2515 can1 (MCP2515_CS, SPI, MCP2515_INT) ; @@ -120,6 +121,8 @@ void setup() { settings.minChargeAmperage = MIN_CHARGE_A; settings.capacity = CAPACITY; settings.debuggingLevel = 1; + settings.currentMissmatch = true; + Save(); } help8Val = 1; @@ -225,6 +228,8 @@ void printHelp() { Serial.println(F("CAPKWH - Sets pack kilowatt-hours")); Serial.println(F("DBG - Sets debugging level")); Serial.println(F("BMS - Sets use to 0 - No BMS, 1 - ESP32 BMS for SoC and cell voltage and temeratures")); + Serial.println(F("MISS - Sets use to 0 - Disable Current Miss-Match check, 1 - Enable Current Miss-Match check")); + Serial.println(F("Example: V=395 - sets CHAdeMO voltage target to 395")); } @@ -291,6 +296,16 @@ void ParseCommand() { RngErr(); } } + else if (cmdStr == "MISS") { + uint8Val = Serial.parseInt(); + if (uint8Val >= 0 && uint8Val < 2) { + settings.currentMissmatch = uint8Val == 1; + Save(); + print8Val = 1; + } else { + RngErr(); + } + } else if (cmdStr == "CAPKWH") { fltVal = Serial.parseFloat(); if (fltVal > 0 && fltVal < 100) { @@ -372,6 +387,8 @@ void printSettings() { Serial.println (settings.packSizeKWH, 2); Serial.print (F("BMS ")); Serial.println (settings.useBms, 1); + Serial.print (F("MISS ")); + Serial.println (settings.currentMissmatch, 1); Serial.print (F("DBG ")); Serial.println (settings.debuggingLevel, 1); Serial.println (F("-")); @@ -411,6 +428,7 @@ void broadcastMessage() { json["amperage"] = Sensor.Amperes; json["power"] = Sensor.KW; json["ampHours"] = Sensor.AH; + json["soc"] = soc; size_t len = serializeJson(json, buffer); // serialize to buffe chademoWebServer.getWebSocket().textAll(buffer, len); @@ -481,9 +499,6 @@ void loop() { digitalWrite(LED_PIN, !digitalRead(LED_PIN)); Count = 0; SerialCommand(); -// #ifdef SIMPBMS -// chademo.setStateOfCharge(simpbms.getStateOfCharge()); -// #endif sendStatusToVCU(); broadcastMessage(); @@ -507,5 +522,12 @@ void loop() { } if (can1.receive(inFrame)) { Sensor.handleCANFrame(inFrame); + if (settings.useBms) { + if (inFrame.id == 0x355) { + soc = (inFrame.data[1] << 8) + inFrame.data[0]; + chademo.setStateOfCharge(soc); + } + } + } } diff --git a/ESP32-Chademo/data/gauges.js b/ESP32-Chademo/data/gauges.js index 445c172..bf0510a 100644 --- a/ESP32-Chademo/data/gauges.js +++ b/ESP32-Chademo/data/gauges.js @@ -8,10 +8,20 @@ var updateGauge = function(key, value) { updateCurrent(value) } else if (key == 'power') { updatePower(value) + } else if (key == 'soc') { + updateSOC(value) } }; +var updateSOC = function(newVal) { + if (chartSoc) { + point = chartSoc.series[0].points[0]; + point.update(Math.round(newVal)); + } +} + + var updateCurrent = function(newVal) { if (chartCurrent) { point = chartCurrent.series[0].points[0]; @@ -25,7 +35,7 @@ var updatePower = function(newVal) { point.update(Math.round(newVal * -1)); } } - + var updateVoltage = function(newVal) { if (chartVoltage) { point = chartVoltage.series[0].points[0]; @@ -41,9 +51,9 @@ var initGauges = function() { chart: { type: 'solidgauge' }, - + title: null, - + pane: { center: ['50%', '85%'], size: '140%', @@ -57,15 +67,15 @@ var initGauges = function() { shape: 'arc' } }, - + exporting: { enabled: false }, - + tooltip: { enabled: false }, - + // the value axis yAxis: { stops: [ @@ -84,7 +94,7 @@ var initGauges = function() { y: 16 } }, - + plotOptions: { solidgauge: { dataLabels: { @@ -95,20 +105,20 @@ var initGauges = function() { } } }; - + chartCurrent = Highcharts.chart('container-current', Highcharts.merge(gaugeOptions, { yAxis: { min: 0, - max: 100, + max: 100, title: { text: 'Current' } }, - + credits: { enabled: false }, - + series: [{ name: 'Current', data: [0], @@ -123,7 +133,7 @@ var initGauges = function() { valueSuffix: ' A' } }] - + })); } @@ -132,9 +142,9 @@ var initGauges = function() { chart: { type: 'solidgauge' }, - + title: null, - + pane: { center: ['50%', '85%'], size: '140%', @@ -148,15 +158,15 @@ var initGauges = function() { shape: 'arc' } }, - + exporting: { enabled: false }, - + tooltip: { enabled: false }, - + // the value axis yAxis: { stops: [ @@ -175,7 +185,7 @@ var initGauges = function() { y: 16 } }, - + plotOptions: { solidgauge: { dataLabels: { @@ -186,20 +196,20 @@ var initGauges = function() { } } }; - + chartVoltage = Highcharts.chart('container-voltage', Highcharts.merge(gaugeOptions, { yAxis: { min: 0, - max: 100, + max: 100, title: { text: 'Voltage' } }, - + credits: { enabled: false }, - + series: [{ name: 'Voltage', data: [10], @@ -214,7 +224,7 @@ var initGauges = function() { valueSuffix: 'V' } }] - + })); } @@ -223,9 +233,9 @@ var initGauges = function() { chart: { type: 'solidgauge' }, - + title: null, - + pane: { center: ['50%', '85%'], size: '140%', @@ -239,15 +249,15 @@ var initGauges = function() { shape: 'arc' } }, - + exporting: { enabled: false }, - + tooltip: { enabled: false }, - + // the value axis yAxis: { stops: [ @@ -266,7 +276,7 @@ var initGauges = function() { y: 16 } }, - + plotOptions: { solidgauge: { dataLabels: { @@ -277,20 +287,20 @@ var initGauges = function() { } } }; - + chartPower = Highcharts.chart('container-power', Highcharts.merge(gaugeOptions, { yAxis: { min: 0, - max: 100, + max: 100, title: { text: 'Power' } }, - + credits: { enabled: false }, - + series: [{ name: 'Power', data: [0], @@ -305,12 +315,104 @@ var initGauges = function() { valueSuffix: ' KW' } }] - + + })); + } + + var initSocGauge = function() { + var gaugeOptions = { + chart: { + type: 'solidgauge' + }, + + title: null, + + pane: { + center: ['50%', '85%'], + size: '140%', + startAngle: -90, + endAngle: 90, + background: { + backgroundColor: + Highcharts.defaultOptions.legend.backgroundColor || '#EEE', + innerRadius: '60%', + outerRadius: '100%', + shape: 'arc' + } + }, + + exporting: { + enabled: false + }, + + tooltip: { + enabled: false + }, + + // the value axis + yAxis: { + stops: [ + [0.2, '#DF5353'], // red + [0.6, '#DDDF0D'], // yellow + [0.8, '#55BF3B'] // green + ], + lineWidth: 0, + tickWidth: 0, + minorTickInterval: null, + tickAmount: 2, + title: { + y: -70 + }, + labels: { + y: 16 + } + }, + + plotOptions: { + solidgauge: { + dataLabels: { + y: 5, + borderWidth: 0, + useHTML: true + } + } + } + }; + + chartSoc = Highcharts.chart('container-soc', Highcharts.merge(gaugeOptions, { + yAxis: { + min: 0, + max: 100, + title: { + text: 'SoC' + } + }, + + credits: { + enabled: false + }, + + series: [{ + name: 'SoC', + data: [0], + dataLabels: { + format: + '
' + + '{y}
' + + '%' + + '
' + }, + tooltip: { + valueSuffix: ' %' + } + }] + })); } initVoltageGauge(); initCurrentGauge(); initPowerGauge(); + initSocGauge(); -} \ No newline at end of file +} diff --git a/ESP32-Chademo/data/index.html b/ESP32-Chademo/data/index.html index bd9ed1b..dd82d38 100644 --- a/ESP32-Chademo/data/index.html +++ b/ESP32-Chademo/data/index.html @@ -15,19 +15,19 @@
-

Chademo Status

+

Chademo Status

Waiting
-

EVSE Max Voltage

+

EVSE Max Voltage

-V
-

EVSE Threshold Voltage

+

EVSE Threshold Voltage

-V
-

EVSE Max Current

+

EVSE Max Current

-A
@@ -37,21 +37,24 @@

EVSE Max Current

+
+
+
-

IN 1

+

IN 1

-
-

IN 2

+

IN 2

-
-

OUT 1

+

OUT 1

-
-

OUT 2

+

OUT 2

-
@@ -59,7 +62,7 @@

OUT 2

Wifi Settings -

Upload Update +

Upload Update

Settings