cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Scanning API sample receiver version 1 outdated

Kind of a big deal

Scanning API sample receiver version 1 outdated

Hello all,

 

I wanted to play around with the scanning API yesterday and I noticed that the source code of the Sample Version 1 Receiver code on this link was a bit outdated and no longer worked for me:

https://documentation.meraki.com/MR/Monitoring_and_Reporting/Scanning_API

 

I wanted to share the things I needed to fix to get it to work:

  • Connect middleware isn't shipped with express anymore so I had to install it manually after installing express:
sudo npm install connect
  • Due to that reorganisation in the nodejs modules the code also changed a bit, see the source code below for an updated version.
  • Also on the Meraki end, the structure of the JSON post changed, and some names were slightly changed. this too caused some changes in the source code.

Here's the edited source code that works:

// nodejs Meraki Presence receiver by Kris Linquist (klinquis@cisco.com) updated by @BrechtSchamp on the Meraki Community
//
// Prerequisite: the express node module and the connect node middleware.  Use 'sudo npm install express' and 'sudo npm install connect' to install. 
// Then start this script with 'nodejs merakiReceiver.js' (sudo required if port <1024)
//
// Meraki will send a HTTP GET request to test the URL and expect to see the validator as a response. 
// When it sends the presence information, it will also send the secret.  This script validates that the secret is correct prior to parsing the data.
//
// This script listens for the uri {request_uri}:port/meraki
//
// Tested on RPi running raspbian 9.8 stretch with node.js v9.11.2 and npm version v5.6.0

var listenport = 9201; //TCP listening port var secret = "xxxxxxxxxxxxx"; //Secret that you chose in the Meraki dashboard var validator = "xxxxxxxxxxxxxxxxx"; //Validator string that is shown in the Meraki dashboard var express = require('express'); var app = express(); var bodyParser = require('body-parser'); app.use(bodyParser.json()); app.get('/meraki', function(req, res) { res.send(validator); console.log("sending validation") }); app.post('/meraki', function(req, res) { try { var jsoned = req.body; if (jsoned.secret == secret) { for (i = 0; i < jsoned.data.observations.length; i++) { console.log("client " + jsoned.data.observations[i].clientMac + " seen on ap " + jsoned.data.apMac + " with rssi " + jsoned.data.observations[i].rssi + " at " + jsoned.data.observations[i].seenTime); } res.sendStatus(200); // to let the dashboard know parsing went fine } else { console.log("invalid secret from " + req.connection.remoteAddress); } } catch (e) { // An error has occured, handle it, by e.g. logging it console.log("Error. Likely caused by an invalid POST from " + req.connection.remoteAddress + ":"); console.log(e); res.end(); } }); app.listen(listenport); console.log("Meraki presence API receiver listening on port " + listenport);

Hope it helps someone down the line!

2 REPLIES 2
Meraki Employee

Re: Scanning API sample receiver version 1 outdated

Hi,

 

Thanks for sharing your findings.

 

FWIW, the more recent version of the Scanning API documentation is on the Meraki.io site.

https://create.meraki.io/build/scanning-api-docs/

 

The newer doc provides a few other examples (node, python, etc). The Node version I wrote has the package.json file etc included, so it handled the changes with the NPM libraries.

 

https://github.com/dexterlabora/cmxreceiver

 

 

 

Kind of a big deal

Re: Scanning API sample receiver version 1 outdated

Thanks for the reply!

 

I do notice that the outdated sample code is still referred to in the meraki.io scanning api docs, and it's drawing my attention more than your sample code :P.

 

Great work!

Welcome to the Meraki Community!
To start contributing, simply sign in with your Cisco account. If you don't yet have a Cisco account, you can sign up.