Coder Social home page Coder Social logo

nstoykov / mqtt2postgresbridge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sepppenner/mqtt2postgresbridge

0.0 1.0 0.0 20 KB

MQTT2PostgresBridge is a project to connect a locally running broker to a Postgres database and store the messages in a database table. The project was written and tested in Python 3.

License: MIT License

PLpgSQL 9.87% Python 89.13% Shell 0.99%

mqtt2postgresbridge's Introduction

MQTT2PostgresBridge

MQTT2PostgresBridge is a project to connect a locally running broker to a Postgres database and store the messages in a database table. The project was written and tested in Python 3.

Build status GitHub issues GitHub forks GitHub stars License: MIT Known Vulnerabilities

Adjust your settings:

  • Adjust the broker to the address you want to use: broker_source
  • Add your custom filters to filterMessage() if you want to filter messages
  • Adjust your credentials (uncomment if anonymous):
client_source.username_pw_set("mqtt", "IoT")
  • Adjust your PostgreSQL credentials:
DatabaseHostName = 'YourHost'
DatabaseUserName = 'YourUser'
DatabasePassword = 'YourPassword'
DatabasePort = 5432
  • Run the script SetupDatabase.sql on your database to setup the database correctly

  • Add filters to the bridging like described in the bridgeFiltering.py file if needed:

def filterMessage(payload, topic, qos):
	"Filters the messages depending on the configuration for the attributes payload, topic and QoS. 'True' means that the message is not forwarded."
	# Examples below:
	if(payload == "10 %"):
		print('Filtered: payload == "10 %"')
		return True
	if(topic == "humidity" and qos == 0):
		print('Filtered: topic == "humidity" and qos == 0')
		return True
	if(topic == "temperature" or qos == 2):
		print('Filtered: topic == "temperature" or qos == 2')
		return True
	#Add your filters here

Setup on the Raspberry Pi

sudo apt-get install python3
sudo apt-get install python3-pip
sudo pip3 install paho-mqtt
sudo pip3 install psycopg2

or

sudo apt-get install python3
sudo apt-get install python3-pip
sudo pip3 install -r requirements.txt

Running the programms:

python3 bridge.py
python3 bridgeFiltering.py

Installing the latest version of Python (Currently 3.7.4) on the Raspberry Pi:

https://gist.github.com/SeppPenner/6a5a30ebc8f79936fa136c524417761d

Paho MQTT client documentation

Postgres client documentation

See also

Change history

See the Changelog.

mqtt2postgresbridge's People

Contributors

sepppenner avatar

Watchers

James Cloos 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.