Misty Lessons
  • Misty Lessons
    • 📖Welcome to Misty Lessons
    • 📚Get to know your Misty
    • 📲Connect to Misty
    • 👩‍💻Misty Studio
    • 🖥️Desktop Environment
    • ⬆️Update your Misty
    • 👥Projects
  • Blockly
    • 🧩Blockly Lessons
      • 🤸Lesson 1: Movement
      • 🎶Lesson 2: Voice and Sound
      • 🎭Lesson 3: Expressions
      • 🎥Lesson 4: Robot Cinema
      • 🛠️Lesson 5: Events
      • ☺️Lesson 6: Face recognition
      • 🔢Lesson 7: Variables and Functions
      • 💬Lesson 8: NLP
    • 🏫Blockly projects
  • Blockly Elements
    • ⚛️Misty Blocks
      • Movement
      • Speech
      • Audio
      • Vision
      • Events
      • Miscellaneous
      • NLP
      • System
    • 🔁Basic Blocks
      • Logic
      • Loops
      • Math
      • Text
      • Lists
    • 🅰️Advanced Blocks
      • Variables
      • Functions
  • Python
    • 🐍Python Lessons
      • 🦿Lesson 1: Loco-motion
      • 🤖Lesson 2 : Build a character
      • 🧠Lesson 3: Create memories
      • ⚒️Lesson 4: Event skills
      • 👀Lesson 5: Expand awareness
      • 🔗Lesson 6: Compact code
      • 🗣️Lesson 7: Start a conversation
  • Python Elements
    • 🐸Misty Python API
      • Motion and Mobility
      • Display and LED
      • Record Assets
      • Change/Remove Assets
      • Stream Assets
      • Get Assets
      • Events
      • Sensor Events
      • Speech and NLP
      • Arduino Backpack
      • System
      • Slam
    • 📗Python Definitions
  • Python Projects
    • 🔮MistyGPT
    • 🚨Misty Intruder Alert
    • 📺Conference Assistant
    • 🏷️QR code detector
    • 🕵️‍♂️Misty follow human
    • 👋Misty wave back
    • 🖲️Misty OA
    • 🌐Get weather
    • 🚚Misty Delivery
    • 🫂Motivational Misty
    • 🖼️Misty Museum Guide
    • 🎃Who for Halloween
  • ARDUINO
    • ♾️Arduino Backpack
    • 🦎Arduino
    • 🔧Arduino Lessons
      • 🔌Arduino to Misty
      • ➕Misty to Arduino
  • ARDUINO PROJECTS
    • 🛠️Misty Tracker
    • 🦾Misty Arm
  • Community Projects
    • 🌤️Misty weather forecaster
  • HARDWARE EXTENSION
    • ⚙️Arduino breadboard support
    • 🦾Misty arm
    • 🥤Tin holder
  • Resource Database
    • 📁Image files
    • 📁Audio files
    • 📁Languages
    • 📁Known objects
    • 📁NLP Actions
    • 📁Action Commands
    • 📁ChatGPT PDF files
    • 📁AR Tag Dictionary
    • ⚙️Technical Specifications
Powered by GitBook
On this page
  1. Python Projects

Misty Intruder Alert

Last updated 8 months ago

In this project you can learn how to have Misty trigger an intruder alert if she doesn't recognize a person and send a message to your phone.

If Misty detects a face that's not stored in her memory, she will access your WhatsApp web and send a text message to your phone number saying: "Intruder!". If she does recognize the person, she will send the message "person_name is home!". Before executing the code, open and log in with your phone number.

We will utilize the Python pywhatkit library for this purpose, which enables message sending on WhatsApp in a semi-automatic way. To install pywhatkit, use the following command line in your terminal: "pip install pywhatkit". Press enter and wait for the installation of all the required packages. Another required action prior to using Whatsapp is to train Misty on the faces you want her to recognize as friends (misty studio Explore>Vision>Train faces) and upload all the files you'll run in the code, both images and audio files (misty studio Explore>Expressions>Upload audio files or Upload images or videos).

Note: Sometimes the WhatsApp message might not be sent before the website closes. In that case, try running the code again. To reset Misty after running the code, you can access its Misty Studio and in the wizard section, click on the "Body Reset" action.

It can only be used in a desktop environment and is not compatible with the Misty Studio Python Interface, so before initiating, ensure you have all the necessary resources for the task.

from mistyPy.Robot import Robot
from mistyPy.Events import Events
import time
import pywhatkit
from datetime import datetime

misty = Robot("YOUR_ROBOT_IP_ADDRESS") #your Robot IP Address

def send_whatsapp_message(MyNumber, MyTextMessage): #function to send a message on WhatsApp
    myobj = datetime.now()
    pywhatkit.sendwhatmsg(MyNumber, MyTextMessage, myobj.hour, myobj.minute + 1, 10, True)

MyNumber = "___" #your phone number (don't forget to include the country code)

misty.start_face_recognition()

def recognized(data):
    print(data)  
    if data["message"]["label"] == 'unknown person': #intruder
        misty.display_image("e_Anger.jpg")
        misty.transition_led(255, 0, 0, 0, 0, 255, "Blink", 100)
        misty.move_arms(-80, -80)
        misty.speak("Intruder! Intruder!")
        misty.play_audio("Police Siren Sound Effect.mp3", 50)
        MyTextMessage = "Intruder!"
        send_whatsapp_message(MyNumber, MyTextMessage)
    else :
        misty.display_image("e_Joy2.jpg") #familiar face
        misty.change_led(0, 255, 0)
        for i in range (2):
            misty.move_arms(80, -80, 50, 50)
            time.sleep(1)
            misty.move_arms(80, 0, 50, 50)
            time.sleep(1)
        MyTextMessage = data["message"]["label"] + " is home!"
        send_whatsapp_message(MyNumber, MyTextMessage)


misty.register_event(event_name='face_recognition_event', event_type=Events.FaceRecognition, callback_function=recognized, keep_alive=False)
misty.keep_alive()

You can use this link to access the Police Siren Sound Effect.mp3 file

🚨
https://web.whatsapp.com/
https://youtu.be/HKieGUH9pzg