Posted on Leave a comment

Connecting IoT Sensors data to Node-RED

This is the continuation of the Temperature sensor project in the previous post. The concept is to allow the data from sensors (temperature, motion) can be displayed in Apple Homekit, so that the user can interact with the information and control the IoT connected devices (Lights, Fan, etc). It is best described in the following picture.

The following instruction shows how to install Node-RED on a linux computer running Debian OS.

sudo npm install -g --unsafe-perm node-red

You will also need to install the mosquitto MQTT message broker, here are the command required

sudo apt-key add mosquitto-repo.gpg.key
sudo wget
sudo apt-get update
sudo apt-get install mosquitto

You will also need the latest Python library, so grab them using the following instruction

sudo apt-get install python-dev

Test the installation. In this example I was using Linux Debian, so typing the command node if you get the following in the command prompt, that means the installation is successful. So then you can exit node by typing .exit command in the prompt >.

If all goes well, you can run the node-red command in the command prompt. You should get the following message. This shows that the node-red is now running at

Node-RED Settings

Node-RED setting file called settings.js, on Linux it is located in the /usr/lib/node-modules/node-red folder. You will have another settings.js file in the .node-red folder in your home folder. This setting will be loaded by default.

Creating the flow in Node-RED

Now that you have a running Node-RED, it is time to create the flow. In this example we will create a simple flow to read temperature posted by our ESP8266. Let’s start by firing up your favourite browser and point to the following URL:

You will be presented with a blank screen similar to the following picture. Now to start creating a flow, drop an “Inject” node from input section. We will use this as a trigger to get the temperature reading. Once you dropped it in, double click to set the property. We call the node “timestamp” and we set the interval to repeat every 4 minutes.

The next step is to connect this with an “http” node, so drop an “http” node and configure this as http GET to call a server side script in the webserver. What the script needs to return is the temperature in JSON format as below:


So my data_store2.php script does exactly that, as shown in the following code:

 /* readtemperature file from temp.txt file    return the value back in JSON format for HomeKit  */ 
$theparam = $_GET;
$file = './temp.txt';
$temperature = file_get_contents($file);
echo '{"CurrentTemperature":'.$temperature.'}';

Now the final step is to connect to the “Homekit” node from the Advance nodes menu. Once you drop the “Homekit” node, you can double click to configure the property as below.

Once all had been connected, it is time to deploy the node. You can do this by clicking on the “Deploy” button at the top of the Node-RED window. You will need to click the “Deploy” button whenever you make any changes to the node. Sometime the deployment might stop the Node-RED server, so you just have to run the node-red command again in the command prompt.

If all goes well, you can now test this node by clicking on the button next to “timestamp” node, the temperature should be read from the webserver and displayed in Homekit, similar to the following picture.

That conclude this session on how to configure the Node-RED to work with our temperature sensor data from ESP8266. Please let me know if you have any questions related to this and don’t forget to subscribe for update on the similar projects. The next session we are going to connect this to the Apple homekit in IPhone or IPad.

Posted on Leave a comment

Connecting Touch sensor to Bluetooth Amplifier

TTP223 Touch sensor

First of all, I would like to wish everyone a Happy New year of 2019, this will be my first post of 2019. I hope you had a great start of the year.

I had discovered a capacitive touch sensor TTP223 which simulate a switch function by “touch”, it is using the capacitive of your hand or any other organic matter to allow the switch function. It can be configured to as “Toggle” or “On/Off”.

I recently post a review about various Bluetooth Amplifier that I had been testing. And the CSR8635 Dual 5W Bluetooth Amplifier had a particular interesting feature where you can “Skip” tracks, “Vol+” Vol-“, “Play/Pause” which also double up as “Pick up” call function. The problem with this is the Switch needs to connect each function to the “common” connection. So I am trying to experiment whether this will work using the touch sensor above.

Touch Sensor and Bluetooth Amplifier

The picture on the left shows how the functionality of the touch sensor. When the touch area is being touch, it will connect the I/O pin to the Vcc. While the Bluetooth Amplifier switch needs to connect the “Next” pin to the “common” pin. After some research the common pin is connected to Vcc. So I wonder whether I can connect the I/O pin straight away to the “Next” pin. So I had experimented using the circuit below, and it seems to work ok.

Connecting the Touch Sensor to Bluetooth Amplifier control pins

So I had connected a 10K ohm resistor to limit the current that flow from Vcc of the touch sensor to the Bluetooth amplifier. It seems to be working ok at this stage. I had connected 2 pin, the “Next” pin and “Play/pause” pin. Both seems to work ok.

You can see the final connection in the following picture.

Touch sensors connected to Bluetooth Amplifier controls

If you like this, please let me know or subscribe to the blog to receive frequent tips on simple circuits.