add connection watchdog
This commit is contained in:
		@@ -24,6 +24,8 @@ var codingEnabled = false;
 | 
			
		||||
/* disable / enable live stream */
 | 
			
		||||
var liveStreamVisible = false;
 | 
			
		||||
 | 
			
		||||
/* connection watchdog */
 | 
			
		||||
var watchdogCounter = 0;
 | 
			
		||||
/* control_if block id */
 | 
			
		||||
var controlBlockId = "";
 | 
			
		||||
/* last hightlighted block id */
 | 
			
		||||
@@ -44,6 +46,15 @@ Sumorobot.prototype.connect = function() {
 | 
			
		||||
    /* to have access to this object */
 | 
			
		||||
    var self = this;
 | 
			
		||||
    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 */
 | 
			
		||||
    this.websocket.onopen = function(evt) {
 | 
			
		||||
        console.log("INFO websocket connected");
 | 
			
		||||
@@ -70,6 +81,9 @@ Sumorobot.prototype.connect = function() {
 | 
			
		||||
        var battery = JSON.parse(data)["battery_voltage"];
 | 
			
		||||
        $("#battery").html(battery + "V");
 | 
			
		||||
        $("#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 */
 | 
			
		||||
    this.websocket.onerror = function(err) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user