ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Can't see topic with rostopic for android publisher [closed]

asked 2014-04-19 22:52:31 -0500

Elvish Champion gravatar image

updated 2016-01-12 09:44:27 -0500

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";
        }
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2017-04-20 17:37:50.109041

Comments

Sounds like the same problem that I'm having.

http://answers.ros.org/question/223602/android_core-emulator-registers-topic-but-not-sending-events/

Had any luck since you posted your question?

-piet

piet.delaney@gmail.com gravatar image piet.delaney@gmail.com  ( 2016-01-06 19:49:37 -0500 )edit

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.

Elvish Champion gravatar image Elvish Champion  ( 2016-01-11 13:35:40 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-01-11 17:00:42 -0500

piet.delaney@gmail.com gravatar image

Perhaps you could post it to git hub for me to look at.

-piet

edit flag offensive delete link more

Comments

I added the code here. I hope it can be useful.

Elvish Champion gravatar image Elvish Champion  ( 2016-01-12 09:45:22 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-04-19 22:52:31 -0500

Seen: 779 times

Last updated: Jan 12 '16