Connect industrial gateway Option CloudGate to thethings.iO

Some of our customers use industrial routers from 3rd party manufacturers for several reasons. Some of these reasons are important requirement because of the environment, certifications, connectivity or needs on the field. Industrial routers or gateways are getting important on use cases such as the industry. Option have created the CloudGate router which is a really interesting gateway to use if you need to have an IoT swiss army knife.

CloudGate & thethings.iO

CloudGate & thethings.iO

Today we’re going toconnect the CloudGate router, from Option, to thethings.iO IoT platform in 3 simple steps. As an example we are going to connect the DL100-M485 temperature and humidity datalogger to a CloudGate that will send the data to thethings.iO. The DL100-M485 sensor uses the Modbus RTU protocol over the RS485 interface to transmit the temperature (both ºC and ºF) and the relative humidity (%).

The necessary components for this example are:

  • A CloudGate
  • Industrial serial expansion card (from Option)
  • DL-100M485 sensor
  • 12V DC power adapter (to provide power to the sensor)
  • Cables (to connect the sensor to the CloudGate).
  • A 120 Ohm resistor
  • Internet through Ethernet port

Set up the CloudGate hardware for thethings.iO

Option CloudGate connected to thethings.iO

Option CloudGate connected to thethings.iO

This is the step by step to connect the Option CloudGate to thethings.iO IoT platform:

  • Install the industrial serial card on the CloudGate.
  • Connect the green cable (D+) from the sensor to Tx+ pin on the industrial serial card.
  • Connect the white cable (D-) from the sensor to Tx-pin on the industrial serial card.
  • Connect the 120 Ohm resistor form D+ to D-.
  • Connect the 12V+ with de red cable from the sensor.
  • Connect the GND with the black cable from the sensor.

In order to connect the Option CloudGate to the IoT platform thethings.iO we will use Luvit-Red. Remember that the luvit-red package must be installed in our CloudGate. Luvit-red is available in the cloudgate universe. After registering and registering the Cloudgate, choose the latest Luvit-red version available to be installed on the CloudGate. Once the router restarts, the package will be installed. Luvit-Red is a visual tool to program workflows with the sensor data and other data from the CloudCode or from thethings.iO.

Set up a thethings.iO account and dashboard

If you still don’t have an account, please register at thethings.iO IoT platform.

In order to create a new thing:

  1. Enter to your account and click on Things.
  2. Press on Create new IoT product.
  3. Give a name and choose Other for the board.
  4. Finish the steps and remember the thing Token.

Program Luvit-red workflow to send data to thethings.iO

Luvit-red is a visual programming platform based on modules connections. In order to send the sensor values to thethings.iO, we are going to need the Modbus pull, Modbus extract, Function, JSON, and HTTP request modules.

    1. Modbus pull:
      1. Change the serial port to /dev/ttySP4 with 9800 and the parity of 8 bits and 1 stop bit.
      2. In this case we want to read 2 registers, located at the address 30001 and 30002. The operation Read Input Registers starts in the position 30001, so we only need to start at the same address (0 offset) and read 2 registers.

thethings-modbus-module

  1. Modbus extract:
    • With this module we are going to format the values as 16 bit integers. We should read 2 values and divide them to 100 to have the exact value (with commas). The result will be an array of 2 elements called Industrial and addressable in the payload of the message.

    theThings-extract-module

  2. Function:
    • Now we need to create the payload of the message: data and data1 will store the value of both humidity and temperature.

    thethings-parser-module

  3. JSON:
    • This module will transform the previous message into a well-parsed JSON.
  4. HTTP request:
    • All the messages will be sent using and HTTP POST. The URL should be https://api.thethings.io/v2/things/ followed by the thing token you created at thethings.iO

    thethings-POST-module

  5. Final connection:thethings-all-modules
    1. After connecting all the modules with its neighbours we should achieve the same flow as the next one:

Build thethings.iO Dashboard

Now it’s time to create a dashboard in your thethings.iO account to show all the values taken by the sensors. First we are going to create a Product table to show all the sensor values at the same time.

  1. Click on the Add Widget blue button.
  2. Give a name to the Widget.
  3. Select Product inside Data Source.
  4. Select the product you just created before.
  5. Select Table and check Realtime.
  6. Click on Costumize it and select the values you want to show (the name of the key in the function module).
  7. Accept and Save!

Now lets create some charts:

  1. Click on the Add Widget blue button.
  2. Give a name to the Widget.
  3. Select Thing Resource inside Data Source.
  4. Select thing you just created before.
  5. Select the name of the resource you want to display and the format (pie, chart, graph…).
  6. Click on Costumize it and select the number values you want to show.
  7. Accept and Save!

This is an approximate result of the dashboard that we have built in 2 minutes.

thethings-dashboard-cloudgate

Create more widgets and make awesome Dashboards with thethings.iO and let us know why you use Option CloudGate with the IoT platform thethings.iO!

Sigfox IoT Dashboard with thethings.iO IoT platform

In today’s post we are going to show you how to create (step by step) a Sigfox IoT Dashboard with thethings.iO IoT platform.

Sigfox thethings.iO

In this example we’ll use the same board an peripherals as the previous post (Connecting the SmartEverything to thethings.iO). Please follow the first two steps in order to flash the code in the SmartEverything. The Smart Everything board is a 32-bit ARM Cortex-M0+ that supports Arduino and brings a Sigfox module (Telit LE51-868 S), a GPS module with embedded antenna (Telit Jupiter SE868-A), a Proximity sensor (ST VL6180X), Humidity and temperature sensor (ST HTS221), accelerator sensor with Axis sensors (ST LSM9DS1), and a Pressure Sensor (ST LPS25H). In addition to this, the SmartEverything also has NFC and Bluetooth Low Energy modules.

Let’s start the tutorial

Now, make sure you have an account at thethings.iO. If not, register quickly by clicking here.

Once you have done this, you can start with this Step by Step.

In order to receive the data from Sigfox, you’ll need to redirect all the messages using a callback from our Sigfox profile. You’ll need to configure our thethings.io profile for this:

  1. Navigate to Things (2nd row at the left).
  2. Create a new product: Insert your product name. Then choose a name for each resource you’re going to use. Finally choose Sigfox inside Format.thethings-io-newproduct
  3. Press on the product you have created. Copy the url in the Subscription URL.

thehtings-io-sigfox-details

Now lets move to the Sigfox backend:

  1. Go to Device:
  2. Navigate to Callbacks.
  3. Click new
  4. sigfox-callbacks-list-thethingsChoose the following configuration:
      1. Type: DATA UP-LINK.
      2. Channel: URL.
      3. Url pattern: Paste your previous subscription URL from thethings.iO.
      4. Use HTTP method: POST and click Ok.sigfox-callback-thethings

Parsing data from Sigfox

Now go to thethings.iO IoT platform and you will need to specify how to parse the data that Sigfox forwards to thethings.iO, in order to display the correct values:

  1. Go to Cloud Code
  2. Navigate to Functions and Edit the parser with the name that you gave to the product before.
  3. Parse your resources by splitting the string that Sigfox sends (An hexadecimal number containing all the sensor values, one after the other). In the preview params, copy the sigfox payload you send from Sigfox and change “quote” to “data” to prove your function.
function parseF(s) { // Use this function in order to patch the GPS data stored as floats in the code
 var a = ((s & 0x7FFFFF | 0x800000) * 1.0 / Math.pow(2,23) * Math.pow(2, ((s>>23 & 0xFF) - 127)));
 if (s >= 2147483647) { //If >= (it's a negative latitude or longitude)
 a =-a;
 }
 return a;
}

function main(params, callback){
 var result = [
 {
 //Replace with your own payload parse 
 "key": "temperature",
 "value": parseF(parseInt(params.data.substring(8,16),16))
 },
 {
 "key": "humidity",
 "value": parseF(parseInt(params.data.substring(0,8),16))
 }
 ]
 callback(null, result) 
}

Creating the dashboard Widgets

It’s time to create an IoT Dashboard with thethings.iO to show all the values of your sensors!

    1. Click on the botom right cross (+)thethings-io-widget-create
    2. Introduce a name for the widget.
    3. Select Thing Resource.
    4. Select Sigfox.
    5. Select your thing Token.
    6. Select the resource that you want to show.
    7. Select how you want to show your resource (Lines, bars, log…) and choose realtime (if you want to see the values updating in realtime). Play with the value inside Custom Parameters.

Repeat this process until you finish your awesome IoT Dashboard!

thethings-io-new-sigfox-dashboard

3 reasons to use thethings.iO IoT platform

Every company that wants to be successful in the Internet of Things realm have a lot to do. One of the most crucial part is the IoT platform. Some of the key questions when building an IoT product are: Should I build my own IOT platform? should I use an IaaS as an IoT platform? or should I work with an existing IoT platform ready to go?

thethings.iO IoT platform

thethings.iO IoT platform

The answer is, don’t reinvent the wheel and keep IoT simple! We strongly recommend to use an existing IoT platform. At thethings.iO, we will be very happy to listen about your IoT use case or project and showcase you how does it look a tailored IoT platform for your product and customers with thethings.iO technology. And the most important part, making your life much easier for less!

Here find the main 3 reasons to use thethings.iO as the IoT platform our your connected product, if you are building an Internet of Things product.

IoT platform

IoT platform

1) The IoT platform working from the very first minute

thethings.iO IoT platform is the simplest IoT platform in the market. We know that launching a connected product is hard but it should not be complex to store data, monitor the data with flexible IoT dashboards and analyze the data from your devices and customers.

thethings.iO is a complete IoT platform solution that works literally in minutes. By working with thethings.iO, we save your time building your own IoT platform and maintaining it, with a fix cost. At thethings.iO we offer scalability, flexibility and security since you connect your first pilot until your production product is scaling to millions.

IoT Dashboards

IoT Dashboards

2) Customizable IoT dashboards

At thethings.iO, our customers and users can access to the data from any sensor, anytime anywhere. Historical data or real-time streams are pushed to thethings.iO panel. With unlimited API requests and data storage included, thethings.iO provides beautiful historical charts and real-time charts that you need to monitor and control your products.

thething.iO provides customizable and flexible dashboards to our customers. The IoT dashboards enable customers to visualize insights from the Big Data, we provide aggregations and KPIs, revealing trends or even detecting anomalies. Some of the features most used are the predictive maintenance, assets management or understanding the final customers usage of the connected products (churn, ROI, etc).

All of these data showed with a flexible dashboard and amazing widgets under the brand of our customers (logos, colors and URLs) makes thethings.iO one of the mot flexible and beautiful IoT platform in the market.

IoT Analytics

IoT Analytics

3)Cloud Code ready with deep analytics

As we are working with massive amount of data from the devices connected to thethings.iO, we have built a tool with enough flexibility to apply Big Data and Analytics algorithms on the top of the data in real-time or every some time (hours, days, etc), this is Cloud Code.

At thethings.iO Cloud Code feature you can work oriented to events with Triggers and get real-time alerts every time that any of your things send data. Configurable in just few clicks on or enjoying the power to code all what you need, thethings.iO offers this flexibility to non-technical managers or developers. The main goal of triggers is to get an instant alert when special conditions appears (e.g. temperature is too low, device is our of a virtual fence, button is pushed, among other).

The cloud code also offers Jobs which are algorithms executed every hour or every day. The aim of Jobs are providing a such powerful tool that enable technical people to aggregate data, summarizing the data, revealing trends, and detecting anomalies through Big Data algorithms such as predictive maintenance or artificial intelligence algorithms.

thethings.iO is ready to rock

Today thethings.iO is an IoT platform company operating on several verticals of the Internet of Things with a lot of experience on the industry, logistics and connected home use cases. We have close relationship with engineering companies, telcos and app developers to understand how to build end-to-end solutions.

All in one, thethings.iO IoT platform is the right place for every company seeking the best IoT platform and IoT dashboards to use with their networked products. Our main goal is to build the most simple IoT platform, so thethings.iO IoT platform is very easy and intuitive to use, and technical support is always available. You get your things connected quickly and easy with most of the IoT protocols such as HTTP, MQTT, CoAP, ModBus and Websockets.

So, why wait? There are a lot of advantages of a state of the art IoT platform waiting for you at thethings.iO.

Connect STMicroelectronics boards to thethings.iO

Today, we’re gonna show you how to connect your STMicroelectronics board with thethings.iO. At this post we are going to connect exactly STMicroelectronics Discovery-F746NG board to take advantage of the mbed platform.

STMicroelectronics & thethings.iO

STMicroelectronics & thethings.iO

The STMicroelectronics Discovery-F746NG is a development kit board of the ST32F7 series of microcontrollers based on ARM Cortex-M7 processor. The board brings a microcontroller with 1MB of flash memory and 340KB of RAM connected with a 4.3 inches 480×272 TFT with capacitive touch screen. It brings Ethernet connectivity for Internet and for example Arduino UNO connectors. One of the most interesting part for this demo is that this board support mbed IDE.

thethings.iO-stm32f746ng

We decided to connect it to the Internet with thethings.iO to build a functional pilot for a customer.

How to connect STMicroelectronics Discovery-F746NG to thethings.iO

In order to connect with thethings.iO IoT platform, we’re going to need a thingToken to identify our board with the IoT platform and the business logic on the top. Find here the instructions to make it happen:

    1. Login or Register to thethings.iO (or quickly register here).
    2. If you already have a thing to work with, skip two steps. Navigate to Things (third row on the left)  and click on “Create new IoT product”. Insert a name, choose 8266 as the board and JSON as the format.

thethingsio-things-manager

  1. Click on the created product and click on “Get activation codes”. If you don’t have enough activation codes, generate more using “Genereate Activation Codes”. Now press on the “+” below “Activate” Row and copy the thing Token.

Making the firmware at the mbed platform

One of the interesting parts of this board is the use of the mbed platform that simplifies a lot the way to deploy new firmware on the board.

    1. Navigate to mbed developers site and login (or signup if you don’t have an account).

thethings.iO-mbed-login

    1. Click the  “Compiler” button. This link will redirect you to the mbed online compiler.thethings.iO-mbed-compiler
    2. A floating window will emerge, asking for a platform to work with. Select your board (DISCO-F746NG).
    3. On the top part of the mbed online compiler, click on Import.

 

  1. Press “Click here to import from URL”.

thethingsio-mbedcompiler-import

  1. Insert the following link: 
    1. For the HTTP version https://developer.mbed.org/users/charlyo/code/thethingsiO-DISCO_F746NG-http/
    2. For the MQTT version https://developer.mbed.org/users/charlyo/code/thethingsiO-DISCO_F746NG-mqtt/
  • The program is going to be imported into your workspace. Remember to change the TOKEN define with your thing token.
  • Connect the board to the computer: Connect both ST-LINK (mini USB) and FS (micro USB) to the computer. A new drive unit is going to appear in your computer:

thethings-usb-disco_f746ng

  • Click on compile. After compile is done, download the file into the USB disk that appeared when you connected the board to the computer.
  • The code is going to be flashed into the board and executed afterwards on the board.

thethings-io-stm-demo-crop

thethings.iO STMicroelectronics library

Once we know how to program the STMicroelectronics board with ARM mbed platform. It’s time to build a code that send the sensors’ data to thethings.iO. Find thethings.iO IoT platform STMicroelectronics library at our github account for HTTP and MQTT, with an example for each.

This is the library that connects the STMicroelectronics board to thethings.iO with HTTP. It have 4 basic calls to thethings.iO API: activate, read, readAll and write.



#include "ThethingsiO_DISCO_F746NG.h"

ThethingsiO_DISCO_F746NG::ThethingsiO_DISCO_F746NG()
{
    this->interface.init();
    this->interface.connect();
    this->buffer = network::Buffer(1024);
}

ThethingsiO_DISCO_F746NG::ThethingsiO_DISCO_F746NG(string token)
{
    this->interface.init();
    this->interface.connect();
    this->thingToken = token;
    this->buffer = network::Buffer(1024);
}

ThethingsiO_DISCO_F746NG::~ThethingsiO_DISCO_F746NG()
{

}

string ThethingsiO_DISCO_F746NG::thingReadAll(int limit)
{
    std::string request("GET /v2/things/");
    request.append(thingToken);
    request.append("/all_resources?limit=");
    stringstream convert;
    convert << limit;
    request.append(convert.str());
    request.append(" HTTP/1.1\r\nHost: %s\r\nUser-Agent: curl/7.43.0\r\nAccept: application/json\r\n\r\n");
    if (socket.open() < 0) {
        printf("Failed to open TCP Socket\n\r");
        return "Failed to open TCP Socket\n\r";
    }
    if (socket.connect("api.devices.thethings.io", 80) < 0) {
        printf("Failed to connect with thethings.iO\n\r");
        return "Failed to connect with thethings.iO\n\r";
    }
    if (socket.write((void *)request.data(), request.size()) < 0) { printf("Failed to write HTTP request\n\r"); return "Failed to write HTTP request\n\r"; } int result = this->socket.read(buffer);
    //printf("Received %d bytes:\n\r%s\n\r", string string string string string string string int result, (char *)buffer.data());
    string response = string((char*)buffer.data()).substr(string((char*)buffer.data()).find("\r\n\r\n"));
    buffer.flush();
    socket.close();
    return response;
}

string ThethingsiO_DISCO_F746NG::thingRead(string resource, int limit)
{
    std::string request("GET /v2/things/");
    request.append(thingToken);
    request.append("/resources/");
    request.append(resource);
    request.append("?limit=");
    stringstream convert;
    convert << limit;
    request.append(convert.str());
    request.append(" HTTP/1.1\r\nHost: %s\r\nUser-Agent: curl/7.43.0\r\nAccept: application/json\r\n\r\n");
    if (socket.open() < 0) {
        printf("Failed to open TCP Socket\n\r");
        return "Failed to open TCP Socket\n\r";
    }

    if (socket.connect("api.devices.thethings.io", 80) < 0) {
        printf("Failed to connect with thethings.iO\n\r");
        return "Failed to connect with thethings.iO\n\r";
    }

    if (socket.write((void *)request.data(), request.size()) < 0) { printf("Failed to write HTTP request\n\r"); return "Failed to write HTTP request\n\r"; } int result = this->socket.read(this->buffer);
    //printf("Received %d bytes:\n\r%s\n\r", string string string string string string string int result, (char *)buffer.data());
    string response = string((char*)this->buffer.data()).substr(string((char*)this->buffer.data()).find("\r\n\r\n"));
    this->buffer.flush();
    socket.close();
    return response;
}

int ThethingsiO_DISCO_F746NG::thingWrite(string resource, string value)
{
    string body;
    body.append("{\"values\":[{\"key\":\"");
    body.append(resource);
    body.append("\",\"value\":\"");
    body.append(value);
    body.append("\"}]}");
    std::string writerequest("POST /v2/things/");
    writerequest.append(thingToken);
    writerequest.append(" HTTP/1.1\r\nHost: %s\r\nUser-Agent: curl/7.43.0\r\nAccept: application/json\r\nContent-Type: application/json\r\nContent-Length: ");
    stringstream convert;
    convert << body.length();
    writerequest.append(convert.str());
    writerequest.append("\r\n\r\n");
    writerequest.append(body);
    writerequest.append("\r\n");
    if (socket.open() < 0) {
        printf("Failed to open TCP Socket\n\r");
        return -1;
    }
    if (socket.connect("api.devices.thethings.io", 80) < 0) {
        printf("Failed to connect with thethings.iO\n\r");
        return -1;
    }
    if (socket.write((void *)writerequest.data(), writerequest.size()) < 0) { printf("Failed to connect with thethings.iO\n\r"); return -1; } int result = socket.read(buffer); //printf("Received %d bytes:\n\r%s\n\r", string string string string string string string int result, (char *)buffer.data()); string response = string((char *) buffer.data()); //printf("%s\n", (char *) buffer.data()); int ret = response.find("status:created"); buffer.flush(); socket.close(); if (ret >= 0) return 0;
    else return -1;
}

string ThethingsiO_DISCO_F746NG::thingActivate(string activationCode)
{
    string body;
    body.append("{\"activationCode\":\"");
    body.append(activationCode);
    body.append("\"}");
    std::string writerequest("POST /v2/things/");
    writerequest.append(" HTTP/1.1\r\nHost: %s\r\nUser-Agent: curl/7.43.0\r\nAccept: application/json\r\nContent-Type: application/json\r\nContent-Length: ");
    stringstream convert;
    convert << body.length();
    writerequest.append(convert.str());
    writerequest.append("\r\n\r\n");
    writerequest.append(body);
    writerequest.append("\r\n");
    if (socket.open() < 0) {
        printf("Failed to open TCP Socket\n\r");
        return "Failed to open TCP Socket\n\r";
    }
    if (socket.connect("api.devices.thethings.io", 80) < 0) {
        printf("Failed to connect with thethings.iO\n\r");
        return "Failed to connect with thethings.iO\n\r";
    }
    if (socket.write((void *)writerequest.data(), writerequest.size()) < 0) { printf("Failed to write HTTP request\n\r"); return "Failed to write HTTP request\n\r"; } int result = socket.read(buffer); //printf("Received %d bytes:\n\r%s\n\r", string string string string string string string int result, (char *)buffer.data()); string response = string((char *) buffer.data()); response = response.substr(response.find("\r\n\r\n")); buffer.flush(); socket.close(); //string string string int result = "{\"status\":\"created\",\"message\":\"thing activated\",\"thingToken\":\"5RWZ6xFogVSJEla3b2gbToHGF1Ko-R8vTNoS3FMl8mM\"}" return response; } string ThethingsiO_DISCO_F746NG::getToken() { return this->thingToken;
}

void ThethingsiO_DISCO_F746NG::setToken(string token)
{
    this->thingToken = token;
}

Try it and let us know how do you connect your STMicroelectronics board to thethings.iO. We are going to publish your example at our github and at thethings.iO blog.

How to visualize your SCADA diagram at thethings.iO in 3 steps

Imagine you have a number of different Internet-connected devices that fit together within one system. This could be a plant with humidity, light and pH sensors or, on a larger scale, a connected home system with numerous connected devices or a factory where you can monitor and control the valves, faucets, among others. The possibilities are endless, but either way, these instances can all be easily monitored through the use of a SCADA diagram.

A SCADA (Supervisory Control and Data Acquisition) diagram allows you to create a visual representation of your system’s processes and monitor them in a unique, dynamic diagram. Created in the ’60s, SCADA systems have evolved as one of the most important representational systems for industrial and infrastructure processes.

And now you can create your own SCADA diagram on thethings.iO dashboard! By the way, this is just the first version of the SCADA diagrams at thethings.iO dashboard, so we will update them soon. Follow these three simple steps to make a customized SCADA diagram.

Step 1: Go to the Dashboard and Create a Widget

Before you can start making your own SCADA chart, you need to sign up at thethings.iO and connect a device! If you already have an account and a connected thing, all you need to do is to log in. If not, click here to learn how to connect your first thing in 6 simple steps.

Once you are logged in, you will see a “meter” icon on the left-side navigation panel; this represents your customizable dashboard. Go to the dashboard and select the “Edit Dashboard” button in the top right corner. Now you can edit all your widgets and organize them any way that you prefer.

Scroll down until you see the “Add a new widget!” container and click the “Add Widget” button. A window will pop up in which you must type the name of your widget. Select the “Scada Control” option from the Data Source drop-down menu and click “Add” to create the widget.

Step 2: Adding Your Own Image

Now that you have created the widget, it’s time to personalize it with an image of your system! Scroll to the SCADA widget that you made in the last step and click the “Select Image” button. Upload your desired picture and resize the widget to fit your preference.

Step 3: Tagging Things on Your SCADA diagram

Once you have the image of your system uploaded, you must place your things on it! For example, I will be placing a “light” icon over the location of the lamp in the house diagram. You will place the things you want to monitor in their correct locations on your own image.

To do this, click the “Tag Thing” button on the right side of your widget. Hover the crosshair mouse over the location you want to tag and click. Select the Product, Thing and Resource of the item that you are trying to represent. Next, select an icon to represent your thing. You can choose from specific icons like a microphone or a car, or opt for a more general icon like a circle.

The final step to tagging your things is the optional Color Management feature. Here you can choose to change the color of your icon based on its last sent data value. A certain color can be applied to either a range of data values or one specific value. This feature makes the monitoring of your connected devices especially easy. With only a glance you can tell the status of your things.

Click the “+” button to add as many color management options as you desire and then click “Add Thing” to finish tagging your thing. Continue tagging different things until all the ones you wish to show are displayed on the SCADA diagram.

After you have tagged all your things you are finished! Click the “Save Dashboard” button and view your new SCADA chart in action! You can even click each icon to view a list of the last values along with the date.

Got an IoT product you need to connect? Head over to the simplest IoT platform on the market and sign up now.

thethings.iO September’16 Fresh New Features!

At thethings.iO we are constantly learning from our customers to improve our IoT platform. At thethings.iO we use a software continuous delivery, that means, that when we have a new feature we deploy it immediately (after unit testing and other). Yesterday, because of the specific features that we deployed we had to schedule a maintenance outage.

We are glad to announce that yesterday we delivered these next 3 great new features:

Users Management

Create users and grant access to developers, testers and people from your organization to the dashboard. Grant different permissions to the users depending of their role. The users will be able Read, Read&Write or Administrate the account.

iot-users-manager-thethingsio

Activation Codes By Product

One of the most requested features used to be the possibility to move acquired Activation Codes among products. Since yesterday that was not possible. We have improved the Activation Codes and made the way you provision the new things more dynamic.

First of all, now you can share Activation Codes among products and we also open the possibility to have an Activation Code that activates multiple things. That means that now, with only one activation code for product, you are able to activate as many thing things as you need.

Apps Management

We improved the Applications Manager user interface. Now, using the new Application scope, it’s possible to define in a better and easy way how your Apps will interact with thethings.iO.

iot-app-scope-thethingsio

One more thing

Yesterday we also published our status page!

Status Page

We created the status page https://status.thethings.io where you can check the status of all our services, the average of the response time and a board of incidences.

iot-status-page-thethingsio

At thethings.iO we are building the simplest IoT platform in the market for several verticals such as Industry 4.0, Agriculture, Logistics or Connected Home. Feel free to contact us for more information.

Connect the ESP8266-V12 Wemos to thethings.iO

One of our favorite WiFi device is the ESP8266. After explaining how to connect ESP8266 v1 to the IoT platform thethings.iO, here we would like to explain how to connect ESP8266 v12 or WEMOS to thethings.iO. In this case we are working on a Wemos D1 Mini.

Wemos esp8266v12

Wemos esp8266v12

We decided to work in some projects with the Wemos D1 Mini (that brings the esp8266 v12) because they work great. For less than 5$ you get a very powerful SOC (System On Chip) of 32 bits at 160MHz with RAM and EEPROM plus the WiFi. Just to tell you more information about the Wemos, this is a WiFi board based on the microcontroller ESP8266EX and it brings 11 digital pins and 1 analog input. The digital pins are input and output pins with support of interrupt, i2c and pwm. The analog input support a maximum of 3.2V input. The Wemos is compatible with Arduino and nodemcu.

Wemos D1 Mini

Wemos D1 Mini

Today we’re going to connect the ESP8266 v12 (a wemos) to thethings.iO using MQTT protocol and the Arduino language.

Let’s get started!

  1. Create a thing to work with:
    1. Login to thethings.iO (or quickly register here).
    2. If you already have a thing to work with, skip two steps. Navigate to Things (third row on the left)  and click on “Create new IoT product”. Insert a name, choose 8266 as the board and JSON as the format.thethings-create-product
    3. Click on the created product and click on “Get activation codes”. If you don’t have enough activation codes, generate more using “Genereate Activation Codes”. Now press on the “+” below “Activate” Row and copy the thing Token.thethings-activate-code
  2. Installing the esp8266 libraries for the Arduino IDE:
    1. Make sure you have the latest Arduino (check here). Install it in your computer.
    2. Open Arduino and navigate to preferences.
    3. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager’field. You can add multiple URLs, separating them with commas.thethings-preferences-arduino
    4. Open Boards Manager from Tools > Board menu and install esp8266 platform (and don’t forget to select your ESP8266 board from Tools > Board menu after installation).thethings-install-board
  3. Uploading the code to the board:
      1. Clone or download the code from our repo. Link here. First read the README to understand how to use the addValue and send calls.
    
    #include 
    #include 
    
    // Update these with values suitable for your network.
    
    const char* ssid = "SSID";
    const char* password = "PASSWORD";
    const char* mqtt_server = "mqtt.thethings.io";
    
    #define TOKEN "YOURTOKEN"
    
    String topic = "v2/things/" + String(TOKEN);
    
    WiFiClient espClient;
    PubSubClient client(espClient);
    long lastMsg = 0;
    
    int cont = 0;
    
    String msg ="{\"values\":[";
    
    void addValue(String key, String value) {
        if (cont == 0) msg += "{\"key\":\""+key+"\",\"value\":\""+value+"\"}";
        else msg +=",{\"key\":\""+key+"\",\"value\":\""+value+"\"}";
        cont++;
    }
    
    void addValue(String key, int value) {
        if (cont == 0) msg += "{\"key\":\""+key+"\",\"value\":\""+value+"\"}";
        else msg += ",{\"key\":\""+key+"\",\"value\":\""+value+"\"}";
        cont++;
    }
    
    void addValue(String key, float value) {
        if (cont == 0) msg += "{\"key\":\""+key+"\",\"value\":\""+value+"\"}";
        else msg += ",{\"key\":\""+key+"\",\"value\":\""+value+"\"}";
        cont++;
    }
    
    void send() {
        msg += "]}";
        client.publish((char*)topic.c_str(),(char*)msg.c_str());
        msg = "{\"values\":[";
        cont = 0;
    }
    
    void setup() {
      pinMode(BUILTIN_LED, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
      Serial.begin(115200);
      setup_wifi();
      client.setServer(mqtt_server, 1883);
      client.setCallback(callback);
    }
    
    void setup_wifi() {
    
      delay(10);
      // We start by connecting to a WiFi network
      Serial.println();
      Serial.print("Connecting to ");
      Serial.println(ssid);
    
      WiFi.begin(ssid, password);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
    
      Serial.println("");
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
    }
    
    void callback(char* topic, byte* payload, unsigned int length) {
      Serial.print("Message arrived [");
      Serial.print(topic);
      Serial.print("] ");
      for (int i = 0; i < length; i++) { Serial.print((char)payload[i]); } Serial.println(); } void reconnect() { // Loop until we're reconnected while (!client.connected()) { Serial.print("Attempting MQTT connection..."); // Attempt to connect if (client.connect("ESP8266Client")) { Serial.println("connected"); client.subscribe((char*)topic.c_str()); } else { Serial.print("failed, rc="); Serial.print(client.state()); Serial.println(" try again in 5 seconds"); // Wait 5 seconds before retrying delay(5000); } } } void loop() { if (!client.connected()) { reconnect(); } client.loop(); long now = millis(); if (now - lastMsg > 2000) {
        lastMsg = now;
        addValue("value", (int)random(1,5));
        send();
      }
    }
    
    1. Connect the board to the computer and select your esp8266 board inside “Tools” > “Board”. Also don’t forget to select the proper port.
    2. Change “YOURTOKEN”, “SSID” and “PASSWORD” with your credentials.
    3. Flash the code.

Now you are ready to build a dashboard with the IoT platform thethings.iO and store, visualize and analyze all the data from your Wemos in real-time.

IoT platform dashboard

IoT platform dashboard

If you work with ESP8266 or Wemos, you need an IoT platform. Don’t hesitate to try thethings.iO and keep us updated with your projects.

Developing Android app with the thethings.iO

Last week we explained how to create Apps and IoT dashboards from thethings.iO, this week its time to build real mobile apps connected to an App Id. Because most of thethings.iO IoT platform customers do not only make a connected product, but also build mobile applications. Mobile apps are useful to let final customers access to the data generated by the connected products and even interact with them, all with a great UX. iOS and Android are the predominant operating systems at the moment, so we built some simple examples on Android and iOS in order to show to our customers what they need to connect their mobile app with thethings.iO.

Developing Android app with thethings.iO

Developing Android app with thethings.iO

We designed an Android application in order to show you how all thethings.iO’s API calls work from Android SDK. From the user registration and login to the link thing or read and write. All the useful API calls that any Android developer need to connect a mobile app with the IoT platform thethings.iO in few minutes.

Find below a step by step guide about how to use the Android app available at our github repo thethings.iO-android-app . Having said that, remember to have Android Studio installed on your computer.

  1. Building the app:
    1. Open Android Studio
    2. Choose “Check out project form Version Control”. Select Git from the list. Paste the previous github link.thethings-project-checkout
    3. Select the directory and press clone. Maybe will need to install some dependencies (toolkit 21).
  2. Creating an app from thethings.iO
    1. Login (or quickly register here) to your thethings.iO account.
    2. Navigate to Apps (fourth row of the menu) and click on “Create new IoT application”.thethings-app-manager
    3. Select the name and press “Create”. Remember to copy and paste your app-id. You’ll need it later.
  3. Choosing app permisions
    1. Navigate to the product you want to share with the app (third row of the menu).
    2. Click on “Product details”.thethings-resource-permisions
    3. Write the name of the resources that will be available in the app (each one followed by a space).
  4. Clone thethings.iO Android app on your local repository and launch it
    1. The first display will request some of the basic credentials. Fill your login credentials (inside “Account setup”): Username, password, app-id and the thing-Id you want to interact with.thethings-app-credentials
    2. Press “Api Calls”.
    3. If it’s the first time you use the app, click on “Register”. If it’s not, click on Login. The user will be logged in the app details (at thethings.iO).thethings-app-options
    4. Press “Link thing” to start using the specified thing.
    5. Use the rest of the options at your will.

This Android app shows you all the API calls that you need to connect Android with thethings.iO. If you need more help, please post a message on thethings.iO developers forum and we will solve it ASAP.

thethings.iO API calls for mobile apps

There is a long documentation on thethings.iO developer portal to build mobile app for IoT with thethings.iO. Find here the most important API calls that you can call through HTTP, MQTT, CoAP or Websockets from iOS, Android or whatever mobile OS that you are using.

Register

The first call is to Register a user at thethings.iO IoT Platform. This endpoint also login the user (returns the session token and roles), so you don’t have to do another API call to login the user.

POST https://api.thethings.io/v2/register

curl -i -H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"email": "YOUR EMAIL HERE", "password": "a hard to guess password", "app": "The appID given in the panel"}' \
-X POST "https://api.thethings.io/v2/register" -k

Login

Here you can Login a user on your app through thethings.iO IoT Platform. This API call returns the session token and roles. Roles identifies the resources and things that the user has authorized the App to access.

POST https://api.thethings.io/v2/login

curl -i -H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"email": "YOUR EMAIL HERE", "password": "a hard to guess password", "app": "The appID given in the panel"}' \
-X POST "https://api.thethings.io/v2/login" -k

Link Thing

This is one of the most important API calls because it joins a user and a thing. That means that it’s a procedure that entitles the owner of a thing.

This procedure needs a thingToken (or the thingId) and a sessionToken of the user (after log in or register). And it requires some kind of direct communication between the mobile app and the thing.

For example, when setting up for first time a thing with WiFi, you usually have to configure the WiFi for the thing. That means that the thing generates a hotpsot, the app connects to that WiFi and the user (after login or registration through the app) introduces the WiFi’ SSID and WiFi’s password. The thing gets the information and get connected to the Internet. At this moment the thing call the API activate and receives the thingToken of the thing. With this thingToken, the App will be able to do the REST call to link the think to the user and store the relation at the platform. The other possibility is to send the sessionToken of the user (after log in or registration) during the WiFi configuration (sending the SSID + WiFi password and the sessionToken).

Note that in order to link the thing the user must be logged in and the thing must be activated (i.e. have a thingToken)

This operation can only be done for applications which have been authorized for the thing developer, this kind of apps are called official apps.

POST https://api.thethings.io/v2/me/things


curl -i -H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: { {SESSION TOKEN} }" \
-d '{"thingToken": "{ {thingToken} }"}' \
-X POST "https://api.thethings.io/v2/me/things" -k

Find all the documentation about how to make a mobile app connected to the IoT platform thethings.iO at the developers site.

Today we explained a step by step to build an Android app connected with your things at thethings.iO. Feel free to use our Android app on thethings.iO’s github account. Don’t waste your time and create and account at the most simple IoT platform in the market.