Update on Philips Hue Node-RED Node

Based on recent communication with guys from Node-RED, the Hue node has been modified to include the following features:

  • You can now set also the brightness level (0->100) of a lamp
  • By setting the status to AUTO, you can set the lamp parameters using the message on the input node as follows:
    • msg.lamp sets the lamp ID
    • msg.color sets the lamp color (e.g., msg.color=”DF0101″ will set the color to red)
    • msg.brightness sets the lamp brightness (e.g., msg.brightness=50)
    • msg.payload is used to se the lamp status (on/off/alert) (e.g., msg.payload=”alert” will flash the Lamp once

    Please note, by setting the status to AUTO on the node configuration, the rest of the node parameters are ignored, you need to set all parameters through the message input.

You can find the current version of Hue node here (hardware->hue).

By the way, current Node-RED version is 0.7.1, which includes some nice new features, including headless mode, UI updates and more!

Also, make sure you check the flows published by users here!

So, here is a nice example for flashing a Hue Lamp when #iot is used on Twitter:


[{"id":"e973b4e.f168c48","type":"twitter in","twitter":"","tags":"#iot","user":"false","name":"iot","topic":"tweets","x":111,"y":128,"z":"d192ee66.2e6d1","wires":[["a2a6b979.5d5948","74b8bc6d.8b4744"]]},{"id":"a2a6b979.5d5948","type":"function","name":"set_payload","func":"msg.payload = \"alert\";\nmsg.lamp = 2;\n\nreturn msg;","outputs":1,"x":286,"y":127,"z":"d192ee66.2e6d1","wires":[["aef74415.5108b8"]]},{"id":"aef74415.5108b8","type":"HueNode","name":"FlashHue","username":"","discovery_mode":"","lamp_id":"2","color":"EBF5FF","brightness":"100","lamp_status":"AUTO","x":467,"y":127,"z":"d192ee66.2e6d1","wires":[[]]},{"id":"74b8bc6d.8b4744","type":"debug","name":"","active":true,"console":false,"complete":false,"x":254,"y":224,"z":"d192ee66.2e6d1","wires":[]}]

Makerland 2014

Makerland 2014, the first event of this Makerland series, took place in Warsaw, Poland between 17-19 March. I have to say it was definitely a big success and a positive experience for anyone that has participated! 350 makers have attended and made stuff by either participating in one of the numerous tutorials or by hacking and making things on the last day.

The venue has been great, and the Makerland team has done their best! Many local and international companies were also there demonstrating their products.

The first two days were full of keynotes and workshops. Participants learned to do wearable computing:

Learned how to use the RaspberryPi to detect when hens have eggs:

Played with micro-drones:

Controlled Sphero Robot balls using Arduinos and JavaScript (thanks to cylonjs):

And of course, learned how to use Node-RED to control the Philips Hue!

The venue was also full of 3D printers that printed cool stuff all the time!

There were even portable 3D scanners tested on participants!

The last day the hackathon took place, where almost 300 people had the chance to play with all available hardware and goodie’s from workshops and sponsors and create cool projects!

UPDATE: Check some of the cool hackathon projects here!

Overall it was an awesome experience, I had a great time, met wonderful and talented people and made new friend and of course learned new things and making and hacking stuff!

A big thanks to the Makerland team and looking forward to the next event!

RoboPet: Building a connected Robot for interacting with Pets remotely

Recently there has been an Arduino Robot competition organised by RobotChallenge. The best 10 ideas were rewarded with an Arduino Robot for building and presenting their project at the event (RobotChallenge 2014, Vienna, Austria). My team (Massimo, Riccardo, Ivan, Luca, Antonio, Roberto and me) in CREATE-NET submitted the RoboPet, which made it to the 10 finalists!. The idea is simple:

1) The Arduino Robot is equipped with a laser pointer that can be pointed to different directions using two servos.

2) An Android phone in interfaced with the Arduino Robot for allowing the remote control of the robot and the laser pointer.

3) The phone provides also live video feed of the robot.

We decided to use WebSockets for the communication between the Android phone and for making the video feed available in the user’s browser (through WebRTC).

This is how the architecture of the system looks like:

And here is the demo video we created for the project. Please, be kind to ‘like‘ the video, the more likes we get the higher the chances to present RoboPet at RobotChallenge in Vienna!

After a very short time our proposal was accepted and we received the Arduino Robot:

The first thing we tried was check how to move the robot in different directions. It turned out this was the easiest part. The following Arduino code snippet demonstrates how to move the robot forward, left, right and backward:


//read the motor speed from the potentiometer on board:

int val=map(Robot.knobRead(),0,1023,-255,255);
Robot.motorsWrite(val,val); // move forward
delay(2000);

Robot.motorsStop(); // fast stop
delay(1000);

Robot.motorsWrite(-val,-val); // backward
delay(1000);

Robot.motorsWrite(0,0); // slow stop
delay(1000);

Robot.motorsWrite(-val,val); // turn left
delay(2000);

Robot.motorsStop(); // fast stop
delay(1000);

Robot.motorsWrite(val,-val); // turn right
delay(2000);

Note on Arduino Robot wheels movement: Despite it being easy to program, after some time we noticed that the Arduino Robot has issues with the wheels, preventing it from moving properly. We have tried different surfaces, performed wheel calibration but the Robot in many cases fails to move properly (especially to turn left or right). Also, looking at the Arduino forum, the wheels movement issue does not seem very uncommon, see here and here.

Next step was to find ways to interface the Robot with the servo motors and the Bluetooth module for communication with the Android phone. This was the toughest part and one of the main reasons we had to ask for a delivery date extension from the competition organisers. The reasons:

a) serious lack of documentation on Arduino Robot (we even posted questions in the official Arduino forum but got no feedback until this day). The only online resources available for the Arduino Robot is this page, that contains generic info on what the Robot can do, but without proper documentation on how to do it! For example, there is a reference about 6 PWM pins available on the control board and 2 on the motor board, but there is no indication where to find these pins!

b) Although Arduino Robot in fact consists of two Arduino boards connected to each other, there is a lack of available pins for interfacing with networking modules, especially when it comes to serial communication. Many digital pins are available, but SoftSerial on Arduino Leonardo (same MCU chip with the Arduino Robot) operates (the Rx) only on specific pins, that on the Arduino Robot happen to be used by the TFT screen.

So the only way to proceed was to remove the screen and use the MOSI pin to connect it as Rx pin to the Bluetooth module. We used a BlueSMiRF module for the wireless communication between the Arduino Control board and the phone. Initially the SoftSerial library was throwing compilation errors when selecting the Arduino Control as a target device, so we had to tinker a bit with the library itself and some header files for the Arduino Robot.

In the meantime, Riccardo was preparing the laser pointer by disassembling an ordinary laser pointer, attaching wires to get power from the robot board and mounting it on top of 2 servos for pointing it at X and Y axis: 

To keep the complexity low, Riccardo added a random laser movement function in the Arduino sketch. We then mounted the servos with the laser pointer on the Arduino Robot. We also added a metal holder for attaching the phone:

 

The phone runs a background service that connects to the Bluetooth module and sends commands that are received over a WebSocket connection. At the same time it runs a webpage connected to a WebRTC video streaming session that is transmits the video from the front phone camera to any client subscribed to that stream (a webpage or another smartphone device).

The Arduino receives the commands over the SoftSerial pins through the Bluetooth module and interprets them to move forward, backward, left, right and on/off for starting the laser pointer.

All source code for the Arduino, Android and the WebRTC/WebSockets part can be found here. A demo video will follow soon.

Counting Twitter hashtags with Philips Hue

This a script I wrote some time ago for a demonstration at an IoT workshop. The idea was to use a commercial IoT product such as the Hue (which had been just released during that time) and combine it with an existing service on the Internet (like Twitter).

In this case counting Twitter hashtags is visualised through the Hue: When a new hashtag (e.g., #iot) is detected the lamp will blink once and an internal counter is increased. When a defined threshold is reached the lamp color will change to blue.

You don’t need to install any library to use the script and control the Hue. The Hue REST API is used by sending the appropriate requests.

You can find the script on github: https://github.com/hdoukas/TweetHue

Some updates on the IoT (open source) World

I would have created many separate posts for the following news, but unfortunately time is short. So here is a list with some updates about open source software and hardware on the IoT World:

– Node-RED is currently at version 0.4.0 (updated:) 0.5.0

It features new configuration options for npm updates and new nodes (helpful when installing a new Node-RED version), new graphical improvements and more. Also new nodes have been added in the node-red-nodes repository, including a wemo node (for controlling Belkin Wemo sockets and switches), as well as two Philips Hue nodes (see earlier post). You can check the new nodes here.

– openPicus new software and hardware releases

openPicus has recently released the FlyportPRO which targets more professional users. It comes in a very small factor, for professional users that want to integrate it directly to their product. More information here.

Flyport Light has been introduced at a very competitive price for projects that do not require any connectivity.

There is a new version 2.5 of the IDE.

MQTT will become available as a library for the Flyport as well!

Finally, a great Xmas project is hosted at the FCO Airport in Rome, powered by Flyport! There is an interactive Christmas tree that you can control the lights from your browser! More about it here.

– Arduino Intel Galileo on MacOSX

As you probably already know the Intel Galileo has been released. Here is an interesting post/step-by-step tutorial on how to use the board on a Mac.

 

– The ‘Open Informant’ wearable badge

A very interesting open source project has been developed by Superflux for Wearable Futures 2013 Conference. The concept behind the project is to visualise communication that may contain NSA trigger words. A smartphone app is used to scan through your messages and identify keywords that could trigger a NSA investigation on you! The words are then displayed on a e-ink wearable display, powered by an Arduino Mini and BLE. More info here.

– The ThingFul Project

You probably have heard of ThingFul project by Usman Haque. As stated on their website, “Thingful is a discoverability engine for The Public Internet of Things, providing a geographical index of where things are, who owns them, and how and why they are used.”. It is an interesting concept, although to my opinion, IoT object and service discovery is not that simple, and for sure an API would be more useful for discovering and identifying objects.

For sure it is worth trying registering your devices, hopefully there will be more features revealed/enabled in the near future.

– Building your own IoT service with open source tools

On December 12th I was invited to speak at the BDigital IoT Forum in Barcelona. I presented the concept of COMPOSE european project and more specifically, how makers and entrepreneurs can benefit from open source components of the project for building their own IoT services and applications. You can check the slides of my presentation here.

Creating a node for Node-RED: The Philips Hue Node

Guys at Node-RED are working hard to provide updates and bug fixes. Currently the most recent version is v.03.0 which adds some neat features like tabs to the workspace and the very much useful ‘switch‘ node which can route messages according to simple rules defined in the UI (like If msg.payload != true send to 1).

There are still things to do and there is always room for improvement, but Node-RED is a great tool as it is, and besides, if you need something that does not exist, you can always add it by implementing your own node. As in my previous post, where I implemented a Bluetooth 4.0 device scanning node.

There is not a lot of documentation yet on how to create your own node, and although there is the 99-sample.js.demo sample file, it might not be very clear on how to do it. So I decided to write down in this post the steps for creating a new node.

Note: Creating a new node is a good practise when you can build something that can be re-used from the community. For instance, porting an existing Node.js library to Node-RED and exposing all (or most) of its functionality. If you need only to import an module and use it on a specific workflow, you can do it through the function node using the built-in os module:

osModule:require('os')

Node-RED node essentials:

Each Node-RED node consists of two source files: The nodename.js and nodename.html files. The former contains the execution logic of the node and the latter the graphical element html code, which also defines parameters like what are the inputs, etc.

Both files need to be placed inside a folder name nodename under Node-RED/nodes/node-red-nodes/hardware, software, …

An Example -Building the Philips Hue Node:

I wanted to create a node that controls a Philips Hue wireless lamp through the Hue API. I made a search first online and luckily I found node-hue-api, by Peter Murray, which turned out the simplified the process a lot. Node-hue-api is a great Node.js library that exposes the full Hue API, so that you can build your own Node.js app to look for a bridge, get registered lights, register new lights, change the light status of a lamp, etc.

So, I started with the node samples provided by Node-RED. You can find them in ../nodes/node-red-nodes and the filenames are 99-sample.html.demo and 99-sample.js.demo. I saved them in a folder named ‘philips_hue’ and renamed them to 103-philips_hue.js and 103-philips_hue.html.

The sample code in 103-philips_hue.js (from 99-sample.js.demo) is more or less self-explanatory. It starts with importing the main RED module:

and then implements the main node function. In the 99-sample.js.demo file it is called SampleNode(n) so I changed it to HueNode(n).

Inside this function you write the main code of your node’s logic. The sample comes with a simple “Hello world !” message sent to the output of the node. No matter what you implement in this function, you need to start with initialising the RED node with the following:

RED.nodes.createNode(this,n);

Also, keep in mind that any code inside this main function will be executed upon registering the node in Node-RED, that is when and every time you start Node-RED. It will also be executed every time you provide an ‘input’ to the node.

If you need your node’s code to be executed only upon receiving an input, you have to add the following ‘event’ listener:

and add your code accordingly.

Designing the Node – the philips_hue.html

Before jumping into code implementation, it is good to identify first what the node inputs will be. In my case, I wanted the node to be able to act in dual mode: a) provide a scanning feature for identifying the IP address of a Philips Hue bridge in the local network and then querying it for registered lamps and b) provide a way to turn on/off and flash a particular lamp. So I decided to go with a checkbox in the philips_hue node configuration window. Also, one mandatory input to the node should be the authorization id or username that will authenticate the node as valid to use the Philips Hue API and perform commands on the bridge. More information on that and how to use the Philips API can be found here.

I have modified the default code from 99-sample.html.demo to look like the following:

The first edit was to change the data-template-name to “HueNode”. This is what my new node is called and will be also mapped within the code.

Secondly, I added the textfield for entering the ‘username’ used for authentication with the bridge. When adding your input parameter, make sure you change the id to “node-input-parametername” and the placeholder to “parametername“.

Next, I added the the html segment for the checkbox that will enable bridge scanning:

I added the input fields for the Lamp ID variable and for selecting the status of the lamp the same way. The status was a list with options like AUTO, ON and OFF. AUTO refers to when user wants to set the status of the specific lamp using the msg.payload, e.g., msg.payload = “ON”.

Finally I modified the javascript code at the end of the file by adding the variable’s I am using for input from the user:

You can see that on top of the code the ‘HueNode‘ is registered and under the defaults, each input parameter is defined accordingly.

You can check the complete code for philips_hue.html here.

The Code Implementation – the philips_hue.js

After having defined the inputs next step is the code implementation. Back to the philips_hue.js file, I have imported in the beginning of the file the node-hue-api library that will be used through two variables, hue and hueAPI.

Inside the main HueNode(n) function the user input parameters are saved into variables.

Then on “input” the code checks for bridge discovery mode and performs so using the node-hue-api methods.

When bridge discovery is done, the IP address of the located bridge is stored and then the lamp query begins for identifying registered lamps. At the end, the output of the discovery (JSON formatted string with information about the light names and IDs) is stored in a msg.payload and sent to the node output.

In a similar way, when discovery_mode!=1 the code uses the node-hue-api to change the state of a registered lamp through its lamp ID (1, 2, 3, …). The code segment for controlling the lamp status performs bridge discovery again so there is no need to use the discovery mode first if you want just to control the lamp.

You can find the complete code for philips_hue.js here.

The following Node-RED sketch demonstrates how to turn on lights when it is getting dark:


[{"id":"235afb71.dca504","type":"HueNode","name":"Turn Lamp Off","

username":"34fcc05c38c1a66f9cc1a34394809e7","discovery_mode":false,"lamp_id":"1","lamp_status":"OFF","x":560,"y":99,

"z":"62a1ac73.9d5e54","wires":[[]]}]

I am running Node-RED on my RaspberryPi and now I can easily turn on/off the lights based on proximity detection (using the ScanBLE node). Full instructions and code will follow soon!

 

Fast IoT prototyping with SODAQ

I recently came across SODAQ (SOlar Data AcQuisition), an interesting Arduino-based board that promises to make IoT prototyping faster and easier.

What do you need for an IoT project? A microcontroller platform, some sensors and actuators, power and of course a wireless interface. SODAQ provides all these in one board, featuring Grove sensor interfaces and a xBee socket.In addition, there two power connectors, one for a rechargeable battery and one for a solar panel (hence the name). These mean basically two things:

1) You can easily add any Grove compatible (and Seeedstudio provides a huge list!) sensor or actuator by simply plugging it on the board. No needs for soldering or ‘breadboarding’.

2) You can select the best wireless interface that suits your projects (RF, Bluetooth, WiFi, GPRS).

The board is quite small and compact, it is the size of a RaspberryPi, so any Pi-case can do for SODAQ too. People behind SODAQ claim that it draws about 100 times less power than a Pi to connect your things. 

 SODAQ comes with the following specs:

  • Atmega Microcontroller running at 3.3V and 8MHz
  • Arduino Compatible
  • Power supply by LiPo battery (3.7V) or USB cable
  • Solar charge controller with JST connector for Solar Panel up to 2.5W
  • Battery Monitor
  • DS3231 Real Time Clock and Temperature sensor, clock backup powered by LiPo battery
  • 8 MBit data flash module (AT45DB)
  • Micro USB connector
  • 12 Grove connectors connecting Digital, Analog and I2C pins
  • On/Off switch. With the switch in Off position the solar charge circuit is still active and the RTC clock is still powered.
  • ICSP programming header
  • Bee socket for Xbee, GPRSbee or other bee style modules
  • Same size as Raspberry Pi

The board is open source and  looks very promising! Wish I can have one soon to build my next project! You can order yours here.

Using Node-RED to scan for BLE devices

After playing around with Node-RED, I decided to use it for the next project I had in mind. The idea is to use a BLE (aka Bluetooth Low Energy or Bluetooth 4.0) device to automate some actions at home or on my computer. There are a couple (or more) ways to scan for BLE devices, one of them is to use directly some command line tools, like the hcitool, part of BlueZ (assuming that you are on Linux). The other is to use an existing library for your favorite developing environment, like noble for Node.js.

One of the first projects that came in mind was to use my Fitbit Flex for locking my screen/session when I am leaving my computer. The idea is not unique (see here and here for example), but since Fitbit is something I carry always on me, it looks more easy-to-use (and less pervasive) than using a smartphone.

The first step was to write a special node for Node-RED that would do the scanning and checking for a specific BLE device (by name and UUID). Writing the module was quite easy (after spending some time to understand the logic, documentation is still a bit poor on this. The 99-sample.js.demo is much more helpful). I also decided to share the new node to the community by making a pull request at the node-red-nodes repository which is dedicated for hosting nodes created by the community. The request was accepted (btw I was the first non-IBM-er to pull to  the repository) and now you can find the scanBLE node here.  The node icon looks like this:

Many thanks to Dave C-J  for adding the Bluetooth icon on the node.

So to use scanBLE in your flow, you install it first (check here for short instructions) and add it in your canvas. Doubleclick and enter the required information (BLE device name for the name of the Bluetooth device you are looking for, and UUID for its UUID). The node will scan all BLE devices and will check for the name and UUID you have entered. When found, it will trigger the message output with the name of the device as payload. For example, if you are looking for your ‘Fitbit’ device, then msg.payload=’Fitbit’.

To have the computer screen locked when the Fitbit is not around you can use the following flow:


[{"id":"6ccbcca2.933434","type":"debug","name":"","active":true,"complete":false,"x":644,"y":87,"wires":[]},

{"id":"47e20bb6.b81df4","type":"inject","name":"Loop","topic":"","payload":"","repeat":"","crontab":"","once":false,"x":107,"y":120,"wires":[["d3947a09.2c6b88"]]},

{"id":"d3947a09.2c6b88","type":"scanBLE","name":"ScanBLE","ble_name":"Fitbit","ble_uuid":"123455555","x":271,"y":203,"wires":[["31e80866.ce17f8"]]},{"id":"31e80866.ce17f8","type":"function","name":"Check","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n//   console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n//   context = {};\n\nif(msg.payload!='Fitbit'){\n\t//exec('/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend');\n\treturn msg;\n}\n","outputs":1,"x":417,"y":130,"wires":[["d1efa92e.2e1058"]]},

{"id":"d1efa92e.2e1058","type":"exec","command":"/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend'","append":"","useSpawn":"","name":"Lock()","x":556,"y":219,"wires":[["6ccbcca2.933434"],["6ccbcca2.933434"],

["6ccbcca2.933434"]]}]

EDIT: Of course you need to execute a shell command for locking your screen. The flow above executes a command that will lock your Mac session:

 /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend 

If you are on Linux you can try something like

  gnome-screensaver-command -l 

Note: You need a BLE interface for your Mac/Linux computer, I have used this Bluetooth 4.0 Adapter from TRUST.

Meet Node-Red: A workflow editor for your node.js #IoT Projects!

Recently, two IBM guys have released a web-based node.js workflow editor for the IoT: Node-Red.

Node-Red is fully web-based, open source and enables you simply by dragging nodes on the workspace and connecting them to build an IoT project. Fully open-source, it only takes a few minutes to install it. It comes with a ‘Pallete’ –  a selection of actions nodes that can be dragged onto the main canvas – the canvas (or work area for designing your workflow) and an information section where you can view info about the nodes and debugging messages.

Node-Red comes ‘Arduino-ready’: Using Firmata you can control the I/Os of your Arduino (assuming that it is attached through USB on your Node-Red host) using the appropriate node. An Arduino Input Node (the first one on the list) connects to the attached Arduino board and monitors the selected pin (analog or digital) for input. To configure the Arduino parameters simply click on the input node after dragging it into the canvas.

More information on using your Arduino board with Node-Red can be found here.

Network communication: So far Node-Red provides nodes for HTTP connections (the HTTP input node for making a request {POST, PUT, GET and DELETE} to a particular URL), nodes for TCP socket implementation (both server and client sockets), nodes general TCP/UDP sockets and of course (could not have been missed) MQTT nodes for subscribing to a broker and a specific topic, allowing both

For my first Node-Red project (to be presented soon – see screenshot for hints) I needed a generic HTTP request node that would allow users to define HTTP method, server path and port, headers and data. I created myself a new node (named it as HTTP_generic) that allows users to set any parameter like HTTP method, port, path, headers and data request. I have created a pull request, but I have been informed by one of the contributors that they are already working on extending the current HTTP nodes functionality!

Web of Things Hackathon in Zurich

A couple of weeks ago, on September 8th, the 3rd Web of Things Hackathon took place in Zurich! The event was sponsored by Evrythng, COMPOSE EU Project and openPicus provided us with their latest WiFi Flyport devices to play with!

We had a great time, lots of skilled people attended and we also managed to finalise a project, the ‘Augmented Fussball Table!

Check the video below for more details:

1 2 3 4 8