Just a bunch of tips to get a WiFi access point working on startup on the Pandaboard, in addition to getting ntp to work on our local network.

Use
http://nims11.wordpress.com/2012/04/27/hostapd-the-linux-way-to-create-virtual-wifi-access-point/

and
http://www.ubuntugeek.com/network-time-protocol-ntp-server-and-clients-setup-in-ubuntu.html

to get a hostapd.conf

interface=wlan0
driver=nl80211
ssid=flyingpanda
hw_mode=g
channel=1

And the dchpd.conf

File: /etc/dhcp/dhcpd.conf Modified

ddns-update-style none;
ignore client-updates;
authoritative;
option local-wpad code 252 = text;

subnet
10.0.0.0 netmask 255.255.255.0 {
# --- default gateway
option routers
10.0.0.1;
# --- Netmask
option subnet-mask
255.255.255.0;
# --- Broadcast Address
option broadcast-address
10.0.0.255;
# --- Domain name servers, tells the clients which DNS servers to use.
option domain-name-servers
10.0.0.1, 8.8.8.8, 8.8.4.4;
option time-offset
0;
range 10.0.0.3 10.0.0.13;
default-lease-time 1209600;
max-lease-time 1814400;
}

The next thing is to NTP timesync the two. The complication is that the server has to be the laptop that connects to the pandaboard, which hosts the network. Hence, we need to detect when a laptop connects to the pandaboard’s wifi hotspot, and then correspondingly ntpupdate.

The thing to remember here is that ntp works in a hierarchial setup, i.e. there are different ‘strata’ of time accuracy with an atomic clock being stratum 0 and internet time servers being 1 and 2 and so on. In case a local system is not ntp synced, it’s stratum is set by the daemon to be 16. So in the case when out in the field, if the server (laptop) has not been connected to the internet, although the client (pandaboard) can see what time the server is providing, it also sees that the stratum level is 16, and so decides to ignore it. To avoid this, we artificially ‘fudge’ a local timeserver on our server at a stratum level of 10 so that in the event that there’s no available internet time server at a higher strata, the local clock is used to sync all the clients.

Thus, on the server,  relevant lines in /etc/ntp.conf are


# By default, exchange time with everybody, but don't allow configuration.

restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

#Allow the pandaboard to query for time
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap

#Set my stratum to be artificially high
server 127.127.1.0
fudge 127.127.1.0 stratum 10

# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
broadcast 192.168.2.255

And on the pandaboard, /etc/ntp.conf is

restrict default notrust nomodify nopeer
restrict 192.168.2.0 mask 255.255.255.0
restrict 127.0.0.1
server $FIRST_PEER
#I want to listen to time broadcasts on my local subnet
disable auth
broadcastclient

Note that $FIRST_PEER is an environment variable I define for the first IP address that connects to the pandaboard over WiFi in my ~/.bashrc

#Also try to autodetect first connected peer
#If the environment variable is already defined, do nothing
if [ -z "$FIRST_PEER" ]; then
export FIRST_PEER=$(netstat --inet --numeric-hosts | grep ESTABLISHED | grep ssh | sed 's_.*ssh *\([0-9]*.[0-9]*.[0-9]*.[0-9]*\).*_\1_')
sudo service ntp stop
sudo ntpdate $FIRST_PEER
sudo service ntp start
fi

As in my previous excerpt for autoconfiguring the ROS_HOSTNAME and ROS_MASTER_URI, I use the power of sed to pull out the IP address of the first entry that netstat provides me. I then force ntpdate to synchronize with this peer, which is not very elegant right now, since I need to enter the account password every time I ssh in. The alternative would be to set ntpdate as a cron job, or call this same command in one of my initialization scripts, but I’m too lazy to do that now :P

Advertisements