sudo nmap -sn 192.168.1.0/24 | grep -B 2 Raspberry
First you have to find your current IP address and netmask. If you don’t know what a netmask is, chances are you have a 24-bit netmask (which you may have seen in this format: 255.255.255.0).
The -sn option in nmap disables port scanning. This allows for a much faster, host discovery-only scan. After nmap is done, we are piping its output into grep, so that we can filter out our Raspberry Pi devices. The -B option stands for “before”, which means that grep will include the upper two lines of the output too. Without them we would only see the MAC address.
If you put this command in our ~/.bash_profile file with an alias, we can simply type “findpi” into a terminal and are done (see screenshot above)!
alias findpi='sudo nmap -sn 192.168.1.0/24 | grep -B 2 Raspberry'
I really like the MOBA League of Legends which is currently the most played game in the world. In LoL there are two teams of five people fighting on a big map in order to destroy the enemy nexus. After starting a game, many people will visit lolnexus.com during the loading screen, a site that provides live game details. You get insight into their ranking , runes and masteries which can possibly help you to win the game.
For my weekend project I wanted an application to do the following tasks for me:
- Check if player “x” is in a game every 20 seconds
- Start TV using CEC
- Start a web browser and point it to lolnexus.com
- Wait until game is over and turn off TV
Sounds simple right?
Turning a TV on using CEC
Consumer Electronics Control (CEC) is used to control a TV over the HDMI cable. I found a library called libCEC (Tutorial) that compiles on Raspbian. LibCEC installes the command line utility cec-client that I used in my application.
echo "on 0" | cec-client -s
Piping “on 0” into cec-client turns the TV on. You can use “standby 0” to turn it off. Now I need to find out how I can start a web browser on the Raspberry Pi.
Starting a browser in kiosk mode
Kiosk mode means starting it in fullscreen with no visible controls. I used the pre-installed browser Midori for this. But before you can start a browser, you need to start a graphical interface:
The “&” is used to start the process in background. “startx” should now have started a GUI on display :0. Now let’s start the browser:
midori -e Fullscreen --display :0 -a http://lolnexus.com/...
That’s it. Using this knowledge I created a simple application to turn my TV on whenever I started a new game and display lolnexus. Since I often get snacks during loading screen and have to walk past my TV, I can now simultaneously prepare myself for the game.
The application (written in Node.js) can be found on Bitbucket.