Code breaking after adding Firebase library

I’m using 0.6.3. After adding the FirebaseArduino library I get the following compilation error “…/wiring/inc/spark_wiring_arduino_constants.h:111:18: expected unqualified-id before ‘(’ token”.

I seem to have trouble with every library I add in the web ide should I be doing this directly instead?

Without a look at the code, it’s hard to debug. Would you mind posting the share link from the web IDE?

That seems to be an issue with the library. Maybe that’s the reason why the usage counter is still stuck at 0 :wink:

Since the owners didn’t provide a GitHub link, it’s not easy to contact them.

@ScruffR oh I thought that number was file size or something :grin: I guess there are no usable libraries in that case? :disappointed: are there easier ways to import external libraries in the web ide without duplicating each file and modifying the path?

If they are not published in Library Manager then not.
But if you have the sources, you could easily build your project with CLI.

BTW, I have filed a GitHub issue on the Particle side, just in case the library breaks due to some Arduino incompatibility - just in case :wink:

1 Like

Great thanks!

We have had that problem before with max(a,b) being a macro. If you can do #undef max at the top of the library, that might help.

1 Like

Has there been any progress or a workaround on this. I would like to use the FirebaseArduino library. Should the #undef max work and if so where do I apply it?

@bbeardmore don’t bother with it, you can post to firebase via a webhook that posts to the rest API. if you’re retrieving values you can do the same thing with a webhook in GET mode then parse the JSON with arduinojson. had this happily running since particle core.

1 Like

It’s easy to use Firebase from Particle without needing a library:

Hi @rickkas7, great tutorial though I highly suggest you remove using the secret directly in the webhook. That means you’re giving SU to whoever has access to run particle webhook list by any user with access to your project, or the particle admin staff themselves. Using legacy secrets is deprecated, but they haven’t set a EOL so I’m still using the legacy secret to mint a token.
This is how you should create a token:

var FirebaseTokenGenerator = require("firebase-token-generator");
var tokenGenerator = new FirebaseTokenGenerator("3uB0... your short secret");
var token = tokenGenerator.createToken(
  {uid: "[give an admin userID like projectnameadmin1]", canAdmin: true, [any other flags or data as json pairs], createdby: "markt-20180615"},
  {admin: true, expires: 1589077461}
console.log("fb token: " + token);

Then use that in your webhook. You can then use your firebase rules to pickup the ‘canAdmin’ or more specific tags like ‘canPostTemperatures’ to give specific write access on a branch to that user without granting SU over the whole DB tree. IE:

"users": {
          "$user": {
        		".read": "(auth != null  && (auth.canAdmin == true || $user == auth.uid))",    
              	".write": "(auth != null && (auth.canAdmin == true || $user == auth.uid)) && (!data.exists() || !newData.exists())",  
              "config": {
              	".write": "(auth != null && (auth.canAdmin == true || $user == auth.uid))",

If I was being picky, I’d suggest in the tutorial that it should demonstrate sending the data to a specific device subtree. ie “url”: “{{PARTICLE_DEVICE_ID}}/data.json”

Lastly, for firebase to index and order by date effectively, it needs to be (well at least used to be, think its still the case) a number. These days you can run a cloud function to parse the particle published date and make that into a moment().valueof, but the easiest way to do it is back on your particle by adding a millis value field to your json. Then add an indexon in your FB rules for that ‘t’ for time field.

millisForFB = (double) * 1000;// * 1000; // epoch in seconds changed to millis for firebase
    sprintf(charMillis,"%13.0f", millisForFB);
    s.concat(",\"t\":"); // time field
    s.concat(charMillis); // make it a string for concat

Good luck!

Last suggestion, I highly recommend you put the coreid in your webhook post to FB. It means you can easily search your logs (ie FB cloud functions, gateway logs, anything). Just add this to your JSON section:

"coreid": "{{PARTICLE_DEVICE_ID}}",