====== LoRaWAN Setup====== ~~CLOSETOC~~ To configure all the necessary tools to start working with the n-PN board, two main elements need to be downloaded by the user. * An **Integrated development environment (IDE)**. Although the n-PN board can support a wide variety of IDEs to work with, KEIL environment can be chosen for two main reasons: - STM provides all the necessary LoRaWAN protocol drivers for the microcontroller embedded in the n-PN board for this IDE. - KEIL IDE (MDK Version 5) is free for STM32F0 and STM32L0 microcontrollers and due to the n-PN board has an STM32L0 microcontroller, we are allowed to activate the license for this software environment (follow the instructions[[http://www2.keil.com/stmicroelectronics-stm32/mdk|here]]). * The **Nimbus SDK** which contains the minimum files to start working with the n-PN board as well as some basic examples that the user can use as templates (Nimbus SDK is based on STM32CubeExpansion_LRWAN_V1.1.4 and can be found in the next repository: https://bitbucket.org/nimbus_it/pn_lora_node). * After installing KEIL (MDK) IDE(and the license activated) and downloading the Nimbus SDK, there are several basics examples (using LoRaWAN technology) which the user can start working with. The examples can be found following the path: LoRaWAN_Examples / STM32CubeExpansion_LRWAN_V1.1.4 / Projects / Multi / Applications / LoRa /. * Open Any Example folder (Button folder for this example) and open MDK-ARM folder.\\ {{:nblocks:n-pn_gs1.png?700|}} * Open N-PN folder.\\ {{:nblocks:n-pn_gs2.png?700|}} * Open Button project (Double click on Button.uvprojx).\\ {{:nblocks:n-pn_gs3.png?700|}} * The project is ready to be tested.\\ {{:nblocks:n-pn_gs4.png?700|}} **NOTES:** - KEIL IDE (MDK) may not have the libraries installed for the microcontroller embedded in the n-PN board, so a pop-up window will appear asking us to install those libraries. Just follow the instructions to install them up. You may reset your computer after the installation. - If we double click on Button.uvprojx (a project file) and Windows does not recognise the extension file, just choose KEIL (MDK). ====Integrated Development Environment (IDE)==== As stated, KEIL IDE (MDK) was chosen, this section explains the minimum configuration to improve our work flow. * Click on Options for Target… * In Debug tab, make sure to use the right programmer (mostly ST-Link Debugger).\\ {{:nblocks:n-pn_ide1.png?700|}} * In Debug tab, Click on Settings * Make sure under Reset is chosen in Connect (Debug tab).\\ {{:nblocks:n-pn_ide2.png?700|}} * In Flash Download tab, make sure that Program, Verify and Reset and Run are selected.\\ {{:nblocks:n-pn_ide3.png?700|}} \\ ====Firmware Structure==== * In Keil a project is structured as shown below:\\ {{:nblocks:n-pn_ide4.png?700|}} * The main folders are explained below: * **n-PN_Board:** The b-l072z-lrwan1.c file defines all the pinout of the n-PN board. * **Projects/Application:** The main.c file for the application is placed into this folder. * **N-PN/Sensors:** The drivers for the external sensors embedded on n-PN board are placed in this folder. * Keil IDE does not show the header files until the project is compiled, once the project is compiled, the header files can be found under the function files (clicking on the cross sign next to the function file). * Another important file is the header file called **Commissioning.h** which can be found under the main.c file. This header file contains the necessary parameters to configure your own LoRaWAN network: LORAWAN_DEVICE_EUI, LORAWAN_APPLICATION_EUI and LORAWAN_APPLICATION_KEY( These parameters can be obtained from The Things Network website). \\ \\ ====The Things Network==== * The user can create an account on the [[https://account.thethingsnetwork.org/register|THE THINGS NETWORK]], to quickly get started. {{:nblocks:lora_setup01.jpg?500|}} * After creating the account, the user can add Applications and Gateways in the TTN CONSOLE. {{:nblocks:lora_setup02.jpg.png?600|}} {{:nblocks:lora_setup03.png?600|}} * On the application page, the user can register devices under the devices section. {{:nblocks:lora_setup04.png?600|}} {{:nblocks:lora_setup06.jpg?600|}} * All the registered devices will appear on the Devices page. {{:nblocks:lora_setup05.png?600|}} * The following information: LORAWAN_DEVICE_EUI, LORAWAN_APPLICATION_EUI and LORAWAN_APPLICATION_KEY can be obtained from the device overview page by clicking on the selected device. {{:nblocks:lora_setup07.jpg?600|}} * Similarly, a gateway can be added on the gateway page. {{:nblocks:lora_setup08.jpg?700|}} \\ \\