Software apps and online services
An intrusion detection system (IDS) is a device or software application that monitors a network or systems for malicious activity or policy violations. Any malicious activity or violation is typically reported either to an administrator or collected centrally using a security information and event management (SIEM) system.In this project, there is a trivial effort to intrusion detection by the help of the PIR sensor. Whenever someone tries to come in signal will found in the form of a text message on mobile.
Step-1 Hardware Components
We need the following component to build this project:-
1)Passive infrared(PIR) sensor (https://en.wikipedia.org/wiki/Passive_infrared_sensor)
2)Bolt WiFi module
Step-2 Hardware Configuration
The bolt Wifi module is connected to the Passive infrared(PIR) sensor through jumper wires.
Using male to the female wire we will connect the 3 pins (OUT, GND, VCC) of the PIR sensor to the Bolt Wiﬁ Module as follows:-
a) Connect one end (red wire) of the OUT pin of PIR to the 0 (Digital) pin of the Bolt device.
b) Connect the yellow wire of PIR to the GND pin of the Bolt device.
c)Connect the orange wire of PIR to the 5V.
The figure is given below:-
- The figure is given below:- (These all pictures are in working mode. The module is online but makes sure when you are connecting the wires, your Bolt WiFi module is at offline mode.)
- Software Section
First, we need to create a digital ocean account. Please click here https://m.do.co/c/5ea366f842e6and create a new account. Type email id and password for Signing up and we will receive an account verification email. Open the email and click on the link to confirm our account.
After confirming your account, we need to add billing.
In this step, we will choose the appropriate image(version and type of OS) of droplet for this training. First, click on the create button and choose Droplet from the drop-down menu and the 'Create droplet' screen will appear. At the time of this writing, the 64-bit Ubuntu 18.10 image is selected by default and we will use the same version for this training.
In this step, we will choose the size of the droplet i.e. the amount of RAM and storage space it should have.
Datacenter region is the place where our droplet will be deployed. It's like someone has bought a computer for you in that place. For the best performance, choose the data centre nearest to us and our users. More distant server locations may increase the server's latency without providing any practical benefits. I am from India, so I kept Bangalore as the default datacenter region.
- Once we have selected our options, click Create.
after creating adroplet, we will receive a mail where we will get our IP address and login password.
We created a droplet and got the login credentials and server IP over emails. Now, we will learn about tools/software for ssh(login to the server) into our server. for windows os we can use putty to write the code and to execute for mac we will use the terminal for writing as well as running the code.
We will log in through the terminal to Digital ocean server.
3h.Then type password and press enter. Password won’t be visible and we will have to type the same password for the first time, which is mailed to us from DigitalOcean.
3i. After this, we are asked to change our password and we need to type our current password. And then we are asked to enter our new password twice for confirmation. Keep this password somewhere safe, because next time we have to type this new password.
The Bolt Python library makes it easy to interact with the Bolt cloud API from our Python application.
We can control or fetch the data from Bolt cloud to our server(Here Ubuntu from DigitalOcean ), Bolt Python library will help us in building the IoT product.
Before we proceed to this step, first ssh(login) to theUbuntu server and follow the below steps to use Bolt Python library in code.Update the packages on Ubuntu
Execute the command below so that the packages on Ubuntu are updated to the latest version.
sudo apt-get -y update
sudo apt install python3-pip
Step 5. Twilio Configuration5A. SMS Configuration -
sudo pip3 install boltiot
Twilio is a third-party SMS functionality provider. It is a cloud communications platform as a service (PaaS) company. Twilio allows software developers to programmatically make and receive phone calls and also send and receive text messages using its web service APIs.
Creating an account on Twilio
a. Open https://www.twilio.com/ in browser.
b. Click on Get a Free API Key button to sign up.
c. Fill all the necessary details in SIGN UP form. Below is the screenshot of filled sign up form.
d. To verify they will ask for our phone number. Choose India as an option in the dropdown and then enter our phone number
e. After verification, we will redirect to our dashboard and we will need to Create New Project.
f. Click on "Products" as shown on the screen below, and enable the SMS services by clicking on two checkboxes for Programmable SMS and Phone Numbers as shown below. Once you have done this, scroll to the bottom of the screen and click on "Continue".
g. Now, we will need to give a name for our project. I have given the name as My Project. Click on "Continue" once we have entered the project name.
h. Click on "Skip this step" when it asks to Invite a Teammate.
i. Our project should be created at this point. Click on "Project Info" to view the account credentials which is required for our projects
j. We can view the Account SID and Auth Token on this page. The Auth token is not visible by default, we can click on the"view" button to make the Auth token visible as shown below. Copy both and save them somewhere securely.
k. From the drop-down menu, choose "Programmable SMS". Now click on the Get Started button to generate phone number.
l. Click on Get a number button. Then a popup will appear which will have the final number
m. Click on Choose this number button to finalise this number.
n. By this method, we can generate several numbers and we can see these numbers in Active Numbers area.
o. To check whether this is working or not, we have to go to Build with Programmable SMS and send a message to our given phone number. if everything is ok then it ill work, but if the message has not received, then we have to again set up from the beginning.Note
All screenshots are here(related to Twilio)
If you are windows user then run your code on PuTTY.Here we have to install python also for installation guidance please walk through this link https://realpython.com/installing-python/
Step 6. Preparation to code
a) Connect the temperature monitoring circuit as we have done in the previous lesson -
Hardware connections for Intrusion_Alert_System.
b) Login into the putty by entering the IP address of your digital ocean droplet.
c) After successful login, create a file named
conf.py which will store all the credentials related to Twilio. To create a new file type
sudo nano conf.py in the terminal. After that write below code to save all the credentials in a single file.
SID = 'You can find SID in your Twilio Dashboard'
AUTH_TOKEN = 'You can find on your Twilio Dashboard'
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
API_KEY = 'This is your Bolt Cloud accout API key'
DEVICE_ID = 'This is the ID of your Bolt device'
Note: You have to replace all the above value with your credentials. You can find the first four value in Twilio dashboard and the last two in Bolt Cloud dashboard.
We store all the credentials in a separate file since it is sensitive data which should not be shared with anyone. Hence it is a good practice to avoid using credentials in code directly. After replacing all the values, save the file using CTRL+X.d) Now create one more file named intrusion_alert
.py. To do so you have to type
sudo nano intrusion_alert.py in the terminal. Now we will write the main code to collect the data from the Bolt and send SMS if anyone comes in.
The algorithm for the code can be broken down into the following steps -
- Fetch the latest sensor value from the Bolt device.
- Check if the sensor value is 1 then motion detected and send the message.
- Wait for 5 seconds.
- Repeat from step 1.
Step 7. Code Explanation
- In the code, we first have to import our conf file which has all the credentials. The python json and time libraries are also imported in the same line. Since we have saved our conf file with the.py extension, we can directly import it.
import conf, json, time
- json is a python library used for handling all operations on JSON objects. JSON is nothing but a data communication format widely used on the Internet for sending/receiving data between a client and a server. More information on JSON can be found here. Remember, 'json' is the python library used for handling JSON objects and JSON is a data communication format.
- Now we will import the Bolt python library which will let us fetch the data stored in Bolt Cloud. To send the SMS, the Sms library is also imported. The below line of code imports the required libraries.
from boltiot import Sms, Bolt
In the above line, we are importing two objects. First one is SMS which will be used to send SMS alerts and the other one is Bolt which is used for accessing data from your Bolt device like the motion-detecting. For remaining code explanations, please read the comments in the code section.Step 8. Project Output and How it Works :
Logic It will send SMS through Twilio API when PIR sensor state changes from LOW to HIGH.
If PIR value is HIGH - SOMEONE ENTERED
If PIR value is HIGH - NO MOVEMENT IN THE ROOM
1)Make sure your module is offline when you are configuring hardware.
2) If Bolt WiFi module is offline then it will show the result like this "You are offline"
3) Jumper wires are not touching to each other.
Advantages of Intrusion Alert Systemhttps://blogs.seqrite.com/benefits-of-having-intrusion-preventiondetection-system-in-your-enterprise/