Skip to content

SoftGuar/rpi_code

Repository files navigation

Raspberry Pi Bluetooth Services

This repository contains a set of services designed to run on a Raspberry Pi 3B, focused on Bluetooth operations with ESP32 beacons. Each folder in this repo represents a systemd service, including its executable Python script and service configuration.

Services Overview

  1. bluetooth_auto_connect
    • Purpose: Automatically pairs and connects the Raspberry Pi to nearby Bluetooth devices (such as ESP32 beacons) using a script called auto_pair_v2.py.
    • Key Files:
      • auto_pair_v2.py: Python script for scanning and pairing.
      • bluetooth_auto_connect.service: Systemd service definition to run the script automatically at boot or on trigger.

  1. bluetooth_auto_restart
    • Purpose: A watchdog service that restarts the Bluetooth interface or services in case of failure or unresponsiveness.
    • Key Files:
      • bluetooth_auto_restart.service: Systemd service file to periodically restart or monitor the Bluetooth stack.

  1. bluetooth_beacons_scanner_v2
    • Purpose: Scans for nearby Bluetooth beacons (likely ESP32 devices broadcasting BLE signals), processes data such as RSSI, and prepares it for logging or transmission.
    • Key Files:
      • bluetooth_beacons_scanner_v2.py: Scanning logic implementation.
      • bluetooth_beacons_scanner_v2.service: Runs the script as a persistent service.

  1. bluetooth_data_sender
    • Purpose: Sends scanned or processed Bluetooth data (like beacon identifiers, RSSI, or timestamps) to a remote server or local endpoint.
    • Key Files:
      • bluetooth_data_sender.py: Sends collected data (likely over HTTP, MQTT, or another protocol).
      • bluetooth_data_sender.service: Service file for enabling it on boot.

  1. esp32_beacon_listener
    • Purpose: Specifically listens for Bluetooth packets or messages from ESP32-based beacons. May include filtering, formatting, or device identification.
    • Key Files:
      • esp32_beacon_listener.py: Script for listening and handling messages from ESP32 beacons.
      • esp32_beacon_listener.service: Service configuration.

General Setup Instructions

๐Ÿ› ๏ธ Prerequisites

  • Raspberry Pi 3B with Raspberry Pi OS (Lite or Full)
  • Python 3
  • bluetooth, bluez, and systemd installed
  • Your user should have permissions to access Bluetooth

๐Ÿ“ Install a Service

For each folder (service), follow these steps:

# 1. Copy the script and service file to appropriate locations
sudo cp your_service.py /usr/local/bin/
sudo cp your_service.service /etc/systemd/system/

# 2. Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable your_service.service
sudo systemctl start your_service.service

# 3. Check status
sudo systemctl status your_service.service

๐Ÿ” Repeat the above for each service (replace your_service with the name of the service file without the .service extension). ๐Ÿ”ง Example:

sudo cp bluetooth_auto_connect/auto_pair_v2.py /usr/local/bin/
sudo cp bluetooth_auto_connect/bluetooth_auto_connect.service /etc/systemd/system/
sudo systemctl enable bluetooth_auto_connect.service
sudo systemctl start bluetooth_auto_connect.service

Notes

  • Make sure your Python scripts have executable permissions:
sudo chmod +x /usr/local/bin/*.py
  • Services are designed to be modular; you can enable only the ones you need.

Let me know if you want the README in a file, or want me to modify or translate it.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages