MQTT2MQTTBridge is a project to connect a locally running broker to a central MQTT broker. The project was written and tested in Python 3.
- Adjust the brokers to the addresses you want to use:
broker_source
andbroker_target
- 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")
#client_target.username_pw_set("mqtt", "IoT")
- 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
sudo apt-get install python3
sudo apt-get install python3-pip
sudo pip3 install paho-mqtt
or
sudo apt-get install python3
sudo apt-get install python3-pip
sudo pip3 install -r requirements.txt
python3 bridge.py
python3 bridgeFiltering.py
https://gist.github.com/SeppPenner/6a5a30ebc8f79936fa136c524417761d
See the Changelog.