# Swisscom LPN Integration

### Overview <a href="#overview" id="overview"></a>

Swisscom LPN Integration allows converting existing protocols and payload formats to Tesenso IoT Cloud message format and is useful in several deployment scenarios:

* stream device and/or asset data from external system, IoT platform or connectivity provider back-end.
* stream device and/or asset data from your custom application running in the cloud.
* connect the existing device with custom Swisscom LPN based protocol to Tesenso IoT Cloud.

<figure><img src="/files/mjDAjCOpp5ICggbKN1s5" alt=""><figcaption></figcaption></figure>

### Create Uplink Converter <a href="#create-uplink-converter" id="create-uplink-converter"></a>

Before creating the integration, you need to create an Uplink converter in Data converters. Uplink is necessary in order to convert the incoming data from the device into the required format for displaying them in Tesenso IoT Cloud. Click on the “plus” and on “Create new converter”. To view the events, enable Debug. In the function decoder field, specify a script to parse and transform data.

![](/files/-Mi5yl2ALYFzzyLyCE5W)

![](/files/-Mi5yl28BZQAXNGR0YQq)

**Example for the Uplink converter:**

```
// V0.1, 23.06.2021, DS
// V0.2, 05.07.2022, SG

/** Decoder **/

// decode payload to string and json and parse it to data
var payloadJson = decodeToJson(payload);
var dataJson = selectData(payloadJson);

var deviceName = payloadJson.DevEUI_uplink.DevEUI; 

// Result object with device/asset attributes/telemetry data
var result = {
    // Use deviceName and deviceType or assetName and assetType, but not both.
    deviceName: deviceName,
    //deviceType: deviceType,
    // assetName: assetName,
    // assetType: assetType,
    //   customerName: customerName,
    //   groupName: groupName,
    attributes: dataJson.attributes,
    telemetry: dataJson.telemetry
};

function selectData(payloadJson) {
    // TODO: Make this work for all LPN
        var decoded = {
            'telemetry':{},
            'attributes':{}
        }
        decoded.telemetry.ts = new Date(payloadJson.DevEUI_uplink.Time).valueOf();
        decoded.telemetry.time = payloadJson.DevEUI_uplink.Time;
        decoded.telemetry.rssi = payloadJson.DevEUI_uplink.LrrRSSI;
        decoded.telemetry.snr = payloadJson.DevEUI_uplink.LrrSNR;
        //decoded.telemetry.toa = payloadJson.toa;
        decoded.telemetry.frequency = payloadJson.DevEUI_uplink.Frequency;
        //decoded.telemetry.dr = payloadJson.dr;
        decoded.telemetry.data = payloadJson.DevEUI_uplink.payload_hex;
        decoded.telemetry.port = payloadJson.DevEUI_uplink.FPort;
        //decoded.telemetry.bat = payloadJson.bat;
        return decoded;
}

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

function decodeToJson(payload) {
    // covert payload to string.
    var str = decodeToString(payload);
    // parse string to JSON
    var data = JSON.parse(str);
    return data;
}

// console.log(result);
return result;
```

You can change the decoder function while or after creating it. If the converter has already been created, you can click on the “pencil” icon to edit it. \
Copy the configuration example down below for the converter (or your own configuration) and insert it into the decoder function. To save the changes, please click on the “checkmark” icon

![](/files/-Mi64U3-ggwjKrAO7mNJ)

**NOTE** While Debug mode is very useful for development and troubleshooting, leaving it enabled in production mode can significantly increase the disk space used by the database since all the debug data is stored there. It is highly recommended turning the Debug mode off after debugging is complete.

### Create integration <a href="#create-integration" id="create-integration"></a>

Now that the Uplink converter has been created, it is possible to create an integration

![](/files/-Mi654mH4ZYUkMs0KYD4)

**Enable security option**

If necessary, you can specify additional parameters, without which the data will not be included in the integration. To do this, check the Enable security checkbox and click on the Headers filter. Specify an arbitrary value and save the changes

Once the Headers filter has been configured, it will also need to be specified in the uplink message as follows.

```
-H "test-header:secret
```

### Send uplink message <a href="#send-uplink-message" id="send-uplink-message"></a>

To send an uplink message, you need a Swisscom LPN endpoint URL from the integration.\
Let\`s go to the Integrations tab in Tesenso IoT Cloud. Find your Swisscom LPN integration and click on it. There you can find the Swisscom LPN endpoint URL. Click on the icon to copy the url

Use this command to send the message. Replace $DEVICEname, $DEVICEtype and $YOUR\_HTTPS\_ENDPOINT\_URL with corresponding values.

```
curl -v -X POST -d "{\"deviceName\":\"$DEVICEname\",\"deviceType\":\"$DEVICEtype\",\"temperature\":33,\"model\":\"test\"}" $YOUR_HTTP_ENDPOINT_URL -H "Content-Type:application/json"
```

Use this command to send the message. Replace $DEVICEname, $DEVICEtype, $YOUR\_HTTPS\_ENDPOINT\_URL and $VALUE with corresponding values.

```
curl -v -X POST -d "{\"deviceName\":\"$DEVICEname\",\"deviceType\":\"$DEVICEtype\",\"temperature\":33,\"model\":\"test\"}" $YOUR_HTTPS_ENDPOINT_URL -H "Content-Type:application/json" -H "$VALUE"
```

The created device with data can be seen in the section **Device groups -> All**

![](/files/-Mi673SPWFtKVxAFgSH6)

Received data can be viewed in the Uplink converter. In the **“In”** and **“Out”** blocks of the Events tab

Use the Dashboards to work with data. Dashboards are a modern format for collecting and visualizing data sets. Visibility of data presentation is achieved through a variety of widgets.

How to work with dashboards read [here](/tesenso-iot-cloud/dashboards/dashboards.md#dashboards).

### Downlink Converter <a href="#downlink-converter" id="downlink-converter"></a>

Create Downlink in Data converters. To see events enable Debug

![](/files/-Mi65fgL0YEpKIP1cU7B)

Add a converter to the integration. You can customize a downlink according to your configuration. Let’s consider an example where we send an attribute update message. So we should change code in the downlink encoder function under line **//downlink data** input:

```
data: JSON.stringify(msg)
```

where **msg** is the message that we receive and send back to the device

An example of downlink converter:

```
// Encode downlink data from incoming Rule Engine message

// msg - JSON message payload downlink message json
// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc.
// metadata - list of key-value pairs with additional data about the message
// integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter

var result = {

    // downlink data content type: JSON, TEXT or BINARY (base64 format)
    contentType: "JSON",

    // downlink data
    data: JSON.stringify(msg),

    // Optional metadata object presented in key/value format
    metadata: {
    }
};

return result;
```

## Swisscom LPN REST API

### Generate Token for Swisscom API

{% embed url="<https://dx-api.thingpark.com/getstarted/#/>" %}

#### 1. Generate token with the following settings:

* Target profile identifier: *swisscom-api*
* your swisscom lpn user *email*
* your swisscom lpn user *password*

<figure><img src="/files/6TpzGmMoLcb7Ncr6C2WJ" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/ttQHKf6rH4QzMlGrX4qf" alt=""><figcaption></figcaption></figure>

#### DX Core API

Account management, offer subscription, device and base station provisioning:

{% embed url="<https://dx-api.thingpark.com/core/latest/swagger-ui/index.html?shortUrl=tpdx-core-api-contract.json>" %}

### Swisscom LPN Portal V.2.3 Developer Guide

{% file src="/files/gPC6vDAb4oSOzDLbUbey" %}

### Bulkinport of Swisscom LPN Devices

{% embed url="<https://www.mycloud.swisscom.ch/s/S0088E8E446D414229B312EFCC267431F5D1668F308/>" %}
Link zu aktuellste Dokumentationen er Swisscom
{% endembed %}

{% file src="/files/CvMySHlzy5ccSKrwEODL" %}

{% file src="/files/h6Xef8EavRMsJusJLfKM" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tesenso.com/tesenso-iot-cloud/integrations/swisscom-lpn-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
