Skip to content

Commit c1d63f8

Browse files
authored
Merge pull request openWB#62 from openWB/web
fix graph after reboot
2 parents abde7d2 + b526a54 commit c1d63f8

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

graphing.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ graphing(){
6363
if ((speichervorhanden == 1 )); then
6464
dataline="$dataline,\"bat-all-power\":$(convertTokW $speicherleistung),\"bat-all-soc\":$speichersoc"
6565
fi
66-
# smarthoome 1
66+
# smarthome 1
6767
if (( verbraucher1_aktiv == 1 )); then
6868
dataline="$dataline,\"load1-power\":$(convertTokW $verbraucher1_watt)"
6969
fi
7070
if (( verbraucher2_aktiv == 1 )); then
7171
dataline="$dataline,\"load2-power\":$(convertTokW $verbraucher2_watt)"
7272
fi
73-
# end JSON
73+
7474
dataline="$dataline}"
7575
printf "$dataline\n" >> /var/www/html/openWB/ramdisk/all-live.json
7676
echo "$(tail -$livegraph /var/www/html/openWB/ramdisk/all-live.json)" > /var/www/html/openWB/ramdisk/all-live.json
@@ -108,6 +108,7 @@ graphing(){
108108
mosquitto_pub -t openWB/graph/alllivevaluesJson14 -r -m "$([ ${#all14livevalues} -ge 10 ] && echo "$all14livevalues" || echo "-")" &
109109
mosquitto_pub -t openWB/graph/alllivevaluesJson15 -r -m "$([ ${#all15livevalues} -ge 10 ] && echo "$all15livevalues" || echo "-")" &
110110
mosquitto_pub -t openWB/graph/alllivevaluesJson16 -r -m "$([ ${#all16livevalues} -ge 10 ] && echo "$all16livevalues" || echo "-")" &
111+
# end JSON
111112

112113
# csv graphing
113114
header="Zeit,Timestamp,EVU,Ladeleistung,PV,LP1,LP2,Ladeleistung2,Speicherleistung,SpeicherSoC,LP1SoC,LP2SoC,Hausverbrauch,Verbraucher1,Verbraucher2,LP3,LP4,LP5,LP6,LP7,LP8,SH1,SH2,SH3,SH4,SH5,SH6,SH7,SH8,SH9,SH1T0,SH1T1,SH1T2"

publishvars2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,6 @@ def pub_settings():
268268
pub.pub("openWB/set/general/range_unit", "km")
269269
pub.pub("openWB/set/general/price_kwh", 0.2)
270270
pub.pub("openWB/set/general/grid_protection_configured", True)
271+
272+
# graph
273+
pub.pub("openWB/graph/config/duration", 30)

web/themes/dark/livechart.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var smartHomeBgColor = style.getPropertyValue('--d1bgCol');
2626

2727
var initialread = 0;
2828
var graphloaded = 0;
29+
var maxDisplayLength;
2930
var boolDisplayHouseConsumption;
3031
var boolDisplayLoad1;
3132
var boolDisplayLoad2;
@@ -585,7 +586,9 @@ function putgraphtogether() {
585586
if ( (all1 == 1) && (all2 == 1) && (all3 == 1) && (all4 == 1) && (all5 == 1) && (all6 == 1) && (all7 == 1) && (all8 == 1) && (all9 == 1) && (all10 == 1) && (all11 == 1) && (all12 == 1) && (all13 == 1) && (all14 == 1) && (all15 == 1) && (all16 == 1) ){
586587
var alldata = all1p + "\n" + all2p + "\n" + all3p + "\n" + all4p + "\n" + all5p + "\n" + all6p + "\n" + all7p + "\n" + all8p + "\n" + all9p + "\n" + all10p + "\n" + all11p + "\n" + all12p + "\n" + all13p + "\n" + all14p + "\n" + all15p + "\n" + all16p;
587588
allChartData = parseData(alldata);
588-
if ( allChartData.length >= 30 ) {
589+
console.log("allChartData.length: "+allChartData.length);
590+
if ( allChartData.length >= 30 ) { // 5 minutes * 6 measurements/min
591+
console.log("received at least "+maxDisplayLength+" data sets for graph");
589592
Object.keys(allChartData[allChartData.length - 1]).forEach(function(key){
590593
if(key != 'time' && key != 'timestamp'){
591594
initDataset(key);
@@ -594,9 +597,10 @@ function putgraphtogether() {
594597
// after receipt of all data segments, unsubscribe from these topics to save bandwidth
595598
unsubscribeMqttGraphSegments();
596599

600+
initialread = 1 ;
601+
$('#waitforgraphloadingdiv').text('Graph lädt...');
597602
checkgraphload();
598603
// now we are ready to receive small updates for graph data
599-
initialread = 1 ;
600604
} else {
601605
all1 = 0;
602606
all2 = 0;
@@ -623,24 +627,24 @@ function putgraphtogether() {
623627

624628
function updateGraph(dataset) {
625629
chartUpdateBuffer = chartUpdateBuffer.concat(parseData(dataset));
626-
// console.log('buffer: '+chartUpdateBuffer.length);
627630
if(initialread == 1 && myLine != undefined){
628631
chartUpdateBuffer.forEach(function(row, index){
629-
// console.log('adding row: '+index);
630632
allChartData.push(row);
631633
});
632-
// ToDo: remove data based on configured size
633-
if(allChartData.length > 30){
634-
allChartData.splice(0, chartUpdateBuffer.length);
634+
if(typeof maxDisplayLength !== "undefined" && allChartData.length > maxDisplayLength){
635+
// allChartData.splice(0, chartUpdateBuffer.length);
636+
allChartData.splice(0, allChartData.length - maxDisplayLength);
635637
}
638+
console.log("allChartData.length: "+allChartData.length);
636639
chartUpdateBuffer = [];
637640
myLine.update();
638641
} else {
639-
// console.log('graph not yet initialized, data stored in buffer');
642+
console.log('graph not yet initialized, data stored in buffer');
640643
}
641644
}
642645

643646
function checkgraphload(){
647+
console.log("checkgraphload: graphloaded: "+graphloaded+" initialread: "+initialread);
644648
if ( graphloaded == 1 ) {
645649
myLine.destroy();
646650
loadgraph(0); // when reloading graph, no more "pumping" animations
@@ -665,6 +669,7 @@ function checkgraphload(){
665669
typeof boolDisplayEvu === "boolean" &&
666670
typeof boolDisplayPv === "boolean" &&
667671
typeof boolDisplayLegend === "boolean" ) {
672+
console.log("all bools received");
668673
if ( initialread != 0 ) {
669674
if ( graphloaded == 0 ) {
670675
graphloaded = 1;
@@ -735,6 +740,10 @@ function forcegraphload() {
735740
if ( !(typeof boolDisplayLegend === "boolean") ) {
736741
showhidedataset('boolDisplayLegend');
737742
}
743+
if ( typeof maxDisplayLength === "undefined" ) {
744+
console.log("setting graph duration to default of 30 minutes");
745+
maxDisplayLength = 30 * 6;
746+
}
738747
checkgraphload();
739748
}
740749
} // end forcegraphload

web/themes/dark/processAllMqttMsg.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,15 @@ function processGraphMessages(mqttmsg, mqttpayload) {
10901090
}
10911091
graphrefreshcounter += 1;
10921092
}
1093+
else if ( mqttmsg == 'openWB/graph/config/duration' ) {
1094+
console.log("graph duration: "+mqttpayload+" minutes");
1095+
var duration = JSON.parse(mqttpayload);
1096+
if( isNaN(duration) || duration < 10 || duration > 120 ){
1097+
console.log("bad graph duration received: "+mqttpayload+" setting to default of 30");
1098+
duration = 30;
1099+
}
1100+
maxDisplayLength = duration * 6; // we get 6 measurements in every minute
1101+
}
10931102
} // end processGraphMessages
10941103

10951104
function processETProviderMessages(mqttmsg, mqttpayload) {

web/themes/dark/setupMqttServices.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ var topicsToSubscribe = [
7474
["openWB/optional/et/config/max_price", 1], // configured max price
7575

7676
// graph topcis
77+
["openWB/graph/config/duration", 1], // maximum duration to display in landing page
7778
["openWB/graph/boolDisplayLp1", 1],
7879
["openWB/graph/boolDisplayLp2", 1],
7980
["openWB/graph/boolDisplayLp3", 1],

0 commit comments

Comments
 (0)