Rosbridge_server - formatting header with JSON
I have a simple python script that I can't upload because I don't have 5 points. My script "advertise" sensormsgs/Joy and then tries to send one with a header. The same code works for the json string that defines a joytopic 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": "sensormsgs/Joy", "topic": "joytopic" } '''
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": "joytopic", "msg": { {"header": { "seq": 0, "stamp": {"secs": 123.0, "nsecs": 456.0} "frameid": \" \"}} "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: ['serviceresponse', 'unadvertiseservice', 'callservice', 'publish', 'fragment', 'subscribe', 'advertiseservice', 'unsubscribe', 'unadvertise', 'advertise']. Original message was: [rospy.internal][INFO] 2016-04-05 13:15:44,276: topic[/joytopic] adding connection to [/rostopic153291459876539132], 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: ['serviceresponse', 'unadvertiseservice', 'callservice', 'publish', 'fragment', 'subscribe', 'advertiseservice', 'unsubscribe', 'unadvertise', 'advertise']. Original message was: { "op": "publish", "topic": "joytopic", "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 /joytopic... [rospy.internal][INFO] 2016-04-05 13:15:49,634: topic[/joytopic] removing connection to /rostopic153291459876539132 [rosout][WARNING] 2016-04-05 13:15:49,634: Could not process inbound connection: [/rosbridgetcp] is not a publisher of [/joytopic]. Topics are [['/rosout', 'rosgraphmsgs/Log']]{'messagedefinition': "# 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
Asked by salsalam on 2016-04-05 12:27:20 UTC
Comments