So I wanted to connect my Smart-Home DIY system to Apple HomeKit and so it turns out it is not so hard to do.
My system has an open source nodejs server and an easy to use API to control lights, TV, AC and more.
The only thing I was missing is an easy to use UI with automation and security.
It happens to be that I am an Apple fan with an iPhone so why not connect it to HomeKit and as a bonus I will have Siri commands from my iPhone and apple watch and even from the apple TV.
To do that I used Node-Red. installing it on windows is easy and you can even install it on raspberry pi. If you want to get an idea what Node-Red is doing exactly check their intro
Once you have Node-Red installed you will have to install a plugin named node-red-contrib-homekit.
You just click the menu icon -> Manage palette -> Install tab -> search for: 'node-red-contrib-homekit-bridged' -> click install
After that you will be able to build something Node-Red calls 'flow' which is actually a configuration or a description of your emulated apple devices and what to do when you press a button on the HomeKit app.
The end result will look something like this:
All you have to do now, is configure an 'Emulated HomeKit Device' and tell it what to do.
To add one just drag from the left panel a node named 'HomeKit' and then drag a node named 'http request' we will connect them to each other in a second.
So let's start with the 'HomeKit' node.
After placing it on the 'flow canvas' we can double click it and configure it, we will do a light switch:
You will have to define a Bridge (a backend container for the switch) and named it (in my case 'Light1'), the pin code is used when scanning from the Apple Home app - you can just leave it as is, basically just give it a name and save. then in the 'properties' assign it the service type Lightbulb (there are many services you can explore and each looks and behave differently on the apple Home app).
Now let's configure the http request node.
Double click it and in the URL type 'http://YOUR_LOCL_IP_:PORT/API'
Now just connect the HomeKit node to the http request node by dragging a line between the little squares at the edge of the nodes.
To make this node available we have to run the flow, so click 'deploy' on the top right
Now let's scan and configure this emulated device from the Home app on IOS.
That's it, when ever you click on the IOS app light button you will make an http call.
Note that the 'homekit-node' will send your http-node (or function) a 0 or 1 depending if the light should go off or on, this is why I have a function node in between the http-node and the homekit-node where I modify the URL before placing the http request, so my server will know if it is an 'on' or' off command.
Hope it works for you and that you will enjoy it as much as I do 👨💻
,Performance tests in several basic scenarios to estimate languages runtime performance
Lately I was trying to understand how virtual memory works and how JVM work and perform.
My intuition was ' if a JVM is written in C, it is probably less performant than C '
So after a lot of reading and investigations I found out that the story is much more complicated then I have initially thought.
JVM has many optimization which makes it very fast most of the time, it does has an overhead but the optimization in JIT make every thing worth it.
basically the JVM will loaded into native virtual memory (and be shared with other processes when possible)
it will use sophisticated algorithms to allocate memory on the native heap to create managed heap.
it will JIT to perform well, will vectorise actions and what not to make the run time overhead worth it.
The V8 engine is highly optimized and make all kind of clever things to perform faster, for example making a behind the scene classes and types and caches to speed up the execution.
Any way I thought that I have to make my own test to better understand the performance difference in various situations, so here it is, my results
1. java and node win when performing loops and in memory
hope you will find this info helpful!