After last Christmas, I decided to buy myself a Pebble. I really wanted to write some kind of code for it. Since I was on break/had a ton of snow days, I set up a Feed the Beast (modded) Minecraft server to play with friends, running via Hamachi (a VPN).

The Pebble arrived around 6 pm on the first of three consecutive snow days leading up to the weekend. I proceded to stay up until 7:30 the next morning working playing with it, mostly in a frustrated attempt to get SSH running on Windows via Cygwin. (Note to all: if you’d like to maintain your sanity, please do not do this. Linux exists for a reason.) One quick Ubuntu install later, I copied over the world files and had the Minecraft server running.

I wanted to be able to see who was currently logged into my Minecraft server whenever I glanced at my watch. This turned out to be fairly easy, with a few scripts and the MyData app for Pebble, but was complicated by my use of Hamachi.

Note that this guide explains how to do this for a server running Linux, only. These steps will not run on Windows or OSX servers (but probably could with a bit of coaxing).

You’ll need these three scripts on your server (click download zip, or copy paste them from here into text files).

#!/bin/bash # starthttp.sh
cd /home/ian/server/mineservpoll
python -m SimpleHTTPServer 8000
statuscheck.sh
#!/bin/bash
python /home/ian/server/mineservpoll/status.py > /home/ian/server/mineservpoll/status
status.py
from mcstatus import MinecraftServer
import json
# If you know the host and port, you may skip this and use MinecraftServer("example.org", 1234)
server = MinecraftServer.lookup("localhost:25565")
# 'status' is supported by all Minecraft servers that are version 1.7 or higher.
status = server.status()
query = server.query()
print(json.dumps({"content": ', '.join(query.players.names), "refresh": 300, "vibrate": 1, "font": 4, "theme": 1, "scroll": 33, "light": 0, "blink": 0, "updown": 1 }))

Run your server on Linux

This has been documented very well elsewhere, so I’m not going to go into it. Google it, or feel free to drop me a line if you have problems. Make sure you know your IP, since you’ll need it later.

Forward your ports, or Hamachi

Again, this has been well-documented. Pick a port that you like and forward it in your router. I’ll be using 8000 here. If you’re using Hamachi, things are a little more complex. You’ll need to install Hamachi on your server (using either the command line version or the GUI), as well as on your phone.

Set up Python/bash scripts, Cron task, Minecraft Server

Run command means open a terminal and enter the command.

Don’t forget to download these files.

  • Make a new folder in your server folder called mineservpoll.
  • Unzip the three scripts and put them in this folder.
  • Open starthttp.sh and change /home/ian/server/mineservpoll to the path of your folder.
  • In that same file, change the port to whatever you like.
  • Open statuscheck.sh and change /home/ian/server/mineservpoll/status.py > /home/ian/server/mineservpoll/status to your server folder’s path.
  • Open status.py and change localhost:25565 to your server’s external IP (or Hamachi IP) and port.
  • Open up your server.properties file, and set enable-query to true. Save/exit.
  • Run pip install mcstatus to get the necessary Python package.
  • Run crontab -e. Add the following lines, then save and exit.
    • @reboot /path/to/starthttp.sh
    • * * * * * /path/to/statuscheck.sh
  • You might also consider adding @reboot /path/to/your/startServer.sh to your cron task.
  • Reboot your computer.

Pebble App

Search for “MyData” on the Pebble app and load it onto your watch. Open the settings menu and type in the IP address of your server, followed by a colon and your port (eg 256.256.256.256:8000) and save your settings. If you’re using Hamachi, entert the Hamachi IPv4 address for the server, along with the port.

That’s it! Upon clicking the refresh button, your watch should display any currently-logged-in users.

Feel free to drop me a line if you run into any hiccups. Twitter’s best.