Skip to content

Testing Activities

Alberto Trentadue edited this page Mar 21, 2019 · 2 revisions

First testing demo

As first demo for end-2-end test purpose we have implemented a IoT classic about simple applications, that is a LoRaWAN connected temperature & humidity sensor.

In this application a DHT22 temperature & humidity sensor is read by an Arduino Mini board and its values are send over the LoRa link to an Application Server passing through the LoRa Gateway, the Gateway Bridge and the LoRa Server. These reading are then re-routed to Thingsboard and displayed into graphs in a dashboard.

The sensor node implementation is described above.

The data packet over LoRA

LoRa communication is fully oriented to the minimal usage of energy by the remote sensors. Besides the inherent low power required to establish the radio link with the gateway, every possible care must be taken to reduce power consumption at the remote node. Data transmission is one of the most power consuming operation performed by the remote node, therefore it is important to reduce transmit time to the very minimum possible.

In our Arduino code, we have reduced the amount of transmitted data to only 3 bytes:

  • One byte for the temperature
  • One byte for the relative humidity
  • A terminating '\0' character

These bytes are copied into a 3-character string and this string is then passed to the LMIC routine to be sent at the appropriate time slot over the LoRa link.

Gateway relay to the Network Server

The 3-character string is received as LoRa packet by the gateway and then encapsulated into a JSON document to be relayed to the Network Server (via the Gateway Bridge). The JSON document includes a number of other fields including, among others, the gateway identifier, location and operational status and the link signal strength perceived from the node.

The Gateway Bridge on the Network Server encapsulates in turn the JSON document into an MQTT message directed to the LoRa server. The MQTT topic used to relay the JSON document to the LoRa Server has the form gateway/<gateway_mac>/rx

The LoRa Server receives the document and based on the application and device identifiers (AppEUI and DevEUI), forwards the message to the appropriate Application Server (consider that there may be more than one Application Servers in a deployment)

An important operation is to extract the application data from the JSON document and translate it into usable format (remember that the application data is stil a 3-character string included in the JSON). For this reason the LoRa Server configuration includes the possibility to configure a Decoder for each application deployed. The Decoder is a piece of JavaScript code that takes the JSON document as input and replace the raw data string sent by the remote node in meaningful fields within the JSNO document. In our example the Decoder defined for our demo is:

// Decode decodes an array of bytes into an object.
//  - fPort contains the LoRaWAN fPort number
//  - bytes is an array of bytes, e.g. [225, 230, 255, 0]
// The function must return an object, e.g. {"temperature": 22.5}
function Decode(fPort, bytes) {
  var myObject = {};
  var humid = Number(bytes[0]).toString();
  var tmp = Number(bytes[1]).toString();
  myObject.temp = tmp;
  myObject.hum = humid;
  return myObject;
}

This piece of code has the effect to modify the JSON so that two additional fields "temp" and "hum" are added in the JSON data object, derived by reading the 2 bytes transmitted by the remote node.

Clone this wiki locally