Agri IoT :: Prototype 1 : Controller

This article is a part of a series that I’m doing based on building a agriculture IoT system. With prototype 1 intention is to build a minimal system with basic components.

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

Objectives ::

Controller should,

  • Be manageable with web/gui interface.
  • Open in nature ( for custom modifications )
  • Compatible to multiple Hardware gw/sensors ( no vendor lock in )
  • Cost effective
  • Should work without internet

Based on these OpenHab2 was selected.

Components::

  • PC running Debian Jessie

Howto::

OpenHab2:  is a vendor neutral opensource solution  that can be used as a intranet of things controller

Installation:

  • Java

Check and make sure java version installed is 1.8 or greater.

# sudo apt-get install software-properties-common
# sudo add-apt-repository "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main"
# apt-get update
# install oracle-java8-installer
# java -version
  • Openhab
 # wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -
 # echo 'deb http://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list
 # apt-get update
 # apt-get install openhab2
  • Install mqtt binding

Access http://<controller_ip>:8080/ and select Standard which is the recommended setup
After installation access http://<controller_ip>:8080/paperui/index.html#/extensions under Bindings >> MQTT Binding >> Intall

Make sure the installation got completed by loging to Apache karaf

ssh openhab@localhost -p 8101
Default pass : habopen
openhab> log:tail

Mosquitto : Light weight MQTT broker ideal for IoT setups

# wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
# apt-key add mosquitto-repo.gpg.key
# cd /etc/apt/sources.list.d/
# wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
# apt-get update
# apt-get install mosquitto mosquitto-clients

Configuration:

Edit /etc/openhab2/services/mqtt.cfg and add below lines to it to allow openhab2 connect to the mqtt broker mosquitto

broker.url=tcp://<controller_ip>:1883       
broker.clientId=openhab

Edit /etc/openhab2/sitemaps/agri.sitemap and add below lines to it

sitemap demo label="Main Menu"
{
Frame label="MQTT" {
Text item=Agri_moisture
}
}

Edit /etc/openhab2/items/agri.items and add below lines to it

Group All
Number Agri_moisture "Moisture [%.1f ]" <moisture> {mqtt="<[broker:mygateway1-out/1/1/1/0/37:state:default]"}

Output::

View the sensor output on http://<controller_ip>:8080/basicui/app?sitemap=agri

Testing & Troubleshooting::

Find the logs for openhab2 and mosquito  in the below locations,

/var/log/openhab2/event.log
/var/log/openhab2/openhab.log
/var/log/mosquitto/mosquitto.log