Skip to content

Instantly share code, notes, and snippets.

@oakie
Created March 30, 2016 18:49
Show Gist options
  • Save oakie/371c4af93cb50621a7bc5db7c6bbf0bb to your computer and use it in GitHub Desktop.
Save oakie/371c4af93cb50621a7bc5db7c6bbf0bb to your computer and use it in GitHub Desktop.
Sets up a ROS node which subscribes to the topics listed in topics.txt and pushes the messages to the corresponding firebase route.
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from firebase import firebase as fb
import os
class Listener:
def __init__(self, topics):
rospy.init_node('firebase', anonymous=True)
self.firebase = fb.FirebaseApplication('https://<firebase-url>.firebaseio.com/', authentication=None)
for topic in topics:
rospy.Subscriber(topic, String, callback=self.callback, callback_args=topic)
rospy.spin()
def callback(self, msg, topic):
data = {'timestamp': rospy.get_time(), 'msg': msg.data}
print ' <' + topic + '> ' + msg.data
self.firebase.post(topic, data)
if __name__ == '__main__':
filename = os.path.join(os.path.dirname(__file__), 'topics.txt')
topics = list(open(filename, 'r'))
l = Listener(topics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment