This assignment describes how to use basic networking with a focus on concepts most useful to robotics. First we will learn about pipes in Bash or a unix shell. You can do these exercises by sshing into your drone. When you type at a shell, each shell program reads from a stream, known as “standard input” and writes to two output streams, “standard output” and “standard error.” When you “print” in python, it writes its output to standard output. In another language, such as C, you use other functions, such as “printf” to write to standard output. We will ask you to write short programs in python as part of the assignment. You can do the assignment on your drone’s Rasberry Pi once you can SSH into the drone. To do this you will need to at least be able to power your PI and connect to it via the base station.
echoto print things to standard output. Submit the command line that you used.
In addition to writing to standard output, a program can read from
standard input. The program
cat, short for concatentate, reads from
standard input and writes the result to standard output.
catwith no arguments. First think about what might happen. Then type text at the command line and observe the result. What is happening? Why?
Now we will discuss pipes. You can use pipes to redirect standard input, standard output, and standard error. First, you can use “>” to direct standard output to a file. For example, “echo Hello World > test.txt” will write the text “Hello World” to “test.txt”. The program “cat test.txt” can be used to view the file.
echoand output redirect. Verify your work with
lswrites the contents of a directory to standard output. The program
sortreads from standard input, sorts what it reads, and writes the sorted content to standard output. So you can use
ls | sortto print out a sorted directory list. Read the man page for sort (
man sort) to learn how to sort in reverse order. Modify the pipe script above to print the contents of a directory in reverse alphabetical order.
echoto print "hello world." Do not write to any files and use both commands one time.
sort -r. Note that you will have to read the entire contents of standard input into memory in order to sort it.
In addition to standard input and standard output, there is a third stream, standard error. If there is an error in a chain of pipes, it will be printed to the terminal rather than buried in the input to the next program.
ls -a | sortto see all files in a directory sorted. Redirect the output to a file named
ls -a | sort > sorted.txt. What happens to the file
ls -ainstead of using
sortas above. If your program is correct, you should see your status messages printed when you run it, and see only the sorted output written to the
Now we will explore the command
nc to learn more about basic
networking. The command
nc is short for “netcat” and is similar to
cat but works over network connections. It reads from standard
input and writes its contents not to standard output, but to a
nc www.google.com 80When you first connect, it will be silent. Then type any arbitrary text and press enter. What happens?
GET / HTTP/1.1
ncto make a server. In one window, type
nc -l 12345. This will cause
ncto listen on port 12345. In another terminal on the same machine, type
nc localhost 12345. You can type a message in one window and it will appear in the other window (and vice versa). This trick can be very useful to test basic internet connectivity - if the client and server can send packets at all.
roscorelistens on port 11311. Try using
ncto connect to port 11311 on a machine where
roscoreis running, such as the PI. What happens? What protocol is roscore using to communicate?
nmap, which scans through a range of ports (and optionally, through a range of IP addresses) and reports information.
nmap localhoston your Pi. What ports are open? Look up each port and submit what it does.
nc -l 1234command running from above. What is the difference? Why?
roscore? Why or why not? Use
man nmapto find command line options for
nmapthat report the ROS port 11311.
Now we are going to talk about the public internet. So far we’ve been
doing our work using mostly localhost, the local machine we are
connected to, and google.com. The most common situation is that your
base station machine (your laptop or desktop) and your robot are
connected over TCP/IP to the same local network. Then you can look up
your machine’s IP address (
ifconfig in Unix; other ways in other
OSes), and your robot’s IP address, and connect them. How can you
find your robot’s IP address? Well it’s a chicken-and-egg problem.
If you knew the IP address, you can connect to the robot and run
ifconfig and find the IP address, but you don’t know the IP address!
What to do? There are several solutions.
nmapto identify the machines on each network. How many are there?
But what about if there is no public internet connection? What if
you want to fly your drone in the wilderness? Well, there does exist
cellular modems and sattellite connections, but you can also tell your
drone to act as a Wifi Hotspot. It can create a network and run a
DHCP server. You can configure this on your drone using the file
Then you can connect your laptop’s base station using the SSID and passphrase specified in that file, and connect to the drone.
Alternatively you can set up your laptop as the Wifi base station and configure the drone to connect to its network. The details will vary depending on your laptop OS and settings.
Your Pi is configured to be a Wireless AP Master by default. Connect to it with your base station.
You want to fly your drone autonomously for 10 miles while viewing the camera output continuously from your base station. Design a solution that will allow you to do this. What hardware, software, and network access providers do you need? Report the weight, CPU computation, and cost this capability will add to your drone.
You want to connect to the drone over Wifi but also be able to connect to the internet in the CIT using the RLAB network. Design a solution that will allow you to do this. What hardware, software, and access providers do you need? Report the weight, CPU computation, and cost this capability will add to your drone.
When you are done, use this link to create your Networking Github Repo. Commit and push the relevant files (networking.pdf, and any scripts you wrote throughout the assignment) to this Github Repo before the deadline.