Webhook and PHP integration

Hello,

I am seeking advice from the community on webhooks and PHP integration.

What options do I have using these tools to receive seemingly real-time Particle.pubish updates from my device(s)?

My understanding of the abilities of each is limited…

I can successfully GET a ThingSpeak channel feed via PHP script at the moment and was curious if this is the best option. If so, I plan to run this script continuously and write to my db but I feel there is a better way…

Any input is much appreciated.

Let me ping someone that might be able to help, @rickkas7 or @ParticleD are you able to assist?

Server-Sent-Events (SSE) is a great alternative to using webhooks to process data sent from Particle Photon, P1, and Electron devices.

Webhooks make outgoing HTTP connections to an external server each time an event is received by the cloud.

SSE, on the other hand, has your server make an outgoing encrypted TLS/SSL connection to the Particle cloud and keeps the connection open. The Particle cloud can then push events down this connection in near real time.

  • Faster response time.
  • Lower request overhead on your server.
  • Can receive events at full 1 event per second publish rate per device, instead of the 12 webhook calls per minute maximum.
  • Your server can be behind a firewall, including NAT.
  • Your server can does not require a DNS name or a fixed IP address.
  • The connection is encrypted without requiring a TLS/SSL server certificate for your server.

These examples are for node.js, but there are SSE implementations for many languages,

1 Like

@rickkas7,

Many thanks! With what you have provided I have been able to write to a mySQL database with your firmware loaded. I am a complete novice at Javascript and was wondering if you could offer some advice as to how I can move forward implementing this with my own firmware.

Whenever I load my firmware I receive the following ?JSON? in the command prompt.

I am attempting to modify your code so that it writes the following to 3 columns;
device name (deviceFilter), the data field listed below, and a timestamp.

event:  { data: 'START',
ttl: 60,
published_at: '2018-02-20T16:36:11.783Z',
coreid: '27002a000e51353532343635',
name: 'Machine_State' }

Thoughts?

Thanks for your time!