Can't see topic with rostopic for android publisher [closed]
Hi everyone,
I am running the pubsubtalker in my cell phone. I am able to see that the topic is published by the app in Nodes/Topics(all) of the rqt_graph and that rostopic is suscribed to it, but I am unable to see the info with rostopic echo /chatter . Also, rostopic appears alone in Nodes/Topics(active). That might be the reason but I am not sure why the publisher doesn't appear as "active".
The message "Hello World! #" appears in my cell phone since it establishes communication with my pc.
May I ask why am I unable to see the info? Thanks in advance
EDIT:
I made a node that works as a server and publishes de received info in a topic.
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define PORT 3557
#define BUF 256
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
ros::Rate loop_rate(10);
/*Server*/
struct sockaddr_in host, remote;
int host_fd, remote_fd;
unsigned int size = sizeof(struct sockaddr);;
char data[BUF];
host.sin_family = AF_INET;
host.sin_addr.s_addr = htonl(INADDR_ANY);
host.sin_port = htons(PORT);
memset(&host.sin_zero, 0, sizeof(host.sin_zero));
host_fd = socket(AF_INET, SOCK_STREAM, 0);
if(host_fd == -1) {
printf("socket error %d\n", host_fd);
return 1;
}
if(bind(host_fd, (struct sockaddr *)&host, size)) {
printf("bind error\n");
return 1;
}
if(listen(host_fd, 5)) {
printf("listen error");
return 1;
}
while (ros::ok())
{
printf("Server setup, waiting for connection...\n");
remote_fd = accept(host_fd, (struct sockaddr *)&remote, &size);
printf("connection made\n");
int read = recv(remote_fd, data, BUF, 0);
data[read] = '\0';
printf("read = %d, data = %s\n", read, data);
shutdown(remote_fd, SHUT_RDWR);
close(remote_fd);
std_msgs::String msg;
std::stringstream ss(data);
msg.data = ss.str();
ROS_INFO("%s", msg.data.c_str());
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
I used the following function to send the message from the android app to the ROS node.
private class SendToMaster extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
try {
Log.i("Socket", "Connecting");
Socket socket = new Socket("10.16.34.35", 3557);
DataOutputStream os = new DataOutputStream(socket.getOutputStream());
os.writeBytes(message);
os.close();
socket.close();
} catch (Exception e) {
Log.e("Socket", e.getMessage());
}
return "Executed";
}
Sounds like the same problem that I'm having.
Had any luck since you posted your question?
-piet
I couldn't fix it and the files to run ROS in android were removed at that time. Since I only needed to send info from my celphone, my workaround was to make an app that is a client and a node that works as a server. The node publishes the info in a topic.