How can I publish an integer and string (Int16 & String) using roslibjs?
hi
I am recently learning robotic web tools.In git has some samples. I want to publish an indeger / string message .On refreshing the browser I want to get the string message in command prompt. But In my code it is not publish anything right now. Any helps are appreciated.
I run
roscore
rostopic echo /buttons
roslaunch rosbridge_server rosbridge_websocket.launch
I am use the following code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="../include/EventEmitter2/eventemitter2.js"></script>
<script src="../build/roslib.js"></script>
<script>
// Connecting to ROS
// -----------------
var ros = new ROSLIB.Ros();
// If there is an error on the backend, an 'error' emit will be emitted.
ros.on('error', function(error) {
console.log(error);
});
// Find out exactly when we made a connection.
ros.on('connection', function() {
console.log('Connection made!');
});
// Create a connection to the rosbridge WebSocket server.
ros.connect('ws://localhost:9090');
// Publishing a Topic
// ------------------
// First, we create a Topic object with details of the topic's name and message type.
var testStr = new ROSLIB.Topic({
ros : ros,
name : '/buttons',
messageType : 'std_msgs/String'
});
// Then we create the payload to be published. The object we pass in to ros.Message matches the
// fields defined in the geometry_msgs/Twist.msg definition.
var str = new ROSLIB.Message(
a:'hello'
);
// And finally, publish.
testStr.publish(str);
</script>
</head>
<body>
<h1></h1>
<p></p>
<ol>
<li><tt>roscore</tt></li>
<li><tt>rostopic echo /buttons</tt></li>
<li><tt>roslaunch rosbridge_server rosbridge_websocket.launch</tt></li>
</ol>
</body>
</html>
My Doubts
1) Is it there in any problem of the syntax I used?
2) how can I publish Int16 messages?