This is the repo of "Smart Hoop" project for the IoT class. Smart Hoop detects when a basket is scored using Raspberry Pi, an ultrasonic sensor and WebSockets.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.1 KiB

//οριζω την ip του raspberry pi και θετω την τιμη score=0
(function() {
var ws = new WebSocket('ws://192.168.1.11:8080', 'json');
var score = 0;
//ενημερωτικα μηνυματα για τον server και παιρνω την προηγουμενη τιμη απο την μεταβλητη score.
ws.onopen = function () {
console.log('Websocket ws is now open');
ws.send('Hello from SmartHoop!');
document.getElementById('score').innerHTML = score;
};
//με το event score που αποστελενεται απο τον node server αυξανω κατα 1 την μεταβλητη score
ws.onmessage = function (event) {
if (event.data.indexOf('SCORE:') != -1) {
score++;
document.getElementById('score').innerHTML = score;
}
console.log('Message was ', event.data);
};
//σε περιπτωση λαθους δειχνουμε το σφαλμα
ws.onerror = function(error) {
console.log('Error detected: ' + error.data);
}
}());