Building Lora@VSB TTN gateway with RPi & iC880a in 7 steps (legacy)

Used HW: Raspberry-Pi2B & iC880a SPI

 

 

 

 

 

Step 1: Prepare image to SD card

Download the latest Raspbian-lite image, format SD card and install image to it as usual.

 

 

Step 2: Customise OS

Run RPI, login as default user “pi” (default passwd “raspberry”) and customise OS:

Step 2.1: update OS:
# rpi-update
# apt-get dist-upgrade
# apt-get update
# rpi-update
Step 2.2: delete default user PI:
# adduser <new-user>
# deluser pi
Step 2.3: install Persistent IPtables:
# apt-get install iptables-persistent
# vi /etc/iptables/rules.v4

This is an example of file rules.v4:

# Generated by iptables-save v1.4.21 on Thu Feb 16 18:14:59 2017 
*filter 
:INPUT DROP [0:0] 
:FORWARD ACCEPT [0:0] 
:OUTPUT ACCEPT [0:0] 
-A INPUT -i lo -j ACCEPT 
-A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT 
-A INPUT -p udp --dport 1700 -m state --state NEW -j ACCEPT 
-A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED 
COMMIT
Step 2.4: set NTP time:
  1. Go to http://support.ntp.org/bin/view/Servers/NTPPoolServers and click the host name corresponding to your area. Assuming the area is North America, the servers are:
      server 0.north-america.pool.ntp.org
      server 1.north-america.pool.ntp.org
      server 2.north-america.pool.ntp.org
      server 3.north-america.pool.ntp.org
    
  2. Open /etc/ntp.conf in a text editor. If you use the nano editor, run sudo nano /etc/ntp.conf
  3. You should see a list of servers similar to the one below, replace the servers with the ones from step 1::
    server 0.cz.pool.ntp.org iburst
     server 1.cz.pool.ntp.org iburst
     server 2.cz.pool.ntp.org iburst
     server 3.cz.pool.ntp.org iburst
    
  4. Comment out (by adding a # in front of the line) the following two lines:
      restrict 127.0.0.1
      restrict ::1
    
  5. Save the file and exit
  6. Set the correct time zone by running # sudo cp /usr/share/zoneinfo/US/Pacific /etc/localtime. Replace US/Pacific with your time zone. If you are not sure about the possible values, look in /usr/share/zoneinfo
  7. Restart the ntp server: sudo /etc/init.d/ntp restart
  8. Run date in a terminal
  9. If the time is not correct, you might have to force update it. This is because, by default, ntp will not sync if the difference between the system time and the real-time is greater that 1000 seconds. Run sudo ntpd -gq and the restart ntp
Step 2.5: turn off wifi (if you use RPI3 and dont need it):
# iwconfig wlan0 txpower off (if needed tun on: # iwconfig wlan0 txpower auto)

check status:

# rfkill list all

 

Step 3: Putting it all together

Connect the jumper wires between the two boards using the following table:

iC880 pin Description RPi pin
21 +5V 2
22 GND 6 (14, 25)
13 Reset 11
14 SPI CLK 23
15 MISO 21
16 MOSI 19
17 NSS 24

We’re now ready to power up and start configuring our gateway!

      

If you have a 3D printer, you can use a holder to mount both boards together. Download  all *.stl and *.gcode files.

 

Step 4: Setting up the software

  • Use raspi-config utility to enable SPI ([5] Interfacing options -> P4 SPI) and also expand the filesystem ([7] Advanced options -> A1 Expand filesystem):
    $ sudo raspi-config
  • Reboot (it will ask on exit, but you can do it manually with sudo reboot)
  • Configure locales and time zone:
    $ sudo dpkg-reconfigure locales
    $ sudo dpkg-reconfigure tzdata
    
  • Make sure you have an updated installation and install git:
    $ sudo apt-get install git

And add the following block at the end of the file, replacing SSID and password to match your network:

	network={
	    ssid="The_SSID_of_your_wifi"
	    psk="Your_wifi_password"
	}
  • Clone the installer and start the installation
    $ git clone -b spi https://github.com/ttn-zh/ic880a-gateway.git ~/ic880a-gateway
    $ cd ~/ic880a-gateway
    $ sudo ./install.sh spi
    
  • If you want to use the remote configuration option, please make sure you have created a JSON file named as your gateway EUI (e.g. B827EBFFFE7B80CD.json) in the Gateway Remote Config repository. EUI folows MAC addr of eth0 (or wlan0)
  • By default, the installer changes the hostname of your Raspeberry Pi to ttn-gateway (to prevent collisions with other Raspberry Pis in your network). You can override this in non-remote configuration mode.

reset iC880a on boot (GPIO 17 = pin 11 connected to reset pin 13 on iC880a):

put simlink to /etc/rc2.d to following script:

#!/bin/bash
echo "17" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio17/direction
echo "1" > /sys/class/gpio/gpio17/value
sleep 5
echo "0" > /sys/class/gpio/gpio17/value
sleep 1
echo "0" > /sys/class/gpio/gpio17/value
iC880-SPI_reset.sh

 

Step 5: Checking connection to TTN

The best way to check if the gateway is working is registering it on the TTN Console.

 

 

  • Login to thethingsnetwork.org Console
  • Click on Gateways -> register gateway
  • Select the packet forwarder protocol
  • Enter your Gateway EUI (if is printed on start and end of the installer)
  • Enter any description
  • Select Europe 868Mhz as frequency plan
  • Select the correct antenna placement according to your plans
  • Confirm clicking Register gateway

Now you can see the status (which at this point should be connected if we did everything right) and traffic of your gateway! You can check the traffdic on UDP port 1700:

# tcpdump -AUq port 1700

 

And now we’re really done!

 

Step 6: RPI – save SD card

  • turn off SWAP
    $ sudo dphys-swapfile swapoff
    $ sudo dphys-swapfile uninstall
    $ sudo update-rc.d dphys-swapfile remove
  • use tmpfs for /var/log
  • place the script into  /etc/init.d/prepare-dirs to create missing directories in /var/log so that all daemons start. Make sure that the script will be started first on boot before your daemons start: update-rc.d prepare-dirs defaults 01 99.
#!/bin/sh
### BEGIN INIT INFO
# Provides: prepare-dirs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Required-Start:
# Required-Stop:
# Short-Description: Create needed directories on /var/log/ for tmpfs at startup
# Description: Create needed directories on /var/log/ for tmpfs at startup
### END INIT INFO
# example of needed Dirs
DIR[0]=/var/log/lighttpd
DIR[1]=/var/log/cups
DIR[2]=/var/log/apt
DIR[3]=/var/log/ConsoleKit
DIR[4]=/var/log/fsck
DIR[5]=/var/log/news
DIR[6]=/var/log/ntpstats
DIR[7]=/var/log/samba
DIR[8]=/var/log/lastlog
DIR[9]=/var/log/exim
DIR[10]=/var/log/watchdog

case "${1:-''}" in
 start)
      typeset -i i=0 max=${#DIR[*]}
      while (( i < max ))
           do
              mkdir ${DIR[$i]}
              chmod 755 ${DIR[$i]}
              i=i+1
           done
 # set rights
 chown www-data.www-data ${DIR[0]}
 ;;
 stop)
 ;;
 restart)
 ;;
 reload|force-reload)
 ;;
 status)
 ;;
 *)
 echo "Usage: $SELF start"
 exit 1
 ;;
esac

# Create log files
touch /var/log/proftpd/proftpd.log
touch /var/log/proftpd/xferlog
touch /var/log/proftpd/controls.log

# Set owners for the newly created log directories
chown -R proftpd:root /var/log/proftpd/

Step 7: RPI backup img:

# dd if=/dev/mmcblk0 | gzip -1 - | ssh user@backup-server dd of=image.gz