Agri IoT :: Prototype 2 : Gateway & Controller


With prototype 2 of Agri IoT, attempt is to proceed further by adding persistence to the OpenHab2 controller, charting of sensor data is also done. Mysensors v2.0 API is used to build and connect the blocks.  Prototype 2 gateway and controller is covered in this article, check out Agri IoT :: Prototype 2 : Overview & Sensor 

Prototype 1 is covered in below articles,

  1. Agri IoT :: Prototype 1 : Overview
  2. Agri IoT :: Prototype 1 : Sensor
  3. Agri IoT :: Prototype 1 : Gateway
  4. Agri IoT :: Prototype 1 : Controller

Objective ::

  • No changes in gateway same as on prototype 1
  • Controller should be able to store the sensor data
  • Controller will be plotting the data in charts.


  • PC running Debian Jessie
  • NodeMUC
  • NRF240L+


Openhab2 installation  will be configured to have a persistent storage and sitemap/items configuration will be modified to show charts.

  • Install influxdb persistance

Access http://<controller_ip>:8080/paperui/index.html#/extensions under Persistence  >> InfluxDB (v 1.0) Persistence >> Install

Make sure the installation is properly done with

# ssh openhab@localhost -p 8101
Default pass : habopen

openhab> log:tail

  • install influxdb and setup a database

# curl -sL | apt-key add -
# source /etc/os-release
# test $VERSION_ID = "8" && echo "deb jessie stable" | tee /etc/apt/sources.list.d/influxdb.list
# apt-get update && sudo apt-get install influxdb
# systemctl start influxdb
# sudo systemctl enable influxdb

$ influx
Connected to http://localhost:8086 version 0.13
InfluxDB shell version: 0.13
> CREATE DATABASE openhab_db
> CREATE USER openhab WITH PASSWORD 'new_hab_pass'
> GRANT ALL ON openhab_db TO openhab
> exit
  • Configure influxdb

Influxdb should be configured as below. Below configuration logs all sensor data into a database called openhab_db that was created on previous step

Enable http auth

# vi /etc/influxdb/influxdb.conf

[http] enabled = true
bind-address = “:8086” # change to a specific interface if needed
auth-enabled = true # will enforce authentication

# cat /etc/openhab2/persistence/influxdb.persist

Strategies {
   everyHour : "0 0 * * * ?"
Items {
 * : strategy =  everyChange, everyHour

# cat /etc/openhab2/services/influxdb.cfg

# The database URL, e.g. or .
# Defaults to:

# The name of the database user, e.g. openhab.
# Defaults to: openhab

# The password of the database user.

# The name of the database, e.g. openhab.
# Defaults to: openhab

# The retention policy to be used, needs to configured in InfluxDB
# Till v0.13: 'default', since v1.0: 'autogen'
  • Configure multiple sensors and charts

Below item and sitemap configuration is done to show data collected from multiple sensors on the sensor node. 5 charts are also configured.  First chart showing the grouped data with ability to dynamically switch the time period of plotting and rest with hourly data plotted for each sensors.

# cat /etc/openhab2/items/agri.items

Group SoilSensors

Number SoilSensors_Period "Viewing interval" <chart>
Number Agri_moist "Moisture [%.1f ]" <grass> (SoilSensors) {mqtt="<[broker:mygateway1-out/1/1/1/0/37:state:default]"}
Number Agri_temp "Temperature [%.1f °C]" <temperature> (SoilSensors) {mqtt="<[broker:mygateway1-out/1/3/1/0/0:state:default]"}
Number Agri_hum "Humidity [%.1f ]" <humidity> (SoilSensors) {mqtt="<[broker:mygateway1-out/1/4/1/0/1:state:default]"}
Number Agri_lux "Illuminance [%.1f lux]" <light> (SoilSensors) {mqtt="<[broker:mygateway1-out/1/2/1/0/23:state:default]"}

# cat /etc/openhab2/sitemaps/agri.sitemap

sitemap demo label="Main Menu"
Frame label="Agri Sensor" {
Text item=Agri_moist
Text item=Agri_temp
Text item=Agri_hum
Text item=Agri_lux
Switch item=SoilSensors_Period label="Chart Period" mappings=[0="Hour", 1="Day", 2="Week"]
Chart item=SoilSensors period=h refresh=300 visibility=[SoilSensors_Period==0, SoilSensors_Period=="Uninitialized"]
Chart item=SoilSensors period=D refresh=1800 visibility=[SoilSensors_Period==1]
Chart item=SoilSensors period=W refresh=3600 visibility=[SoilSensors_Period==2]

You would be able to see the sensor output and plotted graph here


Testing & Troubleshooting::

Logs related to openhab2 can be viewed in Karaf console.

# ssh openhab@localhost -p 8101
Default pass : habopen

openhab> logs:tail

References ::

Leave a Reply

Your email address will not be published. Required fields are marked *