Skip to content

Commit c1ed0df

Browse files
committed
Added and tweaked comms error display
Delete unreadable json files and re-download
1 parent 7d2ca22 commit c1ed0df

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

data/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ <h2 id="large-modal-header"></h2>
5858
</div>
5959
</div>
6060

61+
<div id="communication-error-bar" class="communication-error-bar">
62+
<p>Communication problem between ESP and STM</p>
63+
</div>
64+
6165
<!-- 'Add CAN Mapping' modal -->
6266
<div id="can-mapping-modal-overlay" class="modal-overlay">
6367
<div id="can-mapping-modal-container" class="can-mapping-modal-container">

data/inverter.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
var paramsCache = {
2727
data: undefined,
2828
dataById: {},
29+
failedFetchCount: 0,
2930

3031
get: function(name) {
3132
if ( paramsCache.data !== undefined )
@@ -77,6 +78,25 @@ var inverter = {
7778
{
7879
if (replyFunc) replyFunc(this.responseText);
7980
}
81+
xmlhttp.onreadystatechange = function()
82+
{
83+
if (xmlhttp.readyState === XMLHttpRequest.DONE) {
84+
console.log(req + ": " + xmlhttp.status);
85+
if (xmlhttp.status != 200) {
86+
paramsCache.failedFetchCount += 1;
87+
if ( paramsCache.failedFetchCount >= 2 ){
88+
ui.showCommunicationErrorBar();
89+
}
90+
}
91+
else {
92+
paramsCache.failedFetchCount = 0;
93+
}
94+
if ( paramsCache.failedFetchCount < 2 )
95+
{
96+
ui.hideCommunicationErrorBar();
97+
}
98+
}
99+
}
80100

81101
if (repeat)
82102
req += "&repeat=" + repeat;
@@ -104,6 +124,7 @@ var inverter = {
104124
inverter.firmwareVersion = parseFloat(param.value);
105125
}
106126
} catch(ex) {}
127+
107128
paramsCache.setData(params);
108129
if (replyFunc) replyFunc(params);
109130
});

data/style.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,3 +635,24 @@ input:checked + .slider:before {
635635
width: 60px;
636636
}
637637
}
638+
639+
/* notification bar */
640+
641+
.communication-error-bar {
642+
display: none;
643+
padding: 15px;
644+
background-color: #f44336;
645+
color: white;
646+
z-index: 100;
647+
margin: 0 auto;
648+
position: relative;
649+
width: 30%;
650+
top: 0px;
651+
clear: left;
652+
height: 20px;
653+
border-radius: 0px 0px 20px 20px;
654+
}
655+
656+
.communication-error-bar p {
657+
text-align: center;
658+
}

data/ui.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ var ui = {
141141
wifi.populateWiFiTab();
142142
ui.populateFileList();
143143
ui.refreshStatusBox();
144-
ui.refreshMessagesBox();
145144
ui.getNodeId();
146145
},
147146

@@ -150,7 +149,6 @@ var ui = {
150149
{
151150
ui.updateTables();
152151
ui.refreshStatusBox();
153-
ui.refreshMessagesBox();
154152
},
155153

156154
getNodeId: function() {
@@ -391,6 +389,16 @@ var ui = {
391389
clearInterval(ui.autoRefreshHandle);
392390
}
393391
},
392+
393+
/** @brief Show notification bar */
394+
showCommunicationErrorBar: function() {
395+
document.getElementById('communication-error-bar').style.display = 'block';
396+
},
397+
398+
/** @brief Hide notification bar */
399+
hideCommunicationErrorBar: function() {
400+
document.getElementById('communication-error-bar').style.display = 'none';
401+
},
394402
/**
395403
* ~~~ DASHBOARD ~~~
396404
*/

src/oi_can.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,15 @@ void SendJson(WiFiClient client) {
332332
twai_message_t rxframe;
333333

334334
File file = SPIFFS.open(jsonFileName, "r");
335-
deserializeJson(doc, file);
335+
auto result = deserializeJson(doc, file);
336336
file.close();
337337

338+
if (result != DeserializationError::Ok) {
339+
SPIFFS.remove(jsonFileName); //if json file is invalid, remove it and trigger re-download
340+
updstate == REQUEST_JSON;
341+
return;
342+
}
343+
338344
JsonObject root = doc.as<JsonObject>();
339345

340346
for (JsonPair kv : root) {

0 commit comments

Comments
 (0)