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, http://www.semtech.com, and the community http://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.
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.
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: http://wiki.dragino.com/index.php
To use the shield on the PSoC 6 MCU Pioneer Kit the following jumper settings are required:
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.
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.
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: http://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 http://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.
SoftwareThe 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)
- IBM LMiC stack v1.6 (https://github.com/mcci-catena/ibm-lmic/releases)
- The main project has been ported from the Arduino based project found here: https://github.com/dragino/Arduino-Profile-Examples/blob/master/libraries/Dragino/examples/LoRa/LoRaWAN/Arduino_LMIC/Arduino_LMIC.ino
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:
- added
#include "oslmic.h"
- added
void hal_ticks_inc(void);
lmic.c
- PSoC Creator:
#if defined(name1) #elif defined(name2) #endif
lorabase.h
- added
#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
- PSoC Creator:
#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.
TestAs 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.
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.
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.
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.
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!
Comments