Giter Club home page Giter Club logo

bt-mqtt-gateway's Introduction

bt-mqtt-gateway

A simple Python script which provides a Bluetooth to MQTT gateway, easily extensible via custom workers.
See Wiki for more information.

Features

  • Highly extensible via custom workers
  • Data publication via MQTT
  • Configurable topic and payload
  • MQTT authentication support
  • Systemd service
  • Reliable and intuitive
  • Tested on Raspberry Pi Zero W

Supported devices

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

  • python3 >= 3.5
  • pip3

Installation

On a modern Linux system, just a few steps are needed to get the gateway working. The following example shows the installation under Debian/Raspbian:

sudo apt-get install git python3 python3-pip bluetooth bluez
git clone https://github.com/zewelor/bt-mqtt-gateway.git
cd bt-mqtt-gateway
sudo pip3 install -r requirements.txt

Configuration

All worker configuration is done in the file config.yaml. Be sure to change all options for your needs. This file needs to be created first:

cp config.yaml.example config.yaml
vim config.yaml
./gateway.py

Attention: You need to add at least one worker to your configuration. Scan for available Bluetooth devices in your proximity with the command:

sudo hcitool lescan

Execution

A test run is as easy as:

sudo ./gateway.py

Debug output can be displayed using the -d argument:

sudo ./gateway.py -d

Deployment

Continuous background execution can be done using the example Systemd service unit provided.

sudo cp bt-mqtt-gateway.service /etc/systemd/system/
sudo vim /etc/systemd/system/bt-mqtt-gateway.service
sudo systemctl daemon-reload
sudo systemctl start bt-mqtt-gateway
sudo systemctl status bt-mqtt-gateway
sudo systemctl enable bt-mqtt-gateway

Attention: You need to define the absolute path of gateway.py in bt-mqtt-gateway.service.

Testing mqtt: Use mosquitto_sub to print all messages

mosquitto_sub -h localhost -d -t # command also help for me to test MQTT messages

Dynamically Changing the Update Interval To dynamically change the update_interval of a worker, publish a message containing the new interval in seconds at the update_interval topic. Note that the update_interval will revert back to the value in config.yaml when the gateway is restarted. I.E:

# Set a new update interval of 3 minutes
mosquitto_pub -h localhost -t 'miflora/update_interval' -m '150'
# Set a new update interval of 30 seconds
mosquitto_pub -h localhost -t 'mithermometer/update_interval' -m '30'

Custom worker development

Built With

  • Python - The high-level programming language for general-purpose programming

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

bt-mqtt-gateway's People

Contributors

4383 avatar bbbenji avatar bendews avatar cybe avatar elviosebastianelli avatar hobbypunk90 avatar unconfigured avatar zewelor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.