Temperature Humidity

Examples

Prerequisite

1. IOT Developer Account
2. Already configured device definition , device and dashboard in IOT Developer Portal.

1.0 Temperature and Humdity

Step 01:

Download the sample code

Step 02:

Extract the files and open it in Arduino IDE or any editors.
Include the following configurations in the code in the file Arduino_DialogNBIoT.

Enter the MAC address you get for the device from the platform in the Arduino_DialogNBIoT file:
    const String DEVICE_MAC_ADDRESS = <your device's mac address>; //your device's mac address
Enter the EVENT_TOPIC which you can get from the platform:
    const String EVENT_TOPIC   = <Your event url/topic >;  //your EVENT url/topic as shown under you device definition
Include the following library in Arduino_DialogNBIoT file:
    #include <Wire.h>
    #include <BME280.h>
    BME280 bme;
Inside void setup() include the following line
    Wire.begin();
    bme.begin();

Step 03:

Your_actions_events would contain the logic which you build. 
As for this example we will be getting Temperature and Humidity and showing it in the Dashboard.

Replace the file your_actions_events with the Temperature&Humidity code:
    void createSendEvent(){

        delay(10000);  // Event trigger time gap

        Serial.println(F("Reading battery percentage left..."));
        float battLevel = ideaBoard.getBattPercent(); // Get voltage in percentage
        delay(1000);

        float humidity = bme.readHumidity();
        delay(1000);
        float temperature= bme.readTemp();


        char json[100] ={0};
        String jsonMessage = "{\"eventName\":\"DataPubllish\",\"status\":\"none\",\"humidity\":"+String(humidity)+",\"temperature\":"+String(temperature)+",\"mac\":\""+DEVICE_MAC_ADDRESS+"\"}";

        jsonMessage.toCharArray(json,jsonMessage.length()+1);


        Serial.print(F("Publishing to topic :"));
        Serial.println(EVENT_TOPIC);
            Serial.println(F("Message : "));
            Serial.println(json);


        if (! sensor.publish(json)) {
            Serial.println(F("Failed"));
            txfailures++;
        } else {
            Serial.println(F("OK!"));
            txfailures = 0;
        }
    }

Step 04:

Make sure you have correctly given the mac address and parameters correctly in the dashboard and the configuration code.

Step 05:

Keep on watching at the dashboard for the values to appear as a chart.
Last updated on 15th Mar 2018