forked from marva/sumorobot-web
		
	update websocket messages
This commit is contained in:
		@@ -38,8 +38,6 @@ Sumorobot.prototype.connect = function() {
 | 
			
		||||
    }, 3000);
 | 
			
		||||
    // When the WebSocket gets connected
 | 
			
		||||
    this.websocket.onopen = function(evt) {
 | 
			
		||||
        // Send authentication packet
 | 
			
		||||
        self.websocket.send(`{"setID": "browser-${self.robotId}@00000514", "passwd": "salakala"}`);
 | 
			
		||||
        // Setup a timer to ping the robot
 | 
			
		||||
        self.watchdogTimer = setInterval(function() {
 | 
			
		||||
            // Send a ping to the robot
 | 
			
		||||
@@ -65,6 +63,7 @@ Sumorobot.prototype.connect = function() {
 | 
			
		||||
        self.sensors = JSON.parse(data);
 | 
			
		||||
        // When sensor data received
 | 
			
		||||
        if (self.sensors['battery_voltage']) {
 | 
			
		||||
            console.log(self.sensors);
 | 
			
		||||
            if (self.sensors['battery_voltage'] > 4.0) {
 | 
			
		||||
                $("#battery img").attr("src", "assets/img/battery_full.png");
 | 
			
		||||
            } else if (self.sensors['battery_voltage'] > 3.1) {
 | 
			
		||||
@@ -93,9 +92,9 @@ Sumorobot.prototype.send = function(cmd, val) {
 | 
			
		||||
    // https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
 | 
			
		||||
    if (!this.terminate && this.websocket.readyState == 1) {
 | 
			
		||||
        if (val) {
 | 
			
		||||
            this.websocket.send(`{"to": "sumo-${this.robotId}@00000514", "cmd": "${cmd}", "val": "${val}"}`);
 | 
			
		||||
            this.websocket.send(`{"cmd": "${cmd}", "val": "${val}"}`);
 | 
			
		||||
        } else {
 | 
			
		||||
            this.websocket.send(`{"to": "sumo-${this.robotId}@00000514", "cmd": "${cmd}"}`);
 | 
			
		||||
            this.websocket.send(`{"cmd": "${cmd}"}`);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user