The beginnings
Some time ago we were faced with a project, that needed long-range wireless communication to obtain some data from remote sensors. We’ve done some market research to find a solution, but the hardware we’ve found was too expensive or the software was not meeting our expectations (and our customer’s). We wanted to have bigger control over the gateway in order to have it customized for the customer’s needs. He wanted to have the possibility to use it with his own specialized dashboard and database. We also wanted it to have the openness to make it a good, general purpose device for usage in the open public cloud network, such as The Things Network.
- The beginnings
- What is the lpnGate
- How to start
- Customizing the image
- Operation
- Other possible uses
- Summary
What is the lpnGate
We’ve decided to create our own custom device. It’s mostly based on off-the-shelf components, like long time proven and well liked APU2 board (used to create advanced routers or firewalls). The board uses open source firmware (coreboot). The operating system is based on well-known and stable OS for routers (OpenWRT) modified for our needs.
Hardware
Those are components used to create lpnGate:
- APU2 board with coreboot firmware
- RAK833 LoRa SX1301 gateway mPCIe card
- 16GB SSD mSATA disk
Software
Main features of lpnGate’s software:
- LPN Plant’s modified OpenWRT
- first public release based on 18.06.1 version of OpenWRT
- added support for dual-image OS
- added swupdate integration for better over-the-air update support
- RAK833 support included
- hardware watchdog support
- by default its designed as general purpose The Things Network gateway
- open to modifications
- standard RS232 port to be used as a debug port
- contributions welcome!
How to start
Where to get
lpnGate is available to buy at our store: direct link
It could also be built by the end-user. All necessary components are also available.
Quick start
All the necessary steps to install the gateway and start using it are pretty straightforward. You can use the manual which is available on the product page.
Customizing image
lpnGate is open to modifications. OpenWRT is available on our github page. Let’s start by building our own custom image.
Building the image
Prerequisites
- some kind of Linux distro (tested on Arch Linux and Ubuntu)
- docker
- git
Download development container
All the compiling is done inside a running container in order to mitigate differences between different Linux distributions.
All the commands are expected to be run in some kind of work directory, e.g.
/home/user/work
First, we need to pull it from docker hub:
docker pull lpnplant/openwrt-docker
We can also build it manually using the Dockerfile from our repository.
We will need the script to start the image:
git clone https://github.com/lpn-plant/openwrt_docker.git
Build
First, let’s clone the repository:
git clone https://github.com/lpn-plant/openwrt.git
Let’s start the container:
./openwrt_docker/scripts/run_docker.sh openwrt
And inside the container:
./scripts/feeds update luci ./scripts/feeds install luci cp configs/apu_config .config make oldconfig make
This should be the compilation output:
make[1] world make[2] toolchain/compile make[2] package/cleanup make[3] -C toolchain/binutils compile make[3] -C toolchain/gdb compile make[3] -C toolchain/fortify-headers compile make[3] -C toolchain/yasm compile make[3] -C toolchain/gcc/minimal compile make[3] -C toolchain/kernel-headers compile make[3] -C toolchain/glibc/headers compile make[3] -C toolchain/gcc/initial compile make[3] -C toolchain/glibc compile make[3] -C toolchain/gcc/final compile make[2] target/compile make[3] -C target/linux compile make[2] diffconfig make[2] package/compile make[3] -C package/libs/libubox host-compile make[3] -C package/libs/ncurses host-compile make[3] -C package/system/usign host-compile make[3] -C package/system/fwtool host-compile make[3] -C package/libs/toolchain compile make[3] -C feeds/luci/modules/luci-base host-compile make[3] -C package/boot/grub2 host-compile make[3] -C package/utils/lua host-compile make[3] -C package/kernel/leds-apu2 compile make[3] -C package/utils/e2fsprogs host-compile make[3] -C package/utils/zoneinfo compile make[3] -C package/libs/libnl-tiny compile make[3] -C package/libs/libjson-c compile make[3] -C package/utils/lua compile make[3] -C package/firmware/linux-firmware compile make[3] -C package/firmware/prism54-firmware compile make[3] -C package/libs/zlib compile make[3] -C package/system/fwtool compile make[3] -C package/system/openwrt-keyring compile make[3] -C feeds/luci/protocols/luci-proto-ppp compile make[3] -C feeds/luci/themes/luci-theme-bootstrap compile make[3] -C package/libs/mbedtls compile make[3] -C feeds/luci/protocols/luci-proto-ipv6 compile make[3] -C package/libs/expat compile make[3] -C package/libs/openssl compile make[3] -C package/utils/bzip2 compile make[3] -C package/libs/libconfig compile make[3] -C package/libs/confuse compile make[3] -C package/libs/libusb compile make[3] -C package/lpn/config compile make[3] -C package/lpn/get-serial compile make[3] -C package/network/utils/curl compile make[3] -C package/network/services/dropbear compile make[3] -C package/utils/busybox compile make[3] -C package/system/opkg host-compile make[3] -C package/libs/libubox compile make[3] -C package/kernel/linux compile make[3] -C package/libs/ncurses compile make[3] -C feeds/luci/libs/luci-lib-ip compile make[3] -C feeds/luci/libs/luci-lib-jsonc compile make[3] -C feeds/luci/libs/luci-lib-nixio compile make[3] -C feeds/luci/contrib/package/lucihttp compile make[3] -C package/libs/ustream-ssl compile make[3] -C package/kernel/button-hotplug compile make[3] -C package/libs/libftdi1 compile make[3] -C package/libs/uclient compile make[3] -C package/network/ipv6/odhcp6c compile make[3] -C package/system/mtd compile make[3] -C package/system/opkg compile make[3] -C package/system/ubus compile make[3] -C package/system/uci compile make[3] -C package/utils/jsonfilter compile make[3] -C package/system/usign compile make[3] -C package/network/utils/iptables compile make[3] -C package/network/utils/iwinfo compile make[3] -C package/network/services/uhttpd compile make[3] -C package/lpn/libmpsse compile make[3] -C package/network/services/dnsmasq compile make[3] -C package/network/services/odhcpd compile make[3] -C package/system/ubox compile make[3] -C package/network/config/netifd compile make[3] -C package/system/rpcd compile make[3] -C package/lpn/lora-gateway compile make[3] -C package/system/procd compile make[3] -C feeds/luci/modules/luci-base compile make[3] -C feeds/luci/libs/rpcd-mod-rrdns compile make[3] -C package/lpn/packet-forwarder compile make[3] -C package/utils/util-linux compile make[3] -C package/utils/bash compile make[3] -C package/utils/xz compile make[3] -C feeds/luci/modules/luci-mod-admin-full compile make[3] -C package/network/config/firewall compile make[3] -C feeds/luci/applications/luci-app-firewall compile make[3] -C feeds/luci/collections/luci compile make[3] -C package/boot/grub2 compile make[3] -C package/system/fstools compile make[3] -C package/utils/f2fs-tools compile make[3] -C package/utils/e2fsprogs compile make[3] -C package/base-files compile make[3] -C package/libs/libarchive compile make[3] -C package/lpn/swupdate compile make[2] package/install make[2] target/install make[3] -C target/linux install make[2] package/index make[2] checksum
After the build, the images are available in bin/targets/x86/64-glibc
.
Flashing the image
Careful! Uploading the wrong image may result in the device that is not functioning and which will need to be reflashed (the procedure how to do that, will be available in one of the next posts). Do it at your own risk!
There are several ways used to flash the new image. The easiest way is to use the lpnGate’s web interface:
And then you can upload a new image (supported image is one, that is ending with -combined-squashfs.img.gz
). Use the Flash new firmware image
part.
You can also backup and restore your settings here.
Operation
lpnGate in its default form is used as a The Things Network public LoRa cloud gateway. After registering it (instructions available in the product manual) you can see the lora_pkt_fwd
logs in the Status/System Log
page in the lpnGate’s web interface:
Fri Jan 25 18:09:31 2019 daemon.info lora_pkt_fwd[3134]: JSON up: {"stat":{"time":"2019-01-25 17:09:31 GMT","rxnb":3,"rxok":3,"rxfw":3,"ackr":100.0,"dwnb":0,"txnb":0}} Fri Jan 25 18:09:31 2019 daemon.info lora_pkt_fwd[3134]: INFO: [up] PUSH_ACK received in 68 ms Fri Jan 25 18:09:33 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:33 2019 daemon.info lora_pkt_fwd[3134]: INFO: Received pkt from mote: 2601186E (fcnt=34789) Fri Jan 25 18:09:33 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:33 2019 daemon.info lora_pkt_fwd[3134]: JSON up: {"rxpk":[{"tmst":1315826699,"chan":0,"rfch":1,"freq":868.100000,"stat":1,"modu":"LORA","datr":"SF7BW125","codr":"4/5","lsnr":9.2,"rssi":-22,"size":25,"data":"QG4YASYA5YcBmPuhiD8Am654loCN+8VJeg=="}]} Fri Jan 25 18:09:33 2019 daemon.info lora_pkt_fwd[3134]: INFO: [up] PUSH_ACK received in 67 ms Fri Jan 25 18:09:35 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:35 2019 daemon.info lora_pkt_fwd[3134]: INFO: Disabling GPS mode for concentrator's counter... Fri Jan 25 18:09:35 2019 daemon.info lora_pkt_fwd[3134]: INFO: host/sx1301 time offset=(1548434858s:66898µs) - drift=95µs Fri Jan 25 18:09:35 2019 daemon.info lora_pkt_fwd[3134]: INFO: Enabling GPS mode for concentrator's counter. Fri Jan 25 18:09:35 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:39 2019 daemon.info lora_pkt_fwd[3134]: INFO: [down] PULL_ACK received in 70 ms Fri Jan 25 18:09:42 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:42 2019 daemon.info lora_pkt_fwd[3134]: INFO: Received pkt from mote: 2601186E (fcnt=34790) Fri Jan 25 18:09:42 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:42 2019 daemon.info lora_pkt_fwd[3134]: JSON up: {"rxpk":[{"tmst":1324781579,"chan":0,"rfch":1,"freq":868.100000,"stat":1,"modu":"LORA","datr":"SF7BW125","codr":"4/5","lsnr":9.0,"rssi":-22,"size":25,"data":"QG4YASYA5ocBVpEVYHS5v/HAcho9nsiOOg=="}]} Fri Jan 25 18:09:42 2019 daemon.info lora_pkt_fwd[3134]: INFO: [up] PUSH_ACK received in 69 ms Fri Jan 25 18:09:49 2019 daemon.info lora_pkt_fwd[3134]: INFO: [down] PULL_ACK received in 67 ms Fri Jan 25 18:09:51 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:51 2019 daemon.info lora_pkt_fwd[3134]: INFO: Received pkt from mote: 2601186E (fcnt=34791) Fri Jan 25 18:09:51 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:51 2019 daemon.info lora_pkt_fwd[3134]: JSON up: {"rxpk":[{"tmst":1332941683,"chan":0,"rfch":1,"freq":868.100000,"stat":1,"modu":"LORA","datr":"SF7BW125","codr":"4/5","lsnr":9.2,"rssi":-22,"size":25,"data":"QG4YASYA54cBSiqaMhX0lcPxyB2jV+uqlg=="}]} Fri Jan 25 18:09:51 2019 daemon.info lora_pkt_fwd[3134]: INFO: [up] PUSH_ACK received in 67 ms Fri Jan 25 18:09:59 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:59 2019 daemon.info lora_pkt_fwd[3134]: INFO: Received pkt from mote: 2601186E (fcnt=34792) Fri Jan 25 18:09:59 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:09:59 2019 daemon.info lora_pkt_fwd[3134]: JSON up: {"rxpk":[{"tmst":1341602027,"chan":0,"rfch":1,"freq":868.100000,"stat":1,"modu":"LORA","datr":"SF7BW125","codr":"4/5","lsnr":10.0,"rssi":-24,"size":25,"data":"QG4YASYA6IcBgXnUUi8vHECHtddlOW69RQ=="}]} Fri Jan 25 18:09:59 2019 daemon.info lora_pkt_fwd[3134]: INFO: [up] PUSH_ACK received in 67 ms Fri Jan 25 18:10:00 2019 daemon.info lora_pkt_fwd[3134]: INFO: [down] PULL_ACK received in 66 ms Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: ##### 2019-01-25 17:10:01 GMT ##### Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: ### [UPSTREAM] ### Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # RF packets received by concentrator: 4 Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # CRC_OK: 100.00%, CRC_FAIL: 0.00%, NO_CRC: 0.00% Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # RF packets forwarded: 4 (100 bytes) Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # PUSH_DATA datagrams sent: 5 (954 bytes) Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # PUSH_DATA acknowledged: 100.00% Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: ### [DOWNSTREAM] ### Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # PULL_DATA sent: 3 (100.00% acknowledged) Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # PULL_RESP(onse) datagrams received: 0 (0 bytes) Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # RF packets sent to concentrator: 0 (0 bytes) Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # TX errors: 0 Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # BEACON queued: 0 Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # BEACON sent so far: 0 Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # BEACON rejected: 0 Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: ### [JIT] ### Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # SX1301 time (PPS): 1317812326 Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: src/jitqueue.c:471:jit_print_queue(): INFO: [jit] queue is empty Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: ### [GPS] ### Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: # GPS sync is disabled Fri Jan 25 18:10:01 2019 daemon.info lora_pkt_fwd[3134]: ##### END #####
In the log above, you can see that gateway received 4 messages from mote with address 2601186E
. The data is encoded in base64 and encrypted. Gateway only passes the data to the cloud server, it can’t access it by itself.
Other possible uses
lpnGate is general purpose gateway, which means it could also act as an advanced router or firewall. It has full functionality of the OpenWRT operating system, that includes installing packages and configuring network interfaces. After installing an additional mPCIe WiFi card like, e.g. one form our shop, you can also get working WiFi access point. At this point (version 18.06.1.1), a modified system with drivers will be required, but possibly we will add support to the official software version in next releases.
Summary
lpnGate is a very versatile device. It is designed to use as an advanced IoT LoRa gateway, that is open to the modifications by the community. It can be used also as a router, firewall or even as a small general purpose server.
In LPN Plant we connect consulting, technical expertise and financial effectiveness to design and implement low power wireless solutions for industry. If you looking for LoRaWAN product developers or just need support in a small piece of your system feel free to set up call with us using calendly. If you enjoying this type of content feel free to sing up to our newsletter and share content on social media.