Git Product home page Git Product logo

mqtt_bridge's Introduction

mqtt_bridge

CircleCI

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, 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

$ pip3 install -r requirements.txt

launch node

$ 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):

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:

<launch>
  <node name="mqtt_bridge" pkg="mqtt_bridge" type="mqtt_bridge_node.py" output="screen">
    <rosparam file="/path/to/config.yaml" command="load" />
  </node>
</launch>

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 configuration

See 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.

serializer: json:dumps
deserializer: json:loads

bridges

You can list ROS <--> MQTT tranfer specifications in following format.

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.

mqtt_bridge's People

Contributors

5tan avatar kapilpython avatar ledmonster avatar marc-hanheide avatar mayershoc avatar ralbra avatar roboterbastler avatar shin-nn avatar tobias-fischer avatar yuma-m avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mqtt_bridge's Issues

Error in: roslaunch mqtt_bridge demo.launch

When test mqtt_bridge, it says: ERROR: parameter [/mqtt_bridge] is not set. Please help.

xx@ubuntu:~$ roslaunch mqtt_bridge demo.launch
... logging to /home/xx/.ros/log/17af3876-2b3e-11e8-ba85-08002773ca37/roslaunch-ubuntu-9564.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://ubuntu:34693/

SUMMARY

PARAMETERS

  • /mqtt_bridge/bridge: [{'topic_from': '...
  • /mqtt_bridge/deserializer: msgpack:loads
  • /mqtt_bridge/mqtt/client/protocol: 4
  • /mqtt_bridge/mqtt/connection/host: localhost
  • /mqtt_bridge/mqtt/connection/keepalive: 60
  • /mqtt_bridge/mqtt/connection/port: 1883
  • /mqtt_bridge/mqtt/private_path: device/001
  • /mqtt_bridge/serializer: msgpack:dumps
  • /rosdistro: indigo
  • /rosversion: 1.11.21

NODES
/
mqtt_bridge (mqtt_bridge/mqtt_bridge_node.py)

auto-starting new master
process[master]: started with pid [9575]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 17af3876-2b3e-11e8-ba85-08002773ca37
process[rosout-1]: started with pid [9588]
started core service [/rosout]
running rosparam delete /mqtt_bridge/
ERROR: parameter [/mqtt_bridge] is not set
process[mqtt_bridge-2]: started with pid [9610]
[Errno 32] Broken pipe
[INFO] [WallTime: 1521440634.096355] MQTT disconnected
[INFO] [WallTime: 1521440635.110383] MQTT disconnected
[INFO] [WallTime: 1521440637.112733] MQTT disconnected
[INFO] [WallTime: 1521440641.116993] MQTT disconnected
[INFO] [WallTime: 1521440649.120404] MQTT disconnected

python3 compatibility (basestring)

Had to substitute basestring with str in app.py and bridge.py to make it work with python3.
I could push the commit if you let me.
Thanks.

LWT

When I shut down my machine AWS Shadow doesn't publish "disconnect" message.
Is there an implementation for LWT? (Last Will and Testament)

mqtt_bridge install

Hello,

I'm having currently issues while installing mqtt_bridge... Following the readme, I installed all dependencies referred, but after downloading the folder and running:

roslaunch mqtt_bridge demo.launch

I get the following output:
[demo.launch] is neither a launch file in package [mqtt_bridge] nor is [mqtt_bridge] a launch file name

Can anyone help on this?

Best regards,
BV

Error in: roslaunch mqtt_bridge demo.launch

Hi,
I have faced with the following errors.
Please, guide me.
Thanks.

sami@sami-Vostro-1520:~/mqtt$ roslaunch mqtt_bridge demo.launch
... logging to /home/sami/.ros/log/3a2302a4-147b-11e8-ba87-904ce5b24de1/roslaunch-sami-Vostro-1520-6658.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://sami-Vostro-1520:36279/

SUMMARY

PARAMETERS

  • /mqtt_bridge/bridge: [{'topic_from': '...
  • /mqtt_bridge/deserializer: msgpack:loads
  • /mqtt_bridge/mqtt/client/protocol: 4
  • /mqtt_bridge/mqtt/connection/host: localhost
  • /mqtt_bridge/mqtt/connection/keepalive: 60
  • /mqtt_bridge/mqtt/connection/port: 1883
  • /mqtt_bridge/mqtt/private_path: device/001
  • /mqtt_bridge/serializer: msgpack:dumps
  • /rosdistro: indigo
  • /rosversion: 1.11.21

NODES
/
mqtt_bridge (mqtt_bridge/mqtt_bridge_node.py)

ROS_MASTER_URI=http://localhost:11311

core service [/rosout] found
running rosparam delete /mqtt_bridge/
process[mqtt_bridge-1]: started with pid [6681]
Traceback (most recent call last):
File "/home/sami/mqtt/src/mqtt_bridge/scripts/mqtt_bridge_node.py", line 5, in
from mqtt_bridge.app import mqtt_bridge_node
File "/home/sami/mqtt/src/mqtt_bridge/src/mqtt_bridge/app.py", line 4, in
import inject
ImportError: No module named inject
[mqtt_bridge-1] process has died [pid 6681, exit code 1, cmd /home/sami/mqtt/src/mqtt_bridge/scripts/mqtt_bridge_node.py __name:=mqtt_bridge __log:=/home/sami/.ros/log/3a2302a4-147b-11e8-ba87-904ce5b24de1/mqtt_bridge-1.log].
log file: /home/sami/.ros/log/3a2302a4-147b-11e8-ba87-904ce5b24de1/mqtt_bridge-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done

roslaunch Error

I have checked reqiurements.txt successfully, and only remained launch the demo.launch file.

conceptbug95@ubuntu:~$ roslaunch mqtt_bridge demo.launch
... logging to /home/conceptbug95/.ros/log/f08b33d8-eb5e-11ea-bbdb-001c42b01667/roslaunch-ubuntu-32640.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://localhost:36857/

SUMMARY
========

PARAMETERS
 * /mqtt_bridge/bridge: [{'topic_from': '...
 * /mqtt_bridge/deserializer: msgpack:loads
 * /mqtt_bridge/mqtt/client/protocol: 4
 * /mqtt_bridge/mqtt/connection/host: 10.0.0.254
 * /mqtt_bridge/mqtt/connection/keepalive: 60
 * /mqtt_bridge/mqtt/connection/port: 1883
 * /mqtt_bridge/serializer: msgpack:dumps
 * /rosdistro: melodic
 * /rosversion: 1.14.9

NODES
  /
    mqtt_bridge (mqtt_bridge/mqtt_bridge_node.py)

ROS_MASTER_URI=http://localhost:11311

running rosparam delete /mqtt_bridge/
process[mqtt_bridge-1]: started with pid [32660]
Traceback (most recent call last):
  File "/home/conceptbug95/catkin_ws/src/mqtt_bridge/scripts/mqtt_bridge_node.py", line 5, in <module>
    from mqtt_bridge.app import mqtt_bridge_node
  File "/home/conceptbug95/catkin_ws/src/mqtt_bridge/src/mqtt_bridge/app.py", line 8, in <module>
    from .bridge import create_bridge
  File "/home/conceptbug95/catkin_ws/src/mqtt_bridge/src/mqtt_bridge/bridge.py", line 10, in <module>
    from .util import lookup_object, extract_values, populate_instance
  File "/home/conceptbug95/catkin_ws/src/mqtt_bridge/src/mqtt_bridge/util.py", line 5, in <module>
    from rosbridge_library.internal import message_conversion
  File "/home/conceptbug95/catkin_ws/src/rosbridge_suite/rosbridge_library/src/rosbridge_library/internal/message_conversion.py", line 45, in <module>
    from rosbridge_library.util import string_types, bson
  File "/home/conceptbug95/catkin_ws/src/rosbridge_suite/rosbridge_library/src/rosbridge_library/util/__init__.py", line 24, in <module>
    "BSON installation does not support all necessary features. "
Exception: BSON installation does not support all necessary features. Please use the MongoDB BSON implementation. See: https://github.com/RobotWebTools/rosbridge_suite/issues/198
[mqtt_bridge-1] process has died [pid 32660, exit code 1, cmd /home/conceptbug95/catkin_ws/src/mqtt_bridge/scripts/mqtt_bridge_node.py __name:=mqtt_bridge __log:=/home/conceptbug95/.ros/log/f08b33d8-eb5e-11ea-bbdb-001c42b01667/mqtt_bridge-1.log].
log file: /home/conceptbug95/.ros/log/f08b33d8-eb5e-11ea-bbdb-001c42b01667/mqtt_bridge-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done

But I don't know how to fix this error.
Even there are no error codes or error messages.

PLEASE guide me how to solve this problem if you know how to do.

About mqtt_ Bridge is linked for a long time and cannot receive data

A few days after the mqttbridge link, the ROS client cannot receive data from the mqtt server, but the device can receive instructions sent to the mqtt server. At this point, restart mqttbridge and you can receive it again. Why? Is there a link timeout operation in mqttbridge that does not receive data?

ros2 subscribe bug

Hi,

I think there is a bug/mistake in the Ros2 branch; while ros2 topics are subscribed to I don't think mqtt topics are subscribed because the initialization of the bridges happens before the mqtt client is connected so the subscription message is never sent. See lines 74 to 80 of https://github.com/groove-x/mqtt_bridge/blob/ros2/mqtt_bridge/app.py:

    # configure bridges
    bridges = []
    for bridge_args in bridge_params:
        bridges.append(create_bridge(**bridge_args,ros_node=mqtt_node))

    # start MQTT loop
    mqtt_client.loop_start()

This can be fixed by moving the last 2 lines to above line 74. Am I missing something or does anyone else agree that this is a bug/issue?

Sending messages from MQTT

Hi just a question since I could not find anything about it in here.
How would I go about sending a message from MQTT to a ROS-topic ? What format is expected ?

I tried something along the lines of

mqtt pub -t command -m "{'data':  'move'}" 

The data printed in

mqtt sub -t command --jsonOutput

looked exactly the same as the data received from rostopic pub.

I set up the bridge following the tutorial precisely, so that should not be an issue.

I also tried sending data from python

import paho.mqtt.publish as publish
import json
publish.single("command", json.dumps({"data": "move next"}))
publish.single("command", "move next"}))

and Node-Red

[{"id":"a6fe74db.61f648","type":"inject","z":"ffe42276.7efb1","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"\"move next\"","payloadType":"str","x":790,"y":500,"wires":[["61ab1db.5bc4164"]]}]

but nothing seemed to work.

So how would I do that ?

Regards

Why don't you use rosdep?

In your description, you use requirements.txt for solving dependency.
However, ros has it's own dependency solving system called rosdep.
Why do you use requirements.txt?

QUESTION : Is it possible to have multiple nodes ?

Hi,

First of all, I want to thank the developpers who made this. Awesome functionnality and works very well.

My question is :
For example, I have two wifi connected robots which I want to use mqtt_bridge with. For now, everything works for the single node that I use, but I wonder if it is possible to have 2 nodes connected to ROS with mqtt_bridge?

Regards,
ogensyts

msgpack not working with AWS

found that msgpack would fail when sending data to topics using AWS and mosquito client locally.
I had to change the code to

#msg_dict = self._deserialize(mqtt_msg.payload)
msg_dict = json.loads(mqtt_msg.payload)

in _create_ros_message(self, mqtt_msg):

Have you seen this?
I am willing to do a PR on this

Encoding problem on Ubuntu 20.04 ROS Noetic

Hi,
I recently moved my project to Ubuntu 20.04 and ROS Noetic from 18.04 and Melodic.
I installed on the new environment the ros-noetic-mqtt-bridge executing the same exacly code, but I'm experiencing a very weird problem. It looks like the bridge is publishing, on my mosquitto mqtt broker, messages with a wrong encoding despite all other publications coming from the classic mosquitto client are correctly encoded.

I tried with no luck to add the serialize/deserialize params in config:

mqtt:
  serializer:
    json: dumps
  deserializer:
    json: loads
  client:
    protocol: 4      # MQTTv311

There are other parameters allowed on serializer that helps me specifying the published message encoding?

ROS can't read the json file

Hello,

I am trying to communicate a non ros-program to ros kinetic via MQTT Broker. I use your node and already configurated it properly. When I launch roslaunch mqtt_bridge demo.launch it runs very well without any problem. As soon I start the communication from a non ros-programm to ros, the launch file throw this error message multiple times "Message type std_msgs/String does not have a field position".

The message program looks like this:

import json
import paho.mqtt.client as mqtt
import time

client = mqtt.Client()
client.connect(192.168.1.111, 1883, 60)
msg = {
    'position': [
        {
            'x_value' : '5',
            'y_value' : '2.6'
        }
    ]
 }
 json_msg=json.dumps(msg)
 channel = "ZIRP/FTS/N1/Pos"
 client = mqttClient
 client.publish(channel, json_msg)

The code is written in python and run in a non ros PC. The code doesn't throw any problem and the mqtt broker receive the message successfully. The sent data structure is string and probably in array but I'm not sure.

the mqtt_bridge configuration:

 mqtt:
    client:
      protocol: 4      # MQTTv311
    connection:
      host: 192.168.1.101
      port: 1883
      keepalive: 60
    private_path: device/001
bridge:
   # echo back
   - factory: mqtt_bridge.bridge:RosToMqttBridge
      msg_type: std_msgs.msg:String
      topic_from: /echo
      topic_to: ZIRP/FTS/N1/Pos
   - factory: mqtt_bridge.bridge:MqttToRosBridge
     msg_type: std_msgs.msg:String
     topic_from: ZIRP/FTS/N1/Pos
     topic_to: /echo

Any idea why ros can't read the message?

Convert ROS service to MQTT

First of all, thanks to the developers for this great work. It provides a useful bridge between ROS topic and MQTT.

I have no problem compiling and running the demo. But I do have a question about conversion between ROS service and MQTT.
There are two methods in my mind:

  1. convert a ROS service to a topic and set its QoS to be 2

or

  1. convert a ROS service to two topics bidirectionally, and use their member variables to reproduce "request - response" logic.
    Considering the network status is unstable, and I don't want a service being called twice after reconnecting, such as reset an actuator. What is the best practice? Do you have any suggestion?

Thanks.

How to turn off serialization

hi, I didn't find the option to turn off serialization when I checked the readme, is there a feature for this, thanks

Error pip3 install dev-requirements.txt

Hi I'm having an issue with pip installing the dev-requirements.txt.

Screenshot from 2022-11-16 10-59-26

My ROS Distro is Melodic and My laptop is running Bionic.
I have another PC that can utilise the Mqtt_bridge on Noetic and Focal.

While looking through pas issues, I came across an error for installing injection and have tried that simulation but it does not resolve this issue.

Thanks for your help!

Unable to install inject

Hello,

I'm trying to use this package for my Master's project work.

I have Ubuntu 20.4 with ROS noetic python3 as well as Ubuntu 16 with ROS kinetic python 2.7.

On noetic, I was able to install all the libraries and run mqtt_bridge successfully, but the codes in app.py and bridge.py don't support python3 language. For example, it doesn't take the base string data type. I tried using str instead-but in line 77 of bridge.py its causing me encoding errors. Do you have any workaround for this? Or m I missing something?

On kinetic, I m unable to install the inject python module. I ran pip2 as well as pip with both suggestions given in this forum.
Error: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-JEKfkg/inject/
It seems the inject python module doesn't support python2 now and only python3 is working with it.

Any suggestions or help is welcome. I tried lots of things. Thank you in advance.

mqtt bridge demo launch running error

Hello
I tried to run demo in my environment.
ubuntu 16.04
kinetic
but error shows as below.

does anyone could help?

thanks in advance!

chengbo@chengbo-VirtualBox:~/mqtt_bridge-master/src/mqtt_bridge$ roslaunch mqtt_bridge demo.launch
... logging to /home/chengbo/.ros/log/61d02a62-1633-11ec-8345-080027c3ceaa/roslaunch-chengbo-VirtualBox-10905.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

/opt/ros/kinetic/lib/python2.7/dist-packages/roslaunch/loader.py:409: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
data = yaml.load(text)
started roslaunch server http://chengbo-VirtualBox:42587/

SUMMARY

PARAMETERS

  • /mqtt_bridge/bridge: [{'topic_from': '...
  • /mqtt_bridge/mqtt/client/protocol: 4
  • /mqtt_bridge/mqtt/connection/host: localhost
  • /mqtt_bridge/mqtt/connection/keepalive: 60
  • /mqtt_bridge/mqtt/connection/port: 1883
  • /mqtt_bridge/mqtt/private_path: device/001
  • /rosdistro: kinetic
  • /rosversion: 1.12.17

NODES
/
mqtt_bridge (mqtt_bridge/mqtt_bridge_node.py)

ROS_MASTER_URI=http://localhost:11311

process[mqtt_bridge-1]: started with pid [11011]
Traceback (most recent call last):
File "/home/chengbo/mqtt_bridge-master/src/mqtt_bridge/scripts/mqtt_bridge_node.py", line 4, in
from mqtt_bridge.app import mqtt_bridge_node
File "/home/chengbo/mqtt_bridge-master/src/mqtt_bridge/src/mqtt_bridge/app.py", line 1, in
import inject
File "/home/chengbo/.local/lib/python3.5/site-packages/inject/init.py", line 121
_bindings: Dict[Binding, Constructor]
^
SyntaxError: invalid syntax
[mqtt_bridge-1] process has died [pid 11011, exit code 1, cmd /home/chengbo/mqtt_bridge-master/src/mqtt_bridge/scripts/mqtt_bridge_node.py __name:=mqtt_bridge __log:=/home/chengbo/.ros/log/61d02a62-1633-11ec-8345-080027c3ceaa/mqtt_bridge-1.log].
log file: /home/chengbo/.ros/log/61d02a62-1633-11ec-8345-080027c3ceaa/mqtt_bridge-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done

when i input roslaunch mqtt_bridge demo.launch

When I run roslaunch mqtt_bridge demo.launch in docker, he prompts me:
RLException: [demo.launch] is neither a launch file in package [mqtt_bridge] nor is [mqtt_bridge] a launch file name
The traceback for the exception was written to the log file

The docker is ros:noetic
and I setup ros-noetic-rosbridge-suite,the roslaunch rosbridge_server rosbridge_websocket.launch is working
what should I do?

Im running $roslaunch mqtt_bridge demo.launch and i get a ton of errors. PLEASE HELP

$roslaunch mqtt_bridge demo.launch
... logging to /home/oshikurou/.ros/log/36ce37ac-b820-11ec-bac1-853923bc7fa7/roslaunch-oshikurou-VirtualBox-12740.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://oshikurou-VirtualBox:35693/

SUMMARY

PARAMETERS

  • /mqtt_bridge/bridge: [{'factory': 'mqt...
  • /mqtt_bridge/mqtt/client/protocol: 4
  • /mqtt_bridge/mqtt/connection/host: localhost
  • /mqtt_bridge/mqtt/connection/keepalive: 60
  • /mqtt_bridge/mqtt/connection/port: 1883
  • /mqtt_bridge/mqtt/private_path: device/001
  • /rosdistro: noetic
  • /rosversion: 1.15.14

NODES
/
mqtt_bridge (mqtt_bridge/mqtt_bridge_node.py)

ROS_MASTER_URI=http://localhost:11311

process[mqtt_bridge-1]: started with pid [12754]
Traceback (most recent call last):
File "/opt/ros/noetic/lib/python3/dist-packages/rosbridge_library/util/init.py", line 21, in
bson.BSON
AttributeError: module 'bson' has no attribute 'BSON'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/oshikurou/catkin_ws/src/mqtt_bridge/scripts/mqtt_bridge_node.py", line 4, in
from mqtt_bridge.app import mqtt_bridge_node
File "/opt/ros/noetic/lib/python3/dist-packages/mqtt_bridge/app.py", line 5, in
from .bridge import create_bridge
File "/opt/ros/noetic/lib/python3/dist-packages/mqtt_bridge/bridge.py", line 8, in
from .util import lookup_object, extract_values, populate_instance
File "/opt/ros/noetic/lib/python3/dist-packages/mqtt_bridge/util.py", line 5, in
from rosbridge_library.internal import message_conversion
File "/opt/ros/noetic/lib/python3/dist-packages/rosbridge_library/internal/message_conversion.py", line 45, in
from rosbridge_library.util import string_types, bson
File "/opt/ros/noetic/lib/python3/dist-packages/rosbridge_library/util/init.py", line 23, in
raise Exception(
Exception: BSON installation does not support all necessary features. Please use the MongoDB BSON implementation. See: RobotWebTools/rosbridge_suite#198
[mqtt_bridge-1] process has died [pid 12754, exit code 1, cmd /home/oshikurou/catkin_ws/src/mqtt_bridge/scripts/mqtt_bridge_node.py __name:=mqtt_bridge __log:=/home/oshikurou/.ros/log/36ce37ac-b820-11ec-bac1-853923bc7fa7/mqtt_bridge-1.log].
log file: /home/oshikurou/.ros/log/36ce37ac-b820-11ec-bac1-853923bc7fa7/mqtt_bridge-1
.log
*
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done

oshikurou@oshikurou:~/catkin_ws$ roslaunch mqtt_bridge demo.launch
... logging to /home/oshikurou/.ros/log/a462086c-c099-11ec-8555-7985461d55a7/roslaunch-oshikurou-7071.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://oshikurou:45847/

SUMMARY
PARAMETERS

/mqtt_bridge/bridge: [{'factory': 'mqt...
/mqtt_bridge/mqtt/client/protocol: 4
/mqtt_bridge/mqtt/connection/host: localhost
/mqtt_bridge/mqtt/connection/keepalive: 60
/mqtt_bridge/mqtt/connection/port: 1883
/mqtt_bridge/mqtt/private_path: device/001
/rosdistro: noetic
/rosversion: 1.15.14
NODES
/
mqtt_bridge (mqtt_bridge/mqtt_bridge_node.py)

auto-starting new master
process[master]: started with pid [7079]
ROS_MASTER_URI=http://localhost:11311/

setting /run_id to a462086c-c099-11ec-8555-7985461d55a7
process[rosout-1]: started with pid [7089]
started core service [/rosout]
process[mqtt_bridge-2]: started with pid [7096]
[INFO] [1650452667.019515]: MQTT connected
[ERROR] [1650455142.213648]: bad callback: <bound method RosToMqttBridge._callback_ros of <mqtt_bridge.bridge.RosToMqttBridge object at 0x7f299e78dbb0>>
Traceback (most recent call last):
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/home/oshikurou/catkin_ws/src/mqtt_bridge/src/mqtt_bridge/bridge.py", line 55, in _callback_ros
self._publish(msg)
File "/home/oshikurou/catkin_ws/src/mqtt_bridge/src/mqtt_bridge/bridge.py", line 60, in _publish
self._mqtt_client.publish(topic=self._topic_to, payload=payload)
File "/home/oshikurou/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 871, in publish
raise TypeError('payload must be a string, bytearray, int, float or None.')
TypeError: payload must be a string, bytearray, int, float or None.

How to set Qos?

hi I want to know how to set Qos in mqtt topic?
can I modify demo.yaml to change Qos?

Error in: src/mqtt_bridge

Hi,
When I try to use mqtt private path to publish topic from mqtt to ROS, Ros can't get message. For example, publishing a topic which is device/001/echo (private_path: device/001) from MQTT, ROS should get message from /private/back but actually not.

I find the promblem is that in class MqttToRosBridge(Bridge):
self._mqtt_client.subscribe(self.topic_from) self._mqtt_client.message_callback_add(self.topic_from, self._callback_mqtt) shold change to
self._mqtt_client.subscribe(self._topic_from) self._mqtt_client.message_callback_add(self._topic_from, self._callback_mqtt)

username_pw set example.

Could i get an example of username and password set for paho as it relates to the demo config?

after roslauch I get "ValueError No JSON object could be decoded"

started roslaunch server http://debian:45571/

SUMMARY

PARAMETERS

  • /mqtt_bridge/bridge: [{'topic_from': '...
  • /mqtt_bridge/deserializer: json:loads
  • /mqtt_bridge/mqtt/client/protocol: 4
  • /mqtt_bridge/mqtt/connection/host: localhost
  • /mqtt_bridge/mqtt/connection/keepalive: 60
  • /mqtt_bridge/mqtt/connection/port: 1883
  • /mqtt_bridge/mqtt/private_path: device/001
  • /mqtt_bridge/serializer: json:dumps
  • /rosdistro: kinetic
  • /rosversion: 1.12.12

NODES
/
mqtt_bridge (mqtt_bridge/mqtt_bridge_node.py)

ROS_MASTER_URI=http://localhost:11311

running rosparam delete /mqtt_bridge/
process[mqtt_bridge-1]: started with pid [4631]
[INFO] [1516109094.645015]: MQTT connected
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 2650, in _thread_main
self.loop_forever(retry_first_connection=True)
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 1481, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 1003, in loop
rc = self.loop_read(max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 1284, in loop_read
rc = self._packet_read()
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 1849, in _packet_read
rc = self._packet_handle()
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 2305, in _packet_handle
return self._handle_publish()
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 2500, in _handle_publish
self._handle_on_message(message)
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 2642, in _handle_on_message
callback(self, self._userdata, message)
File "/home/ruhl/catkin_ws/src/mqtt_bridge/src/mqtt_bridge/bridge.py", line 115, in _callback_mqtt
ros_msg = self._create_ros_message(mqtt_msg)
File "/home/ruhl/catkin_ws/src/mqtt_bridge/src/mqtt_bridge/bridge.py", line 125, in _create_ros_message
msg_dict = self._deserialize(mqtt_msg.payload)
File "/usr/lib/python2.7/json/init.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

I did not publish anything, Just after roslaunch I get the above error.
Help, please.

Adding header meta info to each message

Hi,
It's quite a generic option to add some meta info to each message, like timestamp, uuid, etc.
Can be used for logging, latency measurements, etc.
I'm considering adding such functionality and contributing it.
What is the preferred way to do this?

  1. Optionally add timestamp & uuid fields to the outcoming message, and strip them from incoming messages
{
  timestamp: XXXX
  uuid: YYYY
  ...
  // ROS message fields
  ...
}
  1. Optionally move ROS outcoming message body to some MQTT message payload field and add timestamp & uuid fields to MQTT message header field, and vice verse for incoming messages
{
  header: {
    timestamp: XXXX
    uuid: YYYY
  }
  payload: {
    ...
    // ROS message fields
    ...
  }
}
  1. Add another generic Bridge plugin implementing option 1/2
  2. Extend RosToMqttBridge & MqttToRosBridge with some hooks for message modification, so that one can write custom Bridge plugins based on them
  3. Other

Thanks

cant publish msg from qt mqtt to ros bridge

When i publish /echo msg from qt mqtt app to the ros bridge, i'm getting error:
MQTT to ROS and get ERROR info unpack(b) received extra data.
Here is the function in qt qml application which is publishing the mqtt message with qtmqtt library:

int QmlMqttClient::publish(const QString &topic, const QString &message, int qos, bool retain)
{
    auto result = QMqttClient::publish(QMqttTopicName(topic), message.toUtf8(), qos, retain);
    return result;
}

ROS2 mqtt_bridge?

Hi Author

Your mqtt_bridge is nice to use. By the way, is there any plan to release a ROS2 mqtt_bridge?

Best,
Samuel

how can i send custom messages?

Hello, how can i add custom messages though?
for example in another package of mine i create some msg files : my_pkg.msg:report
but if i try to define it in the demo_params.yaml it throw an error.
|

data queue in ROS with MQTT client

I upload the data from ROS to cloud by MQTT client. Can gRPC Service stop consuming messages from ROS when the communication is broken and ROS queue the messages until communication is reestablished ?

I am in Ubuntu 18.04 Melodic.

Keep getting extra data in message

Let's say im sending the following message:

rostopic pub /velocity std_msgs/String "hello"

I get the following in my MQTT client:
��data�hello

As you can see, I never said something about the unknown character and data part.
Where is it coming from? From messagepack? How can I remove it?

Unable to change format of topic before sending to remote server

I got this set up to listen for messages on a topic and forward them to a remote server using the JSON format and it's working great. I would ideally like to change the format before it's sent to a remote server. For example, instead of { "topic1": "123" }, is there a way to send it out like {"topic": "topic1", "value": "123"}?

TLS Example

Could anyone provide an example on how to configure mqtt_bridge over TLS.
Thanks in advance.

private_path extension

I want to make a second private_path for the ROS topic path equivalent to the normal one.
I made the following changes:

In app.py :

def mqtt_bridge_node():
mqtt_private_path2 = mqtt_params.pop("private_path2", "") 
...
config = create_config(mqtt_client, serializer, deserializer, mqtt_private_path, mqtt_private_path2)
def create_config(mqtt_client, serializer, deserializer, mqtt_private_path, mqtt_private_path2):
    private_path_extractor = create_private_path_extractor(mqtt_private_path, mqtt_private_path2)

In bridge.py:

class RosToMqttBridge(Bridge):
        def __init__(self, topic_from, topic_to, msg_type, frequency=None):
        self._topic_from = self._extract_private_path(topic_from)

In mqtt_client.py:

def create_private_path_extractor(mqtt_private_path, mqtt_private_path2):
    def extractor(topic_path):
        if topic_path.startswith('~/'):
            return '{}/{}'.format(mqtt_private_path, topic_path[2:])
        elif topic_path.startswith('v/'):
            return '{}/{}'.format(mqtt_private_path2, topic_path[2:])
        return topic_path

Unfortunately it doesn't work if I write something like that in my demo_params.yaml file:
topic_from: v/something
whereas this works:
topic_to: v/something

Any ideas what's missing?

Error loging in

How does one log in to the remote server by using account: ?
I cant seem to figure it out

here is the output
[WARN] [1597573564.405444]: Inbound TCP/IP connection failed: connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.

Error when i try send data from mqtt to ros

Hello. When I try to send a message from MQTT mqtt_bridge gives me an error. I try to send this command from ubuntu terminal: mosquitto_pub -t echo -m "hello". Where is my error?

Echo param configurations:

echo back

  • factory: mqtt_bridge.bridge:RosToMqttBridge
    msg_type: std_msgs.msg:String
    topic_from: /echo
    topic_to: echo
  • factory: mqtt_bridge.bridge:MqttToRosBridge
    msg_type: std_msgs.msg:String
    topic_from: echo
    topic_to: /back

Error mesaage:
[INFO] [1510431743.134914]: MQTT connected
Exception in thread Thread-72:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2650, in _thread_main
self.loop_forever(retry_first_connection=True)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1481, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1003, in loop
rc = self.loop_read(max_packets)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1284, in loop_read
rc = self._packet_read()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1849, in _packet_read
rc = self._packet_handle()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2305, in _packet_handle
return self._handle_publish()
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2500, in _handle_publish
self._handle_on_message(message)
File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2642, in _handle_on_message
callback(self, self._userdata, message)
File "/home/denis/fpi_competition/catkin_ws/src/mqtt_bridge/src/mqtt_bridge/bridge.py", line 114, in _callback_mqtt
ros_msg = self._create_ros_message(mqtt_msg)
File "/home/denis/fpi_competition/catkin_ws/src/mqtt_bridge/src/mqtt_bridge/bridge.py", line 124, in _create_ros_message
msg_dict = self._deserialize(mqtt_msg.payload)
File "msgpack/_unpacker.pyx", line 142, in msgpack._unpacker.unpackb (msgpack/_unpacker.cpp:142)
ExtraData: unpack(b) received extra data.

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.