Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 1/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 2/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 3/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 4/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
Introduction
This instructable will cover the basic steps that you need to follow to get started
with open sources such as Watson nodes(Visual Recognition V3, Text To Speech)
for IBM Bluemix, Node-RED, OpenCV, MQTT v3.1. MQTT(Message Queueing
Telemetry Transport) is a Machine-To-Machine(M2M) or Internet of Things (IoT)
connectivity protocol that was designed to be extremely lightweight and useful
when low battery power consumption and low network bandwidth is at a premium.
It was invented in 1999 by Dr. Andy Stanford-Clark and Arlen Nipper and is now an
Oasis Standard.
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 5/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
I’ve already published an instructable of the Smart Gas Valve For Safety. In
addition, I’m going to communicate between A Smart JPEG Camera and A Smart
Gas Valve for M2M Communication by MQTT. Speci cally, this instructable will
cover how to code the Node-RED on Raspberry Pi2 as a MQTT client by connecting
to your home wireless network and how to send sensor data. I will be using A Smart
Gas Valve for M2M communication by MQTT.
Step 0: Introduction
Step 1: Table of Contents
Step 2: Bill of Materials
Step 3: Setting up the Camera & PIR Sensor with Raspberry Pi
Step 4: Programming NodeRED on Raspberry Pi2
Step 5: Setting up MQTT v3.1 on Raspberry Pi2
Step 6: Checking your NodeRED codes with MQTT on Raspberry Pi2
Step 7: Programming Python JPEG Camera
Step 8: Adding IBM Watson, IBM NoSQL DB, Play-Audio, and Twilio
Step 9: Adding autostart les for every boot
Step 10: Testing M2M Communication
Step 11: (Optional) Using OpenCV
Step 12: Download list
Step 13: List of references
Wi dongle X 1ea
Description
If you have Pi-3, it’s unnecessary.
PIR motion sensor X 1ea
Overview
Android smartphone’s portable battery X 2ea
Nod-RED software X 1ea
Free open source
Use the version pre-installed in Raspbian Jessie image since November 2015
Installation guide
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 7/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
(1) Connect the Raspberry Pi2 with a PIR motion sensor as shown above in the
circuit diagram.
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 8/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
(5) Connect a portable battery with Raspberry Pi2. (Use any portable battery to
connect with the same size connector cable on Raspberry Pi2. )
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 9/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 10/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
(2) You can nd an IP address as below. ‘Once Node-RED has started, point a
browser at http://169.254.170.40:1880’ (It depends on your IP address)
(6) You can start coding with visual editor on the web browser.
(7) Try dragging & dropping any node from the left-hand side to right-hand side.
It’s really easy to code. ( You can conveniently use the visual editor o ine as well as
online. ) Download the ‘SmartGasValve_NodeRED.txt’ le. (1) Click the number (1)
at the right-hand side corner shown in NodeRED on the web browser.
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 11/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 12/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
curl -O http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
rm mosquitto-repo.gpg.key
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 13/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
cd /etc/apt/sources.list.d/
As is the case with most packages from Debian, the broker is immediately started.
Since we have to con gure it rst, stop it.
Now that the MQTT broker is installed on the Pi we will add some basic security.
Create a con g le:
cd /etc/mosquitto/conf.d/
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 14/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
Let’s stop anonymous clients connecting to our broker by adding a few lines to
your con g le. To control client access to the broker we also need to de ne valid
client names and passwords. Add the lines:
allow_anonymous false
password_file /etc/mosquitto/conf.d/passwd
require_certificate false
We will use the mosquitto_passwd tool to create a password hash for user pi:
You will be asked to enter your password twice. Enter the password you wish to use
for the user you de ned.
Now that Mosquitto is installed we can perform a local test to see if it is working:
Open three terminal windows. In one, make sure the Mosquitto broker is running:
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 15/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
mosquitto
mosquitto_sub -v -t 'topic/test'
You should see the rst terminal window echo that a new client is connected.
In the next terminal, run the command line publisher:
You should see another message in the rst terminal window saying another client
is connected. You should also see this message in the subscriber terminal:
topic/test helloWorld
We have shown that Mosquitto is con gured correctly and we can both publish and
subscribe to a topic.
When you nish testing all, let’s set up below that.
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 17/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
When you have already used the JSON format of the ‘SmartGasValve_NodeRED.txt’
on Node-RED, it’s automatically set up & coded each data. I have already set up the
each data in each node.
(2) Check information inside each node has been pre lled.
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 18/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 19/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
First of all, you should test the camera module in the terminal window.
raspistill -o test.jpg
cd /home/pi
mkdir pythonPir
cd pythonPir
timeFormat = 0
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN) # For M2M Communication from Gas Valve signal
GPIO.setup(18, GPIO.IN)
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 21/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
camera = picamera.PiCamera()
while True:
input17 = GPIO.input(17) #Pin number 17 activates
input18 = GPIO.input(18) #Pin number 18 activates
now = datetime.datetime.now()
timeFormat = now.strftime("%Y%m%d_%H%M_%S.%s") #To put date and time
in images
When you nish typing, you should press the keys ‘Control‘ + ‘x‘ and press ‘y‘ to
save this le.
cd /home/pi
mkdir camserver
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 22/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
numpy==1.10.1
websocket-client==0.35.0
websocket-server==0.4
ibmiotf==0.2.3
cd /home/pi
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 23/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
Node-RED comes with a core set of useful nodes, but there are a growing number of
additional nodes available for installing from both the Node-RED project as well as
the wider community. You can search for available nodes in the Node-RED library
or on the npm repository.
For example, we are going to search Twilio at the npm web. Click here.
Then, we are going to install Twilio on Raspberry pi.
To add additional nodes you must rst install the npm tool, as it is not included in
the default installation. The following commands install npm and then upgrade it
to the latest 2.x version.
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 24/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
hash -r
cd /home/pi/.node-red
You will need to restart Node-RED for it to pick-up the new nodes.
node-red-stop
node-red-start
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 25/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
Mosquitto
cd /etc/xdg/autostart/
Type the below (this will enclose the le) Or Put ‘ yMosquitto.desktop’ le into
autostart folder.
[Desktop Entry]
Type=Application
Name=flyMosquitto
Comment=Fly my mosquitto
Exec=cd /etc/mosquitto/conf.d/
Exec=mosquitto
Node-RED
cd /etc/xdg/autostart/
[Desktop Entry]
Type=Application
Name=pircameraNodeRED.py
Comment=Start my security camera
NoDisplay=false
Exec=python /home/pi/pythonPir/pircameraNodeRED.py
NotShowIn=GNOME;KDE;XFCE;
Name[en_US]=pircamera.py
Image le Server
cd /etc/xdg/autostart/
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 27/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
[Desktop Entry]
Type=Application
Name=imageFileServer
Comment=Start an image file server
NoDisplay=false
Exec=cd /home/pi
Exec=python -m SimpleHTTPServer 7000
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 28/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
Import the ‘M2M_SmartGasValve.txt‘ into the NodeRED of the smart gas valve.
(3) Check an IP address of the smart gas valve in the Raspberry Pi2.
ifconfig
When you see the IP address, copy the IP address in a terminal window.
(4) Put the IP address into the MQTT node in other Raspberry Pi2.
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 29/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
We have already used the IBM Watson Visual Recognition. Watson Visual
Recognition is very excellent whereas we can’t use it without connecting wi .
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 30/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
OpenCV is possible to use without internet connection but It’s not very easy for a
beginner to install & code into OpenCV. So, I’m going to install the OpenCV.
Install dependencies
Install OpenCV 3
unzip ~/Downloads/opencv-3.1.0.zip
cd opencv-3.1.0/
mkdir build
cd build/
cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=NO -DBUILD_PERF_TESTS=NO ..
make -j3
sudo make install
sudo ldconfig
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 31/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
python
import cv2
cv2.__version__
Run the simple face detect sample, and look at its code to see how it works:
Before, you should connect an USB-cam with Raspberry Pi2
cd /home/pi
cd opencv-3.1.0
python ./facedetect.py
SmartJPGCameraNoCredits_NodeRED_ver0.1.txt
M2M_SmartGasValve.txt
M2M_SmartJPGCamera.txt
pircameraNodeRED.py
requirements.txt
yMosquitto.desktop
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 32/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
imageFileServer.desktop
pircameraNodeRED.desktop
tightvnc.desktop
Node-RED.org: Documentation
Node-RED: Running on Raspberry Pi
Node-RED: Writing Functions
Node-RED: Node-RED Library
Node-RED: node-red-node-watson
Node-RED: Build a face detection app using Watson Visual Recognition v3 service
Node-RED: Build a face detection app usig AlchemyAPI service on Bluemix
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 33/35
1/28/2018 A smart JPEG camera for home security – Tutorials For IoT-Makers
OpenCV: Documentation
Advertisements
Share this:
Like
Be the first to like this.
Author: iotmaker
I am interested in IoT, robot, gures & leadership. Also, I have spent almost every day of the
past 15 years making robots or electronic inventions or computer programs.
View all posts by iotmaker
iotmaker / November 15, 2016 / AI, Computer Vision, Electronics & Sensors, IoT, Robotics, Security,
Uncategorized
Balrockus
July 6, 2017 at 10:25 am
Wow. I just looked at Node red or my Pi a day ago and I think its great. You tutorial
has taught me masses in the initial read through. Over the next few days I will go
through it bit by bit. I can’t thank you enough.
Liked by 1 person
https://iotmakerblog.wordpress.com/2016/11/15/a-smart-jpeg-camera-for-home-security/ 35/35