Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import firebase_admin, time
- from firebase_admin import credentials
- from firebase_admin import firestore
- from threading import Event
- from serial import Serial
- ser = Serial('/dev/ttyACM0', 9600)
- cred = credentials.Certificate('insert-firebase-cert-here.json')
- firebase_admin.initialize_app(cred)
- db = firestore.client()
- # Create a callback on_snapshot function to capture changes
- def on_snapshot(doc_snapshot, changes, read_time):
- for doc in doc_snapshot:
- print(u'Received document snapshot: {}'.format(doc.id))
- packet = doc.to_dict()
- az = packet['AZ']
- el = packet['EL']
- sendstring = "W" + az + " "+ el + "\r\n"
- print("Moving to AZ=" + az + ", EL=" + el)
- ser.write(str.encode(sendstring))
- doc_ref = db.collection(u'stations').document(specify-stationId)
- # Watch the document
- doc_watch = doc_ref.on_snapshot(on_snapshot)
- Event().wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement