def getterFirebase(): global getTemp import ufirebase as firebaseGet gc.collect() URL = 'watchpet-322' try: getTemp = firebaseGet.get(URL) print('fn', getTemp) except Exception as e: # Here it catches any error. if isinstance( e, OSError ) and res: # If the error is an OSError the socket has to be closed. return 0 gc.collect()
def getterFirebase(): global air_status import ufirebase as firebaseGet gc.collect() URL = 'watchpet-322' try: getData = firebaseGet.get(URL) air_status = getData['AIR'] print('fn', air_status) except Exception as e: # Here it catches any error. if isinstance( e, OSError ) and res: # If the error is an OSError the socket has to be closed. return 0 gc.collect()
def readDestination(): try: URL = 'guidancesystem-f0136' #name of database destination = firebase.get(URL + '/users/007eob@gmail,com/Destination') except: print("Cannot read from firebase, reconnecting to wifi") wifiConnect() time.sleep(3) readDestination() value = next(iter(destination.values())) #most recent destination object print(value) beaconId = value[ "bluetoothId"] #bluetooth Id of most recent destination object print(beaconId) print("Beacon ID", str.encode(beaconId)) return beaconId
def updateFirebase(): try: URL = 'guidancesystem-f0136' #name of database destination = firebase.get(URL+'/users/007eob@gmail,com/Destination') print(destination) value = next(iter(destination.values())) #most recent destination object print(value) fbID = value["fbId"]#next(iter(value.values())) #bluetooth Id of most recent destination object print(fbID) path = URL+'/users/007eob@gmail,com/Destination/' + fbID print(path) destination = firebase.patch(path, {"visited": True, "date":todayDate, "time":nowTime}) except: print("Not connected to WiFI, reconnecting now") wifiConnect() print("Retrying write to firebase") updateFirebase()
def getterFirebase(): global feeding_status, playing_status import ufirebase as firebaseGet gc.collect() URL = 'watchpet-322' try: getData = firebaseGet.get(URL) feeding_status = getData['FEEDING'] playing_status = getData['PLAYING'] print('fn feed ', feeding_status, 'fn play ', playing_status) except Exception as e: # Here it catches any error. if isinstance( e, OSError ) and res: # If the error is an OSError the socket has to be closed. print(isinstance(e, OSError)) return 0 gc.collect()
#firebase example import ufirebase as firebase firebase.setURL("https://[PROJECT_ID].firebaseio.com/") #Put Tag1 firebase.put("testtag", "1234", bg=0) #Put Tag2 firebase.put("lolval/testval", { "somenumbers": [1, 2, 3], "something": "lol" }, bg=0) #Get Tag1 firebase.get("testtag", "var1", bg=0) print("testtag: " + str(firebase.var1)) #Get Tag2 def callbackfunc(): print("\nlolval_1: " + str(firebase.lolwhat["testval"]["somenumbers"]) + "\nlolval_2: " + str(firebase.lolwhat["testval"]["something"]) + "\nlolall: " + str(firebase.lolwhat)) firebase.get("lolval", "lolwhat", bg=1, cb=(callbackfunc, ())) print(end="Im getting lolval now") #Do something in this time while 1:
import ufirebase as firebase import ubinascii import time from network import Bluetooth ################################################# # Retrieve Beacon ID of destination # ################################################# URL = 'guidancesystem-f0136' #name of database destination = firebase.get(URL + '/users/EMCJUDYRJKZlouOnzjGVfxpQTWR2/Destination') value = next(iter(destination.values())) print(value) beaconId = value["bluetoothId"] print(beaconId)
exit() #print(WIFI_SSID + " Connected") display.show("OK", color=(10,0,0)) display.clear() m1 = DCMotor('M1') m2 = DCMotor('M2') turnedLeft=False turnedRight=False result={'PIC': {'character': '"S"'}} while True: # response = firebase.get('https://ai-camera-5f64e.firebaseio.com/') result=firebase.get("ai-camera-5f64e") print(result) if result=={'PIC': {'character': '"S"'}}: # stop m1.power(0) m2.power(0) m1.ccw() m2.ccw() #time.sleep(2) elif result=={'PIC': {'character': '"F"'}}: # forward m1.power(100) m2.power(100) m1.ccw()
(0,0,0x1f0000), (4,0,0x1f0000), (1,1,0x1f0000), (3,1,0x1f0000), (2,2,0x1f0000), (1,3,0x1f0000), (3,3,0x1f0000), (0,4,0x1f0000), (4,4,0x1f0000)]) #Wi-Fi configuration & connection #wifi_connection.wifiConnection("WINSTARS", "28092299", s_time) #wifi_connection.wifiConnection("KWAN", "27023816", s_time) #wifi_connection.wifiConnection("Gary", "okt32s4A4", s_time) wifi_connection.wifiConnection("Karen", "91492071", s_time) #Firebase settings URL = 'aiautodoor-390ed' firebase.put(URL+'/state', 'close') #default settings while True: state = firebase.get(URL+'/state') if state == 'close': doorCloses() elif state == 'open': doorOpens()