{"id":149,"date":"2017-08-15T08:04:17","date_gmt":"2017-08-15T08:04:17","guid":{"rendered":"http:\/\/lora.vsb.cz\/?page_id=149"},"modified":"2017-08-15T11:16:58","modified_gmt":"2017-08-15T11:16:58","slug":"building-ttn-gateway","status":"publish","type":"page","link":"https:\/\/lora.vsb.cz\/index.php\/building-ttn-gateway\/","title":{"rendered":"Building LoRaWAN TTN gateway"},"content":{"rendered":"<h1><span style=\"color: #0000ff;\">1. Hardware<\/span><\/h1>\n<ul>\n<li>Used Hardware: <a href=\"http:\/\/www.banana-pi.org\/m2u.html\" target=\"_blank\" rel=\"noopener\">Banana-Pi M2U<\/a>\u00a0quad-core mini single board computer\u00a0<strong> +<\/strong> <a href=\"https:\/\/wireless-solutions.de\/products\/radiomodules\/ic880a.html\">iC880a<\/a> LoRaWAN Concentrator 868MHz\u00a0(bought\u00a0<a href=\"https:\/\/www.soselectronic.cz\/products\/imst\/ic880a-spi-234084\">here<\/a>)<\/li>\n<li>Banana-Pi advantage: internal 8 GB <a href=\"https:\/\/www.datalight.com\/solutions\/technologies\/emmc\/what-is-emmc\">eMMC<\/a>\u00a0storage<\/li>\n<li>OS Raspbian\u00a0<a href=\"http:\/\/www.banana-pi.org\/m2u-download.html\">2017-05-25-raspbian-jessie-preview3-bpi-m2u-sd-emmc.img<\/a>, how to burn it to MMC find <a href=\"https:\/\/bananapi.gitbooks.io\/bpi-m3\/content\/en\/howtoburnlinuximagetoemmc.html\">here<\/a>\n<ul>\n<li><strong>Step 1:<\/strong> Start up the computer with the SD card which has been burnt with the Linux images.<\/li>\n<li><strong>Step 2:<\/strong> Put the images which you&#8217;d like to burn to the EMMC Storage to the USB drive.<\/li>\n<li><strong>Step 3:<\/strong> Run &#8222;fdisk -l&#8220; command line on your BPI-M3 and you can see the EMMC path as &#8222;\/dev\/mmcblk1&#8220;<br \/>\n<code>sudo fdiskfa -l<\/code><\/li>\n<li><strong>Step 4:<\/strong>Switch to the path of images, and run the command.<br \/>\n<code>sudo dd if=2017-05-25-raspbian-jessie-preview3-bpi-m2u-sd-emmc.img of=\/dev\/mmcblk1 bs=10MB<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>see also video on <a href=\"https:\/\/www.youtube.com\/watch?v=o9YmGhqUYg4&amp;feature=youtu.be\">youtube.<\/a><\/p>\n<h1><span style=\"color: #0000ff;\">2. Customise OS<\/span><\/h1>\n<h6><strong>uninstall Xserver:<\/strong><\/h6>\n<pre>sudo apt-get remove --auto-remove --purge 'libx11-.*'\r\nsudo apt-get autoremove --purge<\/pre>\n<p>(Repeat <code>apt-get autoremove --purge<\/code> until no orphans remain)<\/p>\n<h6><strong>update OS:<\/strong><\/h6>\n<pre># rpi-update\r\n# apt-get dist-upgrade\r\n# apt-get update\r\n# bpi-update\r\n# bpi-tools -u\r\n# bpi-tools -U<\/pre>\n<h6><strong>delete default user PI:<\/strong><\/h6>\n<pre># adduser new-user\r\n# deluser pi<\/pre>\n<h6><strong>install Persistent IPtables:<\/strong><\/h6>\n<pre># apt-get install iptables-persistent\r\n# vi \/etc\/iptables\/rules.v4\r\n\r\n# Generated by iptables-save v1.4.21 on Thu Feb 16 18:14:59 2017\r\n*filter\r\n:INPUT DROP [0:0]\r\n:FORWARD ACCEPT [0:0]\r\n:OUTPUT ACCEPT [0:0]\r\n-A INPUT -i lo -j ACCEPT\r\n-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 22,80 -j ACCEPT\r\n-A INPUT -p udp --dport 1700 -m state --state NEW -j ACCEPT\r\n-A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED\r\nCOMMIT\r\n<\/pre>\n<h6><strong>set NTP time:<br \/>\n<\/strong><\/h6>\n<p>1. Go to <a href=\"http:\/\/support.ntp.org\/bin\/view\/Servers\/NTPPoolServers\" target=\"_blank\" rel=\"noopener\">http:\/\/support.ntp.org\/bin\/view\/Servers\/NTPPoolServers<\/a> and click the host name corresponding to your area. Assuming the area is North America, the servers are:<\/p>\n<div>\n<pre>  server 0.north-america.pool.ntp.org\r\n  server 1.north-america.pool.ntp.org\r\n  server 2.north-america.pool.ntp.org\r\n  server 3.north-america.pool.ntp.org\r\n<\/pre>\n<p>2. Open \/etc\/ntp.conf in a text editor. If you use the nano editor, run <code>sudo nano \/etc\/ntp.conf<\/code><\/p>\n<p>You should see a list of servers similar to the one below, replace the servers with the ones from step 1::<\/p>\n<pre>server 0.cz.pool.ntp.org iburst\r\n server 1.cz.pool.ntp.org iburst\r\n server 2.cz.pool.ntp.org iburst\r\n server 3.cz.pool.ntp.org iburst\r\n<\/pre>\n<\/div>\n<p>3. Comment out (by adding a # in front of the line) the following two lines:<\/p>\n<div>\n<pre>  restrict 127.0.0.1\r\n  restrict ::1\r\n<\/pre>\n<\/div>\n<p>4. Save the file and exit<\/p>\n<p>5. 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<\/p>\n<p>6. Restart the ntp server: sudo \/etc\/init.d\/ntp restart<\/p>\n<p>7. Run <code class=\"highlighter-rouge\">date<\/code> in a terminal<\/p>\n<p>8. If the time is not correct, you might have to force update it. This is because, by default, <code class=\"highlighter-rouge\">ntp<\/code> will not sync if the difference between the system time and the real-time is greater that 1000 seconds. Run <code class=\"highlighter-rouge\">sudo ntpd -gq<\/code> and the restart <code class=\"highlighter-rouge\">ntp<\/code><\/p>\n<h6><strong><br \/>\nTurn off WiFi:<\/strong><\/h6>\n<pre># iwconfig wlan0 txpower off (if needed tun on: # iwconfig wlan0 txpower auto)<\/pre>\n<p>check status:<\/p>\n<pre># rfkill list all<\/pre>\n<h1><span style=\"color: #0000ff;\">3. Assemble it all together<\/span><\/h1>\n<p>step by step <a href=\"https:\/\/www.thethingsnetwork.org\/labs\/story\/how-to-build-your-own-lorawan-gateway\">here<\/a><\/p>\n<h6><strong>Connect the jumper wires between the two boards using the following table:<\/strong><\/h6>\n<table>\n<thead>\n<tr>\n<th>iC880a pin<\/th>\n<th>Description<\/th>\n<th>RPi physical pin<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>21<\/td>\n<td>Supply 5V<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>22<\/td>\n<td>GND<\/td>\n<td>6 (14, 25)<\/td>\n<\/tr>\n<tr>\n<td>13<\/td>\n<td>Reset<\/td>\n<td>11<\/td>\n<\/tr>\n<tr>\n<td>14<\/td>\n<td>SPI CLK<\/td>\n<td>23<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td>MISO<\/td>\n<td>21<\/td>\n<\/tr>\n<tr>\n<td>16<\/td>\n<td>MOSI<\/td>\n<td>19<\/td>\n<\/tr>\n<tr>\n<td>17<\/td>\n<td>NSS<\/td>\n<td>24<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #ff0000;\"><em>OK! We&#8217;re now ready to power up and start configuring our gateway!<\/em><\/span><\/p>\n<h1><span style=\"color: #0000ff;\">4. Setting up the software<\/span><\/h1>\n<ul>\n<li>Use <code>raspi-config<\/code> utility to enable SPI&gt; (<code>[5] Interfacing options -&gt; P4 SPI<\/code>) and also expand the filesystem (<code>[7] Advanced options -&gt; A1 Expand filesystem<\/code>):\n<pre> $ sudo raspi-config\r\n<\/pre>\n<\/li>\n<li>Reboot (it will ask on exit, but you can do it manually with <code>sudo reboot<\/code>)<\/li>\n<li>Configure locales and time zone:\n<pre>  $ sudo dpkg-reconfigure locales\r\n  $ sudo dpkg-reconfigure tzdata\r\n<\/pre>\n<\/li>\n<li>Make sure you have an updated installation and install <code>git<\/code>:\n<pre>$ sudo apt-get install git\r\n<\/pre>\n<\/li>\n<li>Create new user for TTN and add it to sudoers\n<pre> $ sudo adduser ttn\r\n<\/pre>\n<\/li>\n<\/ul>\n<ul>\n<li>Logout and login as <code>ttn<\/code> and remove the default <code>pi<\/code> user\n<pre>$ sudo userdel -rf pi\r\n<\/pre>\n<\/li>\n<li>Configure the wifi credentials (check <a href=\"https:\/\/www.raspberrypi.org\/documentation\/configuration\/wireless\/wireless-cli.md\">here for additional details<\/a>)\n<pre>  $ sudo nano \/etc\/wpa_supplicant\/wpa_supplicant.conf \r\n<\/pre>\n<\/li>\n<\/ul>\n<p>And add the following block at the end of the file, replacing SSID and password to match your network:<\/p>\n<pre>network={\r\n\t    ssid=\"The_SSID_of_your_wifi\"\r\n\t    psk=\"Your_wifi_password\"\r\n\t}\r\n<\/pre>\n<ul>\n<li>Clone <a href=\"https:\/\/github.com\/ttn-zh\/ic880a-gateway\/tree\/spi\">the installer<\/a> and start the installation\n<pre>  $ git clone -b spi https:\/\/github.com\/ttn-zh\/ic880a-gateway.git ~\/ic880a-gateway\r\n  $ cd ~\/ic880a-gateway\r\n  $ sudo .\/install.sh spi\r\n<\/pre>\n<\/li>\n<li>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. <code>B827EBFFFE7B80CD.json<\/code>) in the <a href=\"https:\/\/github.com\/ttn-zh\/gateway-remote-config\">Gateway Remote Config repository<\/a>. EUI folows MAC addr of eth0 (or wlan0)<\/li>\n<li>By default, the installer changes the hostname of your Raspeberry Pi to <code>ttn-gateway<\/code> (to prevent collisions with other Raspberry Pis in your network). You can override this in non-remote configuration mode.<\/li>\n<li><strong>reset iC880a on boot <\/strong>(GPIO 17 = pin 11 conected to reset pin 13 on iC880a):<\/li>\n<\/ul>\n<p>put simlink to \/etc\/rc2.d to following script:<\/p>\n<pre>#!\/bin\/bash\r\n\r\necho \"17\" &gt; \/sys\/class\/gpio\/export\r\necho \"out\" &gt; \/sys\/class\/gpio\/gpio17\/direction\r\necho \"1\" &gt; \/sys\/class\/gpio\/gpio17\/value\r\nsleep 5\r\necho \"0\" &gt; \/sys\/class\/gpio\/gpio17\/value\r\nsleep 1\r\necho \"0\" &gt; \/sys\/class\/gpio\/gpio17\/value\r\niC880-SPI_reset.sh (END)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h1><a id=\"user-content-checking-connection-to-ttn\" class=\"anchor\" href=\"https:\/\/github.com\/ttn-zh\/ic880a-gateway\/wiki#checking-connection-to-ttn\" aria-hidden=\"true\"><\/a><span style=\"color: #0000ff;\">5. Checking connection to TTN (<em>The Things Network)<\/em><\/span><\/h1>\n<p>The best way to check if the gateway is working is registering it on the TTN Console.<\/p>\n<ul>\n<li>Login to <a href=\"http:\/\/www.thethingsnetwork.org\">www.thethingsnetwork.org<\/a> <em><strong>Console<\/strong><\/em><\/li>\n<li>Click on <em><strong>Gateways -&gt; Register gateway<\/strong><\/em><\/li>\n<li>Select the P<em><strong>acket forwarder<\/strong><\/em> protocol<\/li>\n<li>Enter your Gateway EUI (if is printed on start and end of the installer)<\/li>\n<li>Enter any description<\/li>\n<li>Select <em><strong>Europe 868 MHz <\/strong><\/em>as frequency plan<\/li>\n<li>Select the correct antenna placement according to your plans<\/li>\n<li>Confirm clicking <em><strong>Register gateway<\/strong><\/em><\/li>\n<\/ul>\n<p>Now you can see the status (which at this point should be <code>connected<\/code> if we did everything right) and traffic of your gateway!<\/p>\n<p><strong><span style=\"color: #339966;\">And now we&#8217;re really done!<\/span><\/strong><\/p>\n<h1><span style=\"color: #0000ff;\">6. Backups<\/span><\/h1>\n<h6>RPI &#8211; save SD card<\/h6>\n<p><a href=\"http:\/\/ideaheap.com\/2013\/07\/stopping-sd-card-corruption-on-a-raspberry-pi\/\">http:\/\/ideaheap.com\/2013\/07\/stopping-sd-card-corruption-on-a-raspberry-pi\/<\/a><\/p>\n<h6><strong>RPI backup img:<\/strong><\/h6>\n<pre># dd if=\/dev\/mmcblk0 | gzip -1 - | ssh user@backup-server dd of=image.gz<\/pre>\n<h6 id=\"firstHeading\" class=\"firstHeading\" lang=\"en\"><strong>Raspi UPS HAT Board:<\/strong><\/h6>\n<p><a href=\"http:\/\/www.raspberrypiwiki.com\/index.php\/Raspi_UPS_HAT_Board#how_to_USP_HAT_use_via_i2c\">http:\/\/www.raspberrypiwiki.com\/index.php\/Raspi_UPS_HAT_Board#how_to_USP_HAT_use_via_i2c<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Hardware Used Hardware: Banana-Pi M2U\u00a0quad-core mini single board computer\u00a0 + iC880a LoRaWAN Concentrator 868MHz\u00a0(bought\u00a0here) Banana-Pi advantage: internal 8 GB eMMC\u00a0storage OS Raspbian\u00a02017-05-25-raspbian-jessie-preview3-bpi-m2u-sd-emmc.img, how to burn it to MMC find here Step 1: Start up the computer with the SD card which has been burnt with the Linux images. Step 2: Put the images which [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-149","page","type-page","status-publish","hentry","post"],"_links":{"self":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/comments?post=149"}],"version-history":[{"count":53,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/149\/revisions"}],"predecessor-version":[{"id":204,"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/pages\/149\/revisions\/204"}],"wp:attachment":[{"href":"https:\/\/lora.vsb.cz\/index.php\/wp-json\/wp\/v2\/media?parent=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}