# Losant IoT

## Losant Connector Setup

### Losant Setup

#### Step 1 : Make a Losant Account if you don't have one already

Go to <https://www.losant.com>, Click sign-up and follow the instructions

#### Step 2 : Set up a Losant application

* Go to the **`Applications`** section of your Losant Dashboard \[ <https://app.losant.com/applications> ]
* Click on **`Add Application`**
* Either choose a Template that suits you or choose **`Blank Application`**
* Enter a name for your application and click **`Create Application`**

#### Step 3 : Create a Device Recipe

Any remote device communicating with the Losant server must be modeled in a Losant application, so that it is properly identified and the data it sends can be properly parsed. For ease of replication, we can make a Device Recipe with the required model. To create a new recipe :

* Click on **`Device Recipes`** in the Sidebar
* Click the **`Add Device Recipe`** button in the top-right corner
* Give a name for your recipe and choose `Set my own default names, tags and attributes`
* Click the **`Create Recipe`** button
* This should take you to the `Properties` tab of your Device Recipe. In this page, ensure that the **`Device Class`** is **`Standaone`**
* Now go to the `Attributes` tab. The parameters to be sent to the Losant Server have to be defined here as attributes along with a suitable data type.
* Once you have added the attributes necessary for your device, click **`Update Attributes`**.

#### Step 4 : Create Devices

* Click on the **`Devices`** tab in the sidebar.
* Click on the downward arrow beside the **`Add Device`** button in the top-right corner
* Click on **`Create from Recipe`**.
* Choose the recipe that was made in the previous step and click **`Create from Recipe`**.
* Optionally, rename the device and click **`Save Device`**

#### Step 5 : Create an access key

Any device connecting to our application will need to provide authentication credentials. In Losant, these credentials are defined in the form of an access key and a corresponding access secret. A given access key can be shared by more than one device; in our application we are going to create a single access key which will be used by all devices.

* Click on the **`Access Keys`** tab in the sidebar.
* Click the **`Add Access Key`** button in the top-right corner.
* Give a descriptive name for your Access Key.
* In the `ACCESS KEY DEVICE RESTRICTIONS` Section, select the devices that the key applies to. Choose **`All Devices`** if you are unsure.
* Click on **`Create Access Key`**
* **Save your keys** as the Secret key cannot be recovered after this. Click on **`Download to file`** to save it on your PC as a text file.
* Once saved, acknowledge that you have saved the key and close the window.

#### Step 6 : Create a Dashboard.

Losant allows creating personalized dashboards to display data coming from any device in a given application, and also to send commands to a device.

* Click on the **`Dashboards`** tab in the sidebar.
* Click the **`Add Dashboard`** button in the top-right corner.
* Enter a name for your Dashboard and click **`Create Dashboard`**
* Click on **`Add Block`**.
* Losant provides you with many templates for Dshboard blocks. Choose one that is suitable to you.
* In the block settings, choose the attributes to be used to generate the view and click on **`Add block`**

###

### IoTify Network Simulator Templates

Now that we have our Losant application and dashboard set up, we need to create a template for each device in the IoTify Network Simulator.

#### You can import our Losant Connector Template Boilerplate from the link below

`https://raw.githubusercontent.com/iotify/nsim-examples/master/connectors/losant-connector.json`

> Paste this URL in the dialog box that opens when you click **`Import a Template`** from the Network Simulator templates page \[ <https://beta.iotify.io/network/templates> ]

#### Or make your own from scratch :

* Choose a template that suits your application or click on **`Blank Template`**
* Select the **`MQTT(S)`** protocol and enter a name for your template.
* In the template editor, Go to the `MQTT` tab to set the connection parameters
  * Ensure that the protocol is **`mqtt(TCP)`**
  * Enter **`broker.losant.com`** and the `Endpoint URL`
  * In the topic field, enter **`losant/<device-id>/state`**
    * To get `device-id`, click on the devices tab of your Losant Application homepage. The device Id is listed below the Device name. Click on the button beside the ID to copy it.
  * Enter the same `device-id` in the **`ClientID`** field.
* Go to the `Security` tab and provide the authentication credentials to connect to our Losant application
  * Enter the `Access Key` as the `Username`
  * Enter the `Access Secret` as the `Password`

    > These can be found in the **`.txt`** file we downloaded while making the Access key in Losant
* Go to the `Device Model` Tab.
  * In the message generator section, define the message to be sent to simulate your device.
* Click the **`Save`** button one you are done editing the template.

### Simulation

In the simulate tab of the IoTify Network Simulator, use the newly created template to run a simulation. Ensure that the Number of clients in each simulation is set to 1.

Observe your data being populated in the Losant Dashboard.<br>
