Skip to content
This repository was archived by the owner on Jun 16, 2024. It is now read-only.
Diogo Lobo do Souto Ferreira edited this page Jun 13, 2024 · 4 revisions

1. Group 10 - Smart Mouse Trap Project Wiki

2. Table of Contents


3. Overview

This project is an intelligent mouse trap system that utilizes Raspberry Pi, Arduino, and a mobile app to detect mice, notify the owner, and allow remote control of the trap. The system integrates various components to ensure smooth operation and real-time communication.

4. Components

Broker

Location: src/broker.py

Description: The broker component manages the communication between different parts of the system. It listens for connections, handles incoming messages, and routes them to the appropriate services.

  • Key Functions:

    • server(service): Starts the server for a specified service.
    • message_control(service, msg_flag, msg_content): Handles messages based on their flag.
    • stop(service, client_socket): Ensures all endpoints are online.
    • play(service, client_socket): Syncs all endpoints.
    • send(service, client_socket, msg_flag, msg_content): Sends encoded messages.
    • recv_all(service, client_socket, length): Receives messages from a socket.
    • toggleOffline(service): Sets the service status to offline.
    • toggleClose(service): Closes the communication socket.
  • Usage:

    python broker.py

Field Brain

Location: src/field_brain.py

Description: The field brain is responsible for communicating with the Arduino and managing local operations such as sending commands and receiving sensor data.

  • Key Functions:

    • client(service): Manages the main client functionality.
    • recv(service, msg_flag, msg_content): Handles received messages.
    • arduino_client(service): Manages communication with the Arduino.
    • message_control(service, serial_socket, msg_flag, msg_content): Controls behavior based on received messages.
    • play(service): Syncs the client with the server.
    • send(service, msg_flag, msg_content): Sends encoded messages.
    • recv_all(service, length): Receives messages from a socket.
  • Usage:

    python field_brain.py

Photos

Location: src/photos.py

Description: This module handles photo capture using the Raspberry Pi camera. It continuously captures photos at set intervals.

  • Key Functions:

    • photos_control(service): Main functionality for capturing photos.
    • main(): Starts the photo capture thread.
  • Usage:

    python photos.py

Mobile App

Location: src/main.py

Description: The mobile app provides a user interface for interacting with the mouse trap system. It allows the user to send commands and view the status of the trap.

  • Key Functions:

    • build(): Builds the GUI.
    • connect(text): Connects to the specified IP address.
    • start_clock(): Starts the clock for GUI updates.
    • updateGUI(*args): Updates the GUI with current information.
    • sendOpenR(): Sends an open request.
    • sendCloseR(): Sends a close request.
    • sendPhotoR(): Sends a photo request.
    • disconnect(): Disconnects the app.
    • client(service): Manages the main client functionality.
    • recv(service, msg_flag, msg_content): Handles received messages.
    • play(service): Syncs the client with the server.
    • send(service, msg_flag, msg_content): Sends encoded messages.
    • recv_all(service, length): Receives messages from a socket.
  • Usage:

    python main.py

Field Muscle (Arduino)

Location: src/mouse_trap_controller/field_muscle.ino

Description: The field_muscle.ino Arduino code controls the servo motor and sensor.

  • Key Functions:

    • setup(): Initializes the Arduino.
    • loop(): Main loop function.
    • actuateServo(command): Controls the servo motor.
    • getCurrentDistance(): Gets the current distance from the sensor.
  • Usage: Upload the field_muscle.ino code to the Arduino.

5. Setup

Prerequisites

  • Raspberry Pi with Python installed.
  • Arduino with the necessary libraries.
  • Network setup to allow communication between the devices.

Installation

  1. Clone the repository.

  2. Install the required Python libraries.

  3. Upload the Arduino code (field_muscle.ino) to the Arduino.

6. Running the Project

  1. Start the broker:

    python broker.py
  2. Start the field brain:

    python field_brain.py
  3. Start the photo capture service:

    python photos.py
  4. Start the mobile application:

    python main.py

7. Troubleshooting

  • Connection Issues: Ensure all devices are on the same network and the IP addresses are correctly set.
  • Arduino Communication: Check the serial connection and ensure the correct port is specified.