Project: Cisco Meraki Presence Based Remote Control
What is it?
The meeting room in our office (like a lot of meeting rooms) has a large screen in it. People use Chromecast or a cable to present information on it.
Imagine walking into your meeting room at work and the room sets itself up for you because it recognises you are present. In this particular case, the TV is turned on when you are in the room, and turns off again when you leave.
How does it work?
This project uses a Cisco Meraki MR access point in the room and the Meraki Scanning API to detect 802.11 and bluetooth beacons that are being generated within about 3m of that Cisco Meraki access point. Because only beacons are being monitored you don't have to be attached to the WiFi or paired with anything bluetooth. All you need is one or more users in the room to have a "smart" device with WiFi or BLE built in. The code runs on a Raspberry Pi. The Raspberry Pi has an infrared LED attached to it, which allows it to simulate a typical "remote control" for turning devices off, on - and generally control them. It would only be a small additional effort to control additional "things", such as turning power outlets on and off, lighting control, heating control, etc.
Why did you do it?
This is a "proof of concept" project I have done to demonstrate the use of Cisco Meraki location analytic capabilities. Location analytics is about more than "Retail", "shopping" or improving in-store customer experiences.
This is not a production ready system, but a fun project to encourage others to explore new ways of using their Cisco Meraki kit. I'm hoping to expand peoples views of what can be done.
How much does the project cost?
Assuming you already have a Cisco Meraki MR, maybe USD$60.
What do I need?
A Raspberry Pi, an IR LED, a transistor, a 220 Ohm resister, and a 10k Ohm resister, some spare wires and a prototype breadboard.
Do I need a PhD?
You don't need a PhD but knowing how to take an MR apart and re-engineer it would help. Just kidding. I wouldn't describe this as suitable for beginners. Ideally you would have some experience with basic electronics and Python, some familiarity of Linux and some similarity with Cisco Meraki - or a strong desire to learn new skills and don't mind spending some extra time while you gain those skills. I would say this would be suitable for teenagers and above (I'm nearly 50 - so older people can do this too!). I think a school with Cisco Meraki MR access points could base a series of classes around the ideas contained here, or have students come up with new control system ideas and then build them. Lets bring on a new generation of engineers!
First we need to get a Raspberry Pi up and running with an IR LED attached. There are so many projects covering this aspect I am not going to go into re-invent the wheel (I'm more interested in the Cisco Meraki bit). Let me get you started by pointing you at this simple project:
Get yourself to the point where using the Raspberry Pi you can remote control a device, like a TV.
Now we need to get a web server up and running on the Raspberry Pi so that the Meraki API can talk to us.
First start by NATing a port through from the outside world to your Raspberry Pi. In "my" code (which I got copied from the Meraki Developer area for scanning and simply modified) I used port tcp/6000.
If you have a Cisco Meraki MX, you can configure the NAT in "Security Appliance/Firewall". A sample might look like:
Next we need to configure the Meraki Scanning API to send data to our Raspberry Pi. Make a note of the dynamic DNS entry on your MX ("Security Appliance/Appliance Status"). Now following this guide to enable the scanning API.
Next download the meraki-cmx-reciever.py script to your Raspberry Pi. Fill in the "validator" and "secret" (the secret is a password you make up), and then run it. After this go back to the Dashboard and click "validate". The validation should now work.
Now you can stop the script, and we'll make a few more edits. Find out what the MAC address is of your AP ("Wireless/Access Points/[click on AP]"). Update the below line in the script to use your AP MAC address.
if data['data']['apMac'] == 'e0:xx:xx:xx:xx:xx' :
You should also update the below lines with the previous command you tested for controlling the IR LED.
With the script running it will look for devices with a reported RSSI of 45 or greater. This means you need to be within 2m to 3m of the AP. At this point it will trigger the "on" action. The time for this detection is greatly affected by how often your device sends beacon requests. I have found 2 minutes for a WiFi device is common. I've also seen it take 6 minutes. And the more devices in the room the more beacons will be sent and the faster it will take action.
I have not had much luck with BLE bluetooth devices. I have found they don't beacon often enough to be usefull.
If your Rasberry Pi is near the AP the AP may pick up the Raspberry Pi being in the room. You can either physically cable the Raspberry Pi and then disable the WiFi built in ("ifdown wlan0"), or you can add some extra code to exclude the MAC address of any WiFi devices that are permanently in the room. The script spits out lots of info ("debug") so you can see the details.
Once the script has not seen any devices with an RSSI greater than 45 for 4 poll cycles it assumes no one is left in the room and turns the TV off again.
Feel free to edit and "hack" the script to do whatever you would like. Here are a couple of pictures of the setup I used (I put the IR LED right below the TV IR receiver).
Thanks for the feedback @colo. I work for a Cisco Meraki Partner and as you can see, I find the branding confusing myself. I guess there have been a lot of documents written over time, and thanks to the Internet they don't disappear.