Use Lora/GPS HAT + RaspberryPi to set up a Lora Node

From Wiki for Dragino Project
Jump to: navigation, search

Use LoRa/GPS HAT + RaspberryPi to set up a LoRa Node

Use LoRa/GPS HAT + RaspberryPi to set up a LoRa Node


Introduction

Over here,we will use LoRa/GPS HAT + RaspberryPi to set up a LoRa Node and use the LoRa/GPS HAT + Raspberry Pi to build a single channel LoRaWAN gateway.

This demo include:

  • How to use LoRa/GPS HAT to set up single channel gateway for TTN network.
  • How to use LoRa/GPS HAT to set up a LoRa Node.
  • How is the communication between the LoRa Node and LoRa Gateway.


Hardwares

In this project,we use the things as followed list:

  • LoRa/GPS HAT(868MHZ) X 2
  • Raspberry Pi 2/3 model B(Installed Raspbian) X 2
  • LED display screen X 1
  • USB cables X 2
  • Antennas(868MHZ) X 2
  • PC X 1
  • Wireless network card X 2
  • Mouse and keyboard x 1
  • Some wires


Network structure

Network structure of RPi node

The construction of this network is as the photo above.

LoRa Node:

The Mega2560 will get sensor data and control the LoRa Shield to send this data to the RPi LoRa Gateway via LoRa wireless protocol.

LoRa Gateway:

The RPi LoRa Gateway will receive this data and upload it to the TTN network via the Internet.

TTN Server:

The TTN Server will get the data packets from the RPi LoRa Gateway and the data will be stored in the corresponding place,so users can take what they need from the Internet.

PC:

We can use the PC to get the data and check the status of this LoRa Gateway network.

Create a Gateway on TTN network

TTN

Before we start this project we must have a TTN account,we can create one at this page: http://thethingsnetwork.org/signup/

Create ttn gateway

NOTE: Create your own LoRa gateway is not necessary, if there are TTN lora gateway around, you don't have to create your own one. in this instruction, we want to demo the full network structure so we create gateway here.

Gateway EUI

Login the TTN network by your own account and configure 'My Profile' on the web.

TTN Gateway

Click 'add a gateway' and you will enter a page to type your gateway message.In the next step,we will get a Gateway ID after we run the packet forward on the RPi.Then type the Gateway ID to the Gateawy EUI column(In hexadecimal, no colons,uppercase letters).

We can see the ruuning result as the 3rd picture in this step,we get a Gateway ID: b8:27:eb:ff:ff:29:4b:3b,so we type B827EBFFFF294B3B to the Gateway EUI column.

Single Channel LoRa Gateway

By the way,we also need to modify other settings(Select the Status active,type a title for this Gateway,delect Automatically update status and coordinates...),save it and you will see your profile such as above picture.It means we just have created a Gateway for our TTN account.


Build a single channel LoRaWAN gateway

Gateway Status

In this step,we will use the RPi and the LoRa/GPS HAT to build a single channel LoRaWAN Gateway.We should configure the RPi and connect it with the LoRa/GPS HAT.Complete the operations as following description:

Configuration

  • Connect the Raspberry Pi to the Internet;
  • Use 'raspi-config ' to ensure that SPI can be used on RPi ;
  • Use 'git clone git://git.drogon.net/wiringPi' to install the GPIO access library written in C for the BCM2835 used in the Raspberry Pi;
  • Get the single channel LoRa Gateway source code from here ;
  • Edit the 'main.cpp' to change configuration (look for: "Configure these values!").

Defaults:

  • LoRa: SF7 at 868.1 Mhz
  • Server: 54.229.214.112, port 1700 (The Things Network: croft.thethings.girovito.nl)

So,we don't need too change the code here.

Dragino LoRa/GPS_HAT

Connect the Dragino LoRa/GPS HAT and the RPi as above,run packet forwarder as root. Then we can get a Gateway ID and see the running result on the RPi as below picture.

Get a Gateway ID

We also can get the Gateway status from http://thethingsnetwork.org/api/v0/gateways/B827EBFFFF294B3B/ as the last photo at this step. In this URL you should change 'B827EBFFFF294B3B' to your own Gateway ID. If you can see the Gateway status on the web,it shows the LoRaWAN Gateway is working!

Note: If the packet forwarder shows the "unrecognized transceiver" message,this mean the RPi can't detect LoRa/GPS HAT, in this case please further check your pin/wiring configuration.

Use LoRa/GPS HAT + RaspberryPi to set up a LoRa Node

In the LoRa Node side,the operations are as below:

1.Wiring,you need to connect them by yourself.

RPi -------------------- LoRa/GPS HAT
WiringPi pin 4 -------------------- DIO1
WiringPi pin 5 -------------------- DIO2

2.Connect the LoRa/GPS HAT with the RaspberryPi,power it.

3.Use 'git clone git://git.drogon.net/wiringPi' to install the GPIO access library written in C for the BCM2835 used in the Raspberry Pi.

git clone git://git.drogon.net/wiringPi

4.Get the LMIC source code from https://github.com/ernstdevreede/lmic_pi/archive/master.zip. Unzip the 'master.zip'.

 unzip master.zip

Enter the code file.

 cd lmic_pi-master/examples/thethingsnetwork-send-v1

Then edit the node_eui(DEVADDR) in thethingsnetwork-send-v1.cpp,

 sudo nano thethingsnetwork-send-v1.cpp

Make it and run thethingsnetwork-send-v1 as root.

 make
 
 sudo ./thethingsnetwork-send-v1

So the LoRa Node will start to send packets.

The other operations are same as Getting GPS to work on a Raspberry Pi 2 Model B.

Conclusion

Running Result on TTN

Above all completed,open the URL with your node_eui and you will see the running result on the ttn network.For example,our 'DEVADDR'/node_eui is '09984507',so we can check it on http://thethingsnetwork.org/api/v0/nodes/09984507/.

By the way,we can get this LoRa Shield from http://www.aliexpress.com/store/all-wholesale-products/1390863.html


Reference


FAQ

Run the command 'sudo ./thethingsnetwork-send-v1'causes the following error:-wiringPiSetup*: You must only call this once per program run. This is a fatal error. Please fix your code.

These trouble shooting message is from https://github.com/mxmxmx/terminal_tedium/wiki/trouble

audio i/o

audio inputs not working? make sure you got the amixer settings right

externals

if using pd-extended, i gather there's potential issues with wiringPi / multiple calls to wiringPiSetup(). if things throw an error along the lines of wiringPiSetup*: You must only call this once per program run. This is a fatal error. Please fix your code, a quick fix is to hack wiringPi.c: replace line # 2058 with return 0; and re-build wiringPi: 1) uninstall wiringPi:

 cd wiringPi 
 ./build uninstall
 cd ..
 rm -r wiringPi

2) reinstall:

git clone git://git.drogon.net/wiringPi

3)

 cd wiringPi 
 git pull origin 

4) locate the file called wiringPi.c, open it with nano or vim, go to line 2058 (or thereabouts) and replace:

(void)wiringPiFailure (WPI_FATAL, "wiringPiSetup*: You must only call this once per program run. This is a fatal error. Please fix your code.\n") ;

with:

return 0;

5)

cd wiringPi 
./build 
terminal tedium