Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for smartEVSE #42

Open
wants to merge 15 commits into
base: v3_gui
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
782 changes: 351 additions & 431 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"knockout-mapping": "^2.6.0"
},
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^5.1.1",
"css-loader": "^1.0.1",
Expand All @@ -22,7 +22,7 @@
"mini-css-extract-plugin": "^0.4.5",
"optimize-css-assets-webpack-plugin": "^5.0.4",
"style-loader": "^0.23.0",
"uglify-js": "^3.11.0",
"uglify-js": "^3.11.3",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^4.44.2",
"webpack-bundle-analyzer": "^3.9.0",
Expand Down
198 changes: 123 additions & 75 deletions src/home.htm

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,15 @@ border: none;
color: rgb(255,125,20);
}

#progressBack {
.progressBack {
width: 100%;
border-color: #19a6ff;
border-style: solid;
border-width: 1px;
border-radius: 4px
}

#progressBar {
.progressBar {
width: 1%;
height: 30px;
background-color: #008080;
Expand Down
14 changes: 11 additions & 3 deletions src/view_models/ConfigViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

function ConfigViewModel(baseEndpoint) {
"use strict";
var self = this;
var endpoint = ko.pureComputed(function () { return baseEndpoint() + "/config"; });
BaseViewModel.call(this, {
"ssid": "",
Expand Down Expand Up @@ -46,8 +47,9 @@ function ConfigViewModel(baseEndpoint) {
"tempt": 0,
"scale": 1,
"offset": 0,
"version": "0.0.0",
"version": "-",
"time_zone": false,
"divert_feed_type": "grid_ie",
"divert_enabled": false,
"divert_PV_ratio": 1.0,
"divert_attack_smoothing_factor": 0.4,
Expand All @@ -58,7 +60,7 @@ function ConfigViewModel(baseEndpoint) {
}, endpoint);

function trim(prop, val) {
if(val.trim() !== prop()) {
if (val.trim() !== prop()) {
prop(val.trim());
}
}
Expand All @@ -78,7 +80,12 @@ function ConfigViewModel(baseEndpoint) {
this.www_username.subscribe((v) => { trim(this.www_username, v); });
this.hostname.subscribe((v) => { trim(this.hostname, v); });
this.sntp_hostname.subscribe((v) => { trim(this.sntp_hostname, v); });

this.canUpdateControllerFirmware = ko.pureComputed(function () {
return self.firmware() && (self.firmware().startsWith("SmartEVSE_") || self.firmware()=="-");
});
}

ConfigViewModel.prototype = Object.create(BaseViewModel.prototype);
ConfigViewModel.prototype.constructor = ConfigViewModel;

Expand All @@ -90,11 +97,12 @@ ConfigViewModel.prototype.update = function (after = function () { }) {
this.mqtt_port_enable(data.hasOwnProperty("mqtt_port"));
this.mqtt_reject_unauthorized_enable(data.hasOwnProperty("mqtt_reject_unauthorized"));
// HACK: not sure why this is needed
if(data.hasOwnProperty("mqtt_protocol")) {
if (data.hasOwnProperty("mqtt_protocol")) {
this.mqtt_protocol(data.mqtt_protocol);
}
}, "json").always(() => {
this.fetching(false);
after();
});

};
21 changes: 15 additions & 6 deletions src/view_models/OpenEvseViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ function OpenEvseViewModel(baseEndpoint, configViewModel, statusViewModel) {
self.delayTimerStart = ko.observable("--:--");
self.delayTimerStop = ko.observable("--:--");

self.isSmartEVSE = ko.pureComputed(function () {
return self.config.firmware() && self.config.firmware().startsWith("SmartEVSE_");
});

// Saftey tests
self.gfiSelfTestEnabled = ko.observable(false);
self.groundCheckEnabled = ko.observable(false);
Expand All @@ -90,12 +94,17 @@ function OpenEvseViewModel(baseEndpoint, configViewModel, statusViewModel) {
self.diodeCheckEnabled = ko.observable(false);
self.ventRequiredEnabled = ko.observable(false);
self.allTestsEnabled = ko.pureComputed(function () {
return self.gfiSelfTestEnabled() &&
self.groundCheckEnabled() &&
self.stuckRelayEnabled() &&
self.tempCheckEnabled() &&
self.diodeCheckEnabled() &&
self.ventRequiredEnabled();
if (self.isSmartEVSE()) {
return self.tempCheckEnabled() &&
self.diodeCheckEnabled();
} else {
return self.gfiSelfTestEnabled() &&
self.groundCheckEnabled() &&
self.stuckRelayEnabled() &&
self.tempCheckEnabled() &&
self.diodeCheckEnabled() &&
self.ventRequiredEnabled();
}
});

self.tempCheckSupported = ko.observable(false);
Expand Down
91 changes: 77 additions & 14 deletions src/view_models/OpenEvseWiFiViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function OpenEvseWiFiViewModel(baseHost, basePort, baseProtocol)
self.showSolarDivert = ko.observable(false);
self.showSafety = ko.observable(false);
self.showVehiclePauseStatus = ko.observable(false);

self.toggle = function (flag) {
flag(!flag());
};
Expand Down Expand Up @@ -490,6 +490,7 @@ function OpenEvseWiFiViewModel(baseHost, basePort, baseProtocol)
// -----------------------------------------------------------------------
self.divertGroup = new ConfigGroupViewModel(self.baseEndpoint, () => {
return {
divert_feed_type: self.config.divert_feed_type(),
divert_enabled: self.config.divert_enabled(),
mqtt_solar: self.config.mqtt_solar(),
mqtt_grid_ie: self.config.mqtt_grid_ie(),
Expand All @@ -499,7 +500,7 @@ function OpenEvseWiFiViewModel(baseHost, basePort, baseProtocol)
divert_min_charge_time: self.config.divert_min_charge_time()
};
}).validate((divert) => {
if (divert.divert_enabled && divert.mqtt_solar === "" && divert.mqtt_grid_ie === "") {
if (divert.divert_enabled && "internal"!==divert.divert_feed_type && divert.mqtt_solar === "" && divert.mqtt_grid_ie === "") {
alert("Please enter either a Solar PV or Grid I/E feed");
return false;
}
Expand All @@ -514,9 +515,10 @@ function OpenEvseWiFiViewModel(baseHost, basePort, baseProtocol)
});

self.isEcoModeAvailable = ko.pureComputed(function () {
return self.config.mqtt_enabled() &&
return self.config.mqtt_enabled() && self.config.divert_enabled() &&
("" !== self.config.mqtt_solar() ||
"" !== self.config.mqtt_grid_ie());
"" !== self.config.mqtt_grid_ie() ||
"internal" === self.config.divert_feed_type());
});

self.ecoMode = ko.pureComputed({
Expand Down Expand Up @@ -545,13 +547,13 @@ function OpenEvseWiFiViewModel(baseHost, basePort, baseProtocol)
return "" !== self.config.mqtt_grid_ie();
});

self._divertFeedType = "grid_ie";
self.divertFeedType = ko.computed({
read: () => {
var ret = self.haveSolar() ? "solar" :
var ret = "internal"===self.config.divert_feed_type()? "internal" :
self.haveSolar() ? "solar" :
self.haveGridIe() ? "grid_ie" :
self._divertFeedType;
self._divertFeedType = ret;
self.config.divert_feed_type();
self.config.divert_feed_type(ret);
return ret;
},
write: (val) => {
Expand All @@ -561,20 +563,24 @@ function OpenEvseWiFiViewModel(baseHost, basePort, baseProtocol)
} else if("grid_ie" === val && self.haveSolar()) {
self.config.mqtt_grid_ie(self.config.mqtt_solar());
self.config.mqtt_solar("");
}
self._divertFeedType = val;
}
self.config.divert_feed_type(val);
}
});
self.divertFeedValue = ko.computed({
read: () => {
return "solar" === self.divertFeedType() ?
self.config.mqtt_solar() :
self.config.mqtt_grid_ie();
if ("solar" === self.divertFeedType()) {
return self.config.mqtt_solar();
} else if("grid_ie" === self.divertFeedType()) {
return self.config.mqtt_grid_ie();
} else {
return false;
}
},
write: (val) => {
if("solar" === self.divertFeedType()) {
self.config.mqtt_solar(val);
} else {
} else if("grid_ie" === self.divertFeedType()){
self.config.mqtt_grid_ie(val);
}
}
Expand Down Expand Up @@ -761,6 +767,63 @@ function OpenEvseWiFiViewModel(baseHost, basePort, baseProtocol)
});
};

// -----------------------------------------------------------------------
// Event: Update
// -----------------------------------------------------------------------

// Support for OTA update of the Controller
self.updateControllerFetching = ko.observable(false);
self.updateControllerComplete = ko.observable(false);
self.updateControllerError = ko.observable("");
self.updateControllerFilename = ko.observable("");
self.updateControllerLoaded = ko.observable(0);
self.updateControllerTotal = ko.observable(1);
self.updateControllerProgress = ko.pureComputed(function () {
return (self.updateControllerLoaded() / self.updateControllerTotal()) * 100;
});

self.otaUpdateController = function () {
if ("" === self.updateControllerFilename()) {
self.updateControllerError("Filename not set");
return;
}

self.updateControllerFetching(true);
self.updateControllerError("");

var form = $("#upload_controller_form")[0];
var data = new FormData(form);

$.ajax({
url: "/updateController",
type: "POST",
data: data,
contentType: false,
processData: false,
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
self.updateControllerLoaded(evt.loaded);
self.updateControllerTotal(evt.total);
}
}, false);
return xhr;
}
}).done(function (msg) {
console.log(msg);
if ("OK" == msg) {
self.updateControllerComplete(true);
} else {
self.updateControllerError(msg);
}
}).fail(function () {
self.updateControllerError("HTTP Update failed");
}).always(function () {
self.updateControllerFetching(false);
});
};

// -----------------------------------------------------------------------
// Receive events from the server
// -----------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/view_models/StatusViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function StatusViewModel(baseEndpoint) {
"divert_update": 0,
"divert_active": false,
"ota_update": false,
"controller_update": false,
"time": false,
"offset": false
}, endpoint);
Expand Down