add connection watchdog
This commit is contained in:
parent
93dc55d833
commit
a33ebbf72b
@ -24,6 +24,8 @@ var codingEnabled = false;
|
|||||||
/* disable / enable live stream */
|
/* disable / enable live stream */
|
||||||
var liveStreamVisible = false;
|
var liveStreamVisible = false;
|
||||||
|
|
||||||
|
/* connection watchdog */
|
||||||
|
var watchdogCounter = 0;
|
||||||
/* control_if block id */
|
/* control_if block id */
|
||||||
var controlBlockId = "";
|
var controlBlockId = "";
|
||||||
/* last hightlighted block id */
|
/* last hightlighted block id */
|
||||||
@ -44,6 +46,15 @@ Sumorobot.prototype.connect = function() {
|
|||||||
/* to have access to this object */
|
/* to have access to this object */
|
||||||
var self = this;
|
var self = this;
|
||||||
this.websocket = new WebSocket(this.wsUri);
|
this.websocket = new WebSocket(this.wsUri);
|
||||||
|
/* setup connection watchdog */
|
||||||
|
setInterval(function() {
|
||||||
|
if (watchdogCounter == 0) {
|
||||||
|
$("#battery").removeClass("connected");
|
||||||
|
$("#battery").html("Disconnected");
|
||||||
|
}
|
||||||
|
/* reset watchdog counter */
|
||||||
|
watchdogCounter = 0;
|
||||||
|
}, 3000);
|
||||||
/* when the WebSocket gets connected */
|
/* when the WebSocket gets connected */
|
||||||
this.websocket.onopen = function(evt) {
|
this.websocket.onopen = function(evt) {
|
||||||
console.log("INFO websocket connected");
|
console.log("INFO websocket connected");
|
||||||
@ -70,6 +81,9 @@ Sumorobot.prototype.connect = function() {
|
|||||||
var battery = JSON.parse(data)["battery_voltage"];
|
var battery = JSON.parse(data)["battery_voltage"];
|
||||||
$("#battery").html(battery + "V");
|
$("#battery").html(battery + "V");
|
||||||
$("#battery").addClass("connected");
|
$("#battery").addClass("connected");
|
||||||
|
/* keep track of data packets */
|
||||||
|
/* to see if we have a connection to the robot */
|
||||||
|
watchdogCounter += 1;
|
||||||
};
|
};
|
||||||
/* when there is an WebSocket error */
|
/* when there is an WebSocket error */
|
||||||
this.websocket.onerror = function(err) {
|
this.websocket.onerror = function(err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user