Skip to content

Commit

Permalink
Ready for v1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiejones85 committed Mar 29, 2023
1 parent b90bf97 commit bc63a82
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 128 deletions.
26 changes: 13 additions & 13 deletions ESP32-Chademo/Chademo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion ESP32-Chademo/Chademo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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;
Expand Down
37 changes: 6 additions & 31 deletions ESP32-Chademo/ChademoWebServer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "ChademoWebServer.h"
#include <SPIFFS.h>
#include <EEPROM.h>
#include <AsyncElegantOTA.h>;


AsyncWebServer server(80);
AsyncWebSocket ws("/ws");
Expand Down Expand Up @@ -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();
}

Expand All @@ -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) {
Expand All @@ -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"];

}
28 changes: 25 additions & 3 deletions ESP32-Chademo/ESP32-Chademo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) ;
Expand Down Expand Up @@ -120,6 +121,8 @@ void setup() {
settings.minChargeAmperage = MIN_CHARGE_A;
settings.capacity = CAPACITY;
settings.debuggingLevel = 1;
settings.currentMissmatch = true;

Save();
}
help8Val = 1;
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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("-"));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -481,9 +499,6 @@ void loop() {
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
Count = 0;
SerialCommand();
// #ifdef SIMPBMS
// chademo.setStateOfCharge(simpbms.getStateOfCharge());
// #endif
sendStatusToVCU();
broadcastMessage();

Expand All @@ -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);
}
}

}
}
Loading

0 comments on commit bc63a82

Please sign in to comment.