rospy_message_converter json2ros
Hi,
I'm trying to send a string msg
after it will be converter by the library rospy_message_converter
from JSON
to ros
.
I need to send the message over the std_msgs/String
type but with some sub-values in it.
Like: under the data
struct it will be:
"name" : "Ben"
"age" : 15
"weight": 50
I couldn't find any example of something like that. Again, I need to send this value by std_msgs/String
and not with a custom msg
.
This is what I tried:
from rospy_message_converter import json_message_converter
from std_msgs.msg import String
import rospy, json
if __name__ == "__main__":
rospy.init_node('api_test', anonymous=True)
name = 'Ben'
age = '15'
# json_str = '{"data": {}'.format('{"Engaged": {}}'.format(engaged))
json_str = '{"data": {"name": {0}}}'.format(name)
message = json_message_converter.convert_json_to_ros_message('std_msgs/String', json_str)
pub = rospy.Publisher("/pub",String, queue_size=1)
while not rospy.is_shutdown():
pub.publish(message)
rospy.sleep(0.5)
Thanks a lot, Aviad