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

Agri IoT :: Prototype 1 : Gateway

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

Objectives ::

Gateway should,

  • Be mobile and compact ( not too many wires )
  • Capable enough to connect to sensor and controller ( RF and Wifi )
  • Have enough mem to expand the code. ( for future needs if any )

Based on the above  NodeMuc was selected which has ESP8266 a wifi chip and a capable microcontroller . Please check out mysensors docuemtation here for other gateway types.

Components ::

  • NodeMuc ESP8266
  • NRF24L01+
  • Micro usb cable.

Howto::

Hardware:

Connect NodeMuc and NRF24L01+ as described here.

NodeMCU Radio
GND GND
3V3 VCC
D2 CE
D8 CSN/CS
D5 SCK
D7 MOSI
D6 MISO

Completed setup would look like below. I’m using micro USB cable to power the gateway.

Software:

Install esp8266 board support on your Arduino IDE . Tools >> Board >> Board Manager is where you can install it. Once installed select NodeMuc board with Tools >> Board

The example mysensor GatewayESP8266MQTTClient code  ( You can find the same also on Examples >> Mysensor >> GatewayESP8266MQTTClient ) can be used with minor changes to program Gateway. Please change the below parts in the code according to your environment.


// Set WIFI SSID and password
#define MY_ESP8266_SSID "MySSID"
#define MY_ESP8266_PASSWORD "MyVerySecretPassword"

// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,178,87

// If using static ip you need to define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// MQTT broker ip address.
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68

Testing & Troubleshooting::

Use Arduino IDE serial monitor and set the baud rate to 9600 . You can find gateway related debug output there, you’ll find sensor radio messages also if you have followed the sensor setup part.

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