Introduction: LoRaWAN Gateway
LoRaWAN is a protocol designed for creating large-scale public networks; the technology allows for sensors to talk to the internet without 3G or WiFi. Community crowdsourced projects, such as The Things Network, aim to provide access to this technology by deploying gateways globally that others can freely connect to.
The purpose of this Instructable is to provide a guide for people to create their own outdoor LoRaWAN Gateway using off-the-shelf components, rather than purchasing a commercial offering. Many of the components used in this Instructable, such as the coax cables, can be substituted for cheaper alternatives (from sites like Ebay); however, for the purpose of this guide I tried to keep the number of suppliers to a minimum.
Step 1: Quick Overview of the Files:
Bom Part 1.csv - A list of parts sourced from Farnell.
Bom Part 2.csv - Other required parts sourced from places like Amazon.
Bracket.dxf - Template for the rear bracket. This is cut from a sheet of steel and will require a shear & bender.
Internal Plate.dxf - Internal plate for mounting the Raspberry Pi, this requires a lasercutter.
Hole Template.dxf - Template to help mark out the positioning of the bulkhead connectors.
Step 2: Required Tools & Machines
- Screwdriver (phillips)
- Allen Keys
- Drill
- 12, 10, 8, 4mm drillbits
- 22mm Hole Saw
- M12 Tap & Holder
- File / Deburring Tool
- Fine Tooth Jigsaw / Rotary Multitool with small angle grinding attachment
- RJ45 Crimping Tool, Connectors, Boots and Cable (a RJ45 cable tester is also handy!)
- Sheet Metal Bender & Shear
- Lasercutter (for producing the internal adapter plate)
- A3 Printer (for printing templates 1:1)
Step 3: Bottom Holes in the Enclosure
Print or lasercut "hole template.dxf". This template is used to help mark out the location of the bottom holes for the enclosure. Place the template against the top edge of one of the enclosure recesses, so that the holes are situated near the top of the enclosure. Now drill out these holes using the M12 (center hole) and M8 (side holes) drill bits. Use a file / deburring tool to clean up the holes.
Step 4: Side Hole for Pressure Compensated Valve
Using the M10 drill bit, make a hole on one of the long-sides of the enclosure; this hole should be made near the top of the enclosure. Thread this hole using a M12 tap.
Step 5: Install the First Set of Connectors
Install the nylon cable gland and the two SMA bulkhead connectors. The SMA bulkhead connectors should be installed, so that the small rubber o-ring's are within the inside of the enclosure. If necessary, use a small file to enlarge the holes to size as ideally they should be a tight fit. Leave the pressure compensation valve uninstalled for now.
Step 6: Install SMA Coax Cables
Install and tighten the two short SMA coax cables on the internal facing side of the SMA bulkhead connectors.
Step 7: Lasercut the Acrylic and Install M2.5 Standoffs
Using "Internal Plate .dxf", lasercut the 6mm thick sheet of acrylic to create the internal adapter plate. Now install the M2.5 standoffs and lock them in place with the M2.5 nyloc nuts. If you are using standard nuts (rather than nyloc), a little bit of locktite is required. The rectangular cut-out should be on the left-hand side of the internal adapter piece.
Step 8: Attach Raspberry PI 3 to the Internal Adapter Plate
It is easier to image and configure the Raspberry Pi now (step 21) prior to attaching it to the internal adapter plate. Once the Pi is set up, attach it to the standoffs and secure the Pi in place with the M2.5 screws. The Pi's USB ports should face upwards and the HDMI port face away from the rectangular cut out, as shown in the picture. Once the Raspberry Pi is in place, connect the Linklabs shield to the Pi (its SMA connectors should face the HDMI side of the Raspberry Pi).
Step 9: Install the Internal Adapter Plate
The internal adapter plate can now be installed into the enclosure. Secure it in place with the four M3 screws. If you wish you may tap the standoffs first, but I found the plastic soft enough to self-tap.
Step 10: Install the Pressure Compensation Valve
The pressure compensation valve can now be installed in the remaining hole that we made earlier.
Step 11: Connect the Internal Coax Cables
The coax cables can now be connected to the Linklabs board. The GPS SMA connector should use the coax that runs to the left hand side bulkhead connector and the 868MHz SMA connector should run to the one on the right.
Step 12: Prepare the Wall Bracket
Print off "Bracket.dxf" onto a sheet of A3 paper at 1:1 scale. Cut out this template and glue it (with prit stick) to the sheet of stainless steel. Use this as a guide to cut out all of the required holes:
- Use the 22mm hole drill for the largest hole
- Use a M4 drill bit for the four smaller holes and the top (optional) wall bracket holes
- Use a M8 drill for the remaining holes
- Cut out the remaining bit of metal to make the wall connector holes (use a rotary multi-tool / fine tooth jigsaw) -- this is optional based on your own needs
- De-burr all of the holes
Use a shear to cut the sheet of steel to size and break the edge with a file (you should probably round off the corners too). Finally (once all the holes have been made!) use a former to make a 90degree bend in the metal. This bend should be placed between the top two holes (for the antennas) and the 'wall holes' - you can use the enclosure to help work out where to place this bend, keep in mind you need clearance for the antenna connectors!
Useful Note: We adapt the back of the "wall bracket" depending on what we wish to mount it too. For example we use metal pole clips to allow us to secure them to a pole mounted on a tripod for portable testing.
Step 13: Secure the Wall Bracket to the Enclosure
Secure the wall bracket to the back of the enclosure. You will need M4 bolts for this; again secure them in place with nyloc nuts / loctite.
Step 14: Install the GPS Antenna
Install the GPS antenna into the largest top hole and tighten the two nuts. Now install the 90' TNC connector and finally the TNC to SMA connector. The SMA connector should face towards the direction of the second antenna hole.
Step 15: Install the Bulkhead Jack SMA Cable
Install the bulkhead jack SMA cable into the remaining antenna hole. You will need two M6 washers on either side of the metal bracket to help secure the connector; tighten the brass nut to lock everything in place.
Step 16: Route the Coax Cables
Route both SMA coax cables and attach them to the bottom SMA bulkhead connectors; the coax for the GPS should run to the bulkhead on the left hand side of the enclosure and the coax for the 868MHz antenna should run to the bulkhead on the right hand side.
Step 17: Install the Rubber Duck Antenna
Install the 868MHz rubber duck antenna; this antenna should get you started and it is discrete.
You can replace it with a larger antenna, for example a Procom CXL900-3/L NType 824-894MHz collinear antenna; however antenna location (is it worth installing more shorter range gateway units vs a few larger ones?), suitable mounting brackets and local regulations should be considered before doing so.
Step 18: Install the Enclosure Clips and Lid
Clip in place the two enclosure clips and attach the lid to one of them (We prefer the bottom one nearest the enclosure bulkhead connectors).
Step 19: Crimp RJ45 Cable and Install POE Splitter
Run a suitable length of RJ45 cable through the cable gland and crimp the cable internally. Install the POE splitter (a bit of double-sided foam tape and help secure it) and connect the RJ45 cable to it. The splitter's power and network connectors should run to the respective receptacles on the Raspberry Pi - be warned the power cable is a very tight fit!
Note: We have run these gateways with an Anker Astro E1 5200mAh battery placed where the POE splitter fits and have had the Raspberry Pi 3's wireless connecting to a 3G/LTE hotspot (or old Android phone); this is useful if you wish to try out different places for siting the gateway before going to the hassle of installing it.
Step 20: Hardware Complete
Finally your hardware is ready!
Step 21: Software
We recommended using Raspbian Jessie Lite as the operating system for the Raspberry Pi. The packages linked to here will set up an installation meant for The Things Network backend (protocol version 2). If you require protocol version three (which currently isn't compatible with the Things Network), you will need to build the latest Gateway and Packet Forwarder binaries (https://github.com/Lora-net/).
- Download Raspbian Jessie Lite and flash the image to a SD card.
- Edit "config.txt" located in the boot partition and append the following:
# Enable SPI interface dtparam=spi=on # Enable GPS PPS dtoverlay=pps-gpio,gpiopin=4 #Disable Bluetooth on pi 3 dtoverlay=pi3-miniuart-bt
3. Edit "cmdline.txt"; the contents of the file should currently look something like this:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Remove all references to ttyAMA0. The file will now look something like this:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
4. Start / Reboot the Raspberry Pi. On first boot Raspbian will expand the root filesystem to the size of your SD card.
5. If you wish to use the .deb package that we have created to install the required binaries & services for the gateway then follow the next set of steps; otherwise now is the time to go and build from source. It can be useful to temporarily use a "root" privileged shell for the next set of steps:
sudo -s
6. Now create a file "/etc/apt/sources.list.d/lorawan.list" and append the following:
deb http://shed.kent.ac.uk/repos/apt/debian jessie main
7. You also need to get the repo keys:
wget -O - https://shed.kent.ac.uk/repos/apt/conf/shed.gpg.key | apt-key add -
8. Now run this command:
apt-get install apt-transport-https ; apt-get update
9. Once the repositories have finished updating (hopefully without error), install the following packages:
apt-get install linklabslorawangateway pps-tools
10. If everything went without a hitch you will now have a gateway setup. The installation of the package "linklabslorawangateway" should set up files in "/opt/linklabs" and "/lib/systemd/system". As part of the installation it will use your Pi's mac address for the gateway's ID; this can be overridden in the file "/opt/linklabs/config/local_conf.json". Whilst not configured in this guide, pps-tools allows you (with an update to NTP) to use the GPS second pulse to keep a more accurate record of time on your gateway.
11. To connect to the Things Network you will want to modify "/opt/linklabs/config/global_conf.json". Scroll down to the line:
"server_address": "shed.kent.ac.uk"
And for Europe change it too:
"server_address": "router.eu.thethings.network"
12. Reboot the Raspberry Pi and you should be good to go.
Useful Notes:
- The systemd linklabs.service calls the scripts "start.sh" and "stop.sh" located in the "/opt/linklabs/bin/" directory. It can be useful to modify these scripts for your specific needs.
- The Things Network guide recommends modifying "local_conf.json" for gateway specific settings; in our case we keep server settings in "global_conf.json" and only use "local_conf.json" for the Gateway ID - this is because we remotely manage our gateways from a configuration management tool called Salt Stack; you may wish to adjust these files to match the Things Network's recommendations.
- Because the GPS unit is utilised by the packet_fowarder program, it will be unavailable for use by other services; such as NTP (however the time pulse is accessible) - you will still need to set coarse time from a network NTP server.
22 Comments
Question 5 years ago on Introduction
Could you send me please the manufacturer part number of the ABS enclosure that you are showing in the pictures? I love the way it closes with the side clips.
5 years ago
As said before you did a really fantastic job, with both the gateway and the instructable. I recently published a tutorial for building LoRaWAN gateways for The Things Network at https://frightanic.com/iot/build-a-lorawan-gateway-for-the-things-network/. While my gateway hardware is not as elaborate as yours I think the entry barrier for beginners may be a bit lower.
6 years ago
Hi Daniel, For what radio environment/application would this be an ideal solution?
How does this device interact with the conventional Service-provider supported, Residential broadband setup (modem, router, access point, client)? What is the max downlink, radiated power(in watts or dbm) and the max radius? Many thanks Daniel!
Reply 6 years ago
Hi Instruct_:
LoRaWAN is ideal for public networks where there is one / few "providers". The protocol is noise resistant, has very good range (in theory 15KM line of site -- realistically several kilometer in urban environments), and has relatively low power demands (when compared with GSM), but this comes at the cost of bandwidth. It is most suited for "data dribblers", so devices that occasionally send data to the Internet (i.e. remote sensors).
Because LoRaWAN generally uses ISM bands, it gets effected by duty cycle regulations, so you are legally limited on the amount of airtime you are using within in a period of time. Things network have a calculator which can give you a ballpark idea of number of msgs within 24hour (https://docs.google.com/spreadsheets/d/1voGAtQAjC1... Gateways also are effected by the duty cycle rules, so whilst message acknowledgments for nodes is supported by LoRaWAN, its better if you can live without it (as it needs this downlink time for join requests and session key exchanges with nodes -- as the transport layer is symmetrically encrypted).
In terms of service providers, there isn't one in the traditional sense. Community groups like The Things Network provide the backend network servers that route messages from your sensor to the right application, and also handle things like message de-duplication when multiple gateways pick your message up; but ultimately the gateways that actually form the network are owned by the community themselves (i.e. you and I). There's nothing stopping you from operating a completely private LoRaWAN network (by running your own network servers), but at the same time it could mean you start competing for airtime with other networks that exist in the same area; hence why its better suited for fewer network providers in a single area and for those to be made available for everyone to use. This page gives a more in-depth overview of the general architecture of a LoRaWAN network (https://www.thethingsnetwork.org/wiki/Home)
Hope this helps!
Reply 6 years ago
Setting up ones own gateway and service does mean one does not have to pay for the service.
6 years ago
Hi can you use this in a "Mobile situation" like a motorhome, as we live almost fulltime in one and need a better solution for our connectivity this sounds like it could be of great help in fringe area's?
Great project BTW.
Reply 6 years ago
Hi, the gateway itself can made to be highly mobile as we use one for mobile testing (it happily runs on a battery all day long) -- if you use a Pi zero, rather than a Pi 3 the unit uses around 20watt hours a day. However, it sounds like you are wishing to use this to improve your Internet connectivity to your motorhome, in which case this would likely not be suitable for your needs. This kind of wireless network is primarily designed for very low bandwidth system (sensors that 'dribble' data), so things like emails, web browsing, etc. whilst we may think of them as lightweight, would require bandwidth that this kind of network could simply not provide (and likely quickly go beyond the allowed duty cycle). Hope this helps.
6 years ago
Hi Daniel
Very nice project and well explained.
I have a thought though which might make it easier to make and cheaper.
If you turned the box on its side and mounted the antennas directly to the box with a single plate on the outside for the earth plane you would have only the short coax cables inside the box and it would be easy to waterproof the 2 antenna holes with sealer under the metal plate.
This would also give you room to separate the 2 antennas 1/4 wavelength.
The pressure compensation valve should be mounted at the lowest point so that any moisture that does get in will be expelled when (due to heating) the pressure increases. I have done many of this kind of enclosure and is certainly works.
Many thanks again for a good project
Ian
6 years ago
Your project is very nicely done. Both thumbs up!
I do, however, have a few comments:
(1) It may be better to change a few dimensions and avoid using the right angle adapter for the GPS antenna. Every connector and adapter adds insertion loss. The right angle adapter wastes a bit of your sensitivity.
(2) The R-Pi mounting plate does not need to be laser cut. A small hand saw and about 10 minutes of careful work will yield the same thing. When I make internal mounting plates for boards (to avoid placing holes directly in the enclosure), I either use screws to attach the plate to the enclosure standoffs, or if there are no standoffs, I solvent weld the plate to the enclosure using tetrahydrofuran. For less permanency, I use double sided foam tape instead.
(3) Question: The Wi-Fi antenna and GPS antenna share the same ground plane (mounting bracket). Is it important to consider the SPACING between them?
Reply 6 years ago
Hi, Thanks for the comments!
(1) You could increase the height of the wall bracket and put a straight TNC to SMA adapter in (to go from the GPS antenna to the SMA coax). For us the receiver gain from the GPS antenna meant the little extra loss from another adapter was negligible for us.
(2) Yup you can just use a saw if you want; I considered that when I first wrote the Instructable, but guessed any person comfortable in doing that would just do so anyway.
(3) This is a tricky question. Technically you should have at least 1/4 wavelength spacing of the lower frequency between the antennas - so in this case about 86mm (which we don't have); otherwise one antenna can effect the characteristics of the other (mostly the omni). If this is of concern you can widen the adapter plate or increase the length of the plate and offset the mounting holes to obey this rule. I'll try and take it down the antenna lab on campus to see how the antennas are effecting each other and report back to this comment. However, it's also worth mentioning that if you intend to have fewer gateways and are able to site it somewhere good (e.g. mast) then I personally wouldn't bother with the rubber duck and go straight for something like a collinear antenna. We like using the rubber duck for testing and on our portable rigs, but would jump to a good basetation antenna in a heart beat.
6 years ago
if your going to use this in an urban enviroment whats the need for GPS? Couldn't you use an NTP server?
Reply 6 years ago
We indeed use an NTP server for coarse time. A LoRaWAN gateway is able to provide its location to the network (which is included in the meta data of every received packet), so at the moment we primarily use GPS for this. However, the actual reason for GPS in this gateway was for the longer term; current LoRaWAN deployments are generally "Class A" deployments, which means nodes wake up and send messages and then can get downlink messages shortly after a transmit (this is the lowest powered version of LoRaWAN). In a "Class B" network, the nodes on the network open extra receive windows at scheduled times; but to do this they need a time synchronized beacon from the gateway; as such, the inclusion of GPS was a decision to make this gateway hardware ready for Class B networks. However, to reduce the price, you can leave the GPS parts out and just "fake gps" in the packet forwarder (if you know their static location at configuration time).
Reply 6 years ago
Awesome thanks for taking the time to explain. I have a usb gps for syncing my domain controller already so I'll probably just sync off its ntp.
6 years ago
How does this compare to the "official" instructions from The Things Network? This one certainly looks more expensive and more sophisticated.
Reply 6 years ago
In terms of the number of nodes able to be supported and available channels, there is no difference (the ic880a board has the exact same underlying chips as the Linklabs one that we use). The biggest difference between that one and ours is we have GPS included; although this alone shouldn't currently be a massive difference as most networks only support Class A Lorawan networks. Other minor differences is the choice of shield creates a more secure connection between it and the Lorawan shield (rather than breadboard jumper cables); we use a 802.3af compliant device (rather than a passive splitter), so it plays nicer over long distances with switches that have POE built in, etc.
6 years ago
Awesome. Any idea what the transmission range (distance) would be on this?
Reply 6 years ago
This is heavily dependant on a large number of factors; including: antenna choice, urban density, things in the fresnel zone, etc, but we easily get a few kilometre in a city with ours using the rubber duck antenna. We have been working on a few tools to help map the signal quality using a phone and Arduino+LoRaWan shield combination (kinda like OpenSignal, but for LoRaWAN networks); so we'll release these soon to help people get a more accurate idea of what is possible.
6 years ago
Congrats! Nicely done!
6 years ago
Thanks for the detailed instructable...would you have any idea on the frequency range support on thise LoRA transceiver? I believe the frequencies allowed for LoRA are different in different countries..
Reply 6 years ago
Hi, the shield used in this gateway is designed for making use of frequencies around 868MHz; so primarily it is meant for European markets (making use of the ISM band there). LoRa itself is designed to be used on pretty much "any" frequency; with specific hardware implementations designed for different parts of the bands.