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