Skip to main content

Soil Moisture, Temperature, and Electrical Conductivity Solution LoRaWAN Network Server Guide

Network Server and Visualization Configuration

This section outlines the operational steps for connecting the device to the network server in both the LoRaWAN and NB-IoT application scenarios.

Figure 11975: Application scenarios

LoRaWAN Application

Cloud Network Server Setup

The cloud network server deployment scenario involves connecting the gateway and devices to third-party cloud network servers. This server integrates visualization applications to manage real-time soil moisture, temperature, and EC data.

This section provides instructions on creating a Datacake visualization application using the TTN v3 cloud network server.

Figure 11976: Cloud Network Server Application Flow
Connect Gateway to TTN

For this example, you will use the TTNv3 cloud server and RAK7289 V2 WisGate Edge Lite 2 to demonstrate how to connect the RAK business gateway to a cloud server.

  • Register the Gateway
  1. Register an account and log in to the TTN v3 website. If you already have a TTN account, you can log in using your The Things ID credentials.
Figure 11977: Log in to the TTN website
  1. Once logged into the site, click on Register a gateway to begin the registration process for a new gateway.
Figure 11978: TTN home page
  1. Input the Gateway EUI and then click on Confirm to proceed.

The Gateway EUI serves as a distinct 64-bit extended identifier for the gateway. It is accessible from the Overview page of the gateway management platform or the label situated behind the gateway.

Figure 11979: Enter the Gateway EUI
  1. Choose the appropriate frequency plan used by the gateway, and click Register gateway to complete the registration process of the gateway.
Figure 11980: Configure the Gateway frequency

Your gateway dashboard should look the same with Figure 7.

Figure 11981: Successfully registered the gateway
  • Generate a Token

TTNv3 supports TLS server authentication and client tokens, which require trust files and keys to configure the gateway and successfully connect to the network.

  1. To generate a key file, navigate to API keys from the Overview page of the registered gateway, then click Add API key.
Figure 11982: Add API keys
  1. In the Add API key page, set the Name field, tick off the checkboxes, then click Create API key.
Figure 11983: Configure the API key
  1. A new window pops up with the generated key. Copy the new API key by clicking the icon and then the I have copied the key button.
Figure 11984: Copy and save the API key

Configure the Gateway

  1. Navigate back to the gateway management platform Web UI. Click on the left navigation bar to access the LoRa > Configuration tab. Complete the following settings and save them.
  • Basics Station Server Type: LNS Server
  • Server URL: wss://eu1.cloud.thethings.network
  • Server Port: 8887
  • Authentication Mode: TLS server & Client Token - Authentication
  • Trust (CA Certificate): Click the link to download.
  • Client Token: Copied API Keys
Figure 11985: Configure the Gateway
  1. After saving the changes, return to the TTN gateway interface, and navigate to the Gateways tab to confirm that the gateway is now connected to TTNv3 as a Basics Station.
Figure 11986: Gateway connected Successfully
Connect Sensor Hub to TTN
  1. Return to the TTNv3 homepage and select Create an application to add a node.
Figure 11987: Select create an application
  1. Click + Create application to initiate the creation of a node.
Figure 11988: Create a new application
  1. Enter the desired Application ID in the provided field, then click on Create application.
Figure 11989: Fill in the Application ID field
  1. Click on the + Register end device button to add a new end device to the application.
Figure 11990: Add the end device
  1. Set the parameters of the end device, as shown in Figure 17.
Figure 11991: End device parameters
  • JoinEUI, DevEUI, and AppKey can be automatically generated by clicking Generate on the TTN web page. These parameters are customizable as well.
NOTE

Ensure that the three parameters - JoinEUI, DevEUI, and AppKey - are consistent with the parameters set in the WisToolBox application.

  1. After completing the settings, return to the WisToolBox app, and click JOIN NETWORK to send the end device network join request.
Figure 11992: Sending end device network join request
  1. As shown in Figure 19, the Sensor Hub has successfully joined the TTNv3 network server.
Figure 11993: Successfully joined the TTNv3 networks server
Visualize Data Through Datacake

Datacake is a versatile IoT platform. It offers a range of features tailored for effective data visualization and management, making it a preferred choice for IoT projects requiring efficient monitoring and analysis.

Create Datacake Integration

  1. In the TTN console, navigate to Integrations on the sidebar, proceed to the Webhooks section, and then click +Add webhooks to set up an integration.
Figure 11994: Adding an integration
  1. From the list of webhook templates, select the Datacake template.
Figure 11995: Select the Datacake template
  1. Generate an API key on Datacake to enable webhook authentication. To get started, register a Datacake account, and then log in.
Figure 11996: Datacake IoT platform main page
  1. Navigate to the Datacake workspace. Select Members on the sidebar, switch to the API Users tab, then click the Add API User button.
Figure 11997: Add API User
  1. Enter the name of the API User, for instance, TTS API. Set the relevant parameters accordingly and click Save to finalize the creation process.
Figure 11998: Set parameters
  1. Click the Copy button to copy the generated Datacake API Token.
Figure 11999: Copy the generated Datacake API Token
  1. Back on the TTN website, enter sensorhub in the Webhook ID field (as an example), and paste the Datacake API Token you previously copied into the Token field. Click the Create Datacake Webhook button to generate the Datacake Webhook.
Figure 12000: Create Datacake Webhook

Add Sensor Hub to Datacake

  1. To add a new device, select Devices in the sidebar and click the +Add Device button.
Figure 12001: Add Device
  1. Choose LoRaWAN from the options and click Next to proceed.
Figure 12002: Select LoRaWAN
  1. As the Sensor Hub is a new device, there is no pre-existing template. Create a template by clicking New Product, enter the Product Name, and click Next to proceed.
Figure 12003: Create a new product
  1. Choose a network server for your device. In this guide, select The Things Stack V3, then click Next to continue.
Figure 12004: Select the Things Stack V3
  1. In the STEP 3 Devices tab, enter the device DEVEUI and NAME fields, and click Next to continue.
Figure 12005: Add DEVEUI and Name
  1. In Step 4 Plan, select the preferred subscription plan, and click Add 1 device to add the device. For this example, choose Free.
Figure 12006: Select a subscription plan
  1. The registered device can now be viewed on the Devices tab.
Figure 12007: Registered Device

Create a Payload Decoder

  1. Click the successfully registered device and go to the Configuration tab. Scroll down to the Payload Decoder field, then copy and save the decoder code.
Figure 12008: Configuration tab
Figure 12009: Decoder Code
Click to view the code
function Decoder(bytes, port) {  
var decoded = {};
var str = bin2HexStr(bytes);
var i = 0;
while (i < str.length) {
var channelId = parseShort(str.slice(i, i + 4), 16);
var value = parseShort(str.slice(i + 4, i + 8), 16);
i += 8;
switch (channelId) {
case 0x0167:
decoded.temperature = value / 10.0;
break;
case 0x0270:
decoded.humidity = value / 10.0;
break;
case 0x03C0:
decoded.electric_conductivity = value / 1000.0;
break;
default:
break;
}
}

try {
decoded.lorawan_rssi = (port && port.metadata && port.metadata.rssi) || 0;
decoded.lorawan_snr = (port && port.metadata && port.metadata.snr) || 0;
decoded.lorawan_datarate = (port && port.metadata && port.metadata.data_rate) || '';
} catch (e) {
console.log('Failed to read gateway metadata');
}

return decoded;
}

function bin2HexStr(bytesArr) {
var str = '';
for (var i = 0; i < bytesArr.length; i++) {
var tmp = (bytesArr[i] & 0xff).toString(16);
if (tmp.length == 1) {
tmp = '0' + tmp;
}
str += tmp;
}
return str;
}

// convert string to short integer
function parseShort(str, base) {
var n = parseInt(str, base);
return (n << 16) >> 16;
}

// convert string to triple bytes integer
function parseTriple (str, base) {
var n = parseInt (str, base);
return (n << 8) >> 8;
}
  1. Displace the menu bar to the +Add Field section, and click +Add Field.
Figure 12010: Add Field
  1. The Add Field window appears. Fill out the fields shown in Figure 37 to configure the stored data in the device.
Figure 12011: Configuration fields
NOTE
  • Enter a suitable name in the Name field.
  • The Identifier field will be automatically filled in based on the name.
  • When an uplink is received, refresh the page, and the CURRENT VALUE field will be updated.
  • Leave everything else as default, and click Add Field to complete the setup.
  1. When completed, it will look the same, as shown in Figure 38.
Figure 12012: Successfully added fields

Create a Dashboard

  1. To create a dashboard, click the edit mode switch on the Dashboard tab of the device on Datacake.
Figure 12013: Turn on the edit mode switch
  1. Click +Add Widget to add a visualization widget.
Figure 12014: Add Visualization Widget
  1. Select Value from the menu to create a new dashboard.
Figure 12015: Select Value to create a new dashboard
NOTE

You can select different types of widgets to accommodate various data formats.

  1. In the Title field under the Basics tab, name the widget as Temperature.
Figure 12016: Name the widget
  1. Under the Data tab, click the Field tab dropdown arrow, select Temperature, and set the unit to °C.
Figure 12017: Set the unit
  1. Under the Gauge tab, select the gauge type and color, set the range of values for the widget, and then click Save.
Figure 12018: Set the widget type
  1. To add another widget, ensure the edit mode switch is ON, then click the +Add Widget button again.
Figure 12019: Added Widget
  1. When you finish adding the widgets, turn off the edit mode switch to save the edits.
Figure 12020: Save the edits
  1. Return to the WisToolBox APP, and click JOIN NETWORK to send the end device network access request. Once the request is successfully returned, the data will be uploaded within 60 seconds.
Figure 12021: Send the end device network access request

Built-In Network Server Setup

The RAK gateway comes with a built-in NS, which eliminates the need to deploy NS in the cloud or locally. This gateway is suitable for small-sized industrial application scenarios and offers various advantages such as cost savings, reduced R&D investment, high execution efficiency, and shorter delays.

The built-in network server of the RAK gateway provides MQTT and HTTP integration that allows for post-processing data and implementing solutions based on the needs.

This section will use the public MQTT broker integration as an example to demonstrate how to use the built-in network server to create a visualization application on ThingsBoard.

Figure 12022: Gateway Built-in Server Application Flow
Configure the ThingsBoard
  1. Log in to ThingsBoard. If you don't have an account, create one before proceeding.
Figure 12023: Sign up ThingsBoard
  1. After successfully logging in, you will be directed to the ThingsBoard homepage.
Figure 12024: ThingsBoard homepage
  1. Navigate through Integration center > Integrations > Data converters in the left navigation tree to create a data converter for the uplink.
Figure 12025: Create a data converter for the uplink
  1. Click the Add Data Converter icon and choose the Create new converter option.
Figure 12026: Select Create new converter
  1. Enter the name of the decoder in the Name field (for example, Uplink decoder), leave the Type field as Uplink, and select the JavaScript option.
Figure 12027: Add Data Converter
  1. Edit the decoder code by copying the following code into the edit box, then click Add to include the uplink decoder.
Click to view the code
/** Decoder **/
// decode payload to string
var payloadStr = decodeToString (payload);
var data = JSON.parse(payloadStr).data;
var bytes = atob(data).split('').map(function (c) {
return c.charCodeAt(0);
});

var values = {};
let i = 0;
while (i < bytes.length) {
var channelId = (bytes[i] << 8) | bytes[i + 1];
var value = (bytes[i + 2] << 8) | bytes[i + 3];
i += 4;
switch (channelId) {
case 0x0167:
values.temperature = value / 10.0;
break;
case 0x0270:
values.humidity = value / 10.0;
break;
case 0x03C0:
values.electric_conductivity = value / 1000;
break;
default:
break;
}
}
var integrationName = 'MQTT Integration';
var deviceName = 'dev_ac1f09fffe0903ec';
var result = {
deviceName: deviceName,
attributes: {
integrationName: metadata['integrationName'],
temperature: values.temperature,
humidity: values.humidity,
pressure: values.electric_conductivity,
},
};

/** Helper functions **/

function decodeToString(payload) {
return String.fromCharCode.apply(String, payload);
}

return result;
  1. Navigate to the Integration Center > Integrations menu and click the Add Integration icon to add the MQTT integration.
Figure 12028: Add the MQTT integration
  1. Enter the name of the integration (for example, MQTT Integration) in the Name field and select MQTT in the Type drop-down menu. Click Next to continue.
Figure 12029: Fill in the integration name
  1. In the Uplink data converter options, click Select existing to choose the previously created decoder (Uplink Decoder), then click Next.
Figure 12030: Select the created decoder
  1. In the Downlink data converter interface, no configuration is necessary and just click Skip to bypass this setup.
  2. Configure connection options. Host is the MQTT broker address used for messages. The Host of the external MQTT broker used in this example is broker.hivemq.com. You can choose to use other brokers with a different Host.
  3. Enter the address broker.hivemq.com in the Host field, with the port number 1883. Click the Add topic filter button to configure the subscription topic.
Figure 12031: Configure the connection options

Configure the subscription topic

application/{{application_name}}/device/{{ device_EUI }}/join
application/{{application_name}}/device/{{device_EUI}}/rx
application/{{application_name}}/device/{{device_EUI}}/tx
application/{{application_name}}/device/{{device_EUI}}/ack
application/{{application_name}}/device/{{device_EUI}}/status
  • application_name: The application ID created in the gateway.
  • device_EUI: The device EUI of the end device.
  1. Modify the parameter values corresponding to the topics based on the actual application created and the device used. After configuring the details, click the Add button to save and complete the settings.
NOTE

The values in the subscription topic must be all lowercase. For example, application/1/device/0123456789abcdef/join.

Figure 12032: Configure and add the subscription topics
Configure the Gateway

This section will use the RAK7268 V2 WisGate Edge Lite 2 as an example.

  1. To access the gateway web management platform, refer to the WisGateOS V2 user manual for details.
Figure 12033: WisGate OS Web Management Platform
  1. After successfully logging in, navigate to the LoRa® menu in the left navigation tree and set the Work mode of the gateway to the Built-in network server.
Figure 12034: Set the Work mode
  1. Once done with the setting, click the Applications tab, then the Add application button. You can also click add one now text link to add a new application.
Figure 12035: Applications tab
  1. Configure the following information: Application name, Application description, and Application Type.
  • Unified Application key: Choose this option if all devices will use the same application key. Once selected, a field for the application key appears, where you can manually type in an application key or click the Autogenerate button to generate one.
Figure 12036: Configure the Application
  • After enabling the Auto Add Device option, configure the Application EUI option. The value needs to be consistent with the node value. Once you have verified the application EUI and key, the device will be added automatically to the application.
Figure 12037: Auto Add Device
NOTE

You can obtain the values by either querying the end device or generating it automatically and modifying the corresponding value of the device synchronously.

  1. Once you've completed the configuration, click on Save Application to add the new application.

  2. In the application list, locate the newly created application and navigate to the End devices tab. If you've enabled the Auto Add Device function, the device will be automatically registered upon the addition request.

Figure 12038: End Device Tab
  1. Click the Add end device button. In the End device information interface, fill in the following information:
  • Activation Mode: Select the activation mode of the device, OTAA or ABP.
    • Choosing ABP mode creates two additional fields: Application Session Key and Network Session Key.
    • In this example, use OTAA activation mode.
  • End device (group) name: Enter the name of the end device or the group it belongs to.
  • End device description (optional): Optionally provide a description for the end device.
  • Class: Select Class A for device’s operating mode.
  • Frame Counter Width: Keep the default value.
  • LoRaWAN MAC Version: The protocol version (v1.0.3) of the end device.
Figure 12039: Add new end devices
  1. After completing, click Add end devices to proceed to the next step.

  2. In the Adding end devices interface, enter the device EUI in the End Device EUI (Main) field and select the Add to End Devices list button. Then click Add end devices to complete adding the end device.

NOTE
  • The device EUI configured here must match the end device. You can either obtain it by querying the end device or entering one (1) EUI and synchronously updating the corresponding value of the end device.
  • If the EUI is correct, the device will be displayed in the End devices list.
  • If the EUI is incorrect, the device will be displayed in the End devices with an error.
Figure 12040: Add the device to the device list
  1. Click the Add button to confirm adding the device.
Figure 12041: Confirm to add the end device
  1. When finished, enter the End devices interface, where you can see the created end device.
Figure 12042: End Device Created
Connect the Sensor Hub to the Built-In Network Server

For specific configuration on how to connect SensorHub to the server, refer to SensorHub Network Configuration > LoRaWAN Application Scenario.

Once completed, the device will join the network. As shown in Figure below, the end device SensorHub has successfully connected to the gateway's built-in server.

Figure 12043: End Device SensorHub has been connected
Configure the MQTT Integration
  1. Go to the LoRa® > Configuration > Integration Interface Parameters section.
  2. Toggle the Enable Integration Interface option and select Generic MQTT as the Integration mode.
Figure 12044: Set Up MQTT Integration
  1. In the MQTT Broker Address option, enter broker.hivemq.com then click Save changes.

  2. After the device has joined and has been sending uplink data, check the uplink data in ThingsBoard > Integrations > Your Integration > Events.

Figure 12045: View the gateway uplink data
Visualize Data Through ThingsBoard
  1. After creating the data converter, integrating, and obtaining some data in the Event tab, check the automatically created devices based on the decoder in the Entities > Devices > Groups tab.
Figure 12046: Check the device
  1. Click the group named All in the Device groups menu to automatically create a decoder device.
Figure 12047: Automatically created decoder device
  1. Click the device and go to the Attributes tab, where you will see the node data.
Figure 12048: Data Visualization
  1. To visualize the data, simply select the values you wish to display, then click the Show on widget button.
Figure 12049: Select the value
  1. On the next page, select the desired widget for the data from the Current bundle drop-down menu. In this example, select Humidity.
Figure 12050: Select widget for data
  1. After selecting the widget, click Add to dashboard to proceed.
Figure 12051: Selecting a widget
  1. The Add widget to dashboard window will appear. By default, there is no dashboard in the profile, so you need to select Create new dashboard and enter a name for the dashboard in the new dashboard title field.
  • In this guide, name the dashboard sensorhub_soil_multparam.
Figure 12052: Enter the Dashboard name
  1. After setting the dashboard name, click the Add button to add more widgets. Alternatively, check the Open dashboard option to automatically open the created dashboard after adding the widget.
NOTE

If the Open dashboard option is not selected, you can still easily view the added widgets via Dashboard groups > All > [Group Name].

Figure 12053: Dashboard created
  1. You can visualize other data from the device following the same steps as above. The only difference is that when adding the widget, instead of Create a new dashboard, click Select existing dashboard.
Figure 12054: Adding widgets

NB-IoT/LTE CAT-M1 Application

Connect Sensor Hub to MQTT Server

In the Network Server and Visualization Configuration section, the server has been set as a public MQTT broker: broker.hivemq.com. You can also choose other brokers or servers, such as AWS IoT Core (optional), according to the actual usage scenario.

Figure 12055: NB-IoT LTE CAT-M1 Application Scenario

Visualize Data Through Datacake

In this example, you will use Datacake as the visualization platform. Datacake is a versatile IoT platform designed to visualize data from nodes in a user-friendly manner.

To get started, create an account on the official website and log in.

Add Sensor Hub to Datacake
  1. After logging in to your account, navigate to the Devices tab and click + Add Device to proceed with adding the Sensor Hub end device.
Figure 12056: Add the end device, SensorHub
  1. Select the API option and click Next to proceed.
Figure 12057: Select API
  1. As the device is new and there's no ready-made template, choose New Product from the Datacake Product options. Enter the device name in the Product Name field, then click Next to proceed.
Figure 12058: Select New Product
  1. The SERIAL NUMBER field can be left blank. Datacake will randomly generate a serial number for the device, then click Next.
Figure 12059: Keep the serial number
  1. Select the preferred subscription plan, then click Add 1 device. For this example, choose Free.
Figure 12060: Select a subscription plan
  1. The registered device can now be viewed on the Devices tab.
Figure 12061: Registered Device
MQTT Configuration
  1. Click the name of the device you just created in the list to enter the interface, then select the Configuration tab.
Figure 12062: Configuration Tab
  1. Scroll down to the API Configuration option and copy the Serial number. Save it locally for later use.
Figure 12063: Copy the serial number
  1. Continue scrolling down to the MQTT Configuration option and configure the external MQTT Broker.

  2. Click +Add new MQTT server and configure the relevant parameters.

Figure 12064: Configure the external MQTT broker
  1. Fill in the relevant information based on the actual server used, then click Test Connection to verify whether Datacake can successfully connect to the MQTT Broker.
Figure 12065: Configure the relevant parameters
NOTE

If SSL/TLS encryption and authentication are set for more secure communication, ensure to configure them accordingly in this section. However, for this example, you can skip this option.

  1. If the connection is successful, you will see the message Connection successful. Click Add MQTT Server to complete the addition of the MQTT server.
Figure 12066: Configure the relevant parameters
  1. After successfully adding the MQTT server, click on +Add Uplink Decoder to add a decoder.
Figure 12067: Add Uplink decoder
  1. A new window will appear, and fill in the fields according to your project.
Figure 12068: Add Uplink Decoder
  • Subscribe to topics: Configure the subscription topics, that is, the value of the Publish Topic configured in the Network Server and Visualization Configuration section.
  • Decoder function: Copy the following decoding code and paste it into the Decoder function space.
function Decoder(topic, payload) {
var decoded = [];
var data = JSON.parse ( payload .replace (/\s*/g,"") );
for (var key in data) {
decoded. push (
{
device: "ddc5e012-30e4-4091-a050-b7318bacb209",
field: key,
value: data[key]
}
)
}
return decoded;
}
NOTE

In the above code, make sure that the parameter serial_number (device: 9f05fd20-56b0-4eca-8549-fe544d783056) matches the serial number saved locally earlier.

  1. Once completed, click Add uplink decoder.
  2. In the Fields option, click +Add Field to show the monitoring values of the devices. Each device can create a certain number of fields, also known as a data point.
Figure 12069: Add Field
  1. Set the necessary parameters of the Field. For Fields with multiple data points, add them one by one. Once done, click Add Field.
Figure 12070: Set the related parameters of the field
NOTE

The Identifier field will be automatically filled based on the name.

  1. Once the uplink data is received, the Current value column in the Fields list will display the current monitoring value from the sensor.
Figure 12071: Added sensor monitoring values
Create a Dashboard to Visualize Data

Dashboards can be customized depending on the specific needs and preferences of a project. Follow the steps below to add widgets and visualize the data.

  1. On the device details page, navigate to the Dashboard tab, then toggle on the edit mode switch.
  2. Click on the + Add Widget button to add a widget for visualizing data.
Figure 12072: Open the edit mode
  1. Choose what type of widgets you want to display. For this example, select Value to visualize temperature monitoring values.
Figure 12073: Select and add widgets for visualizing data
  1. Go to the Data tab and choose the data you want to visualize from the available Field options. For this example, select Temperature and set the unit of the field to °C.
Figure 12074: Select the visualization data field
  1. After configuring the widget, click Save. You should now see the successfully created Temperature widget on the Dashboard interface.
Figure 12075: Successfully created Temperature widget
  1. To add more parameter widgets, click the +Add Widget button again with the edit mode toggle switch ON, then repeat Steps 3-5.

  2. Once done with the dashboard configuration, turn off the edit mode switch to save the settings.

Figure 12076: Weather Station data visualization