def pushtoDatabase(stickNumber, moistureValue, lightValue, temperatureValue): #Make string of stickNumber, this has to be done to put it in the URL. stringStickNumber = str(stickNumber) #URL that will update firebase firebase.patch( 'https://' + databaseReference + '+/Pins/' + pin + '/Plants/Stick' + stringStickNumber + '', { 'Water': moistureValue, 'Light': lightValue, 'Temperature': temperatureValue })
def setterFirebase(data): import ufirebase as firebasePost gc.collect() URL = 'watchpet-322' try: firebasePost.patch(URL, data) print('send', data) except Exception as e: # Here it catches any error. if isinstance( e, OSError ): # If the error is an OSError the socket has to be closed. return 0 gc.collect()
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()