Skip to content

Instantly share code, notes, and snippets.

@mwittig
Forked from AppLamp-API/wifibox.js
Last active August 29, 2015 14:19

Revisions

  1. @AppLamp-API AppLamp-API revised this gist Mar 31, 2014. No changes.
  2. @AppLamp-API AppLamp-API revised this gist Mar 31, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions wifibox.js
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,13 @@
    //send a command ( see commands.js )
    box.command(cmd.rgbw.hue(180));
    box.command(cmd.white.allOn());
    TIP: You don't need to know the exact IP of your Wifi Box.
    If you know your DHCP IP range, just replace the last digit to .255
    That way you wil perform a UDP multicast and the wifi box will receive it.
    So for example your network range is 192.168.1.1 to 192.18.1.254,
    then use 192.18.1.255 to perform a multicast.
    **/

    var http = require('http');
  3. @AppLamp-API AppLamp-API revised this gist Mar 31, 2014. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions wifibox.js
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,28 @@
    /**
    Filename: wifibox.js
    //AppLamp.nl led light API: wifi box UDP socket, command sender
    //AppLamp.nl Wifi LED light API: wifi box UDP socket, command sender
    © AppLamp.nl: you can share,modify and use this code (commercially) as long as you
    keep the referer "AppLamp.nl led light API" in the file header.
    Usage in Node JS:
    //load this wifi box class
    var WifiBoxModule = require('wifibox.js');
    var byteCommand = require('commands.js');
    var cmd = require('commands.js');
    //create instance with wifi box ip and port
    var box = new WifiBoxModule("192.168.1.255", 8899);
    //send a command ( see commands.js )
    box.command(byteCommand.bulb.color.hue(180));
    box.command(byteCommand.bulb.white.allOn());
    box.command(cmd.rgbw.hue(180));
    box.command(cmd.white.allOn());
    **/

    var http = require('http');
    var dgram = require('dgram');

    var WifiBox = function (ip, port) {
    this.client = dgram.createSocket('udp4');
    const default_ip = '192.168.1.100';
    const default_port = 50000;
    const default_ip = '192.168.1.255';
    const default_port = 8899;
    this.ip = (ip != undefined && ip.length > 6) ? ip : default_ip;
    this.port = (port != undefined && port > 0) ? port : default_port;

  4. @AppLamp-API AppLamp-API revised this gist Mar 31, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wifibox.js
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    var WifiBoxModule = require('wifibox.js');
    var byteCommand = require('commands.js');
    //create instance with wifi box ip and port
    var box = new WifiBoxModule("192.168.1.100", 50000);
    var box = new WifiBoxModule("192.168.1.255", 8899);
    //send a command ( see commands.js )
    box.command(byteCommand.bulb.color.hue(180));
    box.command(byteCommand.bulb.white.allOn());
  5. @AppLamp-API AppLamp-API renamed this gist May 14, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @AppLamp-API AppLamp-API created this gist May 14, 2013.
    55 changes: 55 additions & 0 deletions wfibox.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    /**
    Filename: wifibox.js
    //AppLamp.nl led light API: wifi box UDP socket, command sender
    © AppLamp.nl: you can share,modify and use this code (commercially) as long as you
    keep the referer "AppLamp.nl led light API" in the file header.
    Usage in Node JS:
    //load this wifi box class
    var WifiBoxModule = require('wifibox.js');
    var byteCommand = require('commands.js');
    //create instance with wifi box ip and port
    var box = new WifiBoxModule("192.168.1.100", 50000);
    //send a command ( see commands.js )
    box.command(byteCommand.bulb.color.hue(180));
    box.command(byteCommand.bulb.white.allOn());
    **/

    var http = require('http');
    var dgram = require('dgram');

    var WifiBox = function (ip, port) {
    this.client = dgram.createSocket('udp4');
    const default_ip = '192.168.1.100';
    const default_port = 50000;
    this.ip = (ip != undefined && ip.length > 6) ? ip : default_ip;
    this.port = (port != undefined && port > 0) ? port : default_port;

    };


    WifiBox.prototype.command = function (threeByteArray) {
    var buffer = new Buffer(threeByteArray);
    this.client.send(buffer
    , 0
    , buffer.length
    , this.port
    , this.ip
    , function (err, bytes) {
    if (err) {
    console.log("udp error:" + err);
    throw err;
    } else {
    console.log('bytes send: ' + [threeByteArray[0], threeByteArray[1], threeByteArray[2]])
    }
    }
    );
    }

    WifiBox.prototype.toString = function () {
    return 'WifiBox: { ip:' + this.ip + ':' + this.port + '}';
    };


    module.exports = WifiBox;