(Optional) Add a LoRaWAN Interface

LoRaWAN devices are supported with SmartServer 4.0 and higher; beta for SmartServer 4.0 and 4.1.

You can use the SmartServer to integrate and manage LoRaWAN (Long Range Wide Area Network) devices.  LoRaWAN is a low power, wide area (LPWA) networking protocol designed to wirelessly connect battery (class A) and line-powered (class C) devices to a network providing bi-directional communication, end-to-end security, mobility, and localization services. The SmartServer LoRaWAN driver sends and receives data to and from LoRaWAN devices via a LoRa Network Server (LNS), which in the case of SmartServer 4.0 and higher is ChirpStack 4.2.

This section describes how to get started using LoRaWAN devices and consists of the following:

LoRaWAN Architecture

A typical LoRaWAN architecture is shown below:


Setting up LoRaWAN

To set up and use LoRaWAN with the SmartServer, follow these steps:

  1. Acquire and configure a LoRaWAN Gateway as described on this page.

  2. Enable LoRaWAN and ChirpStack on your SmartServer as described on this page.
    1. For SmartServer IoT 4.2 and higher, the LoRaWAN driver is enabled by default and ChirpStack is not installed.
    2. For SmartServer Pi 4.3 and higher, the LoRaWAN driver and ChirpStack are disabled by default. For SmartServer Pi 4.2, see (Optional) Add a LoRaWAN Interface for SmartServer Pi (Release 4.2)

  3. Optionally, change the LoRaWAN frequency settings, which default to European frequencies, to the region that matches your LoRa gateway and actual LoRa devices as described on this page.

  4. Import, or create a LoRaWAN device interface (XIF) and device type definition as described on this page. 

  5. Discover devices as described in Site Provisioning.

  6. Optionally, provide a BACnet interface for your LoRaWAN device; see Setting up the BACnet Server. This capability allows you to use a BACnet workstation with your LoRaWAN device.

Receiving Uplink Data from Edge Devices

LoRaWAN devices will send unconfirmed uplink data regularly, along with alarm data as necessary. Regular uplink data may consist of one or more packets, separated by a few seconds. The regular update interval is configurable either using an NFC app or via downlink data and determines battery life for class A devices. Devices send an encrypted base64-encoded hex string over the air that represents all the sensor data, the LNS decrypts the data, converts from base64-encoded to a hex string and the relevant device profile codec converts the hex string to a JSON object which is passed to IAP using MQTT. The entire hex string prior to JSON encoding is available in IAP if required.

Sending Downlink Data to Edge Devices

The LoRaWAN driver sends downlink data to the LNS using MQTT. The LNS forwards the data to edge devices. The LoRaWAN driver uses an LNS-specific MQTT topic, base64-encoded data, and the fport number configured in the XIF for the device type and the datapoint in question.  For non binary applications, external encoders can be used to generate the downlink data.  The data is sent to the LoRaWAN device using a confirmed message. Downlink data may relate to a specific datapoint, or may be a hex string that can be used to configure the regular uplink period, alarm thresholds or form part of a request response mechanism in conjunction with the subsequent uplink data.

Defining the IAP Device UNID

The LoRaWAN device DevEUI is used as the IAP unid. It is either acquired when using automatic discovery for LoRaWAN (the preferred mechanism) or added when manually creating devices.

Acquiring the LoRaWAN Gateway

Purchase an external LoRaWAN gateway such as a RAK 7268 or Multitech MTCAP for the relevant local frequency band. 

Configuring the LoRaWAN Gateway

Ensure that the LoRaWAN gateway is set for Semtech Packet Forwarding on UDP port 1700 for both uplink and downlink connections and that the LNS server IP address is set to the IP address of the SmartServer.  

An example RAK gateway configuration is shown below. Make a note of the Gateway EUI, which is needed to configure ChirpStack.

Using Redundant LoRaWAN Gateways

ChirpStack supports redundant gateways, either for enhanced coverage or for true redundancy.

Enabling the LoRaWAN Driver and ChirpStack

With SmartServer IoT 4.2 and higher, the LoRaWAN driver is enabled by default and ChirpStack is not installed. With SmartServer Pi 4.3 and higher, the LoRaWAN driver and ChirpStack are disabled by default.

To enable the LoRaWAN driver (if needed) and to install and/or enable ChirpStack, follow these steps:

  1. Open the SmartServer Configuration page as described in Accessing the SmartServer IoT Configuration Page. The Network tab appears as the default SmartServer IoT Configuration page. Once the network settings are configured for the SmartServer system, then the System tab will appear as the default.


    SmartServer IoT Network tab



    SmartServer IoT System tab


    For SmartServer Pi, open the SmartServer Configuration page as described in Accessing the SmartServer Pi Configuration Page. The Configuration page view that appears depends on your cache data. As needed, click the SmartServer IoT tab. T
    he System tab (top) will appear as the default as shown below.


    SmartServer Pi System tab

  2. Ensure that the SmartServer can access the internet by using the following command in an SSH session:

    ping google.com

    You should see a response similar to the following:

    apollo@smartserver-17qdkkc:~$ ping google.com
    PING google.com (142.250.179.238) 56(84) bytes of data.
    64 bytes from 142.250.179.238 (142.250.179.238): icmp_seq=1 ttl=114 time=47.9 ms
    64 bytes from 142.250.179.238 (142.250.179.238): icmp_seq=2 ttl=114 time=45.1 ms
    64 bytes from 142.250.179.238 (142.250.179.238): icmp_seq=3 ttl=114 time=41.5 ms
    64 bytes from 142.250.179.238 (142.250.179.238): icmp_seq=4 ttl=114 time=54.7 ms

    Enter CTRL-C to stop pinging. You should then see a summary similar to the following:

    --- google.com ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 7054ms
    rtt min/avg/max/mdev = 41.503/47.285/54.658/4.825 ms

    If there is an issue with internet access, then correct the problem as needed.

  3. Click the LoRaWAN tab. With SmartServer IoT 4.2 and higher, the LoRaWAN driver is enabled by default and ChirpStack is not installed. With SmartServer Pi 4.3 and higher, the LoRaWAN driver and ChirpStack are disabled by default.


    SmartServer IoT LoRaWAN driver is enabled and ChirpStack is not installed


    SmartServer Pi LoRaWAN driver and ChirpStack are disabled


    For SmartServer IoT, if the LoRaWAN driver has been disabled, then it will appear as shown below.


    SmartServer IoT LoRaWAN driver is disabled

  4. Select LoRaWAN Enabled if needed, and then click Update to save the configuration.


    SmartServer IoT LoRaWAN driver is enabled


    SmartServer Pi LoRaWAN driver is enabled

  5. For SmartServer IoT, click Install ChirpStack. The ChirpStack installation starts. This process may take up to 15 minutes, depending on internet speed. The installation will also add a collection of Device Profiles.


    SmartServer IoT ChirpStack is installing

    When the installation finishes, ChirpStack is running. The ChirpStack settings change allowing you to disable/enable ChirpStack as shown below.


    SmartServer IoT ChirpStack is installed and enabled

  6. For SmartServer Pi, select ChirpStack Enabled, and then click Update to save the configuration.


    SmartServer IoT ChirpStack is enabled

  7. Optionally, change the LoRaWAN frequency settings as described in the Changing the LoRaWAN Frequency Settings section below

(Optional) Changing the LoRaWAN Frequency Settings

The SmartServer LoRaWAN frequency settings default to European frequencies. For non-European, SmartServer LoRaWAN implementations, the frequency settings need to be changed to the region that matches your LoRa gateway and actual LoRa devices. These settings need to be changed in the SmartServer chirpstack-gateway-bridge.toml file and in the Device Profiles that are defined in ChirpStack. 

To change the LoRaWAN frequency settings, perform the following steps:

  1. Use an SCP or SFTP client tool (e.g., WinSCP) to copy the chirpstack-gateway-bridge.toml file to your local PC and save a backup. The chirpstack-gateway-bridge.toml file is found at /var/apollo/conf.d/chirpstack/chirpstack-gateway-bridge/chirpstack-gateway-bridge.toml. 

  2. Copy the original chirpstack-gateway-bridge.toml file and keep the same name.

  3. Modify the three topic templates listed under the [integration.mqtt] section shown below by replacing the eu868 region references with the region that matches your LoRa gateway and actual LoRa devices.

    [integration.mqtt]
    event_topic_template="eu868/gateway/{{ .GatewayID }}/event/{{ .EventType }}"
    state_topic_template="eu868/gateway/{{ .GatewayID }}/state/{{ .StateType }}"
    command_topic_template="eu868/gateway/{{ .GatewayID }}/command/#"

    Some LoRa regions, like the United States, support multiple, uplink sub-bands (8). In these cases, the region must also reference the actual uplink sub-band that is in use by the LoRaWAN gateway and the devices. Example: if you are using the SmartServer to interface to a LoRaWAN gateway and sensors in the United States using the LoRa 8-channel, uplink sub-band 0 (902.3 - 903.7), modify the topic templates in the chirpstack-gateway-bridge.toml file by changing eu868 to us915_0 as shown in the example below: 



    Default European frequency settings


    Modified United States frequency settings

  4. Save the modified chirpstack-gateway-bridge.toml file.
     

  5. Replace the chirpstack-gateway-bridge.toml file on the SmartServer with the modified file.

  6. Reboot the SmartServer IoT or Reboot the SmartServer Pi, or restart the SmartServer LoRaWAN driver by disabling it and then re-enabling it using the LoRaWAN Configuration page (described in the Enabling the LoRaWAN Driver and ChirpStack section). 

  7. Log into the ChirpStack administration page by entering http://<SmartServer IP address>:8080 in a web browser URL.

    Example
    http://10.0.1.21:8080

    The ChirpStack administration login page appears.




  8. Enter the login username / email and password (default is admin admin), and click Submit.

    The ChirpStack Dashboard appears.



    The ChirpStack installer, launched from the SmartServer's LoRaWAN Configuration page, pre-installs a collection of Device Profiles for the supported device types found here. Most of these installed Device Profiles specify the eu868 region by default. In order to use these pre-installed Device Profiles and their matching LoRaWAN device type packages (.dtp), which are files available from the SmartServer GitHub Repository, the Device Profiles' Region field has to be updated in ChirpStack to specify the appropriate region. The next step describes how to modify the Region field.

  9. Click the Device profiles tab on the left-side contents.



  10. Select the Device Profile that you want to modify by clicking on the name (i.e., Netvox_R712 in the example below) and use the Region field pull-down menu to select the appropriate region for your implementation (i.e., EU868 is changed to US915 in the example below).



  11. Click Submit to save the Device Profile changes.

    The Device Profile region setting is updated as shown for Netvox_R712 in the example below.

Importing and Creating LoRaWAN Device Interface (XIF) and Device Type Definitions 

You can import and optionally modify LoRaWAN device interface (XIF) and device type definitions. You can also manually create custom LoRaWAN XIF and device type definitions. To import and modify LoRaWAN device interface (XIF) and device type definitions, follow these steps:

  1. Each Device Profile that is added during the ChirpStack installation has a matching LoRaWAN device type package (.dtp) that is available at the SmartServer GitHub Repository. A list of the supported device types can be found here. The .dtp files include the relevant .lorawan, .dtd, .dla, and .btm files. The .dla files define event-driven updates for each datapoint in the .lorawan files.

    Download the required LoRaWAN .dtp files.   

  2. To create a custom LoRaWAN XIF definition (.LoRaWAN), see Creating a LoRaWAN Device Interface (XIF) Definition. You will also need a corresponding ChirpStack device template that will include the relevant codec.

  3. To create a custom LoRaWAN device type definition (.dtd), see Defining Device Types.

  4. If you are running SmartServer 4.3, then install SmartServer 4.3 Update 1 or higher before importing LoRaWAN device types. See SmartServer Release Notes for software downloads.

  5. Import the LoRaWAN device type package (.dtp) or device interface (XIF) or device type definitions (.dtd) using the Import / Export button () on the SmartServer app bar.