LoRa
LoRa is a relatively new physical wireless technology that allows Long Range communication with low power. It is focusing on IoT. Details can be found on the web site of the patent holder, company Semtech, https://www.semtech.com, and the community https://lora-alliance.org.
Based on LoRa technology the LoRaWAN is used globally to build up IoT networks (see Figure 1). IBM provides a free stack (LMiC) on https://github.com/mcci-catena/ibm-lmic/releases. One open source network is hosted by TTN, https://thethingsnetwork.org.
This project describes how to setup PSoC 6 MCU using LoRaWAN based on LMiC to access to TTN.
Figure 1: IoT Network (Source: https://thethingsnetwork.org)
System
One Thing (device) consists of a PSoC 6 MCU pioneer kit (CY8CKIT-062-BLE) and an Arduino Shield (Dragino LoRa) with mounted LoRa radio module (RFM95W/RF96 = SX1276). Figure 1 shows the hardware setup. An existing Arduino LoRa project has been ported to PSoC Creator, the Hardware Abstraction Layer (HAL) has been adapted to PSoC 6 MCU, and the LoRaWAN stack was ported from IBM’s LMiC v1.6.
Figure 2: PSoC 6 MCU based TTN device and TTN gateway
How to build the System
The following hardware is needed:
- 1 pcs PSoC 6 CY8CKIT-062-BLE Pioneer Kit
- 1 pcs Dragino LoRa Shield incl. RFM95W radio module
- Optional: LoRa gateway e.g. LG01
This shield is well documented and has its own website (Wiki-page) where all project details are listed: https://wiki.dragino.com/index.php
To use the shield on the PSoC 6 MCU Pioneer Kit the following jumper settings are required:
Jumper setting to be used for CY8CKIT-062 and Dragino LoRa (Picture source: https://wiki.dragino.com)
The shield uses a radio module RFM95W manufactured by HopeRF, based on Semtech SX1276.
Do not forget to mount the antenna and add the Dragino LoRa shield carefully to the PSoC 6 MCU Pioneer Kit, as shown in Figure 3.
Figure 3: CY8CKIT-062-BLE with Dragino LoRa Shield and included RFM95W radio module
Gateway
In order to access to TheThingsNetwork a LoRa gateway must be reachable.
Whether there is a TTN LoRa Gateway nearby can be checked on the TTN website https://www.thethingsnetwork.org/. In our case, it wasn’t. So, we decided to buy a cheap Single-Channel-Gateway (Figure 4) and to realize our own gateway node connected to TTN.
Figure 4: Picture source: https://www.dragino.com/products/lora/item/119-lg01-s.html
The LG01-S is an open source single channel LoRa Gateway. It lets you bridge LoRa wireless network to an IP network via WiFi, Ethernet, 3G or 4G cellular.
Details are available here: https://www.dragino.com/products/lora/item/119-lg01-s.html
Note, Single-Channel-Gateways, like the LG01, have some limitations. They receive and transmit only on one channel and at one speed. Further, no downlink function is available, so it is not possible for applications to send messages (back) to a device. Not all networks will allow usage of Single-Channel-Gateways, but currently TTN does. So it was the cheapest and quickest solution to use it for the first LoRaWAN test described here.
On the Dragino website https://wiki.dragino.com/index.php?title=Connect_to_TTN it’s explained in details how to get the LG01 configured to be used on TTN.
Software
The complete software project is attached to this project. Nevertheless, newer versions of the used stack may exist. The following section describes the used compilation:
- PSoC Creator v4.2 (www.cypress.com)
In order to use the LMiC library for PSoC 6 MCU, respectively the PSoC Creator tools chain, several modifications have been required, one major issue was related to the usage of #defines:
Original:
#if name1 #elif name2 #endif
PSoC Creator:
#if defined(name1) #elif defined(name2) #endif
Overview about all changes done within LMiC v1.6:
hal.h:
#include "oslmic.h"
void hal_ticks_inc(void);
lmic.c
#if defined(name1) #elif defined(name2) #endif
lorabase.h
#include "oslmic.h"
oslmic.h
#ifndef OSTICKS_PER_SEC #define OSTICKS_PER_SEC 32768 #endif #if OSTICKS_PER_SEC < 10000 || OSTICKS_PER_SEC > 64516 #error Illegal OSTICKS_PER_SEC - must be … #endif
radio.c
#if defined(name1) #elif defined(name2) #endif
And finally, the HAL.c/.h needs to be implemented using the PSoC 6 MCU peripherals and API. Hence, this module has been written from scratch related to the header file and its functional specification.
Take care of the global defines done within PSoC Creator:
- See Project -> Build Settings... -> Compiler -> CM4 -> Preprocessor Definitions:
- CFG_lmic_clib; CFG_eu868; CFG_DEBUG; CFG_sx1276_radio
The attached project includes still 22 warnings (unused variables, signedness issues, etc.) that should be solved in future but does not impact the general testing.
Test
As no public TTN gateway was reachable we have setup our own Single-Channel-Gateway, based on Dragino LG01-S. This gateway has been registered at TheThingsNetwork and shows up in the map (Figure 5, Figure 6) whenever connected to the network.
Figure 5: TTN network map shows Cypress' gateway
Figure 6: Cypress' LoRa gateway details
Within the network console the user can add his device(s), monitor whenever the device is connected to TTN and observe the received data packages (Uplink).
Figure 7 shows online that the Cypress gateway is connected and was seen last time just a minute ago. More than 200 messages have already been received.
Figure 8 shows one package that has been uploaded to the TheThingsNetwork by our PSoC6 device (registered as ‘psoc6lora’). The payload “PSoC6LoRa” was received by our own gateway, and more details like frequency and spreading factor are displayed.
Figure 7: Cypress' gateway online information
Figure 8: PSoC6LoRa device information
After the initial test worked fine to bridge approx. 10 cm (see Figure 2) using LoRa communication to our own gateway, some further tests have been done while a customer visit in the Netherlands, what is a leading country in term of LoRa. From the hotel, approx. 6.7 km have been bridged to the next gateway as shown by Figure 9 and the gateway details in Figure 10.
Figure 9: PSoC 6 MCU LoRa communication between hotel and an external gateway
Figure 10: Details of the gateway that received the PSoC 6 package sent form the hotel
While returning from the customer visit, driving through the Netherlands, the PSoC 6 MCU LoRa device was running in the car, and connected to several gateways next to the highway A12.
Figure 9: Gateways connected from the highway A12
Summary
The PSoC 6 MCU with LoRaWAN software stack has entered successfully to the TheThingsNetwork.
This project should be taken as a very basic proof-of-concept, allowing to validate mainly the LMiC stack running on PSoC 6 MCU.
It does not claim to cover all LoRa aspects, especially related to distance range or low power considerations. Those investigations must be done within one of the next steps.
While some quick tests done in the Netherlands already external gateways in a distance of around 7 km have been reached.
Because only a Single-Channel-Gateway was available internally, not all features, like frequency hopping or downlink, could be evaluated yet. But as this is mainly part of the provided LMiC, it’s expected to work, too.
The completely ported software project is attached to this memo.
Next steps ... maybe to investigate on the low-power operation ... Stay tuned!