Put data to my own database

Hello Group,

I would like to ask you if there is a way I can send data to my own database , or an sql database?

Thank you in advance

Server Sent Events, Particle.variable(), HTTP server, TCP/IP, UDP, and probably some others… Take a pick. Enough options to choose from. It just depends on what you’re comfortable with, and what your back-end looks like.

1 Like

Here is the way I implemented such a solution (your results may vary):

I have a core that performs a publish() once every five minutes with a string containing all the data I need.
I use a web hook to relay that data to a PHP page on my hosted web server.
The PHP script decodes the POST data string into its constituent data fields
The PHP script issues an INSERT into the MySQL database table (also hosted).
Database fills up with data.
I can SELECT against the database as needed from anywhere.

I hope this helps.

3 Likes

Hello,

Thank you for your help! Is it possible to give me any example code?

Thank you in advance

I am using an Azure EventHub with an Eventprocessor for something similar.

In my case i scan an RFID Card with my photon which triggers an azure event in the cloud via a webhook. Azure than processes my event and “answers” by calling a function on that photon. i only use temporary data and just query a db for processing but any value could easily be saved in an azure sql db.

i have to admit though, this is not the easiest thing to get started though if you’re not familiar with
MS / .net / Azure.

but neither is all the C / electronics side of things for someone (like me) who comes from the .net world and i still made some suprisingly significant progress in short time :stuck_out_tongue_winking_eye:

Plus, there is some “ConnectTheDots” Example for Particle + Azure somewhere.

For personal use this should be managable (or neraly at least) with Azures Free offerings.

Although theoretically possible, it would be extremely hard in practice. There are simply way too many different options to be able to give you some example code.
If you use Particle.variable(), you need to poll with the server. Using SSE, you need to have a listener. Using webhooks, you'd have to have an API on the server which can be reached. TCP/IP requires yet another setup.
Then there are the different languages that can be used, and the different server set-ups. The LAMP stack is the 'old trusted' one, but node.js servers are quickly gaining popularity for these kinds of applications.
Taking the above into considerations, I'd be inclined to say:"no, we can't give you any example code". That is, without you telling us what you're planning on using, it's a way too broad of a request.

What kind of server setup are you planning to use, and in which language are you planning to program it?

Another option is to use ThingSpeak (full disclosure, I'm connected to it). There's a library for the Photon/Core in the IDE, and you can set up a free account to store your data.

More info and a video in my posting:

1 Like

I’ve posted some basic PHP stuff on github that you could pick through. iot.php is a simple FIFO dump into a file formatted for a javascript array. It’s general purpose, but the name field is required for a filename. chart.php loads specific fields for charting, so you could use that for testing the data. Just examples, no support. Particle is a much better system. This method has no filters, monitoring, alerts, or anything special. I think it had local datestamp though.

Hi again,

I had success with writing from a mysql , but is it possible also to read from a mysql with the photon?

regards
johnyrobot5

You can certainly have a PHP script on your website read data from a MySQL database and send it to your Photon using something like Particle.function(). Triggering the script is the real question. My suggestion, untested, would be to use Particle.publish() to trigger a webhook, like you did when you pushed data to the server. Let the webhook trigger the PHP script which will then read data from the DB and then send it back to the Photon using Particle.function().

Let me know how this works.

2 posts were merged into an existing topic: Alternative to Webhooks and Particle cloud

Hi Muskie, I’m looking to do the same thing as your solution.

My publish function to the Particle cloud is working fine, and the webhook I created in the console seems to publish my data when tested on requestb.in - However, I get no data inserted into mysql DB when the webhook is sent to my hosted PHP page.

I’m confident in my PHP script for connecting to / inserting into the data base, so I think my problem lies in the PHP code for receiving and processing the webhook. Could I get some example PHP code from your solution?

Thanks

I do think this is something that does need addressing with a set of sample code in a popular language. While there are of course many popular language/platform choices out there the language chosen for an example is not really important. What some sample code needs to demonstrate is how to put all the various bits of functionality together rather than the current very short curl https://api.particle.io/v1/devices/flimflamflow/blah\1 examples in the documentation. It should also include a working method for handling the authentication of “customers” etc so that the entire ecosystem can be demonstrated, picked apart and understood.
Now I understand that for a proper commercial project that needs all these features, they should be getting in expertise to working with the cloud side if they do not possess it in house. However if you are a small hardware developer you might well want something quick and dirty to knock up to test or demonstrate things before you run up further expense paying someone potentially quite expensive.

Longer term I think there is potentially a larger issue, as Particle transitions to a platform independent of its hardware it needs to offer more.

Some of the third party platforms for storing and viewing your data that you might choose to interface to your Photon completely bypass the Particle ecosystem. Many of them either offer OTA firmware updates or have it on their roadmap as well as many of the the other features Particle has.

If people are forced down this 3rd party service route because the roll your own approach is too complicated and Particle don’t have an offering they of their own are going to reach a point at at some point in the product lifecycle where they will question what Particle is for and whether they need it.

2 Likes