Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROS can't read the json file #63

Open
ENTMar opened this issue Feb 17, 2022 · 1 comment
Open

ROS can't read the json file #63

ENTMar opened this issue Feb 17, 2022 · 1 comment

Comments

@ENTMar
Copy link

ENTMar commented Feb 17, 2022

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?

@castaway2000
Copy link

nearly a year old. but i can say you need to include the data key in the message. this is something you would think is done by the MqttToRos engine but no. you cant just send it a serialized message you need to add a data key with the message serialized inside it. like so:

'{"data": "{\"foo\": \"1\"}"}'

hope this helps anyone else who is looking at this kind of issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants