So I was looking for a way to log things like temperature, atmospheric pressure, humidity and other things for my Particle Photons. There are a couple of them in my home and it would be nice to log data and be able to visialize it later on.
I was able to use the Particle cloud templates to get data saved to firebase by sending events from the Photons.
The code
This would be your .ino file1
2
3
4
LogStore *myLogging = new LogStore;
myLogging->save("temperature", "livingroom", myBaroTemp->getTemp(), 0);
app/logging.h1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25class LogStore {
private:
String storeName = "logging";
public:
LogStore() {
// __debug("store.setup", "Setting up logging");
}
void save(char* category, char* title, double value, int date) {
save(category, title, String(value).c_str(), String(date).c_str());
}
void save(const char* category, const char* title, const char* value, const char* date) {
char buf[256];
snprintf(buf,
sizeof(buf),
"{\"category\":\"%s\",\"title\":\"%s\",\"value\":\"%s\",\"date\":\"%s\"}",
category,
title,
value,
date);
Particle.publish("firebase." + storeName + ".commit", buf, PRIVATE);
}
};
Now you need to setup the webhook at https://console.particle.io (go to integrations). Select a new webhook integration and click the “custom template” tab. Paste the template below into the field and fill in the needed values.
1 | { |