Created
March 30, 2016 18:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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