As project associate worked on product development for the automation of the pheromone traps. Integrated with Raspberry Pi (Open source technologies) for the capturing of the insects. Conducted field trails for working of the trap version-1 with battery pack. This is best practice of "Electronics in Extension".
2. 2
Acknowledgement
I express my sincere gratitude towards Mr. Lokesh Makam &
Mr. Chaco Muller, my project coordinators, for giving me
precious information about Barrix and about the work to
being carried out by the organisation in Integrated Pest
Management (IPM) and Organic Agriculture.
I also take this opportunity to thank all the employees of
Barrix fortheirsupport, encouragementandalsofor providing
friendly environment, which was very vital during my
internship period.
Finally, I’m thankful to all the individualswhose names are
not includedhere for theirsupport. Allof them have made my
project a success.
K V Y K Sarvan
3. 3
Index
Project Profile 04
Introduction 05
Hardware 05
First Version 06
Establishing Ad-Hoc
Network
08
Test Results 16
Sending captured images
through mail
20
Trail Tests with Version 1 23
Learning from Version 1 24
Image studying using
better edge detection
25
References 27
4. 4
Project Profile
Project Title: Automationof Pheromone Traps
Project Duration: 4 months
Submitted To: Dr. Ranendu Ghosh & Dr. Rahul
Dubey
Submitted By: K V Y K Sarvan
5. 5
Introduction:
The pheromone traps are used for attracting agent to trap the
pest which cause damage to fields. These are also act as
monitoring purpose and best suitable for organic kind of
farming. Barrix fruit trap or vegetable fly trap are the
conventional trapswhich are presently using by the farmers in
India. These conventional traps are located in far fields and it
is difficult to farmer to find of which kind of pest actually
attacking the field and maintaining those traps is labour
intensive.
In order to reduce the problem the suggested idea for
improving the traps is using Automation in Pheromone Trap.
The automationpart is divided into four versions. As a part of
internship, the execution of first version is taken as task.
Hardware
In order to provide less power consuming and effective
utilization of monitoring system the selected board for this
purpose is “Raspberry Pi”.
Raspberry Pi board and Pi-camera
Network cable with router or switch
Power bank 10000mAh/1A
6. 6
Desktop with Wireless PCI adapter
Nano Wifi adapter(802.11n)
Power Source and 16GB SD Card
The operating systems and programming:
Linux-Raspbian(O.S)
Python-2.7
Eclipse software
Opencv
SSH 3.2.9
Putty and WinSCP
First version
The steps which are includedfor the first version are
described as fallows-
Step 1:- To integrate camera and Raspberry pi model B with
power bank
Step2: To conduct lab tests and send images captured by
raspberry pi to desired person mail id in desired time period.
Step3: Establish Ad-hoc network with desktop/lap top to
Raspberry pi for remotely accessing.
Step4: To conduct the prototype test along with whole setup
in DA-IICT campus
7. 7
The pheromone traps which are used need to be installed in
any branch of trees, so initially for the project purpose we
used NoIR camera for capturing the images during night time
also after for the real time testing used ordinary pi camera.
The full integration of kit can be seen in below images.
Figure 1: NoIR mounted on the Trap Cap along with
pheromone
Figure 2: Set up with Raspberry pi-model B with Trap
8. 8
In order to send the images directlyto desired mail id we used
the python coding for the purpose as .py file along with the
Ad-Hoc, the available methodologies are also tested for
remotely accessing the images.
**************************************************
Establishing Ad-hoc Network:
The executionof the establishingthe network using Raspberry
pi as server and any desktop/lap top as client.
Hardware SetUp- For both Ad-hoc and Remotely Accessing using
Lan cable:
Figure 1: The Setup with Raspberry Pi-model B
9. 9
Figure2: The Kit connected with Camera and Raspberry board
A. Configuring Ad-HOC
The fallowing commands are used to establish ad-hoc using
LxTerminal window:
Sudo ifconfig wlan0 down; sudo iwconfig wlan0 mode ad-hoc
Sudo ifconfig wlan0 up
Sudo iwconfig wlan0 essid raspi
Sudo ifconfig wlan0 192.168.22.22 netmask 255.255.255.0
Sudo ifup wlan0
B. Check wlan0 status
Sudo ifconfig
Sudo iwlist wlan0 scan
10. 10
Troubleshotting
1. Writing the wireless interface file which set statically
Auto lo
iface lo inet loopback
iface eth0 inet dhcp
iface wlan0 inet static
address 192.168.22.22
netmask 255.255.255.0
2. Type sudo su root and ifdown wlan0; ifup wlan0 to restart
wireless interface.
3. Sudolsusb and sudo lsmod used to verify about USB devices
and wifi devices modules loaded or not.
Figure3: The status of Ethernet cable and wifi adapter
11. 11
Figure4: The status of Ad-hoc(signal strength)
By troubleshooting and after repeating A and B steps in
configuring ad-hoc. The establishment of Ad-hoc network can be
seen in below screen shots.
Figure5: The signal strength of ad-hoc of ‘raspi’
12. 12
Figure6: The screen shots of SSH in Laptop as client
Using LAN Cable Capturing desiredimages:
The software’s used for capturing the images in desired time are
‘WinSCP and Putty. After plug-in lan cable to raspberry pi we can
know the IP address of the Lan-system this can be read by using
“raspi config” in client system. The below screenshot show the
mentioning of host name and port number. For most of the
networking port number is selected as 22.
Figure7: The screenshot of PuTTY with IP configuration
13. 13
After selecting session and entering into the Putty setup. The login
and password of the raspberry pi need to be mention. In this
prototype version we used login: pi and password: pi
Then the connection of the raspberry pi with kit can be seen in
below screenshot of window. The controlling of the board and
accessing of the files and data that stored in the pi board can be
done by using any laptop or desktop as client. This type of
connection using Lan cable or Wifi adopter (SSH) function same
way. Initiallyin order to access the server remotely the connection
of both Wifi adopter and Lan cable is used for the better
performance of the prototype.Laterthe entire setupandoperation
are carried by wifi adopter.
Figure8: The screen shot of the client side command prompt.
The visualization of server(raspi board)sidecontentremotely:
14. 14
The data or content of the raspberry pi can also be accessed
by using WinSCP software. The configurationand setup of the
network using WinSCP is same as PuTTy setup. After
configuring the setup using IP address, port and login and
password, the software looks as below screen shot. Based on
kindof function doneby clientside the protocolsare selected.
Figure9: Screenshot of WinSCP Login wizard
15. 15
Figure10: The visualisation of all files and folders in client
Advantages of WinSCP
The desired files and images stored in the raspberry pi can be
accessed by the downloadplug-in availablein WinSCP
Figure11: Screenshot of downloading the “Bactrocera-Dorsals image”
16. 16
The above mentioned softwares of PuTTY and WinSCP are used for
configuration for the remotely accessing of Raspberry pi by desired
client using LAN cable. The client desktop which located in far
distance from trap can access the data of the memory card using
SSH. Later the same operation are carried using the WiFi-adopter as
part of Ad-Hoc network establishment for remotely controlling by
commands. For capturing the images at desired time is explained as
fallows.
Test Results
For Capturing and downloading the images of pest at desired
time is carried by both softwares.
Step1: The PuTTY is configured for accessing the pi which
were connected with Pi-camera.
Step2: After the login and password the preview of the cmd
in client looks as below
17. 17
Step3: The function used below capture the images (flies) by
pi-camera. Before going to capturing part the below
functions are need to be check for proper functioning of
camera.
sudoapt-getupdate
sudoraspi-config(Select enable camera from the list by
‘Enable’)
By the below the command we can capture images for
desired time and can save with unique number in jpg format.
Raspistill –o image_%4d.jpg –t1 1000 –t 20500
18. 18
Figure12: The commands are passed for execution in client side
Figure13: Screenshot of Captured images are stored in /home/pi
19. 19
Figure14: The desired image can be downloaded
Figure15: The pests in trap is marked after capturing by pi-camera
20. 20
Figure16: The images of shaken Pi-camera
Sending captured images through mail
Step by step execution of the images sending through mail is carried
easily by command line but for long we also used open CV library files
for future processing of images in Version 2. In order to carry out the
task of sending images to desired person the below sequences need
to be fallow after entering into client side command line prompt:
To Install SSMTP:-
$sudo apt-get update
$sudo apt-get install ssmtp mailtutils
To configure SMTP:-
$sudo nano /etc/ssmtp/ssmtp.conf
The below commands are added to file
root=postmaster
mailhub=smtp.gmail.com:587
hostname=raspberrypi
AuthUser = Email@gmail.com
AuthPass=*********
21. 21
UseSTARTTLS=YES
UseTLS=YES
To sent images to desired person mail Id we have to install few library
files.
Install mpack:-
$sudo apt-get install mpack
To sent a file with an attachment:-
$mpack –s subject 0001.jpg Email@gmail.com
The above mentioned way of sending images to desired persons mail
Id only satisfy the version 1 objectives for remotely accessing the data
of raspberry pi by client, but for analysing the images and to detect
the desired pest by understanding morphological features of pest the
above commands do not support long run. This involve real time
recognising and classification we have to use different library files. So
to meet this interest we approached “OpenCV”. It is an open source,
real-time computer vision library files. The below python program
sends the images desired mail Id with better quality.
Sending image to desired person by Python programme:
------------------------------------------------------------------------
# Send an HTML email with an embedded image and a plain text message for
# email clients that don't want to display the HTML.
import cv2
import time
import datetime
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
ts=time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
camera_port = 0
ramp_frames = 30
camera = cv2.VideoCapture(camera_port)
retval, im = camera.read()
22. 22
file = st+'.png'
cv2.imwrite(file, im)
# capture object until your script exits
del(camera)
# Define these once; use them twice!
strFrom = 'sarvank20@gmail.com'
strTo = 'Email@gmail.com'
# Create the root message and fill in the from, to, and subject headers
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = st
msgRoot['From'] = strFrom
msgRoot['To'] = strTo
msgRoot.preamble = 'This is a multi-part message in MIME format.'
# Encapsulate the plain and HTML versions of the message body in an
# 'alternative' part, so message agents can decide which they want to
display.
msgAlternative = MIMEMultipart('alternative')
msgRoot.attach(msgAlternative)
msgText = MIMEText('This is the alternative plain text message.')
msgAlternative.attach(msgText)
# We reference the image in the IMG SRC attribute by the ID we give it below
msgText = MIMEText('<b>Here is the <i>new</i> image taken by the camera. The flies
canbe seen.</b> <br><img
src="cid:image1"><br>Success!!', 'html')
msgAlternative.attach(msgText)
# This example assumes the image is in the current directory
fp = open(file, 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
# Define the image's ID as referenced above
msgImage.add_header('Content-ID', '<image1>')
msgRoot.attach(msgImage)
# Send the email (this example assumes SMTP authentication is required)
import smtplib
smtp = smtplib.SMTP()
smtp.connect('smtp.gmail.com:587')
smtp.starttls()
smtp.login(‘indisarvan@gmail.com', '**********')
smtp.sendmail(strFrom, strTo, msgRoot.as_string())
smtp.quit()
------------------------------------------------------------------------
Note: In order to carry out the above .py file, the open CV and python need to
be install on Raspberry pi.
23. 23
Trail Tests with Version 1 Kit:
The trails tests are done
in DAIICT campus for validating and establishing the network with
client. The Power bank is providing power to kit with WiFi adopter in
below figure.
Figure17: The Version:1 kit with power bank without LAN cable
After the trail test of Kit with Power bank in controlled environment
the raspi-camera module-Lan cable the capturing of images are
succeeded up to passing commands and capturing images but the
raspberry pi went blank during storing in memory and actually
corrupted the entire raspbian Operating systems. Which again the
formatting of the O.S need to be carried out. When the trail teat again
conducted with wiFi adapter with general power source for
establishing Ad-Hoc network, the SSH get connected at one moment
and get disconnected at other moment. This shows that the
hypothesis of using Raspberry pi for automation is fully succeed in lab
trails but partial executed in real time environment. In order to carry
out the Version 1 Kit the Connection of LAN cable with uninterrupted
power source is must needed for fully functioning of Version 1.
24. 24
Figure18: The Testing of kit for capturing images
Learnings from version 1:
1) Using Pi-camera in conventional traps for image capturing only
satisfy some portion of View. The mounting of camera on cap of
trap do not cover entire container.
2) The client side or base station have effective communication
with Raspberry pi by using LAN cable more than WiFi Adapter.
3) Initially for studying the images and detection for classification
the conventional pheromone trap design need to be change to
controlled environment.
4) The Operating system of Raspberry pi got corrupted due to
power limitations and when commands are passed continuously
for remotely accessing of pi from client get disconnected (LAN
and Ad-Hoc network).
25. 25
Image studying using better edge detection:
The captured images in traps are tested with image detection
algorithms for better studying of pest data which helps in other in
versions. These below tests are carried by Matlab programs.
Figure19: The identification of Fly by different algorithms
26. 26
Figure20: The identification of pest in trap by edge detection
The above edge detection algorithms specify the better identification
of the pest based on their size and shapes in traps. For classification
and effectively identification based on colour there is need of data set
of several thousand images of any single pest at different orientation.
These data sets are labelled and taken as reference for image tracking,
detection and classification in other versions.