Our IoT LoRa Node pHAT allows you to create an inexpensive LoRa node, compatible with The Things Network, in conjunction with a Raspberry Pi or other single board computers. This pHAT allows quicker prototyping as it has the LoRa stack on the chip. Add sensors, buttons and more to complete your LoRa network!
- Uses RAK811 LoRa Radio with full LoRaWAN Stack embedded.
- Communicates with the Raspberry Pi over UART only using a total of 3 GPIO pins for the module.
- Support LoRaWAN connections and LoRa P2P modes.
- u.FL connector and on-board antenna allowing different antennas to be used or integrated into enclosures with external antennas.
- Also adds 8 extra GPIO pins controllable via the UART including 2 pins which can read analogue sensors!
- Low power – uses less than 50mA during transmission
First go to https://console.thethingsnetwork.org
- If not logged in login using your TTN Username and password.
- If you don’t have an account, click create an account and follow the steps to setup a TTN Account
- Click on applications
- Then click “add application“
- For application ID use “my-iotlora-application-<Yournamehere>“, in my case it is “my-iotlora-application-chris” or use something unique to you.
- Description: use something like “PiSupply IoT nodes”
- Handler registration use “ttn-handler-eu“
- Click “add Application“
- Next click payload formats
- Click the custom bar and change it to Cayenne LPP
- Now click “Devices” in the toolbar
- Then “register device“
- Here create a unique ID, in my case I’ve done “chris-lora-node“
- For device EUI click the two arrows to the left to generate one (we will change this later)
- Then click “Register“
- In this device, next we want to click “Settings“
- Change the activation method to OTAA by clicking the OTAA Button (This may be the default setting)
- For development we want to disable frame counter checks, do this by unticking this field at the bottom
- Now TTN Is ready for our Node pHAT! Keep this page open in a tab for later on
Step 1 – Download and flash the latest Raspbian OS image to your micro SD card. You can download the latest image from here – https://www.raspberrypi.org/downloads/raspbian/
Note: We recommend to download the Raspbian Lite version
Step 2 – Firstly you will need to connect your Raspberry Pi to the Wi-Fi. In the terminal type in the following command:
Select option 2 “Networking Options” then N2 “Wi-Fi” then follow the instructions to enter your Wi-Fi credentials and connect to the Wi-Fi for internet access.
Step 3 – Before we reboot we need to enable the hardware serial on the Raspberry Pi and disable the serial console. So you can go back to the main menu and select option 5 “Interfacing Options” then P6 “Serial” and then select “No” and then “Yes“.
Step 4 – Now before we reboot, lets swap the serial interfaces over for the better one, which is by default assigned to the Bluetooth controller. Open up the terminal window and type in the following command:
sudo nano /boot/config.txt
Scroll down to the bottom and add the following line:
Save and exit with “CTRL+O” and “CTRL+X”
Reboot your Raspberry Pi for all the changes to take effect.
Step 5 – Now lets install the RAK811 Python library. In the terminal window type in the following commands:
sudo apt-get update sudo apt-get install python3-pip sudo pip3 install rak811
There are two different methods for joining the TTN network from your Raspberry Pi pHAT node; OTAA and ABP.
Over-the-Air Activation (OTAA)
Over-the-Air Activation (OTAA) is the preferred and most secure way to connect with The Things Network. Devices perform a join-procedure with the network, during which a dynamic
DevAddr is assigned and security keys are negotiated with the device.
Activation by Personalization (ABP)
In some cases you might need to hardcode the DevAddr as well as the security keys in the device. This means activating a device by personalization (ABP). This strategy might seem simpler, because you skip the join procedure, but it has some downsides related to security.
In the examples below we will show you how to connect to both methods.
We have already setup the “Device” in the TTN Console to use the OTAA method as this much more preferred because its more secure. First we need to find out what our device EUI is for our pHAT node and add that to the device on the TTN Console. Open up the terminal window and type the following to get the device EUI:
rak811 get-config dev_eui
Got to your TTN Console and open your device, then go to settings and add the device EUI to the field and click “Save“.
Go back to your Raspberry Pi and open up a terminal window and type in the following to create a Python script:
sudo nano lora_node.py
Add the following replacing the credentials with your device credentials:
#!/usr/bin/env python3 from rak811 import Mode, Rak811 lora = Rak811() lora.hard_reset() lora.mode = Mode.LoRaWan lora.band = 'EU868' lora.set_config(dev_eui='xxxxxxxxxxxxxxxx', app_eui='xxxxxxxxxxxxxxxx', app_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') lora.join_otaa() lora.dr = 5 lora.send('Hello world') lora.close()
Now you can run the program with the following and you should see in the TTN Console > Device > Data the received data that was sent from your node to a Gateway.
To use the ABP method we first must change this in the device settings in the TTN console. Go to your Device and click on Settings. Here you can select ABP, where it will generate new session keys.
Make sure you save the settings at the bottom of the page.
Go back to your Raspberry Pi and type in the following:
sudo apt-get install git git clone https://github.com/AmedeeBulle/pyrak811.git cd pyrak811 cd examples
Now lets add our session keys to the following file:
sudo nano ttn_secrets_template.py
Save and exit: CTRL+O and CTRL+X
cp ttn_secrets_template.py ttn_secrets.py
Now run the following example, which will send some random data:
sudo python3 abp.py
You should see the following in the TTN console:
Hopefully after following this tutorial you should have been able to setup your Raspberry Pi pHAT node and send packets of data to your Gateway using The Things Network. If for whatever reason that your node is not working or you need help with something then please email us at firstname.lastname@example.org or visit our Discord channel – https://pisupp.ly/chat