How/where do I save Published Events?

My Particle Electron is working great, and the Console is getting nicely filled up with useful data it’s publishing. However, it’s a bit unclear to me where I can actually store this data, as whenever I refresh the console, the old events are removed; how does one store all the published events of a sensor?

Thanks a bunch in advance

Events published by the Particle device to the Particle cloud only live on the cloud for approximately 60 seconds. Webhooks can be created which would allow you to log that data to another server somewhere. One way of doing this is by using IFTTT and Google Sheets which would log your events to a google sheet.

It is not possible to keep every event published forever as this would require a huge amount of data storage on the server and they are trying to provide the cloud service at a reasonable cost.

Well if you are interested in saving locally on your mac/linux. Use the curl command mentioned in the console and pipe the output to a file

1 Like

Hi,

Is this possible even with a multitude of particles? When I go to the IFTTT website, I can only select one device.

I have about 20 different devices here, all running the exact same firmware; during a certain action, they will send out an event. I simply want to have a good overview of the timestamp of each event, and which device broadcasted it. I tried ThingSpeak but it wouldn’t keep track of which device was broadcasting the event.

With ThingSpeak, the example shows a single data channel with:

Name: Dew Point Measurement
Field 1: Temperature (F)
Field 2: Humidity
Field 3: Dew Point

Create a Field 4 for Device ID. This may be the actual device ID of the device or some made up unique identifier. I would advise giving it a unique identifier beyond the native ID for additional security.

You would send the ID with the data packet (4th field). At the other end, you can then sift the data by the inbound ID.

Or with Ubidots it’s more multiple device friendly by design.

Hi,

You’re right, I can just add extra fields in the ThingSpeak platform. However, do you have any tips for retrieving the Device Name? I read somewhere that the Device Name is only stored in the cloud, so telling the electron to retrieve it in the firmware isn’t possible?. Right now I’m outputting the device ID which is also fine, but being able to add another ID to it would be even better.

The way to do that is by having the device ask the cloud for its name and subscribing to the respective cloud event
https://docs.particle.io/reference/firmware/photon/#get-device-name

But there is noone holding you back from storing the device name (or any other label) in EEPROM to reuse it once set.
You could add a Particle.function() (or the likes) to trigger a name retrieval and store that result till you decide to change the name.


And I just saw you double posted this "question" so I just answered the same way as @peekay123 has done on your other thread.
That's why double posting is sternly frowned upon.

Apologies for asking so many questions. I’ve been trying to incorporate the lines of codes from the docs; everything seems to compile nicely until it get’s to the publishing.I suspect the issue is in line 115, but Im not really sure how to code this otherwise.

Sharelink: https://build.particle.io/shared_apps/5952a77650cdc9232700102e

You can already set up the subscription without an active connection in setup(). I’d try that to prevent multiple registrations which will eventually fail after for times.

Since you are using AUTOMATIC mode in conjunction with multi threading, you may also be registering the subscription too late, since there is a finite window to register cloud “assets” after a connection, which will happen any time after power-up due to AUTOMATIC mode.


No problem asking many different questions, just asking the same thing multiple times isn’t appreciated as it ties resources without extra benefit.

I tried to do as you say, calling for the subscription during void setup(). It makes totally sense indeed what you mentioned, as it doesn’t need to keep running that line over and over again every time a connection is made.
The same error appears though;

https://go.particle.io/shared_apps/5952ab9050cdc903ec001095

Apologies again for asking so many questions, though I really appreciate all the assistance which help me understand this stuff much better.

What error would that be?
Stating that would maybe save us the need to actually build the code :wink:

But since I already have, you need to remove the eventName variable from your publish statement.

Oh yea, of course:

for line 115, it’s mentioning no matching functions can be called for “spark/device/name”

This is how it should look

Particle.publish("spark/device/name", data, 60, PRIVATE); 

or even better

Particle.publish("spark/device/name", data, PRIVATE); // data can/should be empty to safe on data

The string literal "spark/device/name" already is the event name.

And the reason for the error message is - not surprisingly - because there is no function overload for Particle.publish() that would take three strings.

Oh I see, that makes sense. I will see how this works, especially with my Webhook as I designed that to fetch only ‘‘Pickup Alert’’ events; having the Event Name field being populated with sensor names can make it a bit more tricky.

Yeah, I figured I couldn’t just add extra strings in as when I tried to remove the EventName string before it worked just fine; I just felt I was doing something work and there must be a way to just add in more fields.

Thanks a bunch for your help, this surely will help me out.

1 Like

When using this code, with your revision:

https://go.particle.io/shared_apps/5952b0a950cdc91611000f46

It compiles just fine. But once the sensor wakes up and connects, it doesn’t actually publish anything anymore.

But it does without the Particle.subscribe() and/or Particle.publish()?
Do you get any events in https://console.particle.io/logs ?
Can you add some Log statements to follow the flow of your FSM?

hi,

yes exactly. Without Particle.subscribe and adding “spark/device/name” in Particle.publish everything works smoothly and I get all the data I want (minus device name). The console right now gives no messages when the sensor wakes up.

I’d have to try that myself, since I can’t see a reason why you wouldn’t at least see the spark/device/name event

But what I fail to see is the original publish you may have had in your original code to publish your actual data.

BTW, to catch a PRIVATE event, you need to subscribe with MY_DEVICES

Original : https://go.particle.io/shared_apps/5952b8ad50cdc92327001374
New: https://go.particle.io/shared_apps/5952b6f850cdc9daf0001314

Been playing around with it for a while but still can’t quite figure out what’s wrong with it.