Rosbridge_server - formatting header with JSON

asked 2016-04-05 12:27:20 -0500

salsalam gravatar image

I have a simple python script that I can't upload because I don't have 5 points. My script "advertise" sensor_msgs/Joy and then tries to send one with a header. The same code works for the json string that defines a joy_topic message with no header. Can someone tell me if I'm forming my json string incorrectly??? Thanks for you help and time...

Script is below;

Blockquote #!/usr/bin/env python

import socket, time import pygame import rospy #from geometry_msgs.msg import Twist #from sensor_msgs.msg import Joy

topicMessage = ''' { "op": "advertise", "type": "sensor_msgs/Joy", "topic": "joy_topic" } '''

if __name__ == '__main__':

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Insert try block
# If rosbridge isn't running errno=111 connection refused
connectError=s.connect(('127.0.0.1', 9090))

s.send(topicMessage)

JoyMessageTryHeader = '''

{ "op": "publish", "topic": "joy_topic", "msg": { {"header": { "seq": 0, "stamp": {"secs": 123.0, "nsecs": 456.0} "frame_id": \" \"}} "axes": [], "buttons": [] }, } ''' JoyMessageTryNoHeader = ''' { "op": "publish", "topic": "joy_topic", "msg": { "axes": [], "buttons": [] } } '''

while True:

print JoyMessageTryNoHeader

s.send(JoyMessageTryNoHeader)

    print JoyMessageTryHeader
    s.send(JoyMessageTryHeader)
    time.sleep(5)

s.close()

This generates errors in rosbridge. [rosout][INFO] 2016-04-05 13:15:33,109: Rosbridge TCP server started on port 9090 [rospy.internal][INFO] 2016-04-05 13:15:33,321: topic[/rosout] adding connection to [/rosout], count 0 [rosout][INFO] 2016-04-05 13:15:44,112: [Client 0] connected. 1 client total. [rosout][ERROR] 2016-04-05 13:15:44,241: [Client 0] Received a message without an op. All messages require 'op' field with value one of: ['service_response', 'unadvertise_service', 'call_service', 'publish', 'fragment', 'subscribe', 'advertise_service', 'unsubscribe', 'unadvertise', 'advertise']. Original message was: [rospy.internal][INFO] 2016-04-05 13:15:44,276: topic[/joy_topic] adding connection to [/rostopic_15329_1459876539132], count 0 [rosout][ERROR] 2016-04-05 13:15:49,119: [Client 0] Received a message without an op. All messages require 'op' field with value one of: ['service_response', 'unadvertise_service', 'call_service', 'publish', 'fragment', 'subscribe', 'advertise_service', 'unsubscribe', 'unadvertise', 'advertise']. Original message was: { "op": "publish", "topic": "joy_topic", "msg": { {"header": { "seq": 0, "stamp": {"secs": 123.0, "nsecs": 456.0} "frame_id": " "}} "axes": [], "buttons": [] }, }

[rospy.internal][INFO] 2016-04-05 13:15:49,633: topic impl's ref count is zero, deleting topic /joy_topic... [rospy.internal][INFO] 2016-04-05 13:15:49,634: topic[/joy_topic] removing connection to /rostopic_15329_1459876539132 [rosout][WARNING] 2016-04-05 13:15:49,634: Could not process inbound connection: [/rosbridge_tcp] is not a publisher of [/joy_topic]. Topics are [['/rosout', 'rosgraph_msgs/Log']]{'message_definition': "# Reports the state of a joysticks axes and buttons.\nHeader header # timestamp in the header is the time the data is received from the joystick\nfloat32[] axes # the axes measurements from a joystick\nint32[] buttons # the buttons measurements from a joystick \n\n================================================================================\nMSG: std_msgs/Header\n# Standard metadata for higher-level stamped data types.\n# This is generally used to communicate timestamped data \n# in a particular coordinate frame.\n# \n# sequence ID: consecutively increasing ID \nuint32 seq\n#Two-integer timestamp that is expressed as:\n# * ....

Blockquote

edit retag flag offensive close merge delete