DEPENDENCY INJECTION AND THE YAGNI PRINCIPLE
One of my new personal projects involves writing an application using Node.js and MongoDB. It’s going to have a RESTful interface for the services, and MongoDB as the database (I haven’t decided about what I’m going to use for the front-end, but Angular.js is a strong contender). I had looked at using mean.io to build it, but after playing with it for a while, it seemed to bring in too many things I wouldn’t end up needing, so I decided to build it all from scratch using Restify for the RESTful services.
LOGGING USING EVENTEMITTERS IN NODE.JS
I’ve been working a lot in node.js lately for a work project. Javascript as a language is an odd duck (pun not intended). It’s got all these incredibly powerful features - dynamic typing, inheritance-by-prototype, functions as first-class objects - but it has some really odd anachronisms, including having to use the C-style for (var i = 0; i < length; i++) loop to iterate over arrays. Node adds a lot to the language as well, such as EventEmitters, which are very powerful.
INHERITANCE IN FUNCTIONAL LANGUAGES
There’s a tendency amongst proponents of functional languages, like Javascript, to consider inheritance an anachronism of older (and, by implication, worse) OO languages and OO design. One example is this discussion by Mikito Takada. This is what he says: I think classical inheritance is in most cases an antipattern in Javascript. Why? There are two reasons to have inheritance: to support polymorphism in languages that do not have dynamic typing, like C++.
USING A RASPBERRY PI AS AN IBEACON
There’s an excellent blog post by by James Nebeker and David G. Young about simulating an iBeacon using a Raspberry Pi and a bluetooth dongle. Since I already had both, I thought I’d give it a try. It worked really well, and I’ve even put together the files necessary to do it in my GitHub repository. You’ll need to install BlueZ as well for this to work. Once you get it all installed and working you can use one of the mobile iBeacon apps, such as iBeacon Locate.
MORE FUN WITH BEAGLEBONE BLACK
I’ve discovered that owning a BeagleBone Black (or, in my case, two) is kind of like owning one of those really, really nice cars that you buy but you can almost never drive because it spends so much time in the shop. It’s a lovely piece of hardware, it really is, but the people who created it seem to have gone to great lengths to make sure that all you can do is sit back and admire
BTLE.JS 0.2.0 RELEASED
I just (okay, a few days ago) released version 0.2.0 of btle.js to npm. This has a bunch of API changes - the connect method now gives you a Device object, instead of a Connection. All the ATT methods are now on the Device object, but, in addition, you can access all the GATT functionality by querying the device for services, which returns Service objects, and services for characteristics, which return Characteristics objects.
FUN WITH BEAGLEBONE BLACK
So, I’ve decided to try to play with ZigBee, and since I have a couple of BeagleBone Blacks hanging around doing nothing, I thought I’d try setting it up on them. First thing I came across was that the BBB’s seem to have issues with accessing their UARTS. Even via bonescript, there seem to be issues. So, first thing I did was to upgrade to the latest firmware, and then do opkg update followed by opkg upgrade to get all the latest stuff.
NODE.JS BIT OPERATIONS
I was working on trying to get the barometer readings from my TI SensorTag using Node.js when I came across this problem. See, the user’s guide has two code examples for the algorithm for the pressure - one in C, and one in Java. The one in C uses primarily bit shift operations, whereas the one in Java uses Math.pow() to do the same thing. Naturally, I tended towards the bit shift operations since it makes the code a bit clearer as to what it’s doing (ultimately, from a performance perspective, it doesn’t matter since Math.
PUBLISHED BLUETOOTH LE MODULE
Well, I published my Node.js module for Bluetooth LE, btle.js (pronounced "Beetle Juice") to npm. Even though it’s labeled version 0.1.0, it’s got most of the functionality that’s necessary for Bluetooth LE - reading attributes, writing commands and requests, and listening for notifications. I’m hoping to add more functionality over the next few weeks/months. The main reason I was doing this was to get my TI SensorTag working with my Raspberry Pi and Bluetooth LE dongle, which it now does.
- 1
- 2