tesla-charge-controller/webapp/index.html

40 lines
1.2 KiB
HTML
Raw Normal View History

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Tesla Charge Control</title>
<script type="text/javascript">
const api_url = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port;
function flash() {
fetch(api_url + "/flash", { method: "POST" })
.then((response) => console.log(response));
}
function refresh() {
fetch(api_url + "/charge-state")
.then((response) => response.json())
.then((json) => update_charge_state(json));
}
function update_charge_state(charge_state) {
var info_div = document.getElementById("info");
while (info_div.childElementCount > 0) { info_div.removeChild(info_div.firstChild) }
var arr = ["Battery " + charge_state.battery_level + "%", "Range: " + (charge_state.battery_range * 1.60934).toFixed(1) + "km", "Charging at " + charge_state.charge_amps + " amps"];
for (line in arr) {
el = document.createElement('p');
el.appendChild(document.createTextNode(arr[line]));
info_div.appendChild(el)
}
}
</script>
</head>
<body></body>
<button onclick="refresh()">refresh</button>
<div id="info"></div>
<button onclick="flash()">flash</button>
</html>