Difference between revisions of "How to build a LoRaWAN gateway"

[checked revision] [quality revision]
m (Building the software image)
m
 

This package contains the frameworks to enable a LoRaWAN® gateway that can be run on STM32MP1 Series with a local server or TheThingsNetwork. This package consists of an OpenEmbedded metalayermeta layer, named meta-st-stm32mpu-app-lorawan, that must be added on top of the STM32MP1 Distribution Package. It brings a complete, consistent, easy-to-build and install LoRaWAN gateway for STM32MP1 Series.
The metalayer meta layer contains the frameworks, tools and applications to run the LoRaWAN gateway. Various images are available for different use cases such as single Arm® Cortex®-A7 core, dual Arm® Cortex®-A7 and -M4 cores, and the possibility to choose between an Ethernet or a Wi-Fi connection.

STM32MP1 LoRaWAN gateway

1 Hardware requirements[edit]

The LoRaWAN concentrator RAK831

LoRaWAN concentrator

The antenna

Antenna
Warning white.png Warning
Plug the antenna on the concentrator before powering up the board.

The converter board

Converter board

This bundle enables to start with all the required hardware components (pick your geographic area).

You can now assemble the modules on the board.

Info white.png Information
STM32MP157X-DKX - hardware description and GPIO expansion connector for more informations

This is how it should look like:

How to plug the modules

2 Software prerequisites[edit]

Install the STM32MP1 Distribution Package, but do not initialize the OpenEmbedded environment (sourcing the envsetup.sh) before having installed the meta-st-stm32mpu-app-lorawan meta layer (see next chapter).

3 Installing the metalayermeta layer[edit]

  • First, clone the git repositories to <Distribution Package installation directory>/layers/meta-st.

If you have a Linux® Virtual Machine, modify your Virtual Machine administrator username to match your Gerrit account. This way you can generate the ssh-rsa key. Your Gerrit username is in the id_rsa and id_rsa.pub keys.

To do so, change the username of the session. Proceed as follows:

1.If you have only one user on the Virtual Machine, create a new one to be allowed to modify the administrator user:

 sudo adduser temporary

Then set the password

2. Allow the temporary user to run sudo by adding the user to sudo group:

 sudo adduser temporary sudo

3. Log out with the command exit, and log in again as temporary user.

4. Change your username:

 sudo usermod -l newUsername oldUsername

… and home-folder name

 sudo usermod -d /home/newHomeDir -m newUsername

5. Log out, go back to administrator user, and delete the temporary user:

 sudo deluser temporary
 sudo rm -r /home/temporary

Then generate a new ssh-rsa key here, add it to your Gerrit account and run the following commands:

 cd <Distribution Package installation directory>/layers/meta-st
 git clone https://github.com/STMicroelectronics/meta-st-stm32mpu-app-lorawan -b thud

4 Building the software image[edit]

First set up the LoRaWAN gateway build environment:

 cd <Distribution Package installation directory>

Different OpenSTLinux expansion packages are available to target different use cases. The following commands need to be executed in the build environment.
You can choose between two different machines:

  • stm32mp1-lorawan-a7 to use only the Arm Cortex-A7 core for the whole application process:
 DISTRO=openstlinux-weston MACHINE=stm32mp1-lorawan-a7 source layers/meta-st/scripts/envsetup.sh
 bitbake st-image-lorawan
  • stm32mp1-lorawan-m4 to use both the Arm Cortex-A7 and Cortex-M4 cores, the Arm Cortex-A7 managing the communications with TheThingsNetwork server and the Arm Cortex-M4 the real-time communications with the concentrator:
 DISTRO=openstlinux-weston MACHINE=stm32mp1-lorawan-m4 source layers/meta-st/scripts/envsetup.sh
 bitbake st-image-lorawan
Info white.png Information
Note that building the image can take more than two hours depending on your host computer performance.

5 Flash the built image[edit]

Follow this link to know how to flash the built image.

6 Launching the LoRaWAN gateway software[edit]

  • Power the board
  • To connect to the board and run commands, use SSH over USB. Connect a USB/micro-USB cable between the Windows machine and the ST-LINK port.
  • Then launch Tera Term (you can download here), and start a serial communication with a baud rate of 115200. Restart the board to be able to access to the command line.
  • Depending on how you want to connect your board to the internet
  • Ethernet connection
Connect the ethernet cable
 cd /usr/local/lorawan-gateway/
 ./LoRaWAN_gateway_launcher.sh ethernet
  • Wifi connection
Do not connect the ethernet cable
 cd /usr/local/lorawan-gateway/
 ./LoRaWAN_gateway_launcher.sh wifi
  • During the launcher script execution, enter your preferred server and up and down ports when it is requested.
Info white.png Information
To use https://www.thethingsnetwork.org in Europe:

Server: router.eu.thethings.network
Up and down ports: 1700

Info white.png Information
To use a local LoRaWAN server:

Server: localhost
Up and down ports: 1700

  • Important: copy your EUI before restarting the gateway.

All these information can be found or changed manually in the global_conf.json and local_conf.json files located in /usr/local/lorawan-gateway/ on the board.

Info white.png Information
To us use a Wi-Fi connection:

Enter your SSID and password.
To change these information, refer to How_to_setup_wifi_connection


Your gateway reboots and after a short time, you will be able to receive or transmit information through LoRaWAN.

7 Source code of the firmware running on the Arm Cortex-M4 core[edit]

To access or modify the code of the firmware running on the Arm Cortex-M4, proceed as follows:

 cd <working directory>
 repo init -u https://github.com/STMicroelectronics/STM32MP1_LoRaWAN-manifests -b refs/tags/STM32MP15-Ecosystem-v1.2.0 -m default.xml
 repo sync


8 LoRaWAN node[edit]

This chapter provides an example of how to create a test node. It is important to note that you can choose the way the Device EUI, address, network session key and application session key are configured:

  • either by defining them on your own in the Commissioning.h file of your code and copying the fields during the registration of the node on TheThingsNetwork or the local server,
  • or by letting TheThingsNetwork or the local server define them randomly during the registration of the node, and then store them in the Commissioning.h file of your code before compiling it.

Refer to test device for an example of test device creation. Make sure that your end-node application duty cycle is compliant with the government regulations defined in [1]. The end-note application described in the present example is regulated so that it can send a new LoRaWAN message at a minimum period of 3 minutes with this low amount of data. To lengthen the delay between two dispatches, change the APP_TX_DUTYCYCLE variable.

9 LoRaWAN server[edit]

You can choose between two different types of server. The following instructions show how to use them.

9.1 How to proceed on TheThingsNetwork[edit]

Log in or create an account on https://www.thethingsnetwork.org:

  1. Go into your CONSOLE.
  2. Click GATEWAYS.
  3. Click register gateway.
  4. Check I'm using the legacy packet forwarder and enter the EUI you previously copied in your EUI. If it is not available, create one and change it in the global_conf.json and local_conf.json files in /usr/local/lorawan-gateway/, then reboot your board.
  5. Enter a description of the gateway: it corresponds to the name you can see on the map of the site.
  6. Select your Frequency Plan.
  7. Select your Router (for Europe choose ttn-router-eu).
  8. You can place your gateway on the map by clicking it or by directly entering its coordinates.
  9. Indicate whether you are using an indoor or outdoor antenna.
  10. Not mandatory: for your application devices, you can use cayenne. This framework stores the data and you can easily visualize them.

9.2 How to proceed with the LoRaWAN local server[edit]

9.2.1 Configuring the server[edit]

A local LoRaWAN server is available natively with this layer.

Warning white.png Warning
More informations about this server are available from here.

The following instructions are the minimum necessary to launch the server:

First start postgresql in order to use psql

 sudo -i -u postgres
 initdb -D /var/lib/postgresql/data
 pg_ctl -D /var/lib/postgresql/data -l logfile start
Info white.png Information
The sudo, initdb and pg_ctl lines are mandatory when rebooting the board.

Then create all the roles and databases required for the application:

 psql
 create role loraserver_as with login password '<PASSWORD>';
 create role loraserver_ns with login password '<PASSWORD>';
Info white.png Information
<PASSWORD> is your password
 create database loraserver_as with owner loraserver_as;
 create database loraserver_ns with owner loraserver_ns;
 \c loraserver_as
 create extension pg_trgm;
 create extension hstore;
 \q
 logout
 cp /etc/loraserver/config/eu868.toml /etc/loraserver/loraserver.toml
Info white.png Information
Note that you need to select another .toml if you are not in Europe.

You can now launch the different parts of this local LoRaWAN server:

 sudo systemctl enable lora-gateway-bridge
 sudo systemctl start lora-gateway-bridge
 sudo systemctl enable loraserver
 sudo systemctl start loraserver
 sudo systemctl enable lora-app-server
 sudo systemctl start lora-app-server

Your Local LoRaWAN is now running.

9.2.2 Configuring the lora-app-server[edit]

To access your application site through a web browser with a computer on the same network:

 ifconfig 

The line above enables to know the IP address.
Then access the application web site IP_address:8080. By default the login and password are admin.
On the application site:

  • Go to Network-servers, click ADD and then enter localhost:8000 for the name and the server. Click ADD NETWORK-SERVER.
Network-servers configuration
  • Go to Service-profiles, click CREATE. Choose a name, take the localhost:8000 server. Select Add gateway meta-data. All the rest is empty. Click CREATE SERVICE-PROFILE.
Service-profiles configuration
  • Go to Device-profiles, click CREATE. Enter the information related to your node. Then save and click again you node to unlock some configuration features. Click CREATE DEVICE-PROFILE.
Device-profiles configuration

If you have a Decode or Encode fonction for your node, you can put them in the CODEC section.

Device-profiles codec

Decode function example:

function Decode(fPort, bytes) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var decoded = {};;
// Decode bytes to int
var batteryInt = bytes[7]
var humidityInt = (bytes[5] << 8) | bytes[6];
var pressureInt = (bytes[1] << 8) | bytes[2]; 
var temperatureInt = (bytes[3] << 8) | bytes[4];
// Decode int to float
decoded.battery = (batteryInt*100)/254        // Battery in %
decoded.humidity = humidityInt / 10;          // Humidity in %
decoded.pressure = pressureInt / 10;          // Pressue in hPa
decoded.temperature = temperatureInt / 100;   // Temperature in °C
return decoded;
} 
  • Go to Gateways, click CREATE. Choose a name, a description, the Gateway_ID of your gateway (you can find it in global_conf.json or local_conf.json), and select the localhost:8000 server. No gateway profile and discovery enabling is needed. Click CREATE GATEWAY.
Gateway configuration
  • Go to Applications, click CREATE. Choose a name, a description, select your service-profile and a codec if you use one. Click CREATE APPLICATION.
Application configuration
  • Click your Application name. Click CREATE in the DEVICES menu. Choose a name, a description, enter the Device EUI of your node as well as your Device-profile. Check Disable frame-counter validation and then click CREATE DEVICE.
Node configuration
  • Click your created node just above. In ACTIVATION, enter the device address, the network session key and application session key of your node. The Uplink frame-counter is incremented. Click (RE)ACTIVATE DEVICE.
Node activation
  • You can now visualize your node frames in LORAWAN FRAMES on each node section.
Device Data

10 Field test[edit]

A successful test at a 10-km distance without obstacles has been realized. It is recommended to place the gateway at the highest possible position:

STM32MP1 LoRaWAN gateway during the distance test
STM32 LoRaWAN node during the distance test
STM32MP1 LoRaWAN gateway distance test


This package contains the frameworks to enable a LoRaWAN<sup>&reg;</sup> gateway that can be run on STM32MP1 Series with a local server or TheThingsNetwork.
This package consists of an OpenEmbedded metalayermeta layer, named '''meta-st-stm32mpu-app-lorawan''', that must be added on top of the [[STM32MP1_Distribution_Package | STM32MP1 Distribution Package]]. It brings a complete, consistent, easy-to-build  and install LoRaWAN gateway for STM32MP1 Series. <br>

The metalayer meta layer contains the frameworks, tools and applications to run the LoRaWAN gateway. Various images are available for different use cases such as single Arm<sup>&reg;</sup> Cortex<sup>&reg;</sup>-A7 core, dual Arm<sup>&reg;</sup> Cortex<sup>&reg;</sup>-A7 and -M4 cores, and the possibility to choose between an Ethernet or a Wi-Fi connection.  
[[File: STM32MP1_RAK831_croped.jpg|thumb|upright=2|center|link=|STM32MP1 LoRaWAN gateway]]

==Hardware requirements==
'''The LoRaWAN concentrator [https://www.rakwireless.com/en/WisKeyOSH/RAK831 RAK831]'''<br>

[[File: concentrator_LoRaWan.jpg|thumb|upright=2|center|link=|LoRaWAN concentrator]]
'''[https://store.rakwireless.com/products/lora-antenna The antenna]'''<br>

[[File: antenna_LoRaWan.jpg|thumb|upright=2|center|link=|Antenna]]
{{Warning| Plug the antenna on the concentrator before powering up the board.}}
'''The converter board'''<br>

[[File: converter_LoRaWan.jpg|thumb|upright=2|center|link=|Converter board]]
'''This [https://fr.aliexpress.com/store/product/LoRa-Gateway-Developer-Kit-RAK831-LoRa-LoRaWan-Module-with-Raspberry-base-on-SX1301-433-868-915MHz/2805180_32830271395.html bundle] enables to start with all the required hardware components''' (pick your geographic area).<br>


You can now assemble the modules on the board.
{{Info| '''[[STM32MP157X-DKX - hardware description#Board assembly|STM32MP157X-DKX - hardware description]]''' and '''[[STM32MP157X-DKX - hardware description#GPIO expansion connector|GPIO expansion connector]]''' for more informations}}
This is how it should look like:
[[File: STM32MP1_concentrator.jpg|thumb|upright=2|center|link=|How to plug the modules]]

==Software prerequisites==
Install the [[STM32MP1_Distribution_Package#Installing_the_OpenSTLinux_distribution | STM32MP1 Distribution Package]], {{highlight| but do not initialize the OpenEmbedded environment (sourcing the envsetup.sh) before having installed the meta-st-stm32mpu-app-lorawan meta layer (see next chapter).}}

== Installing the metalayermeta layer==
* First, clone  the git repositories to <Distribution Package installation directory>/layers/meta-st.
If you have a Linux<sup>&reg;</sup> Virtual Machine, modify your Virtual Machine administrator username to match your Gerrit account.
This way you can generate the '''ssh-rsa''' key. Your Gerrit username is in the ''id_rsa'' and ''id_rsa.pub'' keys.

To do so, change the username of the session. Proceed as follows: <br>


1.If you have only one user on the Virtual Machine, create a new one to be allowed to modify the ''administrator'' user:
 {{PC$}} sudo adduser temporary
Then set the password<br>


2. Allow the temporary user to run sudo by adding the user to sudo group:
 {{PC$}} sudo adduser temporary sudo
3. Log out with the command exit, and log in again as temporary user.<br>


4. Change your username:
 {{PC$}} sudo usermod -l newUsername oldUsername
… and home-folder name
 {{PC$}} sudo usermod -d /home/newHomeDir -m newUsername
5. Log out, go back to administrator user, and delete the temporary user:
 {{PC$}} sudo deluser temporary
 {{PC$}} sudo rm -r /home/temporary
Then generate a new ssh-rsa key [https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key here], add it to your Gerrit account and run the following commands:
 {{PC$}} cd <Distribution Package installation directory>/layers/meta-st
 {{PC$}} git clone https://github.com/STMicroelectronics/meta-st-stm32mpu-app-lorawan -b thud

== Building the software image ==
First set up the LoRaWAN gateway build environment:
 {{PC$}} cd <Distribution Package installation directory>

Different OpenSTLinux expansion packages are available to target different use cases. The following commands need to be executed in the build environment.<br>

'''You can choose between two different machines:'''
* {{highlight|stm32mp1-lorawan-a7}} to use only the Arm Cortex-A7 core for the whole application process:
 {{PC$}} DISTRO=openstlinux-weston MACHINE='''stm32mp1-lorawan-a7''' source layers/meta-st/scripts/envsetup.sh
 {{PC$}} bitbake st-image-lorawan
* {{highlight|stm32mp1-lorawan-m4}} to use both the Arm Cortex-A7 and Cortex-M4 cores, the Arm Cortex-A7 managing the communications with TheThingsNetwork server and the Arm Cortex-M4 the real-time communications with the concentrator:
 {{PC$}} DISTRO=openstlinux-weston MACHINE='''stm32mp1-lorawan-m4''' source layers/meta-st/scripts/envsetup.sh
 {{PC$}} bitbake st-image-lorawan
{{Info|Note that building the image can take more than two hours depending on your host computer performance. }}

==Flash the built image==
Follow this link to know how to [[STM32MP1_Distribution_Package#Flashing_the_built_image | flash the built image]].<br>


==Launching the LoRaWAN gateway software==
* Power the board
* To connect to the board and run commands, use SSH over USB. Connect a USB/micro-USB cable between the Windows machine and the ST-LINK port.
*Then launch '''Tera Term''' (you can download [https://tera-term.en.lo4d.com/download here]), and start a serial communication with a baud rate of 115200. Restart the board to be able to access to the command line.
* Depending on how you want to connect your board to the internet
:* {{highlight|Ethernet connection}}
: Connect the ethernet cable
: <pre<!---->>{{Board$}} cd /usr/local/lorawan-gateway/</pre>

: <pre<!---->>{{Board$}} ./LoRaWAN_gateway_launcher.sh ethernet</pre>

:* {{highlight|Wifi connection}}
: Do not connect the ethernet cable
: <pre<!---->>{{Board$}} cd /usr/local/lorawan-gateway/</pre>

: <pre<!---->>{{Board$}} ./LoRaWAN_gateway_launcher.sh wifi</pre>


*During the launcher script execution, enter your preferred server and up and down ports when it is requested.<br>

{{Info| To use https://www.thethingsnetwork.org in Europe:<br>

Server: '''router.eu.thethings.network''' <br>

Up and down ports: '''1700''' }}
{{Info| To use a local LoRaWAN server:<br>

Server: '''localhost''' <br>

Up and down ports: '''1700''' }}
*'''Important:''' copy your '''EUI''' before restarting the gateway.<br>

All these information can be found or changed manually in the '''global_conf.json''' and '''local_conf.json''' files located in '''/usr/local/lorawan-gateway/''' on the board.<br>

{{Info| {{highlight|To ususe a Wi-Fi connection:}}<br>

Enter your '''SSID''' and '''password'''. <br>

To change these information, refer to '''[[How_to_setup_wifi_connection#Wlan_Network_attachment_-28without_system_which_manage_systemd-networkd_configuration-29|How_to_setup_wifi_connection]]'''
}}<br>

Your gateway reboots and after a short time, you will be able to receive or transmit information through LoRaWAN.<br>


==Source code of the firmware running on the Arm Cortex-M4 core==
To access or modify the code of the firmware running on the Arm Cortex-M4, proceed as follows:<br>

 {{PC$}} cd <working directory>

 {{PC$}} repo init -u https://github.com/STMicroelectronics/STM32MP1_LoRaWAN-manifests -b refs/tags/STM32MP15-Ecosystem-v1.2.0 -m default.xml
 {{PC$}} repo sync<br>


==LoRaWAN node==
This chapter provides an example of how to create a test node.
It is important to note that you can choose the way the '''Device EUI''', '''address''', '''network session key''' and '''application session key''' are configured: 
* either by defining them on your own in the Commissioning.h file of your code and copying the fields during the registration of the node on TheThingsNetwork or the local server,
* or by letting TheThingsNetwork or the local server define them randomly during the registration of the node, and then store them in the Commissioning.h file of your code before compiling it.

Refer to [https://www.hackster.io/victorffs/environmental-sensing-using-lora-and-stm32-c0136e#things test device] for an example of test device creation. Make sure that your end-node application duty cycle is compliant with the government regulations defined in [https://www.thethingsnetwork.org/docs/lorawan/duty-cycle.html]. The end-note application described in the present example is regulated so that it can send a new LoRaWAN message at a minimum period of 3 minutes with this low amount of data. To lengthen the delay between two dispatches, change the APP_TX_DUTYCYCLE variable.

==LoRaWAN server==
You can choose between two different types of server. The following instructions show how to use them.
===How to proceed on TheThingsNetwork===
Log in or create an account on https://www.thethingsnetwork.org:<br>

#Go into your '''CONSOLE'''. <br>

#Click '''GATEWAYS'''. <br>

#Click '''register gateway'''.<br>

#Check '''I'm using the legacy packet forwarder''' and enter the EUI you previously copied in '''your EUI'''. If it is not available, create one and change it in the '''global_conf.json''' and '''local_conf.json''' files in '''/usr/local/lorawan-gateway/''', then reboot your board.<br>

#Enter a '''description''' of the gateway: it corresponds to the '''name''' you can see '''on the map''' of the site. <br>

#Select your '''Frequency Plan'''. <br>

#Select your '''Router''' (for Europe choose '''ttn-router-eu'''). <br>

#You can place your gateway on the map by '''clicking''' it or by directly entering its '''coordinates'''. <br>

#Indicate whether you are using an indoor or outdoor antenna.<br>

#Not mandatory: for your application devices, you can use [https://mydevices.com/cayenne/docs/lora/#lora-the-things-network-create-application-add-cayenne-integration cayenne]. This framework stores the data and you can easily [https://mydevices.com/cayenne/lora/ visualize] them.

===How to proceed with the LoRaWAN local server===
====Configuring the server====
A local LoRaWAN server is available natively with this layer.<br>

{{Warning| More informations about this server are available from [https://www.loraserver.io/guides/debian-ubuntu/ here].<br>

The following instructions are the minimum necessary to launch the server:}}
First start postgresql in order to use psql
 {{Board$}} sudo -i -u postgres
 {{Board$}} initdb -D /var/lib/postgresql/data
 {{Board$}} pg_ctl -D /var/lib/postgresql/data -l logfile start
{{Info|The sudo, initdb and pg_ctl lines are mandatory when rebooting the board.}}
Then create all the roles and databases required for the application:
 {{Board$}} psql
 {{Board$}} create role loraserver_as with login password '<PASSWORD>';
 {{Board$}} create role loraserver_ns with login password '<PASSWORD>';
{{Info| <PASSWORD> is your password}}
 {{Board$}} create database loraserver_as with owner loraserver_as;
 {{Board$}} create database loraserver_ns with owner loraserver_ns;
 {{Board$}} \c loraserver_as
 {{Board$}} create extension pg_trgm;
 {{Board$}} create extension hstore;
 {{Board$}} \q
 {{Board$}} logout
 {{Board$}} cp /etc/loraserver/config/eu868.toml /etc/loraserver/loraserver.toml
{{Info| Note that you need to select another .toml if you are not in Europe.}}
You can now launch the different parts of this local LoRaWAN server:
 {{Board$}} sudo systemctl enable lora-gateway-bridge
 {{Board$}} sudo systemctl start lora-gateway-bridge
 {{Board$}} sudo systemctl enable loraserver
 {{Board$}} sudo systemctl start loraserver
 {{Board$}} sudo systemctl enable lora-app-server
 {{Board$}} sudo systemctl start lora-app-server
Your Local LoRaWAN is now running.

====Configuring the lora-app-server====
To access your application site through a web browser with a computer on the same network:
 {{Board$}} ifconfig 
The line above enables to know the IP address.<br>

Then access the application web site '''IP_address:8080'''. By default the login and password are '''admin'''.<br>

'''On the application site:'''
* Go to '''Network-servers''', click '''ADD''' and then enter localhost:8000 for the name and the server. Click '''ADD NETWORK-SERVER'''.
[[File: LoRaWAN_gateway_app_network_servers.jpg|thumb|upright=2|center|link=|Network-servers configuration]]
* Go to '''Service-profiles''', click '''CREATE'''. Choose a name, take the localhost:8000 server. Select '''Add gateway meta-data'''. All the rest is empty. Click '''CREATE SERVICE-PROFILE'''.
[[File: LoRaWAN_gateway_app_service_profiles.jpg|thumb|upright=2|center|link=|Service-profiles configuration]]
* Go to '''Device-profiles''', click '''CREATE'''. Enter the information related to your node. Then save and click again you node to unlock some configuration features. Click '''CREATE DEVICE-PROFILE'''.
[[File: LoRaWAN_gateway_app_device_profiles.jpg|thumb|upright=2|center|link=|Device-profiles configuration]]
If you have a Decode or Encode fonction for your node, you can put them in the '''CODEC''' section.
[[File: LoRaWAN_gateway_app_device_profiles_codec.jpg|thumb|upright=2|center|link=|Device-profiles codec]]
Decode function example:<br>


 function Decode(fPort, bytes) {
 // Decode an uplink message from a buffer
 // (array) of bytes to an object of fields.
 var decoded = {};;
 // Decode bytes to int
 var batteryInt = bytes[7]
 var humidityInt = (bytes[5] << 8) | bytes[6];
 var pressureInt = (bytes[1] << 8) | bytes[2]; 
 var temperatureInt = (bytes[3] << 8) | bytes[4];
 // Decode int to float
 decoded.battery = (batteryInt*100)/254        // Battery in %
 decoded.humidity = humidityInt / 10;          // Humidity in %
 decoded.pressure = pressureInt / 10;          // Pressue in hPa
 decoded.temperature = temperatureInt / 100;   // Temperature in °C
 return decoded;
 } 

* Go to '''Gateways''', click '''CREATE'''. Choose a name, a description, the Gateway_ID of your gateway (you can find it in global_conf.json or  local_conf.json), and select the localhost:8000 server. No gateway profile and discovery enabling is needed. Click '''CREATE GATEWAY'''.
[[File: LoRaWAN_gateway_app_gateway.jpg|thumb|upright=2|center|link=|Gateway configuration]]
* Go to '''Applications''', click '''CREATE'''. Choose a name, a description, select your service-profile and a codec if you use one. Click '''CREATE APPLICATION'''.
[[File: LoRaWAN_gateway_app_application_profile.jpg|thumb|upright=2|center|link=|Application configuration]]
* Click your '''Application name'''. Click '''CREATE''' in the '''DEVICES''' menu. Choose a name, a description, enter the Device EUI of your node as well as your Device-profile. Check '''Disable frame-counter validation''' and then click '''CREATE DEVICE'''.
[[File: LoRaWAN_gateway_app_node_creation.jpg|thumb|upright=2|center|link=|Node configuration]]
* Click '''your created node''' just above. In '''ACTIVATION''', enter the device address, the network session key and application session key of your node. The Uplink frame-counter is incremented. Click '''(RE)ACTIVATE DEVICE'''.
[[File: LoRaWAN_gateway_app_node_activation.jpg|thumb|upright=2|center|link=|Node activation]]
* You can now visualize your node frames in '''LORAWAN FRAMES''' on each node section.
[[File: LoRaWAN_gateway_app_device_data.jpg|thumb|upright=2|center|link=|Device Data]]

==Field test==
A successful test at a 10-km distance without obstacles has been realized. It is recommended to place the gateway at the highest possible position:
[[File: STM32MP1_LoRaWAN_gateway_distance_test_RAK831.jpg|thumb|upright=2|center|link=|STM32MP1 LoRaWAN gateway during the distance test]]
[[File: STM32MP1_LoRaWAN_gateway_distance_test_node.jpg|thumb|upright=2|center|link=|STM32 LoRaWAN node during the distance test]]
[[File: STM32MP1_LoRaWAN_gateway_distance_test.jpg|thumb|upright=2|center|link=|STM32MP1 LoRaWAN gateway distance test]]
<noinclude>

[[Category:How to run use cases with expansions]]
{{PublicationRequestId | 18223 | 2020-11-24}}</noinclude>
Line 1: Line 1:
 
This package contains the frameworks to enable a LoRaWAN<sup>&reg;</sup> gateway that can be run on STM32MP1 Series with a local server or TheThingsNetwork.
 
This package contains the frameworks to enable a LoRaWAN<sup>&reg;</sup> gateway that can be run on STM32MP1 Series with a local server or TheThingsNetwork.
This package consists of an OpenEmbedded metalayer, named '''meta-st-stm32mpu-app-lorawan''', that must be added on top of the [[STM32MP1_Distribution_Package | STM32MP1 Distribution Package]]. It brings a complete, consistent, easy-to-build  and install LoRaWAN gateway for STM32MP1 Series. <br>
+
This package consists of an OpenEmbedded meta layer, named '''meta-st-stm32mpu-app-lorawan''', that must be added on top of the [[STM32MP1_Distribution_Package | STM32MP1 Distribution Package]]. It brings a complete, consistent, easy-to-build  and install LoRaWAN gateway for STM32MP1 Series. <br>
The metalayer contains the frameworks, tools and applications to run the LoRaWAN gateway. Various images are available for different use cases such as single Arm<sup>&reg;</sup> Cortex<sup>&reg;</sup>-A7 core, dual Arm<sup>&reg;</sup> Cortex<sup>&reg;</sup>-A7 and -M4 cores, and the possibility to choose between an Ethernet or a Wi-Fi connection.   
+
The meta layer contains the frameworks, tools and applications to run the LoRaWAN gateway. Various images are available for different use cases such as single Arm<sup>&reg;</sup> Cortex<sup>&reg;</sup>-A7 core, dual Arm<sup>&reg;</sup> Cortex<sup>&reg;</sup>-A7 and -M4 cores, and the possibility to choose between an Ethernet or a Wi-Fi connection.   
 
[[File: STM32MP1_RAK831_croped.jpg|thumb|upright=2|center|link=|STM32MP1 LoRaWAN gateway]]
 
[[File: STM32MP1_RAK831_croped.jpg|thumb|upright=2|center|link=|STM32MP1 LoRaWAN gateway]]
   
Line 22: Line 22:
 
Install the [[STM32MP1_Distribution_Package#Installing_the_OpenSTLinux_distribution | STM32MP1 Distribution Package]], {{highlight| but do not initialize the OpenEmbedded environment (sourcing the envsetup.sh) before having installed the meta-st-stm32mpu-app-lorawan meta layer (see next chapter).}}
 
Install the [[STM32MP1_Distribution_Package#Installing_the_OpenSTLinux_distribution | STM32MP1 Distribution Package]], {{highlight| but do not initialize the OpenEmbedded environment (sourcing the envsetup.sh) before having installed the meta-st-stm32mpu-app-lorawan meta layer (see next chapter).}}
   
== Installing the metalayer==
+
== Installing the meta layer==
 
* First, clone  the git repositories to <Distribution Package installation directory>/layers/meta-st.
 
* First, clone  the git repositories to <Distribution Package installation directory>/layers/meta-st.
 
If you have a Linux<sup>&reg;</sup> Virtual Machine, modify your Virtual Machine administrator username to match your Gerrit account.
 
If you have a Linux<sup>&reg;</sup> Virtual Machine, modify your Virtual Machine administrator username to match your Gerrit account.
Line 88: Line 88:
 
*'''Important:''' copy your '''EUI''' before restarting the gateway.<br>
 
*'''Important:''' copy your '''EUI''' before restarting the gateway.<br>
 
All these information can be found or changed manually in the '''global_conf.json''' and '''local_conf.json''' files located in '''/usr/local/lorawan-gateway/''' on the board.<br>
 
All these information can be found or changed manually in the '''global_conf.json''' and '''local_conf.json''' files located in '''/usr/local/lorawan-gateway/''' on the board.<br>
{{Info| {{highlight|To us a Wi-Fi connection:}}<br>
+
{{Info| {{highlight|To use a Wi-Fi connection:}}<br>
 
Enter your '''SSID''' and '''password'''. <br>
 
Enter your '''SSID''' and '''password'''. <br>
 
To change these information, refer to '''[[How_to_setup_wifi_connection#Wlan_Network_attachment_-28without_system_which_manage_systemd-networkd_configuration-29|How_to_setup_wifi_connection]]'''
 
To change these information, refer to '''[[How_to_setup_wifi_connection#Wlan_Network_attachment_-28without_system_which_manage_systemd-networkd_configuration-29|How_to_setup_wifi_connection]]'''