Page 272 - Hacking Roomba
P. 272
Chapter 12 — Going Wireless with Wi-Fi 253
As you can see, the Roomba functions seem very similar compared to the RoombaComm func-
tions. The only strange statements are the pack() statements, like:
pack(“C*”, 137, $vhi,$vlo, $rhi,$rlo)
In PHP, in order to send raw bytes with no string or numeric translation (which is normally
what you want), you need to pack the bytes into a variable according to some packing rules. In
the preceding statement, C* means to pack a series of unsigned bytes. The asterisk means an
unknown number of bytes. In the preceding case you could use C5 since you’re packing five
bytes. When receiving data from Roomba, you need to use a corresponding unpack() method.
If you expand roombacmd.php to more fully control Roomba, the first thing to do is to move
the Roomba functions into their own file to build a Roomba PHP library called, for example,
roombalib.php. You can then use this separate file with include ‘roombalib.php’ at the
top of your main PHP file.
The HTML user interface is an example of using multiple Submit buttons for a single form.
Each button sends a different value for cmd. You could have just as easily created multiple links
and set the cmd query argument yourself.
Putting It All Together
Now that you have a working PHP page to control Roomba, you can run it anywhere you can
find a working LAMP system. This includes virtually all web hosting services on the Internet.
In order to run roombacmd.php from one of them, you’ll need to poke a hole in your firewall
to allow computers outside your home network to connect.
Most home routers have a special configuration page just for such changes. Your home network
looks like a single IP address to the rest of the Internet, but that IP address can have many dif-
ferent ports. What your router can do is translate one IP:port pair on the outside part of your
network to another IP:port pair on the inside of your network. This is called port mapping or
port forwarding and is often used to allow online gaming or P2P file sharing to work, so you
may already have some port maps in place.
For example, if your external IP address to the Internet (WAN IP address) is 12.34.56.78
and the IP address of your Roomba is 192.168.0.1, then you’d configure your router to map
port 10001 from one IP address to the other. This can be written in documentation as
12.34.56.78:10001 ---> 192.168.0.1:10001.
If you don’t know your external WAN IP address, go to http://whatsmyip.org — you
should be able to see it.
A final task is to make an enclosure for the WiMicro and carrier board. Having an exposed cir-
cuit board looks cool but as the WiMicro is expensive it’s a good idea to protect it. Any small
enclosure of the right size can be used. Figure 12-13 shows one example using a small project
box. Small cut-aways on the sides are made where the antenna and Roomba cable come out.
Figure 12-14 shows the finished enclosure mounted on the Roomba.