Hello world on HomeKit

I just setup a HomeKit apps on my home, using Apple Siri to control my television.

First, need a smart home device, for example Sony Bravia TV which connected to a home WIFI. Second, requires a HomeKit Server talking HomeKit Protocol. This server will interact with other smart home device registered as accessories. Third, requires a HomeKit client installed on mobile, which talking to HomeKit Server, adding any accessories available from HomeKit server. In usual setup, HomeKit server can installed on Raspberry PI, but I don’t have, use my Mac to host it.

The following procedures will help to setup.

1) Get a Mac with Node JS installed. Get a Apple licensed developer program.

2) Download a HomeKit Demo Swift based project, run it on your mobile. Download at https://github.com/KhaosT/HomeKit-Demo.

3) Download a HomeKit Server, I am homebridge. It is a Node.JS based server. Download at https://github.com/nfarina/homebridge.

4) Download Bravia Controlled library which is also Node.JS based. Download at https://github.com/alanreid/bravia.

5) Follow instruction on how to control Bravia TV by using the library. And then, you may build a HTTP based interface around the Bravia library. And then, you may program HomeKit server apps, add a new accessories, and then send the command requests to Bravia Server via HTTP (Turn on/off TV). The last part is much more tricky, to setup HomeKit client talks to HomeKit server.

6) Important note, once you had HomeKit client installed, navigate to one of accessories, look for the service name, this is the name Siri will look and map into. Name it as “television”, or some fancy name, which you will tell Siri to look for and do the action.

7) After that, if everything goes well, you can turn on your Siri, and say “Siri, turn on television”. Then your television magically turned on. Enjoy.

The problems on installing node-ffi on Mac

I am installing NativeScript on my local Mac and requiring install node-ffi.

I am facing problem as could not recognize libtool -static during installation of node-ffi.

I found out that I had two version of libtool installed, one is for GNU libtool installed via brew install libtool (required by ARDrone3 SDK), and then another one in XCode developer tool. So I had to find way to switch into XCode developer tool.

On my Mac, I had to unlink or remove /usr/bin/libtool and /usr/local/bin/libtool, and then build symlink again as

ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool /usr/bin/libtool

Then rerun npm install -g ffi, finally, it succeeds.

This is the error screen.

node-ffi error screen

This is the success screen.

node-ffi success screen

This issue takes me 4 hours of findings, googling, uninstall / reinstall libtool, node-gyp and finally found the root cause. I even tried to install it in Cloud9, but found that Cloud9 is a Ubuntu and not Mac, so the installation result do not have Mac built binaries, so cannot just copy the result from Cloud9 to my Mac. Everything must be built well on the Mac.

2015 CNY KL TRIP 3D2N

The 2015 CNY KL TRIP

Day 1

今天,大年初一,和家人驾车上 KL 游玩。

我们住的 Grand Pacific Hotel,据说在 KL 有三个分行,最小的那间,但是它的房间还算大。我们来这里都是要靠 Waze Apps 带路的。大路可以用 Apple Maps,来到市区就要用 Waze Apps 了。

今日行程:天后宫,Berjaya  Time Square,  阿罗街。

我们去天后宫请了一只“金 羊咩咩”回家。

阿罗街,我们晚上去,很多吃的东西,太棒了。

天后宫 爸妈 Photo 19-2-15 6 48 42 pm

 

Day 2

我们开始第二天的旅程。通过 Waze Apps 和 Apple Maps 的辅助,我们抵达了如下行程:云顶,双峰塔,某个购物广场(只知道里面有五月天成员开的店),Petaling Street.

上云顶,少不了的就是赌场,我爸妈说他们是没有输赢啦。看到一个舞狮表演,同一个团体的表演我们下午在双峰塔那里看多一次,他们也有跑场的。两边观众都有很多老外。云顶那边还有看到很多中国旅客,而双峰塔那边很多孟加拉人。

我妹要去某个购物广场朝圣-某五月天成员开的店。我们用 Waze Apps。因为驾车有点快加上通讯线路有点慢,所以很多次都来不及,过头。突然间我看到前方有个熟悉的建筑,再看 gate,写着 “selamat datang ke Parlimen” (欢迎来到马来西亚国会大厦),哇!那么“雄伟壮观”。

晚上我们到 Petaling Street。因为早弯一个路的关系,多转了一个大弯才到目的地。但途中我们也算走完整个小印度。在那里我们吃了个很棒的晚餐。

Photo 20-2-15 7 49 24 pm

Day 3

今天,一大早,我们就结束了我们的旅程,驾车回柔佛了。出酒店的时候发现前方能很清晰看到巫统和国大党的建筑。

The Imitation Game: Alan Turing

The Imitation Game: Alan Turing

Today I watched this movie in GV Suntec City, The Imitation Game. The real story about Alan Turing, who known as the pioneer or creator of computer science, how we invented a machine that beats another machine – Enigma, A German Machine that can encode important military message.

Can’t control my tears when watched until the last part of the movie.

No many people know who is him, why he is so important. Without his works, there is no new mathematical fields exist – Computer Science. Without him, we don’t have Computer, Mac, iPhone, or maybe only exist 100 years later. Without him, the world war II may take longer to end, ten million more people be killed.

This is my first time, the hello world to book a movie ticket, through online, watched a movie in cinema. In my previous life, I only went to cinema once, when I am young, brought by my uncle. Then I joined two times with company events. Today, the fourth, but the first, happened. And this is the first time I walked through inner building from City Hall MRT how to find where the tower 4 level 3 is.

Tutorial on setup OpenCV on iOS

This tutorial is to setup OpenCV on iOS. To include opencv2.framework to iOS8 Objective C Project.

By following this tutorial: http://docs.opencv.org/doc/tutorials/ios/hello/hello.html#opencvioshelloworld

1) to download prebuilt opencv2.framework, the fine working version is 2.4.9.

2) to create new XCode Project, target iOS8.0 if you are under XCode 6.0.1 as this version not yet support iOS8.1

3) link opencv2.framework to XCode Project. Go to project build phase, and link following frameworks:
opencv2.framework
AssetsLibrary.framework
AVFoundation.framework
CoreGraphics.framework
CoreImage.framework
CoreMedia.framework
CoreVideo.framework
Foundation.framework
UIKit.framework
Accelerate.framework

Screen Shot 2015-01-20 at 12.42.28 am

4) Create <NameOfProject>-Prefix.pch, with following snippets of code add between ifdef / endif block.

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

5) in ViewController.h, add the following to header
#import <opencv2/highgui/cap_ios.h>
#include <opencv2/opencv.hpp>

Note, the most important line is #include <opencv2/opencv.hpp>, this is important to make the stuffs works. I spent few hours and found this solve my problems, which unable to recognize cvtColor function, OK, will introduce in next steps.

6) To do some testing, by adding a video camera, reading 30 frames per second, process the images by inverting the color…

7) Rename ViewController.m to ViewController.mm as we are going to put C PlusPlus Code. Extension mm allows coexist of Objective C and C PlusPlus.

8) In ViewController.h, add following line
@property (nonatomic, retain) CvVideoCamera* videoCamera;

9) In ViewController.mm, we initialize videoCamera and starts it.

self.videoCamera = [[CvVideoCamera alloc] initWithParentView:_ImageView];
self.videoCamera.delegate = self;
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
[self.videoCamera start];

10) In ViewController.h, add CvVideoCameraDelegate

Like this

@interface ViewController : UIViewController

11) In ViewController.mm, add following snippets of code before @end.

#pragma mark – Protocol CvVideoCameraDelegate

#ifdef __cplusplus
– (void)processImage:(Mat&)image;
{
// Do some OpenCV stuff with the image
Mat image_copy;
cvtColor(image, image_copy, CV_BGRA2BGR);
bitwise_not(image_copy, image_copy);
cvtColor(image_copy, image, CV_BGR2BGRA);
}
#endif

12) Run the project. Cheers.

Photo 20-1-15 12 51 57 am

Install CMake on Mac

CMake, the cross-platform, open-source build system. CMake is a family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice.

To install CMake on Mac, you can download the precompiled binaries here. Under platforms Mac OSX 10.6 or later, I chose cmake-3.1.0-Darwin64.dmg at the time of writing.

Once downloaded, run open cmake-3.1.0-Darvin64.dmg on terminal.

A finder view shown. Drag cmake-3.1.0-Darvin64.dmg to Applications shortcut, it will copy the binary to Applications folder.

Open the applications by sudo.

Do sudo /Applications/CMake.app/Contents/MacOS/CMake

Click on menu Tools, Install for Command line use.

You shall see the result, then you are done.

Screen Shot 2015-01-17 at 7.25.34 pm