Note: This tutorial assumes that you have completed the previous tutorials: Launching a Hub.
(!) Please ask about problems and questions regarding this tutorial on Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Writing a Hub Client

Description: Using the hub client api to conveniently connect/use a rocon hub.

Keywords: rocon, hub, multimaster

Tutorial Level: INTERMEDIATE

rocon_hub_client is a python package designed to help you discover and connect to hubs.

Hub Discovery

Hub discovery works either via a list of uri's passed directly, or via zeroconf. It does this in a background thread which periodically checks for existence of rocon hubs.

   1 import rocon_hub_client
   3 def discovery_callback(ip, port):
   4     # do needed handling here
   7 direct_hub_uri_list=['http://localhost:6380']
   8 hub_discovery_thread = rocon_hub_client.HubDiscovery(discovery_callback, direct_hub_uri_list, disable_zeroconf=False)

Note, the uri list may be empty, and the zeroconf discovery may be optionally disabled. As hubs are discovered, they trigger the discovery callback you have specified.


To get the zeroconf module to work on linux, you'll need something like the following in your launcher (it uses the zeroconf_avahi package).

   1   <node ns="zeroconf" pkg="zeroconf_avahi" type="zeroconf" name="zeroconf"/>
   2   <node pkg="my_hub_client" type="" name="my_hub_client">
   3     <remap from="my_hub_client/add_listener" to="zeroconf/add_listener"/>
   4     <remap from="my_hub_client/list_discovered_services" to="zeroconf/list_discovered_services"/>
   5   </node>

Hub Client

Once you have an ip/port of a discovered hub, you can use the Hub class to connect to the hub.

   1 import rocon_hub_client
   3 try:
   4     new_hub = rocon_hub_client.Hub(ip, port, whitelist, blacklist)
   5 except HubNotFoundError:  
   6     # raised if no redis server at ip, port
   7     pass
   8 except HubNameNotFoundError:  
   9     # raised if rocon hub name is not in redis
  10     pass

Note - the rocon hub name is a key on the redis server of the form rocon:hub:name. Whitelists and blacklists can be used to selectively filter the hubs you wish to connect to.

Wiki: rocon_hub_client/Tutorials/indigo/Writing a Hub Client (last edited 2014-03-25 00:13:17 by DanielStonier)