Pages

Monday, 24 April 2017

OpenHab2 - MQTT binding demo

OpenHab2 - MQTT binding demo

This demo demonstrates how to use MQTT binding addon in OpenHAB2 installed into Orange Pi zero. The idea is very basic. A switch is created on default sitemap. When you turn on the switch, it sends "ON" message to Topic /office/light via MQTT broker that is installed on Orange Pi. When you turn off the switch, it sends "OFF" message to Topic /office/light.

Require

First, install MQTT binding via paperui

Define all the brokers which you want to connect to, in your services/mqtt.cfg file.
cd /etc/openhab2/services

sudo nano mqtt.cfg

The file as follow
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mosquitto.url=tcp://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mosquitto.clientId=lion

# Optional. User id to authenticate with the broker.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

Define demo item in demo.items

Switch mySwitch {mqtt=">[mosquitto:/office/light:command:ON:1],>[mosquitto:/office/light:command:OFF:0]"}

Define sitemap

sitemap default label="My first sitemap"
{
    Switch item=mySwitch label="Office Light"

}

Show log file

Open terminal, then run:
tail -f /var/log/openhab2/openhab.log


Thursday, 23 March 2017

Install Node-RED on Orange Pi

Step 1: Install NodeJs v7.x

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

Step 2: Install Node-RED

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

Step 3: Start Node-RED

root@orangepizero:~# node-red
22 Mar 17:51:35 - [info]

Welcome to Node-RED
===================

22 Mar 17:51:35 - [info] Node-RED version: v0.16.2
22 Mar 17:51:35 - [info] Node.js  version: v7.7.3
22 Mar 17:51:35 - [info] Linux 3.4.113-sun8i arm LE
22 Mar 17:51:37 - [info] Loading palette nodes
22 Mar 17:51:43 - [warn] ------------------------------------------------------
22 Mar 17:51:43 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
22 Mar 17:51:43 - [warn] ------------------------------------------------------
22 Mar 17:51:43 - [info] Settings file  : /root/.node-red/settings.js
22 Mar 17:51:43 - [info] User directory : /root/.node-red
22 Mar 17:51:43 - [info] Flows file     : /root/.node-red/flows_orangepizero.json
22 Mar 17:51:43 - [info] Creating new flow file
22 Mar 17:51:43 - [info] Starting flows
22 Mar 17:51:43 - [info] Started flows
22 Mar 17:51:43 - [info] Server now running at http://127.0.0.1:1880/

Step 4: Adding nodes

cd $HOME/.node-red
npm install <npm-package-name>

replace with specific nodes package name that you can find in nodes library. For example, the folowing commands will install package: Orange Pi GPIO
sudo npm install node-red-contrib-opi-gpio
Restart Node-RED. Then open web-brownser. Navigate to http://orange_pi_ip:1880/
You can see the result as the picture below

Step 5 (optional): Start Node-RED on boot

Install nodered.service file and start and stop scripts.
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service -O /lib/systemd/system/nodered.service
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-start -O /usr/bin/node-red-start
sudo wget https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/node-red-stop -O /usr/bin/node-red-stop
sudo chmod +x /usr/bin/node-red-st*
sudo systemctl daemon-reload

sudo nano /lib/systemd/system/nodered.service
Edit the nodered.service file as follow:
# systemd service file to start Node-RED
[Unit]
Description=Node-RED graphical event wiring tool.
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html
[Service]
Type=simple
# Run as root user in order to have access to gpio pins
User=root
Group=root
Nice=5
Environment="NODE_OPTIONS=--max-old-space-size=128"
#Environment="NODE_RED_OPTIONS=-v"
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
KillSignal=SIGINT
Restart=on-failure
SyslogIdentifier=Node-RED
[Install]
WantedBy=multi-user.target

To then enable Node-RED to run automatically at every boot
sudo systemctl daemon-reload
sudo systemctl enable nodered.service

It can be disabled by
sudo systemctl disable nodered.service

Monday, 20 March 2017

The OpenIoTChallenge 3.0 was through. Thanks to Eclipse IoT Working Group


We - the AgriNode team are proud to receive the Special Acknowledgement from the judging panel. 

https://www.eclipse.org/org/press-release/openiotchallenge3_winners.php


Thanks to the EclipseIoT and the sponsors for organizing the Open IoT Challenge where we have learned about Open-source IoT platforms and made new friends in the IoT world.



Monday, 6 March 2017

Install Eclipse Kura on Orange Pi Zero (9$; 512MB of RAM)

Orange Pi is a series of cheap single-board computers. It can run  It can run Android 4.4, Ubuntu, Debian, Rasberry Pi Image.
In this post, I tried to install Eclipse Kura on a Orange Pi Zero which has  the AllWinner H2 SoC, and has 512MB DDR3 SDRAM.
This board will be the next generation for our system (Agrinode project).
The fist step, we install Kura on the board and test is to verify that it can work correctly as the Raspberry Pi.

This post is also available at AgriNode project page: https://agrinode.github.io/docs/orangepi/


Install Debian on Orange Pi

Install default java JRE/JDK on Debian (JDK 7)

  • Web Browser Plugin
To install the default Web Browser Plugin on your system, run:
apt-get install icedtea-plugin
  • JRE To install the default JRE (Java Runtime Environment) on your system, run:
apt-get install default-jre
  • JDK
To install the default JDK (Java Development Kit) on your system, run:
apt-get install default-jdk

Or you can install Oracle JDK 8

sudo apt-get install oracle-java8-installer

Install Eclipse Kura

OrangePi runs Debian 8. It is compatible with Kura pakage for BeagleBone
  • Install the gdebi command line tool:
sudo apt-get update
sudo apt-get install gdebi-core
  • Download the Kura package:
wget http://download.eclipse.org/kura/releases/<version>/kura_<version>_beaglebone_debian_installer.deb
Note: replace in the URL above with the version number of the latest release (e.g. 2.1.0).
  • Install Kura:
sudo gdebi kura_<version>_beaglebone_debian_installer.deb
  • Reboot the Orange Pi
sudo reboot
  • Kura setups a local web ui that is available using a browser via:
http://<device-ip>
For more detail, please visit: http://eclipse.github.io/kura/doc/beaglebone-quick-start.html

Set up java version

sudo update-alternatives --config java
Video:



Tuesday, 28 February 2017

Final report for Open IoT Challenge 3.0

AgriNode project: Building A Wireless Sensor Network for Agricultural Application

AgriNode project goal is to build an Internet of Things – IoT solutions for various agricultural applications. We successfully developed the AgriNode system which is a Wireless Sensor Network – WSN consisting a gateway and sensor nodes. In the project, We utilized  Low-cost devices (Arduino, Raspberry) and Open-sources IoT platforms (Eclipse Kura, Reactive Blocks).

Webpage: https://agrinode.github.io

Report (PDF version): http://bit.ly/2lQc8Er

Live data: https://agrinode.mybluemix.net/ui/#/0

  

ACKNOWLEDGEMENT


I would like to acknowledge the support of Mr. Benjamin Cabé and Miss Roxanne Joncas from Eclipse Foundation. I also sincerely thank Mr. Tim Jagenberg and Miss Anne Nevin from Bitreactive for the help of building AgriNode project software.



Saturday, 25 February 2017

Hardware choices for AgriNode System- Wireless Sensor Network System


The goal of AgriNode project is to build a Wireless Sensor Network - WSN for agricultural applications such as greenhouse management, monitoring water quality for a fish farm. The system can help farmers to monitor their own farm and support them in decision-making based on sensed data. The Fig. 1 shows the AgriNode system architecture.


In this post, we demonstrate the hardware choices for the Agrinode system. To design AgriNode hardware system, we utilized low-cost electric devices that farmer can cover.

Agrinode hardware system consists of two main parts: a gateway and sensor nodes. 
The gateway (Fig. 2) is a Raspberry Pi 2 with Raspbian Os which is fully compatible with Eclipse Kura - the heat of AgriNode system. A Wifi dongle is added with Raspberry Pi for establishing a WiFi connection which sensor nodes can connect to. 


Fig. 2 - AgriNode Gateway

Each sensor node contains a microcontroller, power module and connected sensors. The microcontroller used in the project is an Arduino board - An Adafuit HUZZAH ESP8266 board. This board has Arduino Leonardo bootloader and also include a WiFi module - ESP8266. The power supply is typically a battery, which may also have a solar panel for charging. A sensor node can have one or more sensor attached to it of various types. For example, it may have the temperature, humidity, and luminosity sensor for use in the greenhouse, or water temperature, pH, DO sensor for use in a fish farm. In our demo test, we use two sensor node as described in the Fig. 3 (Node01) and Fig.4 (Node02)

Node 01 has Adafuit TSL2561 and BMP 180 which can measure luminosity and barometric respectively.


Fig. 3 - Node 01

Node 02 has a DHT22 sensor which can measure temperature and humidity. 


Fig. 4 - Node 02



Saturday, 11 February 2017

Tutorial: Build a Configurable Eclipse Kura Application via Reactive Blocks

Summary. 
This tutorial demonstrates how to build a Kura application into a bundle by using Reactive Blocks.

About Reactive Blocks.
Bitreactive provides the visual development environment that allows java users build their own IoT applications by simply connecting building blocks. Each Reactive Block is designed for a specific purpose such as connecting to Cloud platform (IBM Watson IoT, Xively,...), providing MQTT protocol, LoRaWAN interface,...
Reactive Blocks is a Plugin for Eclipse, which provides a development environment for a developer build a complex application by drag and drop reactive blocks from the Reactive Blocks libraries.
For me, I have a very basic knowledge of Java but I can build a complex java application with Reactive Blocks. Each block has a description in the form of input and output pins and contract. In addition, Reactive Blocks provides the analyze and animation tools which are helpful for testing the applications.

References:
Block by Block Towards IoT Applications
Integrating Reactive Block with JamaicaVM

About "AgriNode bundle".
In this post, I share the workflow of "AgriNode" bundle that will be installed into Eclipse Kura based gateway. The gateway has MQTT server which sensor nodes connect to.
The bundle purpose is to send a command for getting data to sensor nodes via MQTT (with a gateway server: 172.16.1.1:1883). After receiving the command from the gateway, sensor nodes take sensors reading then send data back to the gateway. The gateway then forwards data to the cloud via MQTT protocol (with another broker: blocks2.bitreactive.com).

Requierment.
Eclipse
Install Reactive Blocks for Kura

Build the Agrinode bundle with Reactive Blocks.
Block 1 - Periodic Toggler: To emit a signal (to publish a command message to sensor nodes) every configurable duration, The duration is configurable through Eclipse Kura configuration.

Block 2 - MQTT Publish: This block publishes messages on the local MQTT Broker (172.16.1.1:1883). "init" function:
public MQTTConfigParam init() {
MQTTConfigParam p = new MQTTConfigParam("172.16.1.1");
return p;
}

Block 3 - MQTT subscriber: This block subscribes to messages from sensor nodes (node01, node02,...) on the local MQTT Broker (172.16.1.1:1883). "init1" function:

public MQTTConfigParam init1() {
MQTTConfigParam p1 = new MQTTConfigParam("172.16.1.1");
p1.addSubscribeTopic("node02_data");
p1.addSubscribeTopic("node01_data");
return p1;
}


Block 4 - MQTT Publish: This block publishes messages on the cloud MQTT Broker (blocks2.bitreactive.com). "init2" function:

public MQTTConfigParam init2() {
MQTTConfigParam p2 = new MQTTConfigParam("blocks2.bitreactive.com");
return p2;
}

Deploy the bundle
First, build the project for Kura --> quick build to make a *.dp file --> install *.dp file via Kura Web ui.


Test result.
The data is now available at http://agrinode.mybluemix.net/ui/#/0

The bundle works fine but there is an error that needs to be fixed (I am working on it).
The problem is that the bundle will not send any data to the cloud and can not reconnect to the cloud broker if the internet connection lost occurs. The Block 4 will disconnect and not reconnect to the broker if there is any error.  The only way to get the bundle works again is to reboot the gateway.
The picture below figures out this issue: