Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import firebase_admin, time
  2. from firebase_admin import credentials
  3. from firebase_admin import firestore
  4. from threading import Event
  5. from serial import Serial
  6. ser = Serial('/dev/ttyACM0', 9600)
  7.  
  8. cred = credentials.Certificate('insert-firebase-cert-here.json')
  9. firebase_admin.initialize_app(cred)
  10.  
  11. db = firestore.client()
  12.  
  13. # Create a callback on_snapshot function to capture changes
  14. def on_snapshot(doc_snapshot, changes, read_time):
  15. for doc in doc_snapshot:
  16. print(u'Received document snapshot: {}'.format(doc.id))
  17. packet = doc.to_dict()
  18. az = packet['AZ']
  19. el = packet['EL']
  20. sendstring = "W" + az + " "+ el + "\r\n"
  21. print("Moving to AZ=" + az + ", EL=" + el)
  22. ser.write(str.encode(sendstring))
  23.  
  24. doc_ref = db.collection(u'stations').document(specify-stationId)
  25.  
  26. # Watch the document
  27. doc_watch = doc_ref.on_snapshot(on_snapshot)
  28.  
  29. Event().wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement