Posts

Showing posts with the label firebase-database

I have some data in Firebase and want to retrieve it. Sometimes it can be null. How do I not get an exception for it?

I have some data in Firebase and want to retrieve it. Sometimes it can be null. How do I not get an exception for it? FetchDataMethod private void fetchData() { mDatabaseReference.child("UserData").child(RecieversId).addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot dataSnapshot, String s) { ImageView Image = (ImageView) findViewById(R.id.imageView); TextView Name = (TextView) findViewById(R.id.name); TextView Status = (TextView) findViewById(R.id.status); TextView Email = (TextView) findViewById(R.id.email); TextView Ph = (TextView) findViewById(R.id.ph); TextView Quote = (TextView) findViewById(R.id.quote); for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) { String image = postSnapshot.child("Image").getValue().toString(); String name = postSnapshot.child("Name")....

Firebase transaction in nodeJs

Image
Firebase transaction in nodeJs What I try to achieve is simply increase a value in the database with a transaction. This is working for me as intended, but I always get following error in my firebase console: Function returned undefined, expected Promise or value My current call is as following: exports.reportCounter = functions.database.ref('/user/{userId}/reports/{initiatorId}').onWrite((change,context) => { const userId = context.params.userId; return userRef.child(userId).child("numReports").transaction(function(numReports) { return change.after.exists()?((numReports || 0) + 1):(numReports - 1); }) }); I also tried returning the promise directly: return userRef.child(userId).child("numToIncrement").transaction(function(numToIncrement) { return ((numToIncrement || 0) + 1); }); In both cases, the code is doing what it is supposed to do, but I still receive said error. You should be able to return the promise ...

i used python on raspberry to read ph water from arduino

i used python on raspberry to read ph water from arduino I create a project to read pH water, but my module sensor doesn't fix with raspberry pi 3 so I using Arduino to read pH, then send to raspberry and upload the data to firebase. but, I have some problem, when raspberry read data from Arduino, the looping doesn't work. the error message is serial.util.serialexception here's source code on Raspberry import os import serial import time from firebase import firebase arduino = serial.Serial('/dev/ttyACM0',9600) firebase = firebase.FirebaseApplication('https://raspi-ph.firebaseio.com/', None) def update_firebase(): phair = arduino.readline() if data is not None: time.sleep(1) pieces = data.split("sensor= ") ph = pieces print ph else: print('Failed to get data. Try Again!') time.sleep(10) data = {"Sensor pH": phair} firebase.post('/sensor/ph', data) while Tr...

Android - Firebase Database Quickstart Gradle Project Sync Failed

Image
Android - Firebase Database Quickstart Gradle Project Sync Failed I am trying to build this project Firebase Database Quickstart, but I am facing error in App level build.gradle file. build.gradle Here is my error message By searching google and stackoverflow i found some solution then i add this 'com.google.android.gms:play-services-auth:15.0.1' line in my gradle file so my error reduces from 6 to 3. google stackoverflow 'com.google.android.gms:play-services-auth:15.0.1' Error message after adding this 'com.google.android.gms:play-services-auth:15.0.1' 'com.google.android.gms:play-services-auth:15.0.1' Now i am unable to fix this error. My Google Play services and Google Repository version is up to date and maven { url "https://maven.google.com" } is already added before in the project level build.gradle. maven { url "https://maven.google.com" } Here my App Level gradle file: apply plugin: 'com.android.application' c...