Firebase Yes or No, and I could use some help

Anyone using Firebase?
Anyone want to??
Is it any good???

Very little information on Mbed which I can understand as we do have Pelion which is really good for FOTA updates but where’s the Android or SteveJobsPhone apps so the everyday person can make good use of this? I can’t see anything here, maybe not looking in the right place, nothing unusual there :).

I now have a working Mbed Firebase example that will ‘post’ and ‘get’ data to and from Firebase, but I could use some help with .json data formats to send multiple data fields. For instance, I want to send to my Firebase database 5 temperature sensor values.
For the moment I can send one ‘name’ with one ‘value’ using this:

sprintf(data,"{\"Temp0\":\"%s\"}",Temp[0]); 

I want to send something like this:

sprintf(data,"'{\"%s\" : %s,\"%s\" : %s,\"%s\" : %s,\"%s\" : %s,\"%s\" : %s}'", "Temp0",Temp[0],"Temp1",Temp[1],"Temp2",Temp[2],"Temp3",Temp[3],"Temp4",Temp[4]);

But this doesn’t work, I get this response back from Firebase:

“error” : "Invalid data; couldn’t parse JSON object, array, or value.

Anyone with a bit of .json knowledge may be able to help, would be lovely.

Paul

You have ' at the beginning and end of your json, it might be it.

You should try sending a predetermined string with the right formatting and that is valid json to make sure it works before sending actual data.

Hi Paul,
In addition to what Ladislas mentioned ( json is a python dictionary ), I see that in your enhaced json data, the value is not sent as a string. in your working example, you set the value as a string (\"%s\"), however in your enhanced json example, it is the value is formatted according to its type ( bool? integer? ) - %s
Combining the two answers, please try the following:

sprintf(data,"{\"%s\" : \"%s\",\"%s\" : \"%s\", \"%s\" : \"%s\",\"%s\" : \"%s\",\"%s\" : \"%s\"}", "Temp0",Temp[0],"Temp1",Temp[1],"Temp2",Temp[2],"Temp3",Temp[3],"Temp4",Temp[4]);

Regards

Thanks Ron and Ladislas, that did the trick.
Sorry my json and python knowledge is almost non existent, until recently I thought python was a snake :frowning:

I can now extend and change the data sent to Firebase and works just fine.

Just need to work out how to send the correct message format to use PUT, PATCH and DELETE functions in the REST api.

So if anyone seeing this with Firebase/json/python knowledge, a little help and I can get this on Mbed with some examples.

Paul

1 Like

Hi Paul,
Using REST Api in Python can be done with the Python requests library.
You can find several examples of using the requests library. For example, Using the Requests Library in Python - PythonForBeginners.com

Regards

Thanks Ron, that helped me a lot along with my clever dick son :joy:
Now have all the REST api functions running.

As per the question, we were discussing the Firebase vs Pelion, do you think we will be able to have a route to access the data similar to Firebase ?

Edit…
Looks like Pelion has changed a bit since I last used and I can see some information on this.

1 Like