Cisco Meraki GPS
IFM supplies network engineering services for $NZ180+GST per hour. If you require assistance with designing or engineering a Cisco network - hire us!
Have you got a mobile device (perhaps a boat or vessel, delivery vehicle, etc) which has a Meraki device on board, and you would like the devices actual location to show on the Meraki Dashboard overview map?
Meraki GPS is a Python script that grabs the current GPS (or GNSS if you are a purest) co-ordinates from a network gpsd source (attached via Ethernet or WiFi) and calls the Cisco Meraki API to update that devices location. This guide uses a Raspberry Pi and a GPS module to act as the network gps provider - so the entire solution runs from one little box.
First you are need to build a Raspberry Pi built with a GPS module. Get your soldering iron out and head over to RS Online. Order all the bits and then follow their excellent guide about how to get this portion up and running.
Once you have the hardware running and tested download meraki-gps.py (last updated 21-Feb-2020).
I would recommend making the script executable to make things easier.
chmod +x meraki-gps.py
You need to install these modules on your Raspberry Pi.
sudo apt install python3-pip pip3 install gpsd-py3 pip3 install meraki pip3 install -U python-dotenv
meraki-gps uses dotenv to safely store your credentials. Create a file called .meraki.env in your home directory (note the leading dot in the filename). For Linux this is typically /home/username. For Windows this is typically c:\users\<username>.
Into .meraki.env put this line:
x_cisco_meraki_api_key=<your API key>
If you don't have an API key yet then following the instructions on this page: https://documentation.meraki.com/zGeneral_Administration/Other_Topics/The_Cisco_Meraki_Dashboard_API
Now let's test the script by running it. The command line parameters are listed below. Substitute in your values and start it running.
./meraki-gps.py -o "Your org name" -n "Your network name" -s device-serial-number
Now go check the Meraki Dashboard overview page (or the device's page itself) and it should now be showing where the device is on the map
If you are happy everything is working correctly the next step is to use cron to schedule the script to run regularly.
Cron is a scheduler that lets you run things on a regular basis. To get into the cron editor use "cron -e". An example that runs the script every minute is:
* * * * * /home/pi/meraki-gps.py -o "Your org name" -n "Your network name" -s device-serial-number
An example that runs the script every 10 minutes is:
*/10 * * * * /home/pi/meraki-gps.py -o "Your org name" -n "Your network name" -s device-serial-number
An example that runs the script every 10 minutes on weekdays 7am to 7pm is:
*/10 7-19 * * 1-5 /home/pi/meraki-gps.py -o "Your org name" -n "Your network name" -s device-serial-number
You're finished. Now your mobile Meraki devices will report their actual location in the Meraki Dashboard.