Missile Mayhem
Thursday, April 29th, 2010 at 4:06 pmOr how to I set up my USB missile launcher to be controlled over the internet with Linux.
Get missile launcher to work with pymissile.
Run pymissile with the –network option. This will allow you to connect to it using UDP on port 20000 and send commands at it.
To test this use the netcat command on the same machine:
nc -u 127.0.0.1 20000
Commands are typed as “<command>:<enter>”
w or up - move up x or down - move down a or left - move left d or right - move right f or space - fire s - stop moving q - move diagonally up-left e - move diagonally up-right z - move diagonally down-left k - move diagonally down-right r - fire all missiles sequentially v - fire randomly esc - close daemon
Available commands can be found in the class MissileNetwork class in the source code
Then I set up a web server (lighttpd because it’s only a netbook) on the local machine and forwarded port 80 through the NAT. The webserver runs a PHP script that sends UDP packets. The sample code was grabbed from the fsockopen documentation and modified to fit.
The web frontend uses the function below and some AJAX to send requests.
<?php function send_command($command) { $fp = fsockopen("udp://127.0.0.1", 20000, $errno, $errstr); if (!$fp) { echo "ERROR: $errno - $errstr\n"; } else { fwrite($fp, "{$command}:\n"); fclose($fp); } } ?>
Then I set up the webcam to stream live on UStream so people could see where they were aiming.