How to send data from a Particle Photon to OpenSensors

from on 20.09.2016
0
particle-webhook

The Particle (formerly Spark) Photon is an easy to use WiFi connected micro-controller with a great web interface for managing the small Photon devices (think Arduino Nano connected to and programmed by the cloud). Code that runs on the device is written in Wiring, just like on Arduino. Particle have an app for provisioning and a rich web interface for developing, deploying, integrating and running the devices. And it’s not just for hobbyists, Particle sell the modules for inclusion in your own hardware devices also. https://www.particle.io/

OpenSensors is a cloud-based time-series database that is available for free if you’re happy to make your data publically available. Their team is developing a series of interesting tools to visualise and use the collected data. https://www.opensensors.io/

Generating data from the Photon and sending it to OpenSensors is straightforward. I’ll assume that you’ve already created an account with Particle and set up your Photon. If you haven’t already, get the Particle App “Publish” example running on your Photon. This uses a measured change (in this example the change in a photo resistor’s measured analogue reading) to trigger the publishing of an event from the Photon to the Particle cloud.

picture1

The important line in the app is the publish call. The reference to Spark is because this library predates the company renaming itself as Particle.

Spark.publish(“beamStatus”,”broken”,60,PRIVATE);

Then check that you are receiving the beamStatus event in the Particle console. Note that events only appear on the console page if they occur while you are on that page.

picture2

Now its time to create an OpenSensors account, and log in to their console. First create a new device, and keep a note of the Client Id and the device password.

picture3

Then create a Topic, to accept JSON data with no schema:

picture4

You can test that data can be sent to this topic using Postman (or Curl). You need the link from the Topic Page (/users/mike/test in my case) and the API Key which you can get from the profile page:

picture5

You should now be able to post data to your new topic, like below but with your client id, device password, API key and topic name:

curl -X POST -H “Content-Type: application/json” -H “Accept: application/json” -H “Authorization: api-key <APIKEY>” -d ‘{“data”: “testmessage”}’ https://realtime.opensensors.io/v1/topics//users/mike/test?client-id=<CLIENTID>&password=<DEVICEPASSWORD>

If that data appears in your topic view, then OpenSensors is all set too.

picture6

The final step is then to get Particle to post data to OpenSensors. We will do this using a Webhook, which you can access in the Particle console.

picture7

Hit “New Integration”, and select Webhook. The event name is the event that is published in the Photon, in this case “beamStatus”. The URL is the same URL that we just tested (again, using your real client id and password rather than the placeholders). Open “Advanced Settings”, and ensure the value from the publish call is sent as JSON:

{

“data”: “{{PARTICLE_EVENT_VALUE}}”

}

picture8

Then place the api key as a header, and ensure “Include Default Data” is set to No.

picture9

If you hit the Test button you should receive an acknowledgement that the call succeeded, and see a test message recorded on the OpenSensors topic. Now trigger the photon to publish events, and see them arriving at OpenSensors. You’re done!

picture10

 

Write a comment

Your e-mail address will not be published or shared with third parties. Fields marked with * are required.