Updated at Feb 1, 2017

I finally decided to boost my RPi today. Even the RPi B+ has rolled out already, my RPi model B had not been installed yet. How embarrassing!

Preparation

Display

I have not found any display with HDMI except for the projector in iGEM Team’s Lab. So I chose to use a projector as my screen, which would make my configuration easier.

Network

I bought a USB wireless dongle. And I also have numerous standard ethernet (RJ45) to use.

Power

According to the official document, the power range of RPi is very flexible and it varies with the load. So I will use a commodity phone charger (1000mAh) connected to a mini-USB cable.

Input

I have both keyboard and mouse which can be connected to RPi through USB. But there was a problem: The RPi Model B has only two USB interfaces, which are not enough for keyboard, mouse and WLAN at the same time.

Launch the OS

I already got SD card ready with Raspbian OS. So I just need to power the Pi and here it goes.

The first screen I have seen was the raspi-config. Strange, maybe because I have already installed the system? Oh, it looked like the OS I burned is NOOBS, which can be used out of the box.

In raspi-config, the most important ones for me are Expand Filesystem, Change User Password and ssh in Advanced Options.

After expanding, setting password and setting ssh to enabled, I got into the tty of RPi.

The real problem

Now, the most severe problem I faced now is I don’t always have the extra display. So I need to remotely access the RPi through my laptop.

There are mainly two types of remote access:

  1. VNC – Virtual Network Computing
  2. SSH – Secure Shell

With the previous one, you can get access to graphical interface.

With the later one, you can use shell CLI.

Network

The usage of VNC or SSH is very easy and standard. The core issue is network, i.e. how to know the IP address of my RPi to which I can get access to.

My final goal is to make my RPi controlled wirelessly with WLAN dongle as data transmission route and battery as power supply.

I was not very familiar with network configuration of Linux and routing of USTCnet. So I have to find ways working first.

It seems like there are three kinds of IP that RPi will have:

  1. 192.168.XXX.XXX
  2. 169.254.XXX.XXX
  3. 211.86.XXX.XXX

And whether I plug the RPi in the switch of lab or directly to my laptop, the first kind seems never working (can’t get response with ping ).

The second one seems to be the “DHCP” range.

The third one seems to be the USTCnet’s IP address.

When I directly connected the RPi with my laptop, the second one will work. And when I separately connected RPi and laptop into USTCnet, the third one will work.

Notice: I used cable to connect the RPi to USTCnet till this step.

But the weird thing is when I used my WLAN dongle to connect my RPi to USTCnet, I can’t ping the IPv4 address of wlan0 like eth0.

I have to give up the wireless option for now. The next problem is:

Getting IP address assigned by DHCP

I can’t be sure what IP address will my RPi have when I plug it into somewhere else in USTCnet. So I need a method to know its IP address without a external display’s help.

The solution I came up with is like that:

Let RPi send IP address to my freeshell server by itself after booting

So I first config my freeshell’s nginx to create a domain specially for my RPi’s communication to outer world.

Then I use express framework to route the POST from RPi to somewhere on a web page.

In RPi

I wrote a updateIP.sh in /etc/init.d and use update-rc.d to add it in rc.d so the script in updateIP.sh will execute every time this little machine boots.

In updateIP.sh I wrote something like that:

#!/bin/sh
ip=$(ifconfig | grep -oE "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" | head -1)
curl --data $ip http://url.to.my.freeshell.server

This line stores the IP address from ifconfig in variable $ip. I used grep with regex to get all matched IP addresses in the output of ifconfig, then get the first line with head -1 since the first line contains the first appearing IP address.

So finally we can curl to post my data to the freeshell server.

In Freeshell Server

In index.js, I route the the post like that

router.post('/', function(req, res) {
    var ip = req.body.ip;
    fs.writeFile(__dirname+'/../views/ip.jade', '<body>' + ip + '</body>', function(err){
        if (err) throw err;
        console.log("The IP address has been updated!");
    });
    res.redirect('/ip')
});

And the page index.jade would be a simple page containing a form with post as method and / as action, in which there would be the ip input field.