7 May 2013, 12:10am
Projects:
by

leave a comment

  • Voice-Controlled Lamp Using Ninja Blocks + MacBook

    Here’s a video of my latest quick weekend hack, using voice to switch a lamp on and off:

    Ok, so it’s actually a combination of Watts Clever + Ninja Blocks + Node.js + Automator + Speakable Items. Speakable Items takes the voice commands via MacBook’s internal microphone, then calls the Automator applications, which then runs a Node.js script (which output gets spoken by Automator applications), which then tells Ninja Blocks to actuate Watts Clever power socket.

    Here’s how I set it up:

    Configure Watts Clever remote RF signals on Ninja Blocks dashboard (/hattip: @james and @Jeremy over at the forum).

    Create this simple Node.js script file. I saved it as rf433.js .

    var ninjaBlocks = require('ninja-blocks'),
      app = ninjaBlocks.app({
        user_access_token: 'your-ninjablocks-token'
      });
    
    app.devices({ device_type: 'rf433' }, function (err, devices) {
      var subDevices = app.utils.findSubDevice({ shortName: process.argv[2] }, devices);
      console.log('Switching ' + name);
      Object.keys(subDevices).forEach(function (key) {
        var subDevice = subDevices[key];
        app.device(subDevice.guid).actuate(subDevice.data)
      });
    });
    

    Create two Automator applications, one called ‘Lamp on’, the other ‘Lamp off’, each containing:

    • Run Shell Script, which is used to run rf433.js .
    • Speak Text, which is used to notify when device#actuate is about to be called (that’s the console.log('Switching ' + name); line from the above Node.js script).

    These applications must be available from ~/Library/Speech/Speakable Items/ .

    Configure the Mac’s System Preferences -> Accessibility -> Speakable Items on Lion and Mountain Lion, or System Preferences -> Speech on Snow Leopard.

    Done.

    Overall, this is just an experiment to prove that it can be done. Speakable Items is obviously _not_ Siri, so you can’t expect the same quality of speech recognition. And having to open a MacBook every time I want to use this is obviously too troublesome.

    It would be awesome for Ninja Blocks to have / work with something like Ubi. Every home automation solution needs at least a voice or gesture based input mechanism :).

    Note to self: I’m totally looking forward to the future where every single thing in the house is powered by renewable energy-based wireless electricity, each running a tiny low-powered Node.js server which talks to one another via HTTP. Life would be much more efficient!

    8 Apr 2013, 12:37pm
    Projects:
    by

    2 comments

  • Jenkins Build Status On Ninja Blocks RGB LED

    Nestor v0.1.2 is out and one of its new features is nestor ninja for monitoring Jenkins and displaying the latest build status on Ninja Blocks RGB LED device (if you have a block, it’s the ninja’s eyes).

    Here’s a usage example:
    export JENKINS_URL=<url>
    export NINJABLOCKS_TOKEN=<token_from_https://a.ninja.is/hacking>
    nestor ninja

    Red for build failure, green for build success, yellow for build warning, and white for unknown status. The yellow light looks quite similar to green, and the white one does look blue-ish.

    And the best place to run nestor ninja? On the block itself of course!

    ssh ubuntu@ninjablock.local
    apt-get install upstart
    npm install -g nestor
    cat /usr/lib/node_modules/nestor/conf/ninja_upstart.conf > /etc/init/nestor_ninja.conf
    vi /etc/init/nestor_ninja.conf # and change JENKINS_URL and NINJABLOCKS_TOKEN values
    shutdown -r now

    Log messages will then be written to /var/log/nestor_ninja.log

    18 Dec 2012, 11:33pm
    Projects:
    by

    leave a comment

  • Home Studio v0.3

    This favourite corner of mine in the living room is the latest revision of my home studio.
    My main computer for the past couple of years has been an 11″ MacBook Air, codename: kakashi.

    The study desk had been disassembled and now rests in the garage.

    7 Nov 2012, 10:27pm
    Projects:
    by

    leave a comment

  • Roomba Twist Fix Attempt

    A few months ago my awesome Roomba vacuum cleaner started dancing instead of cleaning the carpet like it’s supposed to. It reversed, then rotated to the right, left, right, left, all the time. I call it ‘doing the Twist’ (Chubby Checker’s).

    The closest explanation I could find on the Internet regarding this problem was something that’s commonly known as Roomba Circle Dance. The problem is that there are a number of solutions which various people claimed to have fixed the problem and I didn’t know which one was applicable to my case.

    I’ve tried cleaning the Roomba to no avail, so the next thing I tried was a solution with the most fun, i.e. replacing a couple of sensor emitters. This involved disassembling the Roomba and soldering those emitters, but that’s ok, I had some experience with making printed circuit board and soldering… like 17 years ago back in junior high school, surely it’s like riding a bike, right? (as I found out later, this statement is NOT true)

    Here’s a video of my Roomba doing the Twist, plus some photos I took while disassembling and reassembling the Roomba followed by the result after the fix (bonus badass Streets of Rage soundtrack as the background music):

    Some pictures of the Roomba 560 internals:

    Glad that these wires didn’t get entangled at all.

    On the other hand, these plastic snap locks totally tested my patience, not wanting to accidentally break any of them.

    The white thingy on the right was the part I had to replace.

    iRobot. Woot woot.

    These simple red white and black wires made me unscrew and re-screw the bumper plate three times, just to get them positioned correctly.

    Spoiler: It turned out that the sensor emitter wasn’t the cause of the problem, so I’m back to square one, but hey, at least I didn’t break the Roomba and managed to reassemble it. For now, I’m using Brian Pratt’s Roomote to control my Roomba from an iPhone and vacuum the carpet. I still need to figure out a way to return the Roomba to its original autonomous state.

    8 Jul 2012, 12:17pm
    Projects:
    by

    2 comments

  • DataGen: Generate Large Test Data Files – Like A Boss

    A couple of months ago I was doing some volume and performance testing against an application that was expecting a 500% data growth, which meant I had to generate lots and lots of dummy data to test whether the storage would hold up and whether the application itself would still perform well.

    I quickly came up with a script that loops through N times, generates dummy data, and creates an XML file. I left the script running while working on something else in parallel, and at the end the script finished after about a couple of hours.

    There were 3 issues with this approach: 1) It sure wasn’t going to be the last time I had to generate large test data. The next time I had to do something similar, I much preferred a simpler solution than scripting. 2) A couple of hours were too long. I wanted a better solution to cut down data generation time. 3) The script ran on an i7 with multiple cores, but only 1 core was being utilised. Plain wrong.

    That’s why I wrote DataGen.

    Use npm to install:

    npm install -g datagen

    Ease of use

    You don’t need to know any scripting language, you only need to create templates to construct your test data in this structure:

    header
    segment 1
    segment 2
    ...
    segment N (number of segments)
    footer
    

    Start by creating example header, segment, and footer templates:

    datagen init

    Example header:

    <?xml version="1.0" encoding="UTF-8"?>
    <data>
    

    Example segment:

    <segment>
      <id>{gen_id}-{worker_id}-{segment_id}</id>
      <name>{first_name()} {last_name()}</name>
      <dob>{date('dd-mm-yyyy')}</dob>
    </segment>
    

    Example footer:

    </data>
    

    The above templates can be used to generate an XML like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <data>
    <segment>
      <id>1-1-1</id>
      <name>Niels Bryant</name>
      <dob>12-08-1992</dob>
    </segment>
    <segment>
      <id>1-1-2</id>
      <name>John Bohr</name>
      <dob>01-11-1970</dob>
    </segment>
    </data>
    

    If you set segment flag (-s/–num-segments) to 10 million in the above example, then DataGen will generate 10 million segments as the XML body containing sequential IDs, random names, and random date of birth.

    Check out DataGen README for a list of available template parameters and functions which can be used to generate sequential number, random number, random name, random date, random word, random email, and random phone number.

    Better performance

    To reduce the test data generation time and to utilise those spare CPU cores, DataGen allows an easy way to spawn multiple processes to generate multiple test data files at the same time by specifying how many workers (-w/–num-workers) DataGen should spawn. Each worker runs on its own process. Data value generation is CPU bound, while file streaming is IO bound.

    As an example, I tested generating 10 million segments where each segment contained all template functions available in DataGen (random number, random dates, all of them, to simulate the most resource intensive processing), using just one worker. It generated a single test data file, 13Gb in size. Here’s how long it took to finish:

    $ time datagen gen -s 10000000 -w 1
    
    real 47m17.610s
    user 40m26.612s
    sys 9m13.167s
    

    Now compare that with the result of generating 10 million segments over 10 workers, 1 million segments each. This generated 10 test data files, 1.3Gb each.

    $ time datagen gen -s 1000000 -w 10
    
    real 10m51.262s
    user 61m24.546s
    sys 16m38.534s
    

    That’s 36 minutes and 26.348 seconds faster, roughly a 76% improvement.

    The above result came from running DataGen on a quad core machine, so 10 processes might involve too many CPU context switches. I’m assuming that the best performance would be to have the number of workers equal to or slightly more than the number of cores. I need to run more tests to verify this.

    I’ve since used DataGen to generate more test data files. It is simple and easy to use, it puts those spare cores to work. Give DataGen a try and let me know what you think.

    Recent Posts

    Recent Comments

    • Alicia: Hello Emma, Hello…, I read your message and wanted to help you, because I have been in Siem Reap a lot of...
    • Alphonse Gallegoz: Psy likened the Gangnam District to Beverly Hills, California, and said in an interview that he...
    • Hans: Your snippets have inspired me to go out and buy a copy. I hope it lives up to the quality quotes you’ve...
    • abu: bakmi gm is the most famous restaurant in indonesia especialy noodles..nice and you must try..
    • Cliffano Subagio: L8 looks like a funky device. Would be cool to display an 8-bit avatar of the user who broke the...

    Most Commented Posts

    Linkroll