Rosanswers logo

EDIT: The exact cause of the issue is coming from my message having some odd bits of data in it.

str is
}chatterstd_msgs/String 992ce8a1687cec8c8bd883ec73ca41d1
str is 
toggle_ledtdstd_msgs/String 92992ce8a1687cec8c8bd883ec73ca41d1

The first string is used to create the publisher and the second is used to create the subscriber, the second has some extra characters (which is throwing the length error and I can't figure out why.

---Original Question---

Okay so I'm following the rosserial arduino tutorials, having just installed hydro. I'm using ubuntu 12.04 and currently attempting to run roslib pubsub, the source code is below. However I am receiving this error:

[INFO] [WallTime: 1379669386.460493] ROS Serial Python Node
[INFO] [WallTime: 1379669386.472761] Connecting to /dev/ttyACM2 at 57600 baud
[INFO] [WallTime: 1379669389.183587] Note: publish buffer size is 280 bytes
[INFO] [WallTime: 1379669389.183904] Setup publisher on chatter [std_msgs/String]
[ERROR] [WallTime: 1379669389.185947] Creation of subscriber failed: unpack requires a string argument of length 4

So yeah, I've seen multiple other quesitons with the same error however no solution appears to be working for me.

I have ran

catkin_make install
source ws/install/setup.bash

this is after having cloned the repo with git. Any help would be appreciated thanks.

The source code is:

* rosserial PubSub Example
* Prints "hello world!" and toggles led

#include <ros.h>
#include <std_msgs/String.h>
#include <std_msgs/Empty.h>

ros::NodeHandle  nh;

void messageCb( const std_msgs::Empty& toggle_msg){
  digitalWrite(13, HIGH-digitalRead(13));   // blink the led

ros::Subscriber<std_msgs::Empty> sub("toggle_led", messageCb );
std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);

char hello[13] = "hello world!";

void setup()
  pinMode(13, OUTPUT);

void loop()
  str_msg.data = hello;
  chatter.publish( &str_msg );

I first compile and run on the arduino then i use

rosrun rosserial_python serial_node.py /dev/ttyACM0

Which then throws the above error.

Originally posted by theplague on ROS Answers with karma: 16 on 2013-09-19

Post score: 0


1 Answer 1


Rosanswers logo

Okay I've found a "solution", the line:

ros::Subscriber<std_msgs::String> sub("toggle_led", &messageCb );


toggle_ledtdstd_msgs/String 92992ce8a1687cec8c8bd883ec73ca41d1

Which is the incorrect length, or something. Thus by shortening the topic to be between 6 or 7 characters the error does not occur. E.g.

ros::Subscriber<std_msgs::String> sub("toggle", &messageCb );

I get:

dtogglestd_msgs/String 992ce8a1687cec8c8bd883ec73ca41d1

Which fits the length and works, i'm not sure if this is problem with rosserial.

Originally posted by theplague with karma: 16 on 2013-09-21

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by GioRos on 2013-09-27:
Hi, i have the same problem, but mine can't be solved as yours...i dont know why...!!!I tried ros hello world example and it works fine but when i try an example with a subscriber, whatever topic name is, i get : (from pubsub ros example) [INFO] [WallTime: 1380287883.995053] ROS Serial Python Node [INFO] [WallTime: 1380287884.001497] Connecting to /dev/ttyACM0 at 57600 baud [INFO] [WallTime: 1380287886.607383] Note: publish buffer size is 512 bytes [INFO] [WallTime: 1380287886.607882] Setup publisher on chatter [std_msgs/String] [ERROR] [WallTime: 1380287886.609524] Creation of subscriber failed: unpack requires a string argument of length 4 I use hydro on ubuntu 12.04 64bit.Is there a way to solve it?I'm stuck here...!Someone can help me? thank!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.