Node WS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var levels = 'LEVEL DATA'; | |
var ready= false; | |
var WebSocket = require('ws'), | |
ws = new WebSocket('ws://hidden-fortress-3752.herokuapp.com'); | |
ws.on('open', function() { | |
console.log('open function fired!') | |
ws.send('Arduino here!' ); | |
ready = true; | |
}); | |
ws.on('error', function(error) { | |
console.log(error); | |
}); | |
ws.on('message', function(msg) { | |
console.log('client received ' + msg); | |
}); | |
setInterval(function() { | |
if (ready) { | |
ws.send(levels, function(error) {console.log(error ) }); | |
console.log('sent: ' + levels); | |
} | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment