Future availability of the Mesh Potato 2

The MP2.0 when available will have 16MB FLASH and 64MB RAM, 11 GPIO lines, and a USB port, making it ideal for prototyping the mesh helper.

But it isn't available yet …

Interim use of TP-LINK TL-WR703N + USB-connected Radio

In the meantime, we have some TP-LINK TL-WR703Ns (version 1.2 models according to their labels), which use the same Atheros 9331 chipset, but have only 4MB FLASH and 32MB RAM, a USB port and no 12v in capability – but still better than the Dragino.

The concept is to connect an Arduino-UNO or compatible board to the USB port, and connect the radio to that. We will then use the usual serial port interface on the Arduino to talk to it.

The TL-WR703N is well supported by OpenWRT: http://wiki.openwrt.org/toh/tp-link/tl-wr703n

Installing Serval on the WR703N (New way)

Perform the following steps on a Linux box, but first …

SYSADMIN GENERAL'S WARNING

Because of the inherent risk of human error when instructing the scripts to format and repartition memory sticks, we recommend that you use an old laptop or similar, and dedicate it to this process, so that you do not endanger your data.

WR703N Instructions

- Make sure you have git, csh and expect installed Depending on your Linux distribution, something like the following should suffice:

$ sudo yum install csh expect git

Alternatively you may need to use

$ sudo apt-get install csh expect git
  1. Download the Mesh Extender Builder software.
$ git clone --quiet https://github.com/servalproject/mesh-extender-builder.git 703n-builder
  1. Allow Edits to the files in the folder
$ chmod 777 703n-builder
$ cd 703n-builder
  1. Edit the files that get the openwrt images to get the right images.(make_image, gather-image-files, and flash-virgin-mr3020)

make_image

# Download and unpack OpenWRT 12.09 image builder (if required).
if [ ! -e OpenWrt-ImageBuilder-ar71xx_generic-for-linux-i486 ]; then
   if [ ! -e OpenWrt-ImageBuilder-ar71xx_generic-for-linux-i486.tar.bz2 ]; then
      wget http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/OpenWrt-ImageBuilder-ar71xx_generic-for-linux-i486.tar.bz2
   fi;
   tar jxvf OpenWrt-ImageBuilder-ar71xx_generic-for-linux-i486.tar.bz2
fi;

# Build image with all the right packages, and the extra configuration files we need.
cd OpenWrt-ImageBuilder-ar71xx_generic-for-linux-i486
make image PROFILE=TLWR703 "PACKAGES=kmod-lib-crc16 kmod-scsi-core kmod-usb-storage-extras kmod-usb-storage libuuid libblkid libcom_err libpthread libext2fs e2fsprogs kmod-nls-cp437 fdisk kmod-fs-ext4 kmod-fs-vfat kmod-nls-iso8859-1 librt terminfo dosfsck uhttpd lua" FILES=../image-files

# Copy build image to here, and show the user
cp bin/ar71xx/openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin ..
cd ..

echo "Mesh Extender firmware image built:"
ls -l openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin

gather-image-files

  1. change line 71 as follows
cp ../openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin .

flash-virgin-mr3020

  1. Change line 12 as follows
firmware=openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin

- Build the OpenWRT image (this will download a lot of stuff the first time you run it, but you can re-run it quickly there after if you change something).

$ ./make_image
  1. Build the serval.up file
$ ./gather-image-files
  1. Insert the USB memory stick into the installation computer, noting its device name(can be found by typing “df” into the console), then unmount all the device partitions, then partition it using the following script, replacing deviceid with the Linux disk device, e.g., sdf. MAKE SURE YOU GIVE IT THE RIGHT DEVICE OR IT MIGHT TRY TO REPARTITION YOUR HARD DRIVE!
$ umount /dev/deviceid
$ ./partition-memory-stick.sh deviceid
  1. Remove and reinsert the USB memory stick so that the kernel notices the new partition table.
  2. Unmount the USB partitons again
  3. Populate the USB memory stick, again replacing deviceid with the right device, e.g., sdf. MAKE SURE YOU GIVE IT THE RIGHT DEVICE OR IT MIGHT ERASE THE PARTITIONS ON YOUR HARD DRIVE!
$ ./populate-memory-stick deviceid
  1. Unplug the USB memory stick and insert it into the MR3020 that is to become a mesh extender.
  2. Power up the MR3020, and connect it via ethernet to the installation machine, and wait a couple of minutes for it to boot up.
  3. If the MR3020 is still running the stock firmware, flash it this way:
$ ./flash-virgin-mr3020

You may need to specify the IP address on the command line if the script doesn't auto-detect the IP address. The most likely address is 192.168.0.254

  1. If the MR3020 already has OpenWRT, flash it this way. (You might need to boot the Mesh Extender into fail-safe mode first.)
$ ./reflash-mesh-extender

You may need to specify the IP address on the command line if the script doesn't auto-detect the IP address. The most likely address is 192.168.1.1 or 192.168.2.1, e.g.:

$ ./reflash-mesh-extender 192.168.2.1

The WR703N should reboot as a fully functional Mesh Extender.

Configuration

SSH access

First thing to make sure of is that the noroot file has been deleted on the USB stick. Once this has been done use

$ ssh root@192.168.2.1

If this works you should be greeted by a splash screen showing serval version and some other details.\

From this you can check if the serval node is functioning properly by using

root@192.168.2.1 $ servald status

this will return either a few lines saying the status and should contain a line saying whether it is running or it will return a message saying servald is not found. If the latter is what is displayed delete noroot and reboot the mesh node with

$ rm /dos/noroot
$ reboot

The serval node should reboot and work once it has rebooted.

Changing name of the device

This is useful as it allows you to identify specific nodes if a few different ones are within range of each other rather than using sid or the phone number.

servald keyring set did `servald id self | tail -1` "Phone number" "Name"

This line allows the user to set the phone number and the name of the device for easy identification.

Disabling noroot lockout

WARNING! THIS CAN ALLOW ANYONE ROOT ACCESS IF NECESSARY PRECAUTIONS AREN'T TAKEN WHICH MIGHT INCLUDE CHANGING THE ROOT PASSWORD.

ssh into the node using the above method. Once you have access use the following to navigate to the folder which contains the script that produces the noroot file.Then open the script in Vi

 
$ cd /etc/init.d
$vi dropbear

Find the two lines in this script that are as follows

passwd -l root # lock
[ -e /dos/noroot ] && return 1

and comment them out by adding a # to the front as follows

# passwd -l root # lock
# [ -e /dos/noroot ] && return 1

Once this has been done you will have root access at all times without having to delete noroot However it is a good idea to change the root password after doing this to discourage unauthorized access. this is achieved by using

$ passwd

Enabling SSH on a Mesh Extender

Remember if you wish to ssh to the Mesh Extender to power it down, remove the USB memory stick and insert it into any computer, and delete the NOROOT file from the FAT file system partition, and reinsert it into the Mesh Extender. ssh as root with password root will now be available until next reboot.

Troubleshooting

Sysupgrade not found

This means that the openwrt currently on the router cannot find the sysupgrade file

  1. Download the sysupgrade image for the router you are flashing from this list http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/
  2. navigate to the folder where the image is located
  3. use the following to get the image onto the routers RAM
$ scp openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-sysupgrade.bin root@192.168.1.1:/tmp
</code
  - ssh into the router then use the following command to flash the sysupgrade image
<code>
# sysupgrade -v /tmp/openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-
sysupgrade.bin 
  1. Follow the serval instructions for your device to reflash serval to the device

Cannot ssh into the device

There can be a few diffferent causes for this issue.

Telnet

This occurs when a root password hasn't been set on the device

  1. Telnet into the device
  2. set the root password
$ telnet 192.168.1.1
# passwd
  1. after this reboot the device and check if the ssh is working if not try the failsafe route

Failsafe

  1. change your computer from DHCP to static ip with an address of 192.168.1.2 and subnet 255.255.255.0
  2. boot your router into failsafe mode e.g. TP-Link models can be booted into failsafe by holding the reset button once the light starts blinking on boot
  3. telnet into the router
$ telnet 192.168.1.1
  1. mount the JFSS2 partition to allow you to edit the password or other files that could be causing the issues with
# mount_root
  1. set the passwd if you forgot your password
# passwd
  1. Reset the router to stock openwrt if issue is not password related by using
# firstboot
  1. Once this is done reboot the router into normal mode using
# reboot -f

After this you will need to change your network settings back to dhcp to connect to the router through telnet/ssh

Installing base OpenWRT on the WR703N

WARNING: The following can brick newer WR703Ns (Firmware 1.7, Ver:1.6 or Ver:1.7 etc on the bottom of the unit. Ver:1.2 is known to be safe). This is an issue with the OpenWRT firmware listed below. You can safely use these instruction with your own built OpenWRT distro, provided it is new enough. We will do that later.

Some more info on getting OpenWRT onto the WR703n can be found here:

http://daviddarts.com/piratebox-diy-openwrt/

This more or less boils down to:

  1. Plug in and boot WR703N
  2. Connect to it using an ethernet cable (it will offer you an IP address by DHCP)
  3. Browse to http://192.168.1.1. If Prompted, login as admin/admin
  4. Choose last menu item on the left.
  5. Choose 3rd menu item.
  6. Choose the file from the first step above and flash it.

You should now have OpenWRT on your WR703N.

Then login with telnet 192.168.1.1 and use passwd root to set a root password (just use root as the password to keep things easy while experimenting). Once you have set a root password, telnet will be disabled, and ssh will be enabled. Log in using ssh root@192.168.1.1 after that.

Enabling External USB Storage

The WR703N only has 4MB of flash, which is too small for a Serval or Commotion build. We use the USB port to solve this problem by connecting a USB memory stick. We are using 16GB ones.

You will need to install the following OpenWRT packages:

  • kmod-lib-crc16_3.3.8-1_ar71xx.ipk
  • kmod-scsi-core_3.3.8-1_ar71xx.ipk
  • kmod-usb-serial-cp210x_3.3.8-1_ar71xx.ipk
  • kmod-usb-serial-pl2303_3.8-rc3-1_ib42x0.ipk
  • kmod-usb-serial_3.3.8-1_ar71xx.ipk
  • kmod-usb-storage-extras_3.3.8-1_ar71xx.ipk
  • kmod-usb-storage_3.3.8-1_ar71xx.ipk
  • libuuid_2.21.2-1_ar71xx.ipk
  • libblkid_2.21.2-1_ar71xx.ipk
  • libcom_err_1.42.4-1_ar71xx.ipk
  • libpthread_0.9.33.2-1_ar71xx.ipk
  • libext2fs_1.42.4-1_ar71xx.ipk
  • e2fsprogs_1.42.4-1_ar71xx.ipk
  • fdisk_2.21.2-1_ar71xx.ipk

Because of the small flash size, you will need to scp them into /tmp/ which is a RAMfs. Note that there are some interdependencies here, so the order of installation will be different.

Install these packages, and if required reboot the 703. Then plug a USB memory stick in. Typing dmesg should show that it has been recognised, e.g., as sda:

45503.970000] USB Mass Storage support registered.
[45504.960000] scsi 0:0:0:0: Direct-Access     SanDisk  Cruzer Switch    1.26 PQ: 0 ANSI: 5
[45504.970000] sd 0:0:0:0: [sda] 31266816 512-byte logical blocks: (16.0 GB/14.9 GiB)
[45504.970000] sd 0:0:0:0: [sda] Write Protect is off
[45504.980000] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00
[45504.980000] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[45505.000000]  sda: sda1
[45505.010000] sd 0:0:0:0: [sda] Attached SCSI removable disk''

Next, use fdisk to partition the USB memory stick. Note that fsck requires about 1MB of RAM for every 1GB of partition size, so I recommend making a 1GB partition that will be used to replace /overlay on the router, and dividing the remaining space into partitions of a few GB each.

On our 16GB sticks I used 1GiB+7GiB+7GiB, the other GiB being missing due to the “marketing GB” differing from the binary GB. You might also like to make a partition for swap and/or /tmp

Then use mkfs.ext4 to create the file system(s), e.g. mkfs.ext4 /dev/sda1

Then uninstall the following packages to make space for the ext4 kernel module (yes, the space is that tight, but don't worry, we can put it back later):

opkg remove e2fsprogs

Now that you have enough space, install the following packages:

  • kmod-fs-ext4_3.3.8-1_ar71xx.ipk
  • blkid_2.21.2-1_ar71xx.ipk
  • swap-utils_2.21.2-1_ar71xx.ipk
  • block-mount_0.2.0-9_ar71xx.ipk

You should now be able to mount your 1GB partition that we will use for /overlay:

mount /dev/sda1 /mnt

Now run the following commands on the router (taken from http://blog.night-shade.org.uk/2013/01/more-storage-on-openwrt/):

tar -C /overlay -cvf - . | tar -C /mnt -xf -

uci add fstab mount
uci set fstab.@mount[-1].device=/dev/sda1
uci set fstab.@mount[-1].options=$options
uci set fstab.@mount[-1].enabled_fsck=0
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].target=/overlay
uci set fstab.@mount[-1].fstype=$fstype

mkdir /home
uci add fstab mount
uci set fstab.@mount[-1].device=/dev/sda2
uci set fstab.@mount[-1].options=$options
uci set fstab.@mount[-1].enabled_fsck=0
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].target=/home
uci set fstab.@mount[-1].fstype=$fstype

mkdir /serval
uci add fstab mount
uci set fstab.@mount[-1].device=/dev/sda3
uci set fstab.@mount[-1].options=$options
uci set fstab.@mount[-1].enabled_fsck=0
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].target=/serval
uci set fstab.@mount[-1].fstype=$fstype

uci commit fstab

/etc/init.d/fstab enable

Reboot and you should have 1GB in /overlay, mounted from USB, as well as large /home and /serval partitions.

Installing and setting up servald

In the short preparation time we have for KiwiEx, we have not had time to configure a single OpenWRT package that includes all setup, so the following recipe is required:

  1. Build yourself a serval ipk from our OpenWRT repository at https://github.com/servalproject/commotion-openwrt (more detailed instructions on doing this will be forthcoming – but the short story is use menuconfig to enable building of Serval as a module and then build it).
  2. Install librt_0.9.33.2-1_ar71xx.ipk
  3. Install the serval-*.ipk you built in step 1
  4. Install the following files in the described locations, and then reboot:

/etc/config/network

Change the IP address in this file from 29.167.164.237 to something random between 28.0.0.0 and 29.255.255.255 Change the IP address from 192.168.2.1 to 192.168.2.x if you want to be able to ssh in without ssh complaining about conflicting keys all the time.

config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config interface 'lan'
	option ifname 'eth0'
#	option type 'bridge'
	option proto 'static'
	option ipaddr '192.168.2.1'
	option netmask '255.255.255.0'

config interface public
	option proto 	static
	option ipaddr	192.168.100.1
	option netmask	255.255.255.0

config interface mesh
    option ifname wlan0-1
    option proto    static
      option ipaddr 29.167.164.237
    option netmask 254.0.0.0

/etc/config/wireless

Change the mac address 5c:63:bf:bb:41:90 to the mac address written on the back of the WR703N case.

config wifi-device radio0
        option type       mac80211
        option channel    6                           
        option hwmode     11ng
        option macaddr	5c:63:bf:bb:41:90
	option htmode	HT20
	list ht_capab	SHORT-GI-20
	list ht_capab	SHORT-GI-40
	list ht_capab	RX-STBC1
	list ht_capab	DSSS_CCK-40
                                                      
config wifi-iface mesh                                
        option device   radio0
        option ssid     mesh.servalproject.org        
        option network  mesh                          
        option mode     adhoc
        option bssid    02:ca:ff:dd:ca:ce             
        option bgscan   0                             
                                                      
config wifi-iface public                      
        option device     radio0
        option network    public              
        option mode       ap                  
        option isolate    0                   
        option ssid       public.servalproject.org
        option hidden     0                       
        option encryption none

/etc/rc.d/S94servald

Don't forget to chmod 755 this file once you have installed it

#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=41

start() {
  # Start servald
  export SERVALINSTANCE_PATH=/etc/serval
  mkdir -p $SERVALINSTANCE_PATH
  /serval/runservald &
}

stop() {
  export SERVALINSTANCE_PATH=/etc/serval
  servald stop
}

/serval/runservald

Don't forget to chmod 755 this and the other scripts.

#!/bin/sh
while [ 1 ]
do
/serval/servald start foreground
done

/etc/serval/servald.conf

The small MDP block size is necessary due to the high bit error rate on the radios, and the suboptimal scheduling of rhizome mdp packets (including the lack of supression of duplicate requests).

The small max_internal_blob_size is to get around the VERY slow performance of sqlite on the USB memory on the WR703N, which could take several minutes to prepare an empty blob, before even beginning to put any data into it.

The long timeout (30seconds) is so that we don't easily drop transfers, especially while the previously mentioned problems persist.

interfaces.1.encapsulation=single
interfaces.1.file=/dev/ttyUSB0   
interfaces.1.socket_type=stream
interfaces.1.type=catear       
interfaces.2.match=eth0 
interfaces.2.type=ethernet
interfaces.3.match=wlan0  
interfaces.3.type=wifi  
interfaces.4.match=wlan0-1
interfaces.4.type=wifi    
rhizome.datastore_path=/serval
rhizome.idle_timeout=30000    
rhizome.rhizome_mdp_block_size=100
rhizome.max_internal_blob_size=16384

/etc/config/dhcp

config dnsmasq
	option domainneeded	1
	option boguspriv	1
	option filterwin2k	0  # enable for dial on demand
	option localise_queries	1
	option rebind_protection 1  # disable if upstream must serve RFC1918 addresses
	option rebind_localhost 1  # enable for RBL checking and similar services
	#list rebind_domain example.lan  # whitelist RFC1918 responses for domains
	option local	'/lan/'
	option domain	'lan'
	option expandhosts	1
	option nonegcache	0
	option authoritative	1
	option readethers	1
	option leasefile	'/tmp/dhcp.leases'
	option resolvfile	'/tmp/resolv.conf.auto'
	#list server		'/mycompany.local/1.2.3.4'
	#option nonwildcard	1
	#list interface		br-lan
	#list notinterface	lo
	#list bogusnxdomain     '64.94.110.11'
        list 'dhcp_option' '3'            
        list 'dhcp_option' '6'


config dhcp lan
	option interface	lan
	option start 	100
	option limit	150
	option leasetime	12h

config dhcp public
        option interface	public
	option start 	50
	option limit	250
	option leasetime	12h

USB Serial Port Drivers on OpenWRT

CP210x

CP2012 datasheet is at http://www.silabs.com/products/interface/usbtouart/Pages/usb-to-uart-bridge.aspx

Follow that, and install the CP210x USB serial adapter drivers from http://downloads.openwrt.org/attitude_adjustment/12.09-beta2/ar71xx/generic/packages/

You will need kmod-usb-serial-cp210x_3.3.8-1_ar71xx.ipk and kmod-usb-serial_3.3.8-1_ar71xx.ipk or similar. Use scp to copy these onto your 703, and then use:

opkg install kmod-usb-serial_3.3.8-1_ar71xx.ipk opkg install kmod-usb-serial-cp210x_3.3.8-1_ar71xx.ipk

FTDI

Yet to be explored.

USB Serial Port Drivers on OSX

CP210x

On OSX to use the SiLabs CP2012 USB adapters on mac, you need to install the drivers from http://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx

Install those, and the USB to serial adapter works on the mac.

FTDI

Powering the WR703N & Radio

Whether using the TL-WR703N, we should use a better voltage regulator to tolerate the 12v - 15v we can expect to see on the LiFePO4 batteries. Jaycar sell such a kit for AUD$7.95 that can provide 5V @ 1A, which should be enough, and is quite easy to build: http://www.jaycar.com.au/productView.asp?ID=KA1797

The TL-WR703N itself uses <1W with nothing connected to the USB port, leaving 4W for the radio and USB memory stick for Rhizome mass storage, which should be enough. Once we get the MP2.0's, they will power themselves and the USB mass storage, leaving all 1A for the Arduino and radio.

The RFD900 radio can use 4W on its' own, so a separate 5v 1A supply is probably a good idea. Our solution for now is to use two of the KA1797 kits.

Arduino Hardware

For the Arduino, we want one that can plug in the USB port, because that is easiest. However, the availability of radio hardware that supports TTL serial with nice firmware, we can skip the Arduino for now. See below for discussion of the radio hardware.

Radio Hardware

Talking with Tridge @ #LCA2013, there is a nice radio that he has already written point-to-point firmware for, that could be easily integrated with the TL-WR703N via a USB to TTL serial adapter.

The radio units are the http://rfdesign.com.au/index.php/rfd900

At Make.Hack.Void in Canberra started testing this with some of Tridge's gear.

We now have a convenient way to test the radios on both Mac and on the WR703N itself, which will allow fairly easy development and integration with servald.

Have ordered an RFD900 bundle from rfdesign.com.au, with a couple of the FTDI brand USB/TTL converters that they supply, just to get things started smoothly. Then once the CP2012s arrive (probably in 3 - 5 weeks), we can use those on future units.

Interfacing with the RFD900 Radios via FTDI on OSX

For ease of development, we will plug the RFD900 into a USB port on a mac, where it will appear as a serial port. On my mac, my first RFD900 shows up as /dev/tty.usbserial-A1011UQN

We can talk to the radio module using something like:

sudo cu -l /dev/tty.usbserial-A1011UQN -s 57600

And then entering +++ to drop to the AT command prompt of the modem. AT commands are the same as listed at http://code.google.com/p/ardupilot-mega/wiki/3DRadio

After plugging both radios in, they synchonised in a few seconds, and I was able to use the AT&T=RSSI to get a running report on the RSSI output from the radio.

With the radio TX power set to +20dbm and +2.1db stub antennae RSSI results were 217 for both left and right antennae, and the noise floor was usually in the range 50 – 60 in my house in suburban Adelaide.

These units are are approximately 0.5dB, where 25 probably somewhere around -121dBm. In my case, the link budget is about 157 RSSI. Using the more accurate formula from the 3Dradio, the RSSI corresponds to -12.8dBm, and the noise floor to -95.4dBm, for a link budget of 82.6dBm.

As the radios are about 30cm apart on my desk, and each 6.02dB allows a doubling of range, this suggests a maximum range of about 30cm x 2^13.7 = 30cm x 13300, or about 4km. The antenna gain is only +2.1dB, so we could increase TX power by another 7dB, which should double the range to around 8km, assuming clear line of sight – which is pretty good for a 1W radio in a suburban area. A lower noise floor could easily increase range to a few tens of kilometres. This is pretty exciting for enabling long-range mesh communications, especially when compared with WiFi's suburban range of <160m.

So the next step is to modify servald to be able to use the radios as a link, and then get it working on the 703N.

For servald, it will be fairly easy to patch the dummynet driver that already reads and writes to an ordinary file. We will just need to implement flow control/throttling, and packet encapsulation in case of communications errors.

Configuring RFD900 Radios for use

Connect as described above and set air speed to 128kbit, and serial speed to 57600, and TX power to +24dBm with a command sequence like:

ATS1=57
ATS2=128
ATS4=24
ATI5
AT&W

We could use 115200 for the serial speed, but that would require a recompile of servald, which currently assumes radios at 57600, and the gain would be small, because 128k/2=64kbit total bandwidth, shared among both ends gives 32000 for each end, and so it is unlikely that the bandwidth will be depleted.

128kbit is the fastest effective radio speed until we get some better forward error correction. 250kbit should work, but proved to be quite unreliable, with desynchronisation and high levels of packet loss.


Login