# Create from scratch

In the left menu, click on **Device Types**.

If no device type has been created within your organization yet, the **Device Types - Create your first device** **type** page will be displayed.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FOcZ9RWZm87PYerQL2l4s%2Fdevice-types-6.png?alt=media&#x26;token=6ce3a8e7-0bd7-4769-87c7-f42c8507a9ed" alt=""><figcaption></figcaption></figure>

Otherwise, the **Device Type** page will be displayed, showing the list of previously created device types.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FkuMGS2auRfb8W7zWrDfr%2F1.png?alt=media&#x26;token=92c79b0f-9668-44a3-821a-a86e80a4ae6b" alt=""><figcaption></figcaption></figure>

## Adding a Device Type

In the Widgelix IoT cloud platform, you have the flexibility to add new devices individually through the **Create** option or import them using the **Load From Repository** option.

### Using Create Option

Click the **+Create Device Type** or **+Create** button, depending on the page you are on.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2F9u1bTK93FxjqbNNYMEz0%2Fdevicetype-2.png?alt=media&#x26;token=d4ce16bb-b4b0-47ef-a6cb-7dec9606fa7b" alt=""><figcaption></figcaption></figure>

The **Device Type** page will be displayed, which consists of the following tabs: **About**, **Uplink Data**, **Downlink Data**, **Tags**, **Additional Parameters**, and **Widgets**.

#### About

The **About** tab allows you to provide basic information about your device type:

In the **Name** text box, enter the **name** of the device.

In the **Description** text box, enter a short **description** including what the device is intended for.

In the **Manufacturer** text box, enter the name of the **device manufacturer**.&#x20;

Click on the **picture box** to browse and upload an **image** of the device.&#x20;

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FamkNPA89I4CaJtVoxIr4%2Fdevicetype-3.png?alt=media&#x26;token=bebd8129-6846-4857-8ba4-aedc99334036" alt=""><figcaption></figcaption></figure>

Click on the **+ Map Marke**r button and select a suitable icon for your device. You can also use the **Search box** to find the icon by typing its name, for example, 'temperature'.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2Ff55jmND3k4tMqjkLcuzg%2Fdevice-types-4.png?alt=media&#x26;token=0d956e8b-dadd-4a5f-9ac4-271dccd403cd" alt="" width="266"><figcaption></figcaption></figure>

Click on the **Next** button.

You will be directed to the **Uplink Data** tab.

#### Uplink Data

The **Uplink Data** tab allows you to provide information about the uplink data that is being sent from your device.&#x20;

{% hint style="info" %}
This section is optional, and you may skip it without providing uplink information.
{% endhint %}

In the **Code** text area, type or paste the **uplink payload formatter** code, which is written in **JavaScript**.

{% hint style="info" %}
Ensure that the uplink payload formatter code has the`decode()`function.
{% endhint %}

Here is an example of an **uplink payload formatter** code:<br>

```javascript
function decode(payload, data) {
  for (var bytes = [], c = 0; c < payload.length; c += 2) {
    bytes.push(parseInt(payload.substr(c, 2), 16))
  }
  
  if (bytes.length === 24) {
    return {
      lastColorRed: bytes[16],
      lastColorBlue: bytes[17],
      lastColorGreen: bytes[18],
      lastColorOnTime: bytes[19],
      lastColorOffTime: bytes[20],
      messagesReceived: getValue(bytes, 8),
      messagesSent: getValue(bytes, 12),
      swRev: bytes[21],
      hwRev: bytes[22],
      adrState: bytes[23],
      rssi: getValue(bytes, 0),
      snr: getValue(bytes, 4),
    }
  } else { return {} }
}


function getValue(bytes, at) {
  return bytes[at] | (bytes[at+1] << 8) | (bytes[at+2] << 16) | (bytes[at+3] << 24);
}
```

To test the **uplink payload formatter**, enter the **binary payload** in **HEX** into the **Payload** text box and then click on the **Run** button.

{% hint style="info" %}
Here is an example of a **binary payload** in HEX that you can use with the above uplink payload formatter:

`D0FFFFFF2500000001000000020000007FFF00FF00240C01`
{% endhint %}

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FPF6N18dmFJz7MJu3GKoL%2Fdevicetype-4.png?alt=media&#x26;token=821a2414-859e-4519-ab5c-00b274ffab32" alt=""><figcaption></figcaption></figure>

If it is valid, the **decoded payload** will display in the **Output** text area and it will look something like this:

```json
{
    "lastColorRed": 127,
    "lastColorBlue": 255,
    "lastColorGreen": 0,
    "lastColorOnTime": 255,
    "lastColorOffTime": 0,
    "messagesReceived": 1,
    "messagesSent": 2,
    "swRev": 36,
    "hwRev": 12,
    "adrState": 1,
    "rssi": -48,
    "snr": 37
}
```

In the **Data Fields** section, you can add **keys** that allow you to extract data from the payload.&#x20;

In the **Name** text box, enter the **key** of the data field exactly as it appears in your **uplink payload formatter**. For example, according to the above uplink payload formatter code, the keys to be used are `lastColorRed`, `lastColorBlue`, `lastColorGreen`,`lastColorOnTime`, `lastColorOffTime`, `messagesReceived`, `messagesSent`, `swRev`, `hwRev`, `adrState`, `rssi` and `snr`.

Select the appropriate **unit** of measurement *(if applicable)* from the **Units** drop-down list.&#x20;

Type the **minimum** and **maximum** values *(if applicable)* for the measurement in the **Min** and **Max** text boxes, respectively.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2Fwvzp4Ko2NYCIneAaVoeV%2Fdevicetype-5.png?alt=media&#x26;token=fe1fbb75-f48f-409f-824a-80ebd5821a90" alt=""><figcaption></figcaption></figure>

Click on the **+** button to add more data fields.

Alternatively, you can load the data fields in bulk from the **decoded payload** in the format of **JSON object literal**:&#x20;

```json
{
    "lastColorOnTime": 255,
    "lastColorOffTime": 0,
    "messagesReceived": 1,
    "messagesSent": 2,
    "swRev": 36,
    "hwRev": 12,
    "adrState": 1,
    "rssi": -48,
    "snr": 37
}
```

Click on the **Load From Payload** button.

Type or paste your **JSON** object literal in the **Load Data Fields from Payload** modal.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FiAC6LhOArvTbkL4MqdJ9%2Fdevicetype-6.png?alt=media&#x26;token=9a07da33-b836-417a-889b-8d24701621f7" alt=""><figcaption></figcaption></figure>

Click on the **Load** button.

The **field names** (keys) will be automatically filled in from the JSON object literal. Then, you can manually set **units**, **min**, and **max** values.

**Widgelix** also supports extracting the **device id** and **device position** *(only applicable if the device has GPS support)* from the payload:&#x20;

**Take device id from payload**: First, turn on the '**Take device id from payload**' slider button. In the **Field name for device ID**, type the **key** exactly as it appears in your **uplink payload formatter**.

**Take position from payload**: First, turn on the '**Take position from payload**' slider button. In the **Latitude field name** and **Longitude field name**, type the **keys** exactly as they appear in your **uplink payload formatter**.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2Fi4SS89CfKzKzVicjnRXo%2Fdevicetype-7.png?alt=media&#x26;token=67b0c662-c4a8-455a-919a-d37627569197" alt=""><figcaption></figcaption></figure>

Click on the **Next** button.&#x20;

You will be directed to the **Downlink Data** tab.

#### Downlink Data

The **Downlink Data** tab allows you to provide information about the downlink data that is being received by your device.

{% hint style="info" %}
This section is optional, and you may skip it without providing downlink information.
{% endhint %}

In the **Code** text area, type or paste the **downlink payload formatter** code, which is written in **JavaScript**.

{% hint style="info" %}
Ensure that the downlink payload formatter code has the`decode()`function.
{% endhint %}

Here is an example of a downlink payload formatter code:

```javascript
function decode(payload, params) {
    const red = ('00' + payload.red.toString(16)).slice(-2)
    const green = ('00' + payload.green.toString(16)).slice(-2)
    const blue = ('00' + payload.blue.toString(16)).slice(-2)
    const on = ('00' + payload.on.toString(16)).slice(-2)
    const off = ('00' + payload.off.toString(16)).slice(-2)
    return `${red}${blue}${green}${on}${off}`
}
```

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FwX5IpmAKX2gSiRExa4YC%2Fdevicetype-8.png?alt=media&#x26;token=d0025a02-392b-43e3-b01f-8a7970ba1047" alt=""><figcaption></figcaption></figure>

To test the downlink payload formatter, type or paste its JSON payload (JSON object literal) into the **Payload** text box and then click on the **Run** button.&#x20;

Here is a sample **JSON payload** you can use to test the downlink payload formatter code listed above:

```json
{
  "red": 255,
  "green": 0,
  "blue": 0,
  "on": 255,
  "off": 0
}
```

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FmbTfHSWbAIwUDJJvkqKV%2Fdevicetype-9.png?alt=media&#x26;token=67e49415-652a-4236-b6b4-9faf6aa2e58d" alt=""><figcaption></figcaption></figure>

If it is valid, the encoded binary payload in HEX will display in the **Output** text box and it will look something like this:

```
"ff0000ff00"
```

Click on the **Next** button.&#x20;

You will be directed to the **Tags** tab.

#### Tags

The **Tags** tab allows you to add tags for your device type.

Tags are useful for easily finding and organizing your device types later on.

{% hint style="info" %}
This section is optional, and you may skip it without adding any tags.
{% endhint %}

To add a tag to a device type, simply type the tag and press `ENTER`. You can add any number of tags that are related to your device type. For example, if the device type is a beacon, you can use tags like `busy indicator`, `status light`, and `class C`.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FHY7RAZibkSQEznghz1kD%2Fdevicetype-10.png?alt=media&#x26;token=34bedd69-8d54-41d5-9acb-ef2a3bb42973" alt=""><figcaption></figcaption></figure>

Click on the **Next** button.

You will be directed to the **Additional Parameters** tab.

#### Additional Parameters

The **Additional Parameters** tab allows you to provide additional parameters for your device type.

{% hint style="info" %}
This section is optional, and you may skip it without providing additional parameters.
{% endhint %}

In the Additional Parameters tab, you can enable extracting **radio** parameters and **battery** parameters from the uplink payload.&#x20;

**Radio**: Enabling the **Radio** option decodes RSSI and SNR from the payload.

* Turn on the **Take radio parameters from payload** slider button.&#x20;
* In the **Field name for RSSI** and **Field name for SNR** text boxes, type the keys exactly as they appear in your uplink payload formatter.

**Battery**: Enabling the **Battery** option decodes battery voltage from the payload.

* Turn on the **Take battery parameters from payload** slider button.&#x20;
* In the **Field name for battery value** text box, type the **key** exactly as it appears in your uplink payload formatter.&#x20;
* In the **Power consumption per cycle, mAh** text box, enter the **power consumption** of your device per transmission in **mAh**.
* Select the **battery type/chemistry** from the **Battery type** drop-down list.&#x20;
* In the **Capacity** text box, enter the **battery capacity** in **mAh**.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FagoCMKx525OIeIt15OtX%2Fdevicetype-11.png?alt=media&#x26;token=0917eab8-3285-4422-81be-15942948a6ca" alt=""><figcaption></figcaption></figure>

Click on the **Next** button.&#x20;

You will be directed to the **Widgets** tab.

#### Widgets

The **Widgets** tab allows you to select the widgets that you want to use for data visualization in order to gain a better understanding of the data.

In the **Widgets** tab, click on the **+Add** **Widget** button.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FnJ2QGw61v9bJWmlKw1CR%2Fdevicetype-12.png?alt=media&#x26;token=56e25f7d-9367-4740-a43d-8a1ad0381e55" alt=""><figcaption></figcaption></figure>

In the Select **Widget** modal, click on the **widget type** that you want to add, for example, **Chart**.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FLrPnzVPBnFEualxh2mGn%2Fdevicetype-13.png?alt=media&#x26;token=7110e798-891b-49ac-8e75-c5808077aa7f" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The complete instructions on how to configure each widget type can be found on the [Widgets](https://docs.widgelix.com/get-started/widgets) page.
{% endhint %}

After adding the necessary widgets, click on the **Save** button to add the device type to your organization.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FE1tUb6iLda1iQoX0kIc7%2Fdevice-types-3.png?alt=media&#x26;token=fa92927f-35d9-4f0b-8fc3-134a4f74ee39" alt=""><figcaption></figcaption></figure>

The new device type is listed on the **Device Type** page.

<figure><img src="https://2494440469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fggsr9Xlsze5cwVr4WMof%2Fuploads%2FcVeD6Rnp1s67TPIr6ofe%2Fdevicetype-17.png?alt=media&#x26;token=6ba530a8-1478-4c3b-b37e-624905164d9a" alt=""><figcaption></figcaption></figure>

### Load From Repository
