<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Marcos Jay T. Concon</title>
    <description>The latest articles on DEV Community by Marcos Jay T. Concon (@mcoscon).</description>
    <link>https://dev.to/mcoscon</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F375550%2F40d789ad-0f7e-486b-be0e-20d879de2042.jpeg</url>
      <title>DEV Community: Marcos Jay T. Concon</title>
      <link>https://dev.to/mcoscon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mcoscon"/>
    <language>en</language>
    <item>
      <title>Twilio Hackathon - Owlish</title>
      <dc:creator>Marcos Jay T. Concon</dc:creator>
      <pubDate>Fri, 01 May 2020 06:50:34 +0000</pubDate>
      <link>https://dev.to/mcoscon/twilio-hackathon-owlish-368</link>
      <guid>https://dev.to/mcoscon/twilio-hackathon-owlish-368</guid>
      <description>&lt;h3&gt;
  
  
  THE WHY
&lt;/h3&gt;

&lt;p&gt;I live in a student populated area notoriously known for home burglaries. I've been fortunate enough to have not been targeted, a couple of my friends living close by have lost items worth hundreds of dollars even with guards patrolling the area at certain intervals. Realistically speaking, a lot of these burglaries have happened even with the guards around. I'd like to get out of my room knowing that my belongings are safe and secure. This is why I built...&lt;/p&gt;

&lt;h3&gt;
  
  
  THE WHAT
&lt;/h3&gt;

&lt;p&gt;Owlish - a camera based application that has its eyes set on efficient monitoring, detection and alerting of anyone that's not supposed to be in your dorm while you're away.&lt;/p&gt;

&lt;h4&gt;
  
  
  Hardware components
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/"&gt;Raspberry Pi 3B+&lt;/a&gt; - where the application is run on&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.raspberrypi.org/products/camera-module-v2/"&gt;A Pi Camera Module V2&lt;/a&gt; - the eyes of the application&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.onsemi.com/support/evaluation-board/rsl10-sense-gevk"&gt;RSL10-SENSE-GEVK dev kit&lt;/a&gt; - to activate the application if you're heading out.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Software components
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.twilio.com/docs/whatsapp/tutorial/send-and-receive-media-messages-whatsapp-python"&gt;Twilio WhatsApp&lt;/a&gt; - to alert via text &amp;amp; media message&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/tensorflow/examples/blob/master/lite/examples/object_detection/raspberry_pi/README.md"&gt;TensorFlow lite&lt;/a&gt; - to detect intruders using deep learning for object detection&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://ianharvey.github.io/bluepy-doc/"&gt;Bluepy&lt;/a&gt; - to interface with the RSL10-SENSE&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cloudinary.com/"&gt;Cloudinary&lt;/a&gt; - to host captured image on the cloud&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  DEMO &amp;amp; CODE
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/mcoscon/twilio_hack"&gt;Github Repo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the image below to view the demo on Youtube&lt;br&gt;
&lt;a href="https://youtu.be/idDMZyX_ofI"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kxa7S5yQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://scontent.fbki2-1.fna.fbcdn.net/v/t1.15752-9/95568337_1142028552813612_8274245158485098496_n.jpg%3F_nc_cat%3D109%26_nc_sid%3Db96e70%26_nc_ohc%3D_br9W-wYAlMAX-HR1KW%26_nc_ht%3Dscontent.fbki2-1.fna%26oh%3D55880f16e666bf15c0f3e4933aae0f54%26oe%3D5ED0FAE0" alt="Watch the video"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  THE HOW
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Hardware setup
&lt;/h4&gt;

&lt;p&gt;The Raspberry Pi is &lt;a href="https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up"&gt;setup&lt;/a&gt; with Raspbian OS along with the &lt;a href="https://www.raspberrypi.org/documentation/configuration/camera.md"&gt;configured&lt;/a&gt; camera module. If properly configured, typing the following command below in the terminal should yield an output as shown.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pi@raspberrypi:~ $ vcgencmd get_camera
supported=1 detected=1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Software setup
&lt;/h4&gt;

&lt;h4&gt;
  
  
  i. Configuring TensorFlow lite Object Detection
&lt;/h4&gt;

&lt;p&gt;With Python 3.7 and Git setup, head over to the TensorFlow lite object detection &lt;a href="https://bit.ly/2y0RqfG"&gt;repository&lt;/a&gt; to install it by following the README.md documentation step by step. Once everything is set up nicely, change directory to wherever the detect_picamera.py in the cloned repository is and type the command below to start the inference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pi@raspberrypi:~ $ cd /home/pi/Desktop/twilio_hack/examples/lite/examples/object_detection/raspberry_pi

pi@raspberrypi:~/Desktop/twilio_hack/examples/lite/examples/object_detection/raspberry_pi $ python3 detect_picamera.py   --model /home/pi/Desktop/twilio_hack/detect.tflite   --labels /home/pi/Desktop/twilio_hack/coco_labels.txt

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note: Only Python versions 3.5, 3.6 &amp;amp; 3.7 are the only versions currently supported for the example so make sure you get one of them installed and set as default! Also, make sure to replace the path to the model and labels with your own when typing the command above.&lt;/p&gt;

&lt;p&gt;The model is able to detect 90 classes including apples, people, and phones. A tad disappointed it couldn’t pick up the apple logo on my phone though :(&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hRs5Cx24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/mcoscon/twilio_hack/master/personTFlite.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hRs5Cx24--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/mcoscon/twilio_hack/master/personTFlite.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code snippet below (from detect_picamera.py) is the entry point where we'll capture and locally save the images.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;detect_objects&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="s"&gt;"""Returns a list of detection results, each a dictionary of object info."""&lt;/span&gt;
  &lt;span class="n"&gt;set_input_tensor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="c1"&gt;# Get all output details
&lt;/span&gt;  &lt;span class="n"&gt;boxes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_output_tensor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;classes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_output_tensor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_output_tensor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;get_output_tensor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

  &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="s"&gt;'bounding_box'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;boxes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
          &lt;span class="s"&gt;'class_id'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;classes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
          &lt;span class="s"&gt;'score'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'intruder'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"JPEG"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  ii. Start &amp;amp; stop the application with RSL10-SENSE Bluetooth Low Energy kit
&lt;/h4&gt;

&lt;p&gt;The original mechanism I had in mind to switch the intruder detection application ON when I had left my dorm or switched OFF when I arrived was by checking whether my phone was connected to my dorm’s WiFi network. This is &lt;a href="https://magpi.raspberrypi.org/articles/wifi-detector"&gt;possible&lt;/a&gt; but comes at a cost of an additional USB WiFi dongle which I didn’t have at the time of prototyping. If anyone has a workaround without using an additional WiFI adapter dongle, do share!&lt;/p&gt;

&lt;p&gt;So instead I used an unused RSL10-SENSE Bluetooth Low Energy device (BLE) I had won from a hardware giveaway a year ago. I figured I could do something useful with it in this hackathon. By default, the firmware in the device is configured to be in Deep sleep mode which starts the BLE advertising for 60 seconds after pressing the RESET button. It then goes back to sleep until the button is pressed again. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JWIgVHfh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/mcoscon/twilio_hack/master/BLEdevice.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JWIgVHfh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/mcoscon/twilio_hack/master/BLEdevice.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;According to their specification, in this mode, the replaceable lithium ion cell battery can last over a year without replacement! If you’d like to further customize the firmware, do visit this &lt;a href="https://www.onsemi.com/pub/Collateral/EVBUM2614-D.PDF"&gt;link&lt;/a&gt; for detailed instructions.&lt;/p&gt;

&lt;p&gt;To link the BLE device and the Raspberry Pi, we’d need to check the MAC address of the BLE device. Typing the command in the terminal below, shows all the scanned BLE devices in the area. Make sure the ‘RESET’ button on the BLE device is pressed beforehand for it to start advertising!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pi@raspberrypi:~ $ sudo hcitool lescan
LE Scan ...
4A:A1:30:61:7E:47 (unknown)
4A:24:DF:D4:2D:45 (unknown)
18:54:EA:40:A9:70 (unknown)
6C:EA:92:04:AE:49 (unknown)
60:C0:BF:28:65:C0 HB_BLE_Terminal

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;'HB_BLE_Terminal' is the device name and contains its corresponding mac address. On the PI, I used the &lt;a href="https://ianharvey.github.io/bluepy-doc/"&gt;Bluepy&lt;/a&gt; python module which allows communication with Bluetooth Low Energy devices. Here's the code snippet which scans and checks BLE devices around&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;rsl10_activate&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;scanner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Scanner&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;withDelegate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ScanDelegate&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="n"&gt;devices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scanner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#scan for 3 seconds and repeat
&lt;/span&gt;        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;dev&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;devices&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Device %s (%s), RSSI=%d dB"&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;addr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;addrType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rssi&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;dev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;addr&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"60:c0:bf:28:65:c0"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
               &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"RSL-10 device found"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="n"&gt;activate_status&lt;/span&gt;
               &lt;span class="n"&gt;activate_status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;activate_status&lt;/span&gt;
               &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  iii. Send and Receive Alert Message with Twilio WhatsApp in Python
&lt;/h4&gt;

&lt;p&gt;The &lt;a href="https://www.twilio.com/docs/whatsapp/tutorial/send-and-receive-media-messages-whatsapp-python"&gt;Twilio documentation&lt;/a&gt; is self explanatory and amazingly simple to follow. You’ll need your account_sid and auth_token which can be obtained from the &lt;a href="https://www.twilio.com/console"&gt;Twilio console&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The only issue here is that sending media with the Twilio WhatsApp API isn't possible with local images, rather an image url with HTTP or HTTPS is expected. That means the captured image of the intruder has to be hosted somewhere to access it via URL.&lt;/p&gt;

&lt;p&gt;I used Cloudinary, a cloud platform to easily manage media such as images and videos. Once registered to their generous free plan, their &lt;a href="https://cloudinary.com/documentation/image_upload_api_reference"&gt;Python SDK&lt;/a&gt; for uploading images and retrieving their respective url's was used. Here's a small code snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;cloudinary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;cloud_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"YOUR_CLOUDINARY_NAME"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  
  &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"YOUR_CLOUDINARY_KEY"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  
  &lt;span class="n"&gt;api_secret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"YOUR_CLOUDINARY_SECRET"&lt;/span&gt;  
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;upload_cloudinary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;#We'll need an identifier to upload different intruders
&lt;/span&gt;    &lt;span class="n"&gt;image_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uuid1&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;image_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;cloudinary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uploader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;public_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;image_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#upload the captured image "detected"
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cloudinary&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cloudinary_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_id&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;#access the uploaded image url via its public_id
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Fixing it all up
&lt;/h4&gt;

&lt;p&gt;So once we've got all our individual software components ready, its time to connect them all together. I had to multi-thread my code with the &lt;a href="https://docs.python.org/3/library/threading.html"&gt;threading&lt;/a&gt; and the &lt;a href="https://docs.python.org/3/library/queue.html"&gt;queue&lt;/a&gt; modules as saving, uploading and sending the message over with Cloudinary &amp;amp; Twilio would block &amp;amp; lag the execution of code on camera frame inference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;scan_bluetooth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;rsl10_activate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;inference&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;start_picamera&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;send_message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cloudinary_twilio_send&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;'__main__'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;scan_bluetooth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;#thread that scans for bluetooth low energy devices
&lt;/span&gt;    &lt;span class="n"&gt;inference&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# thread to start the inference once the RSL-10 BLE dev kit is connected
&lt;/span&gt;    &lt;span class="n"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;#thread to check if an intruder is detected and then send the message over
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and finally here's a wild intruder captured by our application! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IG1IZol_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/gDZ_GxH9P4aLMoY8loKFhXBnkXrn65EyPv2DYDng_pr-kEFnQTe0gYDY5kt1r3MW8FIHOlKDIoL5MoWRn13n63Pod5SkjwMaXePqwlAQQ_b800LeZt8SnB_afLRWx_6w0zB3lIBi" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IG1IZol_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/gDZ_GxH9P4aLMoY8loKFhXBnkXrn65EyPv2DYDng_pr-kEFnQTe0gYDY5kt1r3MW8FIHOlKDIoL5MoWRn13n63Pod5SkjwMaXePqwlAQQ_b800LeZt8SnB_afLRWx_6w0zB3lIBi" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Future Improvements &amp;amp; Todo's
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Using a personal smartphone to activate the system when you're away instead of using the RSL10-SENSE-GEVK dev. &lt;/li&gt;
&lt;li&gt;Using Twilio Autopilot for handoff to relevant authorities (guardhouse in my case).&lt;/li&gt;
&lt;li&gt;Boost inference performance with Coral USB accelerator &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion &amp;amp; Acknowledgement
&lt;/h3&gt;

&lt;p&gt;Had a ton being able to connect different technologies together to create this application. Special thanks to Twilio for organizing this hackathon enabling us to share our ideas and projects whilst promoting innovation and collaboration. This submission falls under the Exciting X-Factors Category. &lt;/p&gt;

&lt;p&gt;If you've got any thoughts about my project, please comment below, I'd like to hear them. Stay safe and thanks for reading!&lt;/p&gt;

</description>
      <category>twiliohackathon</category>
      <category>python</category>
      <category>raspberrypi</category>
    </item>
  </channel>
</rss>
