Skip to content

Commit edb8ea2

Browse files
committed
Add cfgFailsafeCurrent and adapt pvChart
1 parent 3eb86c8 commit edb8ea2

File tree

5 files changed

+72
-61
lines changed

5 files changed

+72
-61
lines changed

data/pvChart.html

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,75 @@
22
<html>
33
<!-- based on https://github.com/tttapa/ESP8266, GPL-3.0 License -->
44
<head>
5-
<title>wbec Chart</title>
6-
<link href='https://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>
7-
<meta name="theme-color" content="#00878f">
8-
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport'>
9-
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
5+
<title>wbec Chart</title>
6+
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport'>
7+
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
108
</head>
119

1210
<body>
13-
<center>
14-
<h1>wbec Chart</h1>
15-
<div id="chart_div"></div>
16-
<div id="loading">Loading ...</div>
17-
<div id="dateselect" style="visibility: hidden;">
18-
<div id="date"></div>
19-
<button id="prev">&lt;</button>
20-
<button id="next">&gt;</button><br>
21-
<button id="zoomout">-</button>
22-
<button id="zoomin">+</button><br>
23-
<button id="reset" style="width: 4.4em;">Reset</button><br>
24-
<button id="refresh" style="width: 4.4em;">Refresh</button>
25-
</div>
26-
</center>
11+
<center>
12+
<h1>wbec</h1>
13+
<h2>Heidelberg Wallbox Energy Control</h2>
14+
<div id="chart_div"></div>
15+
<div id="loading">Loading ...</div>
16+
<div id="dateselect" style="visibility: hidden;">
17+
<div id="date"></div>
18+
<button id="prev">&lt;</button>
19+
<button id="next">&gt;</button>
20+
<button id="zoomout">-</button>
21+
<button id="zoomin">+</button><br>
22+
<button id="reset" style="width: 4.4em;">Reset</button>
23+
<button id="refresh" style="width: 4.4em;">Refresh</button>
24+
</div>
25+
</center>
26+
</body>
2727

28-
<script src="pvChart.js"></script>
28+
<script src="pvChart.js"></script>
2929

30-
<style>
30+
<style>
3131
body {
32-
font-family: 'Roboto', sans-serif;
33-
font-size: 22pt;
34-
margin: 0;
35-
margin-top: 6px;
32+
font-family: 'Arial', sans-serif;
33+
font-size: 22pt;
34+
margin-top: 6px;
35+
background-color: rgb(106, 106, 106);
36+
color: white;
3637
}
3738

3839
h1 {
39-
font-size: 1.5em;
40-
font-weight: normal;
41-
margin: 0px 0px 12px 0px;
40+
font-size: 1.5em;
41+
font-weight: bold;
42+
color: rgb(40, 152, 161);
43+
margin-top: 0;
44+
}
45+
46+
h2 {
47+
font-size: 0.7em;
48+
font-weight: normal;
49+
color: white;
4250
}
4351

4452
button {
45-
font-size: 14pt;
46-
width: 2em;
53+
font-size: 14pt;
54+
width: 2em;
4755
}
4856

4957
center {
50-
padding: 1em;
51-
margin: auto;
52-
width: 90%;
53-
box-shadow: #777 2px 2px 5px;
54-
box-sizing: border-box;
58+
padding: 1em;
59+
margin: auto;
60+
width: 90%;
5561
}
5662

5763
#loading {
5864
margin-bottom: 12px;
5965
}
6066

6167
@media only screen and (max-device-width: 700px) {
62-
center {
68+
center {
6369
width: 100%;
6470
height: 100vh;
6571
overflow: auto;
66-
}
72+
}
6773
}
68-
</style>
69-
</body>
74+
</style>
7075

7176
</html>

data/pvChart.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ function parseCSV(string) {
6868
function drawChart() {
6969
var data = new google.visualization.DataTable();
7070
data.addColumn('datetime', 'UNIX');
71-
data.addColumn('number', 'Verbrauch/Einspeisung');
72-
data.addColumn('number', 'Ladeleistung');
71+
data.addColumn('number', 'Bezug(+)/Einspeisung(-)');
72+
data.addColumn('number', 'Ladeleistung der Wallbox');
7373

7474
data.addRows(dataArray);
7575

7676
var options = {
7777
curveType: 'function',
7878

79-
height: 360,
79+
height: 840,
8080

81-
legend: { position: 'none' },
81+
legend: { position: 'top' },
8282

8383
hAxis: {
8484
viewWindow: {
@@ -88,7 +88,7 @@ function drawChart() {
8888
gridlines: {
8989
count: -1,
9090
units: {
91-
days: { format: ['MMM dd'] },
91+
days: { format: ['dd. MMM'] },
9292
hours: { format: ['HH:mm', 'ha'] },
9393
}
9494
},
@@ -100,7 +100,7 @@ function drawChart() {
100100
}
101101
},
102102
vAxis: {
103-
title: "Leistung (kW)"
103+
title: "Leistung [W]"
104104
}
105105
};
106106

@@ -117,15 +117,18 @@ function drawChart() {
117117

118118
function displayDate() { // Display the start and end date on the page
119119
var dateDiv = document.getElementById("date");
120-
121-
var endDay = viewportEndTime.getDate();
122-
var endMonth = viewportEndTime.getMonth();
123-
var startDay = viewportStartTime.getDate();
124-
var startMonth = viewportStartTime.getMonth()
120+
121+
var startDay = viewportStartTime.getDate();
122+
var startMonth = viewportStartTime.getMonth();
123+
var startYear = viewportStartTime.getFullYear();
124+
var endDay = viewportEndTime.getDate();
125+
var endMonth = viewportEndTime.getMonth();
126+
var endYear = viewportEndTime.getFullYear();
127+
125128
if (endDay == startDay && endMonth == startMonth) {
126-
dateDiv.textContent = (endDay).toString() + "/" + (endMonth + 1).toString();
129+
dateDiv.textContent = (endDay).toString() + "." + (endMonth + 1).toString() + "." + (endYear).toString();
127130
} else {
128-
dateDiv.textContent = (startDay).toString() + "/" + (startMonth + 1).toString() + " - " + (endDay).toString() + "/" + (endMonth + 1).toString();
131+
dateDiv.textContent = (startDay).toString() + "." + (startMonth + 1).toString() + "." + (startYear).toString() + " - " + (endDay).toString() + "." + (endMonth + 1).toString() + "." + (endYear).toString();
129132
}
130133
}
131134

@@ -167,7 +170,6 @@ function updateViewport() {
167170
drawChart();
168171
}
169172
function getViewportWidthTime() {
170-
return defaultZoomTime*(2**zoomLevel); // exponential relation between zoom level and zoom time span
171-
// every time you zoom, you double or halve the time scale
173+
return(defaultZoomTime*(2**zoomLevel)); // exponential relation between zoom level and zoom time span
174+
// every time you zoom, you double or halve the time scale
172175
}
173-

src/globalConfig.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 steff393, MIT license
1+
// Copyright (c) 2023 steff393, MIT license
22
// based on https://github.com/esp8266/Arduino/blob/master/libraries/esp8266/examples/ConfigFile/ConfigFile.ino
33

44
#include <ArduinoJson.h>
@@ -8,7 +8,7 @@
88

99
const uint8_t m = 5;
1010

11-
char cfgWbecVersion[] = "v0.4.5"; // wbec version
11+
char cfgWbecVersion[] = "v0.4.6"; // wbec version
1212
char cfgBuildDate[] = __DATE__ " " __TIME__; // wbec build date
1313

1414
char cfgApSsid[32]; // SSID of the initial Access Point
@@ -18,6 +18,7 @@ uint8_t cfgMbCycleTime; // cycle time of the modbus (in seconds)
1818
uint16_t cfgMbDelay; // delay time of the modbus before sending new message (in milliseconds)
1919
uint16_t cfgMbTimeout; // Reg. 257: Modbus timeout (in milliseconds)
2020
uint16_t cfgStandby; // Reg. 258: Standby Function Control: 0 = enable standby, 4 = disable standby
21+
uint16_t cfgFailsafeCurrent; // <don't use - still beta> Reg. 262: Failsafe Current configuration in case of loss of Modbus communication (in 0.1A)
2122
char cfgMqttIp[16]; // IP address of MQTT broker, "" to disable MQTT
2223
uint16_t cfgMqttPort; // Port of MQTT broker (optional)
2324
char cfgMqttUser[32]; // MQTT: Username
@@ -124,6 +125,7 @@ void loadConfig() {
124125
cfgMbDelay = doc["cfgMbDelay"] | 100UL;
125126
cfgMbTimeout = doc["cfgMbTimeout"] | 60000UL;
126127
cfgStandby = doc["cfgStandby"] | 4UL;
128+
cfgFailsafeCurrent = doc["cfgFailsafeCurrent"] | 0UL;
127129
strncpy(cfgMqttIp, doc["cfgMqttIp"] | "", sizeof(cfgMqttIp));
128130
cfgMqttPort = doc["cfgMqttPort"] | 1883UL;
129131
strncpy(cfgMqttUser, doc["cfgMqttUser"] | "", sizeof(cfgMqttUser));

src/globalConfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 steff393, MIT license
1+
// Copyright (c) 2023 steff393, MIT license
22

33
#ifndef GLOBALCONFIG_H
44
#define GLOBALCONFIG_H
@@ -32,6 +32,7 @@ extern uint8_t cfgMbCycleTime; // cycle time of the modbus (in sec
3232
extern uint16_t cfgMbDelay; // delay time of the modbus before sending new message (in milliseconds)
3333
extern uint16_t cfgMbTimeout; // Reg. 257: Modbus timeout (in milliseconds)
3434
extern uint16_t cfgStandby; // Reg. 258: Standby Function Control: 0 = enable standby, 4 = disable standby
35+
extern uint16_t cfgFailsafeCurrent; // <don't use - still beta> Reg. 262: Failsafe Current configuration in case of loss of Modbus communication (in 0.1A)
3536
extern char cfgMqttIp[16]; // IP address of MQTT broker, "" to disable MQTT
3637
extern uint16_t cfgMqttPort; // Port of MQTT broker (optional)
3738
extern char cfgMqttUser[32]; // MQTT: Username

src/mbComm.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021 steff393, MIT license
1+
// Copyright (c) 2023 steff393, MIT license
22

33
#include <Arduino.h>
44
#include "globalConfig.h"
@@ -148,6 +148,7 @@ void mb_loop() {
148148
case 6: if (!modbusResultCode[id]) { mb.readHreg (id+1, REG_CURR_LIMIT, &content[id][53], 2, cbWrite); } break;
149149
case 7: if (!modbusResultCode[id]) { mb.writeHreg(id+1, REG_WD_TIME_OUT, &cfgMbTimeout, 1, cbWrite); } break;
150150
case 8: if (!modbusResultCode[id]) { mb.writeHreg(id+1, REG_STANDBY_CTRL, &cfgStandby, 1, cbWrite); } break;
151+
case 9: if (!modbusResultCode[id]) { mb.writeHreg(id+1, REG_CURR_LIMIT_FS,&cfgFailsafeCurrent,1, cbWrite); } break;
151152
default: ; // do nothing, should not happen
152153
}
153154
modbusLastMsgSentTime = millis();
@@ -156,8 +157,8 @@ void mb_loop() {
156157
id = 0;
157158
msgCnt++;
158159
}
159-
if (msgCnt > 8 ||
160-
(msgCnt > 7 && modbusLastTime != 0)) { // write the REG_WD_TIME_OUT and REG_STANDBY_CTRL only on the very first loop
160+
if (msgCnt > 9 ||
161+
(msgCnt > 6 && modbusLastTime != 0)) { // write the REG_WD_TIME_OUT and REG_STANDBY_CTRL and REG_CURR_LIMIT_FS only on the very first loop
161162
msgCnt = 0;
162163
//Serial.print("Time:");Serial.println(millis()-modbusLastTime);
163164
modbusLastTime = millis();

0 commit comments

Comments
 (0)