Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Logging From Sonos Speakers With a Webhook

DZone's Guide to

Logging From Sonos Speakers With a Webhook

Want to log your Sonos speakers? Well, Webhook allows Sonos speaker logging, which may be music to your ears. Check out how in this neat tutorial!

Free Resource

Share, secure, distribute, control, and monetize your APIs with the platform built with performance, time-to-value, and growth in mind. Free 90 day trial 3Scale by Red Hat

logging-for-SONOSOur Boston sales office has a big set of Sonos speakers around their office that pumps tunes out across the office. It’s great for camaraderie until someone sticks country music on…On a visit, I had an hour to spare, so I decided to find out if I might be able to log the music activity to Logentries, and it was surprisingly simple.

After some quick googling, I found a few Node.js libraries that interface with Sonos and the Sonos HTTP API by Jishi seemed like the easiest to set up. The HTTP API is a simple node js web server that offers a number of HTTP endpoints that lets you interface with Sonos programmatically, or with manual GET requests. You can view the state of the Sonos device as you change tracks, pause the music, or turn up the jam.

To do a quick test, I installed the code on my laptop with npm:

npm install git://github.com/jishi/node-sonos-http-api.git

Then I fired up the web server and I was up and running in seconds.

cd node_modules/sonos-http-api/
npm start

The Node.js module automatically detects our Sonos speakers.

After I’d confirmed the API was working by sticking on some minimalist techno, I set up the web server to log to Logentries using our webhook logging.

Firing to Logentries

The Web Server’s documentation mentions experimental webhook logging, perfect!

On Logentries, I created a manual TCP token log and copied the token I received. here’s a guide for that.

Once I had my token, I added a settings file to the root directory of the server (node_modules/sonos-http-api/)

(Replace *TOKEN* below with the token you got when creating your manual log).

{
"webhook": "https://webhook.logentries.com/webhook/logs/*TOKEN*"
}

After restarting the server, everything that happened to our Sonos speakers was logged to Logentries, excellent!

sonoslogs

And this data is going to look perfect in our upcoming table view!

sonoslogstableview

Once the data is coming into Logentries, we can run a lot of interesting queries against it.
For example, we can see how the volume changes over the course of an hour:
calculate(average:volume) timeslice(10)

sonosvolumeaverage

The only problem with this was that the web server was running on my laptop, and I couldn’t leave it in Boston when I went back to Dublin, so the next step is to hook this up on a Raspberry Pi, expect an update on that soon!

For another interesting way to use our webhook logging be sure to check out: How to Log Messages from Slack



Discover how you can achielve enterpriese agility with microservices and API management

Topics:
logging ,integration ,log management ,iot

Published at DZone with permission of GearoidOFearghail, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}