Links

Easy Starter Kit Tutorial

With our Easy Starter Kit, you will easily learn how to develop smart measuring devices.
The Easy Starter Kit comes with a Developer Gateway that can connect to the Internet via a cellular connection. This development kit is designed for prototyping your smart product.
In this tutorial you will see how you can easily transfer temperature and humidity values from an Arduino to the app using the Gateway. With the app you can create your custom dashboard to see all the data and you can build your own alert system, such as receiving an E-Mail or SMS when thresholds are exceeded or the device goes offline.

Requirements

All you need for the following tutorial is the Easy Starter Kit. This comes with the following things:
  • Developer Gateway
  • Arduino Mega
  • DHT11 Temperature & Humidity Sensor
  • Wire
  • SIM Card

1. Set up your Gateway

The Gateway and the Arduino work on different logic levels. Mostly you can ignore this for prototypes. If the communication doesn't work properly for you, you should use a logic level shifter. To keep it simple, we will not use this logic level shifter here. If the communication doesn't work properly for you, you should use a logic level shifter.
In this tutorial we operate the Gateway via the 5V interface of the Arduino. This way the Gateway does not have to be powered by its own power source. For this the 5V line of the Arduino must be connected to the 5V IN and GND line of the Gateway.
The Gateway communicates with the Arduino via UART. For this the Gateway and the Arduino must be connected via GND, TX and RX line.

2. Set up your Sensor

Next you have to connect your DHT11 sensor to your Arduino. Connect the signal pin of the DHT11 with pin2 of the Arduino, VCC pin with the 5V pin of the Arduino and GND with GND.
It may be that you have a different DHT11 breakout board. In this case, VCC, GND and signal pin may be assigned differently. Check the datasheet for your DHT11.

3. Gateway Onboarding

Your Gateway is delivered already linked to your account and configured by our team.

4. Set up your Arduino IDE

First, download the latest version of the Arduino IDE.
For this tutorial we need two Arduino libraries. The first one for the DHT11 sensor, the second one for the connection to the Gateway, that implements our Communication Protocol for the Arduino. The Arduino IDE offers a library manager, which can be used to install the libraries. Open the library manager Tools --> Manage Libraries...
Search for the OneIoT Connectivity library by entering oneiot in the search bar. Click on Install.Now the library is installed and you can easily call the Communication Protocol using the library.
Search for the DHT sensor library by entering dht sensor library in the search bar. Click on Install. Now the library is installed and you can use it in the Arduino code to read the DHT11 sensor data.

5. Transfer Data to the App

Open the Arduino IDE with a new sketch and make sure that the two libraries are installed. We include the libraries in the code using the #include statements. We also define the pin for the DHT sensor and the sensor type.
#include <Connectivity.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
The next step is to configure the item numbers. The item numbers are matching the Digital Twin that we created in the cloud with the Device Template.
const int ITEM_TEMP = 1;
const int ITEM_MOISTURE = 2;
Now we need to create the Arduino objects for the sensor and the Gateway connectivity module.
DHT dht(DHTPIN, DHTTYPE);
Connectivity connectivity;
An Arduino sketch always consists of a setup() method where you do the things you want to be done when you start the program and a loop() method that is executed continuously. In our setup method we initialize sensor and Gateway connectivity module.
void setup() {
connectivity.begin(&Serial1);
dht.begin();
}
In the loop method we read the sensor values every two seconds and check if they are correct. The DHT11 sensor returns the temperature in degrees Celsius and the humidity in %. Both values are returned as float from the DHT library.
The Gateway connectivity library uses double values, so we still need to do cast the values to double datatype. In addition to the sensor values, we can also pass a status code for the sensor. For this we have STATUS_OK, STATUS_WARNand STATUS_ERROR to choose from. The code for our loop method then looks like this.
void loop() {
// Every two seconds we read the values and send them to the cloud
delay(2000);
// Humidity measured value from sensor dht11
double humidity = (double) dht.readHumidity();
// Temperature measured value from sensor dht11
double temperature = (double) dht.readTemperature();
// We check whether the sensor values have been read correctly
if (isnan(humidity)){
// If not send a STATUS_ERROR status code
connectivity.send_item_status(ITEM_MOISTURE, STATUS_ERROR);
} else {
// If everything is ok send STATUS_OK status code
connectivity.send_state_change_double(ITEM_MOISTURE, humidity, STATUS_OK);
}
// And the same again for the temperature
if (isnan(temperature)) {
connectivity.send_item_status(ITEM_TEMP, STATUS_ERROR);
}else{
connectivity.send_state_change_double(ITEM_TEMP, temperature, STATUS_OK);
}
}
That was already everything. If you now upload the code to the Arduino and have wired everything as described above, power supply is correct and if necessary a SIM card is inserted, then your DHT11 values are transmitted to the cloud. You can find all the code again here.
You can now log into the app and view your data and play around with all the app features.