Skip to content

Commit

Permalink
Add cfgFailsafeCurrent and adapt pvChart
Browse files Browse the repository at this point in the history
  • Loading branch information
steff393 committed Dec 27, 2022
1 parent 3eb86c8 commit edb8ea2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 61 deletions.
83 changes: 44 additions & 39 deletions data/pvChart.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,75 @@
<html>
<!-- based on https://github.com/tttapa/ESP8266, GPL-3.0 License -->
<head>
<title>wbec Chart</title>
<link href='https://fonts.googleapis.com/css?family=Roboto:300' rel='stylesheet' type='text/css'>
<meta name="theme-color" content="#00878f">
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport'>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<title>wbec Chart</title>
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport'>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>

<body>
<center>
<h1>wbec Chart</h1>
<div id="chart_div"></div>
<div id="loading">Loading ...</div>
<div id="dateselect" style="visibility: hidden;">
<div id="date"></div>
<button id="prev">&lt;</button>
<button id="next">&gt;</button><br>
<button id="zoomout">-</button>
<button id="zoomin">+</button><br>
<button id="reset" style="width: 4.4em;">Reset</button><br>
<button id="refresh" style="width: 4.4em;">Refresh</button>
</div>
</center>
<center>
<h1>wbec</h1>
<h2>Heidelberg Wallbox Energy Control</h2>
<div id="chart_div"></div>
<div id="loading">Loading ...</div>
<div id="dateselect" style="visibility: hidden;">
<div id="date"></div>
<button id="prev">&lt;</button>
<button id="next">&gt;</button>
<button id="zoomout">-</button>
<button id="zoomin">+</button><br>
<button id="reset" style="width: 4.4em;">Reset</button>
<button id="refresh" style="width: 4.4em;">Refresh</button>
</div>
</center>
</body>

<script src="pvChart.js"></script>
<script src="pvChart.js"></script>

<style>
<style>
body {
font-family: 'Roboto', sans-serif;
font-size: 22pt;
margin: 0;
margin-top: 6px;
font-family: 'Arial', sans-serif;
font-size: 22pt;
margin-top: 6px;
background-color: rgb(106, 106, 106);
color: white;
}

h1 {
font-size: 1.5em;
font-weight: normal;
margin: 0px 0px 12px 0px;
font-size: 1.5em;
font-weight: bold;
color: rgb(40, 152, 161);
margin-top: 0;
}

h2 {
font-size: 0.7em;
font-weight: normal;
color: white;
}

button {
font-size: 14pt;
width: 2em;
font-size: 14pt;
width: 2em;
}

center {
padding: 1em;
margin: auto;
width: 90%;
box-shadow: #777 2px 2px 5px;
box-sizing: border-box;
padding: 1em;
margin: auto;
width: 90%;
}

#loading {
margin-bottom: 12px;
}

@media only screen and (max-device-width: 700px) {
center {
center {
width: 100%;
height: 100vh;
overflow: auto;
}
}
}
</style>
</body>
</style>

</html>
34 changes: 18 additions & 16 deletions data/pvChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ function parseCSV(string) {
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'UNIX');
data.addColumn('number', 'Verbrauch/Einspeisung');
data.addColumn('number', 'Ladeleistung');
data.addColumn('number', 'Bezug(+)/Einspeisung(-)');
data.addColumn('number', 'Ladeleistung der Wallbox');

data.addRows(dataArray);

var options = {
curveType: 'function',

height: 360,
height: 840,

legend: { position: 'none' },
legend: { position: 'top' },

hAxis: {
viewWindow: {
Expand All @@ -88,7 +88,7 @@ function drawChart() {
gridlines: {
count: -1,
units: {
days: { format: ['MMM dd'] },
days: { format: ['dd. MMM'] },
hours: { format: ['HH:mm', 'ha'] },
}
},
Expand All @@ -100,7 +100,7 @@ function drawChart() {
}
},
vAxis: {
title: "Leistung (kW)"
title: "Leistung [W]"
}
};

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

function displayDate() { // Display the start and end date on the page
var dateDiv = document.getElementById("date");

var endDay = viewportEndTime.getDate();
var endMonth = viewportEndTime.getMonth();
var startDay = viewportStartTime.getDate();
var startMonth = viewportStartTime.getMonth()

var startDay = viewportStartTime.getDate();
var startMonth = viewportStartTime.getMonth();
var startYear = viewportStartTime.getFullYear();
var endDay = viewportEndTime.getDate();
var endMonth = viewportEndTime.getMonth();
var endYear = viewportEndTime.getFullYear();

if (endDay == startDay && endMonth == startMonth) {
dateDiv.textContent = (endDay).toString() + "/" + (endMonth + 1).toString();
dateDiv.textContent = (endDay).toString() + "." + (endMonth + 1).toString() + "." + (endYear).toString();
} else {
dateDiv.textContent = (startDay).toString() + "/" + (startMonth + 1).toString() + " - " + (endDay).toString() + "/" + (endMonth + 1).toString();
dateDiv.textContent = (startDay).toString() + "." + (startMonth + 1).toString() + "." + (startYear).toString() + " - " + (endDay).toString() + "." + (endMonth + 1).toString() + "." + (endYear).toString();
}
}

Expand Down Expand Up @@ -167,7 +170,6 @@ function updateViewport() {
drawChart();
}
function getViewportWidthTime() {
return defaultZoomTime*(2**zoomLevel); // exponential relation between zoom level and zoom time span
// every time you zoom, you double or halve the time scale
return(defaultZoomTime*(2**zoomLevel)); // exponential relation between zoom level and zoom time span
// every time you zoom, you double or halve the time scale
}

6 changes: 4 additions & 2 deletions src/globalConfig.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 steff393, MIT license
// Copyright (c) 2023 steff393, MIT license
// based on https://github.com/esp8266/Arduino/blob/master/libraries/esp8266/examples/ConfigFile/ConfigFile.ino

#include <ArduinoJson.h>
Expand All @@ -8,7 +8,7 @@

const uint8_t m = 5;

char cfgWbecVersion[] = "v0.4.5"; // wbec version
char cfgWbecVersion[] = "v0.4.6"; // wbec version
char cfgBuildDate[] = __DATE__ " " __TIME__; // wbec build date

char cfgApSsid[32]; // SSID of the initial Access Point
Expand All @@ -18,6 +18,7 @@ uint8_t cfgMbCycleTime; // cycle time of the modbus (in seconds)
uint16_t cfgMbDelay; // delay time of the modbus before sending new message (in milliseconds)
uint16_t cfgMbTimeout; // Reg. 257: Modbus timeout (in milliseconds)
uint16_t cfgStandby; // Reg. 258: Standby Function Control: 0 = enable standby, 4 = disable standby
uint16_t cfgFailsafeCurrent; // <don't use - still beta> Reg. 262: Failsafe Current configuration in case of loss of Modbus communication (in 0.1A)
char cfgMqttIp[16]; // IP address of MQTT broker, "" to disable MQTT
uint16_t cfgMqttPort; // Port of MQTT broker (optional)
char cfgMqttUser[32]; // MQTT: Username
Expand Down Expand Up @@ -124,6 +125,7 @@ void loadConfig() {
cfgMbDelay = doc["cfgMbDelay"] | 100UL;
cfgMbTimeout = doc["cfgMbTimeout"] | 60000UL;
cfgStandby = doc["cfgStandby"] | 4UL;
cfgFailsafeCurrent = doc["cfgFailsafeCurrent"] | 0UL;
strncpy(cfgMqttIp, doc["cfgMqttIp"] | "", sizeof(cfgMqttIp));
cfgMqttPort = doc["cfgMqttPort"] | 1883UL;
strncpy(cfgMqttUser, doc["cfgMqttUser"] | "", sizeof(cfgMqttUser));
Expand Down
3 changes: 2 additions & 1 deletion src/globalConfig.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 steff393, MIT license
// Copyright (c) 2023 steff393, MIT license

#ifndef GLOBALCONFIG_H
#define GLOBALCONFIG_H
Expand Down Expand Up @@ -32,6 +32,7 @@ extern uint8_t cfgMbCycleTime; // cycle time of the modbus (in sec
extern uint16_t cfgMbDelay; // delay time of the modbus before sending new message (in milliseconds)
extern uint16_t cfgMbTimeout; // Reg. 257: Modbus timeout (in milliseconds)
extern uint16_t cfgStandby; // Reg. 258: Standby Function Control: 0 = enable standby, 4 = disable standby
extern uint16_t cfgFailsafeCurrent; // <don't use - still beta> Reg. 262: Failsafe Current configuration in case of loss of Modbus communication (in 0.1A)
extern char cfgMqttIp[16]; // IP address of MQTT broker, "" to disable MQTT
extern uint16_t cfgMqttPort; // Port of MQTT broker (optional)
extern char cfgMqttUser[32]; // MQTT: Username
Expand Down
7 changes: 4 additions & 3 deletions src/mbComm.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021 steff393, MIT license
// Copyright (c) 2023 steff393, MIT license

#include <Arduino.h>
#include "globalConfig.h"
Expand Down Expand Up @@ -148,6 +148,7 @@ void mb_loop() {
case 6: if (!modbusResultCode[id]) { mb.readHreg (id+1, REG_CURR_LIMIT, &content[id][53], 2, cbWrite); } break;
case 7: if (!modbusResultCode[id]) { mb.writeHreg(id+1, REG_WD_TIME_OUT, &cfgMbTimeout, 1, cbWrite); } break;
case 8: if (!modbusResultCode[id]) { mb.writeHreg(id+1, REG_STANDBY_CTRL, &cfgStandby, 1, cbWrite); } break;
case 9: if (!modbusResultCode[id]) { mb.writeHreg(id+1, REG_CURR_LIMIT_FS,&cfgFailsafeCurrent,1, cbWrite); } break;
default: ; // do nothing, should not happen
}
modbusLastMsgSentTime = millis();
Expand All @@ -156,8 +157,8 @@ void mb_loop() {
id = 0;
msgCnt++;
}
if (msgCnt > 8 ||
(msgCnt > 7 && modbusLastTime != 0)) { // write the REG_WD_TIME_OUT and REG_STANDBY_CTRL only on the very first loop
if (msgCnt > 9 ||
(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
msgCnt = 0;
//Serial.print("Time:");Serial.println(millis()-modbusLastTime);
modbusLastTime = millis();
Expand Down

0 comments on commit edb8ea2

Please sign in to comment.