/server_room

Iot with python

Primary LanguagePython

#Server-temp

About

This system uses Computer Vision to detect the temperature reading from the display and a onboard temperature sensor and sends out alerts accordingly. It also records sound using microphone and tries to find out what noise it is wether it is humans,rebbot,normal or door being opened. This repository is where you can find the code that does the same.

Requirements:

  • Python 3.x
  • Installing OpenCV on Raspberry Pi:
    • Refer to this guide, if necessary, to install OpenCV on your Pi.
  • lm35 temperature sensor
  • mcp3008(ADC)
  • microphone with usb jack
  • Installing Librosa on Raspberry Pi:
    • One has to install librosa by first installing berryconda and then installing librosa by command 'conda install -c conda-forge librosa'

Seting up

  • connect picam to camera slot on raspberry pi
  • setting up temperature sensor - Refer to this guide to set up temperature sensor and mcp3008 then copy tempsens code into examples folder of mcp3008 which you you just downloded
  • connect microphone to one of the jacks of raspberry pi

Getting Started

  • Accessing the Raspberry Pi camera with Python and OpenCV: A picture of the temperature display is to be taken to be processed. A picture is taken every 10 mins by setting up a cron job.
  • Accessing the temperature sensor: The value of temperature sensor is read every 10 mins
  • Accessing the microphone: Sound is recorded for 10 seconds every 2 minutes and it's decibel level is evaluated and then find out what kind of that was.

A sample image of the display: Temp display

  • Detecting the temperature on display reading: The temperature reading is displayed as seven segment digits. The steps to detect what digit it reads are as follows:

    • Detecting the bright spots in the image: Thresholding operations followed by dilation, erosion and other preprocessing functions returns an image with only the digits displayed highlighted.
    • Extracting the digit ROI: Contours that are large enough to be a digit(the appropriate width and height constraints requires a few rounds of trial and error) in the image is taken as a digit ROI. A contour is simply a curve joining all the continuous points (along the boundary), having same color or intensity.
    • Identify the digits: Recognizing the actual digits with OpenCV will involve dividing the digit ROI into seven segments. From there, pixel counting on the thresholded image is applied to determine if a given segment is “on” or “off”.
  • Detecting the temperature using lm35 sensor: The value of sensor is read using tempsens code and is converted into temperature in degrees by multiplying it with a constant(28/100) and the obtained temperature is pushed into a text file which is later read in main.py file.

  • Recording sound and finding decibel value of the sound: The sound is recorded using microphone with the command 'arecord -D plughw:1,0 -d 10 test.wav' and it's decibel value can be found using the code predict.py.

  • Classifying sound into it's particular class: A machine learning technique called svm is used to classify sounds first one has to leave the microphone recording for 20 mins to 30 mins and later break these into smaller chunks of 10 seconds to obtain the test cases then we have to train the model on the laptop using train.py and deploy it on pi using scp protocol.

  • Register: A site for users to register by providing a temperature threshold and email/phone number to receive alerts is up and running at this site

Users can opt-out from or resume receiving notifications via sending a mail with a specific subject and keyword by clicking on the link available on the site. Python's imaplib is used to read these received mails. The database of users can be updated by running getsheetdata.py. Google Drive and Sheets API and Python's gspread library is used to implement this. References to this is linked down below. The status of the user's notification preference( active or inactive) is also checked and updated in the process.

Full code on Github: getsheetdata.py, receive_mail.py

  • Mailing service for sending out alerts: Python's smtplib and email libraries are used for sending an email alert along with the image taken as an attachment, as and when the temperature detected exceeds the given acceptable range.

  • SMS alerts: TextLocal is the SMS platform used to send out alerts via text messages programmatically. A SMS-bundle is purchased that provides a set of SMS credits that can be used to send messages(whose format follows a registered template created for the need) to any mobile number 24/7. Their documentation provides the details and requirements to do so.

  • Weekly mail: Every week once a mail is sent out showing the status of the server room

Scheduling tasks

To automate the tasks described above crontab is used. It periodically runs the jobs scheduled to it. The jobs basically are making the files in script_files folder run according to the frequency in which we want them to. The instructions for this model are in cron.txt file.

References