Skip to content

Commit

Permalink
Only hit the watchdog when BackendConnection.state === BackendConnect…
Browse files Browse the repository at this point in the history
…ion.Ready
  • Loading branch information
DanielMcInnes committed Dec 19, 2024
1 parent dda7a38 commit 82b2b18
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
19 changes: 14 additions & 5 deletions .github/patches/index.html.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- index.html 2024-12-17 17:13:52.442569994 +1000
+++ venus-gui-v2.html 2024-12-17 17:08:58.496874189 +1000
--- venus-gui-v2.html 2024-12-19 11:52:03.677046276 +1000
+++ index.html 2024-12-19 13:32:25.962435445 +1000
@@ -12,15 +12,18 @@
<title>venus-gui-v2</title>
<style>
Expand Down Expand Up @@ -62,19 +62,28 @@
qt: {
onLoaded: () => showUi(screen),
onExit: exitData =>
@@ -70,5 +99,15 @@
@@ -70,5 +99,24 @@
</script>
<script src="venus-gui-v2.js"></script>
<script type="text/javascript" src="qtloader.js"></script>
+ <script type="text/javascript">
+ var watchdogHit = false // this gets set to 'true' by a timer in BackendConnection::onWatchdogTimerExpired()
+ setInterval(function() {
+ console.log("starting watchdog timer")
+ setTimeout(function(){ // wait 2 minutes for the page to load, then set a 10 second watchdog timer
+ checkWatchdog()
+ setInterval(checkWatchdog, 10000)
+ }, 120000)
+
+ function checkWatchdog()
+ {
+ console.log("checking watchdog...")
+ console.log("blah3")
+ if (!watchdogHit) {
+ console.error("Watchdog timer expired - reloading page")
+ location.reload()
+ }
+ watchdogHit = false
+ }, 20000);
+ }
+ </script>
</body>
</html>
8 changes: 8 additions & 0 deletions ApplicationContent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,12 @@ Item {
? "qrc:/qt/qml/Victron/VenusOS/components/InputPanel.qml"
: "qrc:/qt/qml/Victron/VenusOS/components/WasmVirtualKeyboardHandler.qml"
}

// Sometimes, the wasm code may crash. Use a watchdog to detect this and reload the page when necessary.
Timer {
running: Qt.platform.os === "wasm" && BackendConnection.state === BackendConnection.Ready
repeat: true
interval: 1000
onTriggered: BackendConnection.hitWatchdog()
}
}
14 changes: 5 additions & 9 deletions src/backendconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,6 @@ void BackendConnection::onReloadPageTimerExpired()
reloadPage();
}

// Sometimes, the wasm code may crash. Use a watchdog to detect this and reload the page when necessary.
void BackendConnection::onWatchdogTimerExpired()
{
emscripten_run_script("watchdogHit = true"); // 'watchdogHit' is defined in venus-gui-v2.html, which checks it periodically and reloads the page if not hit regularly.
}

// If the wasm itself changed the Security Profile, it should normally be notified
// that it is accepted by receiving a Network Config change. Since that event is send
// over a connection which is going to be disconnected, this acts as a fallback if
Expand Down Expand Up @@ -228,6 +222,11 @@ void BackendConnection::openUrl(const QString &url)
emscripten_run_script(ba.constData());
}

void BackendConnection::hitWatchdog()
{
emscripten_run_script("watchdogHit = true"); // 'watchdogHit' is defined in venus-gui-v2.html, which checks it periodically and reloads the page if not hit regularly.
}

#else

void BackendConnection::onNetworkConfigChanged(const QVariant var) { Q_UNUSED(var); }
Expand Down Expand Up @@ -278,9 +277,6 @@ void BackendConnection::initMqttConnection(const QString &address)

VeQItem *item = mqttProducer->services()->itemGetOrCreate("/platform/0/Network/ConfigChanged");
connect(item, &VeQItem::valueChanged, this, &BackendConnection::onNetworkConfigChanged);

connect(&mWatchdogTimer, &QTimer::timeout, this, &BackendConnection::onWatchdogTimerExpired);
mWatchdogTimer.start(1000);
#else
const QStringList parts = address.split(':');
if (parts.size() >= 2) {
Expand Down
10 changes: 3 additions & 7 deletions src/backendconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class BackendConnection : public QObject
// Move this to some mock data manager when available
Q_INVOKABLE void setMockValue(const QString &uid, const QVariant &value);
Q_INVOKABLE QVariant mockValue(const QString &uid) const;
#if defined(VENUS_WEBASSEMBLY_BUILD)
Q_INVOKABLE void hitWatchdog();
#endif

Q_SIGNALS:
void stateChanged();
Expand All @@ -157,9 +160,6 @@ class BackendConnection : public QObject
private Q_SLOTS:
void onNetworkConfigChanged(const QVariant var);
void onReloadPageTimerExpired();
#if defined(VENUS_WEBASSEMBLY_BUILD)
void onWatchdogTimerExpired();
#endif

private:
explicit BackendConnection(QObject *parent = nullptr);
Expand Down Expand Up @@ -198,10 +198,6 @@ private Q_SLOTS:
AlarmBusitem *m_alarmBusItem = nullptr;
#endif
QNetworkAccessManager *m_network = nullptr;

#if defined(VENUS_WEBASSEMBLY_BUILD)
QTimer mWatchdogTimer;
#endif
};

class BackendConnectionTester : public QObject
Expand Down

0 comments on commit 82b2b18

Please sign in to comment.