Getting Started with Losant and a NCD Temperature Humidity Sensor

Getting Started with Losant and NCD Temperature Humidity Sensor

Recently I discovered this really cool company called Losant. They build Enterprise level IoT software solutions and their platform is so easy to use, supporting tons of hardware platforms. So I decided to give it a try.  Losant is a great choice for Raspberry pi, ESP8266, Arduino, and Particle. In this article, I will be interfacing a temperature humidity sensor with Losant through an ESP8266. This is a simple application, but it will give us pretty good idea about how to use Losant with hardware.  It only took a few minutes to build this temperature/humidity sensing application using our plug-and-play hardware platform.

To build this weather station, I will be using following hardware:

  1. ESP8266
  2. SHT25
  3. I2C Shield

To assemble the hardware plug the ESP8266 into the I2C shield and use the I2C cable to connect SHT25 temperature Humidity Sensor.

ESP8266 IoT temperature Humidity data logger

Losant Setup on ESP8266

You will need to install Losant Libraries in your ESP8266, these libraries and installation info can be found on the Losant Website over here.

All hardware works in the same way, so using this setup, you can interface any device or sensor with Losant in just a few minutes.

Step 1: Create an Account on Losant.  To learn more, checkout this blog post.

Step 2: Click “Applications” and create a new application. Here you can fill out the details like your application name and Description.

Losant temp humidity sensor

Step 3: Select Device Attributes

Attributes are the things which ESP8266 will send to Losant. In this case we will report humidity, temperature in °C and temperature in °F.

losant weather station

Selecting Attributes

losant weather kit


Step 4: Create a Dashboard

cloud weather application


Step 5 : Create Access Key : To create an access key, click on “Applications” and select “Security”.  Here you can write your application name.

losant key

Make sure you save your access key and access secret keys.

Step 6 : Now its time to write the arduino lib for ESP8266. The Arduino lib can be found  on github.

void reconnectMQTT(){
   Serial.println("setting up mqtt");
        String subTopic = String("channels/"+ String(channelID) + "/subscribe/json/" + String(readAPIKey));
        int subTopicLength = subTopic.length()+1;
        char subTopicBuffer[subTopicLength];
        String pubMessage = "status=MQTTPUBLISH";
        String pubTopic =String("channels/"+String(channelID)+"/publish/"+String(writeAPIKey));
        int pubTopicLength = pubTopic.length()+1;
        char pubTopicBuffer[pubTopicLength];
        //Publish to MQTT Broker 
        Serial.println(mqttCli.publish(pubTopicBuffer, pubMessage.c_str()) ? "Published" : "NotPublished");
        //Subscribe to MQTT Broker
        Serial.println(mqttCli.subscribe(subTopicBuffer) ? "Subscribed" : "Unsbscribed"); 
           Serial.print("failed, rc=");

void taskWiFiCallback(){
  Serial.print("timeout for this task: t");
          Serial.println("Client not connected");
        String topicString ="channels/"+String(channelID)+"/publish/"+String(writeAPIKey);
       int topicLength = topicString.length()+1;
       char topicBuffer[topicLength];
       String dataString  = String("field1="+ String(tempC,1) + "&field2=" + String(tempF,1) + "&field3=" + String(humid,1));
       int dataLength = dataString.length()+1;
       byte dataBuffer[dataLength];

       Serial.println(mqttCli.write(dataBuffer,dataLength) ? "published" : "published failed");

Arduino Output on the Serial Monitor

Losant ESP8266


Weather Station Data On Losant

losant weather app



Need a Long-Range Wireless temperature humidity sensor?  Here you can learn how to interface Industrial Long range wireless temperature humidity sensors with Arduino.