{"id":1722,"date":"2015-04-29T16:44:52","date_gmt":"2015-04-29T16:44:52","guid":{"rendered":"http:\/\/www.frozax.com\/blog\/?p=1722"},"modified":"2015-04-29T16:45:30","modified_gmt":"2015-04-29T16:45:30","slug":"controlling-your-tv-using-minecraft-useless-but-fun","status":"publish","type":"post","link":"https:\/\/www.frozax.com\/blog\/2015\/04\/controlling-your-tv-using-minecraft-useless-but-fun\/","title":{"rendered":"Controlling your TV using Minecraft: Useless, but Fun!"},"content":{"rendered":"<p><a href=\"http:\/\/www.frozax.com\/blog\/2015\/04\/commander-sa-freebox-dans-minecraft-inutile-donc-indispensable\/\">Version en Fran\u00e7ais<\/a><br \/>\nHere are the details of my latest side-project: controlling my TV from inside Minecraft! It&#8217;s surely slower than using the remote control, but it was interesting to make and it&#8217;s working!<br \/>\nYou can see it in action in the video, and read about the technical aspects below.<\/p>\n<p><iframe loading=\"lazy\" frameborder=\"0\" height=\"360\" src=\"http:\/\/www.youtube.com\/embed\/W9VVCVh9m2g?rel=0\" width=\"640\"><\/iframe><\/p>\n<h1>How does it work ?<\/h1>\n<p>The different components of this project are developed in Python 3, and running on Linux (Ubuntu).<br \/>\nI suppose anyone could easily run it on another platform with minor modifications.<br \/>\nHere are the details of the implementation.<\/p>\n<h2>Controlling the TV<\/h2>\n<p><a href=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2015\/04\/minecraft_free.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2015\/04\/minecraft_free-150x150.png\" alt=\"minecraft_free\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-1731\" \/><\/a><br \/>\nThe TV is plugged into a <a href=\"http:\/\/www.freebox.fr\">Freebox<\/a>, a set-top box provided by the french ISP <a href=\"http:\/\/www.free.fr\">Free<\/a>. The box is connected to the network and we use UDP messages to simulate the remote control. The <a href=\"http:\/\/dev.freebox.fr\/sdk\/\">documentation about the protocol<\/a> is light and it&#8217;s hard to find samples.<br \/>\nI found a draft of a Python implementation of the protocol made by <a href=\"https:\/\/github.com\/MaximeCheramy\/remotefreebox\">Maxime Cheramy<\/a>. It was really useful to get me started in UDP network programming and RUDP in Python. I also used the <a href=\"https:\/\/github.com\/fbx\/foils_hid\/\">C sample<\/a> provided by Free to better understand the packet format used to send the keys. I sniffed the UDP packets using Wireshark, and even took some time to write a dissector for <a href=\"https:\/\/www.wireshark.org\/\">Wireshark<\/a> using the plugin <a href=\"http:\/\/wsgd.free.fr\/\">WSGD<\/a>.<br \/>\nThe latest version of the Python code, as well as the wireshark dissector are available on <a href=\"https:\/\/github.com\/frozax\/remotefreebox\">my public Github<\/a>.<\/p>\n<h2>Controlling the Minecraft server<\/h2>\n<p><a href=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2015\/04\/grass.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2015\/04\/grass-150x150.png\" alt=\"grass\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-1733\" \/><\/a><br \/>\nI&#8217;m running an official Minecraft server (in Java). I wrote a small class allowing me to send commands to the server, and interpret the output. It&#8217;s quite hacky but it&#8217;s working well enough.<br \/>\nAs I run the server in <a href=\"http:\/\/en.wikipedia.org\/wiki\/Tmux\">tmux<\/a>, I can easily find the process using <code>tmux list-panes<\/code>, send commands using <code>tmux send-keys<\/code> and parse the server output using <code>tmux capture-pane<\/code>.<br \/>\nThe latest version of the code <a href=\"https:\/\/github.com\/frozax\/my-python-packages\/blob\/master\/minecraft.py\">is here (minecraft.py)<\/a>.<\/p>\n<h2>Detecting player actions<\/h2>\n<p>In the Minecraft world I made for the occasion, each button of the virtual remote control is connected to a <a href=\"http:\/\/minecraft.gamepedia.com\/Command_Block\">command block<\/a>, as you can see in the screenshot below.<br \/>\n<a href=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2015\/04\/minecraft_remote.png\"><img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2015\/04\/minecraft_remote-300x169.png\" alt=\"minecraft_remote\" width=\"300\" height=\"169\" class=\"aligncenter size-medium wp-image-1729\" srcset=\"https:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2015\/04\/minecraft_remote-300x169.png 300w, https:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2015\/04\/minecraft_remote.png 852w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nThe associated commands set a game rule to a specific number, using <code>gamerule set remote &lt;value&gt;<\/code>. A script is constantly checking for the state of this variable and if it changed, does the following:<\/p>\n<ul>\n<li>Converts the value to a key (using a .json configuration file)<\/li>\n<li>Sends the key through the network to the freebox, using the <code>FreeboxController<\/code> class.<\/li>\n<li>Use other fancy minecraft commands used to change the background of the &#8220;big&#8221; remote control in the game world, using the <code>MinecraftServer<\/code> class.<\/li>\n<\/ul>\n<p>As usual, the code is <a href=\"https:\/\/github.com\/frozax\/fbx-minecraft\">on Github<\/a>.<\/p>\n<p>That&#8217;s it, I hope you liked this post (first post in two years&#8230;).<br \/>\nFeel free to share, comment, or ask me anything at <a href=\"http:\/\/twitter.com\/Frozax\">@Frozax<\/a>!<\/p>\n<div class=\"addtoany_share_save_container addtoany_content_bottom\"><div class=\"a2a_kit a2a_kit_size_32 addtoany_list a2a_target\" id=\"wpa2a_1\"><a class=\"a2a_button_twitter\" href=\"http:\/\/www.addtoany.com\/add_to\/twitter?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2015%2F04%2Fcontrolling-your-tv-using-minecraft-useless-but-fun%2F&amp;linkname=Controlling%20your%20TV%20using%20Minecraft%3A%20Useless%2C%20but%20Fun%21\" title=\"Twitter\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_facebook\" href=\"http:\/\/www.addtoany.com\/add_to\/facebook?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2015%2F04%2Fcontrolling-your-tv-using-minecraft-useless-but-fun%2F&amp;linkname=Controlling%20your%20TV%20using%20Minecraft%3A%20Useless%2C%20but%20Fun%21\" title=\"Facebook\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_google_plus\" href=\"http:\/\/www.addtoany.com\/add_to\/google_plus?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2015%2F04%2Fcontrolling-your-tv-using-minecraft-useless-but-fun%2F&amp;linkname=Controlling%20your%20TV%20using%20Minecraft%3A%20Useless%2C%20but%20Fun%21\" title=\"Google+\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_reddit\" href=\"http:\/\/www.addtoany.com\/add_to\/reddit?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2015%2F04%2Fcontrolling-your-tv-using-minecraft-useless-but-fun%2F&amp;linkname=Controlling%20your%20TV%20using%20Minecraft%3A%20Useless%2C%20but%20Fun%21\" title=\"Reddit\" rel=\"nofollow\" target=\"_blank\"><\/a>\n<script type=\"text\/javascript\"><!--\nwpa2a.script_load();\n\/\/--><\/script>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Version en Fran\u00e7ais Here are the details of my latest side-project: controlling my TV from inside Minecraft! It&#8217;s surely slower than using the remote control, but it was interesting to make and it&#8217;s working! You can see it in action in the video, and read about the technical aspects below. How does it work ?&hellip; <a class=\"more-link\" href=\"https:\/\/www.frozax.com\/blog\/2015\/04\/controlling-your-tv-using-minecraft-useless-but-fun\/\">Continue reading <span class=\"screen-reader-text\">Controlling your TV using Minecraft: Useless, but Fun!<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[144,12],"tags":[147,146,114,145],"_links":{"self":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/1722"}],"collection":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/comments?post=1722"}],"version-history":[{"count":25,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/1722\/revisions"}],"predecessor-version":[{"id":1755,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/1722\/revisions\/1755"}],"wp:attachment":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/media?parent=1722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/categories?post=1722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/tags?post=1722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}