Overview::
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,
- Agri IoT :: Prototype 1 : Overview
- Agri IoT :: Prototype 1 : Sensor
- Agri IoT :: Prototype 1 : Gateway
- 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.
Components::
- PC running Debian Jessie
- NodeMUC
- NRF240L+
Howto::
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 https://repos.influxdata.com/influxdb.key | apt-key add -
# source /etc/os-release
# test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian 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 admin WITH PASSWORD 'new_admin_pass' WITH ALL PRIVILEGES > 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
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. http://127.0.0.1:8086 or https://127.0.0.1:8084 . # Defaults to: http://127.0.0.1:8086 url=http://<controller_ip>:8086 # The name of the database user, e.g. openhab. # Defaults to: openhab user=openhab # The password of the database user. password=new_hab_pass # The name of the database, e.g. openhab. # Defaults to: openhab db=openhab_db # The retention policy to be used, needs to configured in InfluxDB # Till v0.13: 'default', since v1.0: 'autogen' retentionPolicy=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
http://:8080/basicui/app?sitemap=agri
Testing & Troubleshooting::
Logs related to openhab2 can be viewed in Karaf console.
# ssh openhab@localhost -p 8101
Default pass : habopen
openhab> logs:tail
References ::
http://www.homeautomationforgeeks.com/openhab_persistence.shtml
https://community.openhab.org/t/charting-in-oh2/10410
https://community.openhab.org/t/influxdb-grafana-persistence-and-graphing/13761