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))",
"devices":{
".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": "https://test1-c0b7e.firebaseio.com/devices/{{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) Time.now() * 1000;// * 1000; // epoch in seconds changed to millis for firebase
sprintf(charMillis,"%13.0f", millisForFB);
//Serial.println(charMillis);
s.concat(",\"t\":"); // time field
s.concat(charMillis); // make it a string for concat
Good luck!