Stairs/web/app.js
Mark van Renswoude 1f5f0a7d42 Added Ping command
Added prototype Node.js client app
Added UDP protocol documentation
Replaced brzo_i2c library with standard Wire.h while debugging
Removed test code from PCA9685 library
2017-03-24 21:40:56 +01:00

37 lines
950 B
JavaScript

var protocol = require('./protocol');
var dgram = require('dgram');
var on = 0;
var speed = 256;
function lsb(value) { return value & 0xFF; }
function msb(value) { return (value >> 8) & 0xFF; }
setInterval(function()
{
// 0x00, 0x10 = 4096
on += speed;
if (on <= 0 || on >= 4096)
speed = -speed;
var message = new Buffer([protocol.Command.SetMode, protocol.Mode.Static, lsb(on), msb(on)]);
var client = dgram.createSocket('udp4');
client.on('listening', function()
{
var address = client.address();
console.log('UDP client listening on ' + address.address + ":" + address.port);
});
client.on('message', function (message, remote)
{
console.log(remote.address + ':' + remote.port +' - ' + message.toString('hex'));
client.close();
});
client.send(message, 0, message.length, 3126, '10.138.2.12', function(err, bytes) {
if (err) throw err;
console.log('UDP message sent');
});
}, 200);