Agri IoT :: Prototype 3 : Overview & Actuator

Overview::

With prototype 3 of Agri IoT, attempt is to proceed further by creating a actuator node that can be controlled from Openhab. Pro mini 3,3v 8Mhz is selected because of its small form, low power consumption and NRF24L01+ will work with it as a radio. A 4 CH 5V relay module is used to switch on/off devices and to power the whole setup a breadboard 3.3v/5v power supply is used Mysensors v2.0 API is used to build and connect the blocks.  Prototype 3 actuator node setup is covered in this article, rest is in Agri IoT :: Prototype 2 : Gateway & Controller 

Prototype 1&2 is covered in below articles,

  1. Agri IoT :: Prototype 1 : Overview
  2. Agri IoT :: Prototype 2 : Overview

Objective ::

Actuator node should,

  • Be able to switch on/off the supply to devices according to input from Openhab2 controller

Components ::

  • Arduino pro mini 3.3v 8Mhz
  • NRF24L01+
  • CP2102 USB to TTL Serial
  • Relay module 5v
  • Breadboard power supply 3.3v/5v

How to ::

Idea is to power on actuator in the node with one of the Arduino digital out,

Hardware:

Relay

  • 1st relay input should be connected to the digital pin 3 of Arduino pro mini.
  • Relay power should be provided by 5v ourput of breadboard power supply.

Radio:

  • Connection should be made as described here
ARDUINO NRF24L01+
GND GND
5VReg
3.3V
VCC
9 CE
10 CSN/CS
13 SCK
11 MOSI
12 MISO
2 IRQ
  • Power to arduino and radio should be provided by 3.3v output of breadboard powersupply

Software:

Connect the arduino via Mini usb cable. Make sure you select the right options as mentioned here

Upload the sketch to actuator node. If you want to manually set the node ID specific the below line above #include <Mysensor.h>

#define MY_NODE_ID 2 // node id 
#include <MySensors.h>

Testing & Troubleshooting::

Use Arduino IDE serial monitor and set the baud rate to 115200.  You can find sensor node related debug output there.

Reference :: 
https://www.mysensors.org/build/connect_radio
https://www.mysensors.org/build/relay
https://www.arduino.cc/en/Main/ArduinoBoardProMini
http://www.instructables.com/id/NRF24L01-Fixing-Connection-Issues/
https://forum.mysensors.org/topic/5174/solved-non-healing-tsm-msg-len-error-hours-into-run/8

Update : 21/05/2017

Lessons learned the hardway : If your actuator node is disconnecting and staying of the grid it can be because of the noise from the relay module. The message similar to below in your node serial output denotes this.

TSF:MSG:READ,76-76-76,s=76,c=4,t=76,pt=2,l=9,sg=1:19532
TSF:MSG:LEN,20!=32

Things that helped me to fix this

  • Check the earth line of your electrical connections with a tester and make sure there is no current leakage and its well grounded
  • Connect the relay module to a separate 5v DC power supply, make sure you have the ground lines connected across
  • Move the relay board away from the arduino/radio
  • Add a decoupling capacitor to the radio as described here . This helps to smooth en the spikes if any
  • Add the below line to your arduino code before #include <MySensors.h> . This will help in resetting the radio in case of connection issues.
#define MY_TRANSPORT_SANITY_CHECK

Agri IoT :: Prototype 2 : Gateway & Controller

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,

  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.

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

[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. 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

Agri IoT :: Prototype 2 : Overview & Sensor

Overview::

With prototype 2 of Agri IoT, attempt is to proceed further by creating a sensor node that collects more types of data and last much longer on battery. Pro mini 3,3v 8Mhz is selected because of its small form, low power consumption and NRF24L01+ will work with it on 2 AA batteries. Mysensors v2.0 API is used to build and connect the blocks.  Prototype 2 sensor node setup is covered in this article, rest is in Agri IoT :: Prototype 2 : Gateway & Controller 

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 ::

Sensor node should,

  • Be able to collect the soil moisture data, humidity, temperature and luminescence
  • Send the collected data via RF network to gateway.
  • Be battery operated.

Components ::

  • Arduino pro mini 3.3v 8Mhz
  • NRF24L01+
  • CP2102 USB to TTL Serial
  • Soil Moisture sensor
  • LDR
  • DHT11
  • 10K resistor
  • Copper enameled wire
  • Perforated PCB Board 3 x 2 Inches
  • 2 AA batteries

How to ::

Idea is to power each sensor in the node with one of the Arduino digital out, this would be a first step in the long journey to save power.  Sensors would be powered on data collected and powered off.

Hardware:

Schematics:

multisensor_node_schem
multisensor_node_schem

Quick and dirty pcb setup :

Multi Sensor node
Multi Sensor node

Software:

Connect the arduino via Mini usb cable. Make sure you select the right options as mentioned here

Upload the sketch to sensor node.


#define MY_DEBUG // enabling debug
#define MY_NODE_ID 1 // node id 
#define MY_RADIO_NRF24 // enabling support for NRF radio module
#define CHILD_ID_MOIST 1 // Moisture sensor id
#define CHILD_ID_LIGHT 2 // Light sensor id
#define CHILD_ID_TEMP 3 // Temp sensor id
#define CHILD_ID_HUM 4 // Humidity sensor id
#define MOIST_SENS 2
#define LIGHT_SENS 3
#define HUM_SENS 4
#define VAL_MOIST A0
#define VAL_LIGHT A1
#define DIGITAL_HUM 8
#include <MySensors.h>
#include <SPI.h>
#include <DHT.h>
#define DHTTYPE DHT11 

DHT dht(DIGITAL_HUM,DHTTYPE);
MyMessage msgMoist(CHILD_ID_MOIST, V_LEVEL); // constructing the msg
MyMessage msgLux(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);

void setup()
{
 pinMode(MOIST_SENS, OUTPUT);
 pinMode(LIGHT_SENS, OUTPUT);
 pinMode(HUM_SENS, OUTPUT);
 dht.begin();
}

void presentation()
{
 present(CHILD_ID_MOIST, S_MOISTURE); // presenting the sensor 
 present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); 
 present(CHILD_ID_HUM, S_HUM); 
 present(CHILD_ID_TEMP, S_TEMP); 
 sendSketchInfo("SoilSensor", "0.1"); //meta data 
}

void loop()
{
 digitalWrite(MOIST_SENS, HIGH);
 delay(50);
 int moisture = analogRead(VAL_MOIST); //measuring the moisture 
 digitalWrite(MOIST_SENS, LOW); 
 send(msgMoist.set(moisture)); // sending the data 

 digitalWrite(LIGHT_SENS, HIGH);
 delay(50);
 int light = analogRead(VAL_LIGHT); //measuring the moisture 
 digitalWrite(LIGHT_SENS, LOW); 
 send(msgLux.set(light)); // sending the data 
 
 digitalWrite(HUM_SENS, HIGH); 
 delay(1000); // delay to get Humidity sensor ready to read data
 float humidity = dht.readHumidity(); //measuring the humidity 
 float temperature = dht.readTemperature(); //measuring the temperature 
 digitalWrite(HUM_SENS, LOW); 
 send(msgHum.set(humidity,1)); // sending the data 
 send(msgTemp.set(temperature,1)); // sending the data
 
 sleep(300000); // sleeping for 5 minutes
}

Testing & Troubleshooting::

Use Arduino IDE serial monitor and set the baud rate to 115200.  You can find sensor node related debug output there.

Reference :: 
https://www.mysensors.org/build/connect_radio
https://www.mysensors.org/download/
https://www.arduino.cc/en/Main/ArduinoBoardProMini

Agri IoT :: Prototype 1 : Overview

This article is a part of a series that I’m doing to build agriculture based IoT system.

Objectives :: 

Create a remote sensor node that collects and sends data, a gateway that listens to the sensor and posts the data to Controller. The whole setup should be cost effective and at the same time should work to illustrate the concept. The idea is to have a Controller in intranet which can be used as a management platform for sensors deployed in a local area.

Components ::

Sensor node :  Arduino nano with soil sensor and nrf24l01+
Gateway : Nodemuc with nrf24l01+
Controller : Debian pc with OpenHab2 as controller software

Details :: 

Sensor node communicates with Gateway using RF network and Gateway posts the data to controller through local wifi network using MQTT protocol. Controller has a Mosquito broker which assists in communication between Gateway and Openhab2 software.

References :: 

OpenHAB, MQTT, Arduino and ESP8266: Part 1 – Setting up your environment

DIY Smart Home Sensors with Arduino, MySensors and OpenHAB


https://www.mysensors.org/build/

Agri IoT :: Prototype 1 : Sensor

This article is a part of a series that I’m doing to build agriculture based IoT system.

Objective ::

Sensor node should,

  • Be able to collect the soil moisture data.
  • Send the collected data via RF network to gateway.
  • Be battery operated.

Components ::

  • Arduino nano
  • Mini B usb cable
  • NRF24L01+
  • Soil Moisture sensor
  • Jumper wires
  • Breadboard

How to ::

Hardware:

Connection between Arduino nano and radio module ( NRF24L01+ ) should be done as suggested here .

Arduino NRF24L01+
GND GND
5VReg
3.3V
VCC
9 CE
10 CSN/CS
13 SCK
11 MOSI
12 MISO
2 IRQ

Connect soil moisture Analog pin to the A0 pin of Arduino, tt can be powered with the  Arduino 5V pin

Arduino Soil Sensor
GND GND
5V VCC
A0 A0 ( pin at the opposite end of VCC)

Arduino nano  can be powered with  7v to 12v . I’m using a 9V 6F22 battery

Arduino Battery
VIN Positive terminal
GND Negative terminal

Quick and dirty breadboard setup :

Software:

Connect the arduino via Mini usb cable. Make sure you select the right options as mentioned here

Upload the below sketch to sensor node.


#define MY_NODE_ID 1 // node id
#define MY_RADIO_NRF24 // enabling support for NRF radio module
#define MY_DEBUG // enabling debug
#define NODE_ID 1 // sensor id
#include <MySensors.h>
#include <SPI.h>
MyMessage msg(NODE_ID, V_LEVEL); // constructing the msg

const int VAL_PROBE = 0; // initializing the moisture variable

void presentation()
{
present(NODE_ID, S_MOISTURE); // presenting the sensor
sendSketchInfo("SoilSensor", "0.1"); //meta data
}

void loop()
{
int moisture = analogRead(VAL_PROBE); //measuring the moisture
send(msg.set(moisture)); // sending the data
sleep(10000); // sleeping for 10 sec
}

Testing & Troubleshooting::

Use Arduino IDE serial monitor and set the baud rate to 115200. You can find sensor node related debug output there.

Reference :: 
https://www.mysensors.org/build/connect_radio
https://www.mysensors.org/download/
https://www.arduino.cc/en/Main/ArduinoBoardNano