Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/groove-x/mqtt_bridge
mqtt_bridge provides a functionality to bridge between ROS and MQTT in bidirectional
https://github.com/groove-x/mqtt_bridge
Last synced: about 2 months ago
JSON representation
mqtt_bridge provides a functionality to bridge between ROS and MQTT in bidirectional
- Host: GitHub
- URL: https://github.com/groove-x/mqtt_bridge
- Owner: groove-x
- License: mit
- Created: 2016-12-02T10:51:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-10T10:06:31.000Z (over 1 year ago)
- Last Synced: 2024-02-04T16:44:18.707Z (5 months ago)
- Language: Python
- Size: 56.6 KB
- Stars: 151
- Watchers: 16
- Forks: 135
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.rst
- License: LICENSE.txt
Lists
- awesome-robotic-tooling - mqtt_bridge - Provides a functionality to bridge between ROS and MQTT in bidirectional. (Network and Middleware / Real-Time Kernel)
- awesome-robotic-tooling - mqtt_bridge - Provides a functionality to bridge between ROS and MQTT in bidirectional. (Network and Middleware / Real-Time Kernel)
README
# mqtt_bridge
[![CircleCI](https://circleci.com/gh/groove-x/mqtt_bridge.svg?style=svg)](https://circleci.com/gh/groove-x/mqtt_bridge)
mqtt_bridge provides a functionality to bridge between ROS and MQTT in bidirectional.
*mqtt_bridge is not actively maintained now. Feel free to check out [mqtt_client](https://github.com/ika-rwth-aachen/mqtt_client), a high-performance C++ ROS nodelet with recent development!*
## Principle
`mqtt_bridge` uses ROS message as its protocol. Messages from ROS are serialized by json (or messagepack) for MQTT, and messages from MQTT are deserialized for ROS topic. So MQTT messages should be ROS message compatible. (We use `rosbridge_library.internal.message_conversion` for message conversion.)
This limitation can be overcome by defining custom bridge class, though.
## Demo
### Prerequisites
```
$ sudo apt install python3-pip
$ sudo apt install ros-noetic-rosbridge-library
$ sudo apt install mosquitto mosquitto-clients
```### Install python modules
```bash
$ pip3 install -r requirements.txt
```### launch node
``` bash
$ roslaunch mqtt_bridge demo.launch
```Publish to `/ping`,
```
$ rostopic pub /ping std_msgs/Bool "data: true"
```and see response to `/pong`.
```
$ rostopic echo /pong
data: True
---
```Publish "hello" to `/echo`,
```
$ rostopic pub /echo std_msgs/String "data: 'hello'"
```and see response to `/back`.
```
$ rostopic echo /back
data: hello
---
```You can also see MQTT messages using `mosquitto_sub`
```
$ mosquitto_sub -t '#'
```## Usage
parameter file (config.yaml):
``` yaml
mqtt:
client:
protocol: 4 # MQTTv311
connection:
host: localhost
port: 1883
keepalive: 60
bridge:
# ping pong
- factory: mqtt_bridge.bridge:RosToMqttBridge
msg_type: std_msgs.msg:Bool
topic_from: /ping
topic_to: ping
- factory: mqtt_bridge.bridge:MqttToRosBridge
msg_type: std_msgs.msg:Bool
topic_from: ping
topic_to: /pong
```you can use any msg types like `sensor_msgs.msg:Imu`.
launch file:
``` xml
```
## Configuration
### mqtt
Parameters under `mqtt` section are used for creating paho's `mqtt.Client` and its configuration.
#### subsections
* `client`: used for `mqtt.Client` constructor
* `tls`: used for tls configuration
* `account`: used for username and password configuration
* `message`: used for MQTT message configuration
* `userdata`: used for MQTT userdata configuration
* `will`: used for MQTT's will configurationSee `mqtt_bridge.mqtt_client` for detail.
### mqtt private path
If `mqtt/private_path` parameter is set, leading `~/` in MQTT topic path will be replaced by this value. For example, if `mqtt/pivate_path` is set as "device/001", MQTT path "~/value" will be converted to "device/001/value".
### serializer and deserializer
`mqtt_bridge` uses `msgpack` as a serializer by default. But you can also configure other serializers. For example, if you want to use json for serialization, add following configuration.
``` yaml
serializer: json:dumps
deserializer: json:loads
```### bridges
You can list ROS <--> MQTT tranfer specifications in following format.
``` yaml
bridge:
# ping pong
- factory: mqtt_bridge.bridge:RosToMqttBridge
msg_type: std_msgs.msg:Bool
topic_from: /ping
topic_to: ping
- factory: mqtt_bridge.bridge:MqttToRosBridge
msg_type: std_msgs.msg:Bool
topic_from: ping
topic_to: /pong
```* `factory`: bridge class for transfering message from ROS to MQTT, and vise versa.
* `msg_type`: ROS Message type transfering through the bridge.
* `topic_from`: topic incoming from (ROS or MQTT)
* `topic_to`: topic outgoing to (ROS or MQTT)Also, you can create custom bridge class by inheriting `mqtt_brige.bridge.Bridge`.
## License
This software is released under the MIT License, see LICENSE.txt.