Beginners Guide: Connecting An Arduino To thethings.iO

Arduino loves thethings.iO

Arduino loves thethings.iO

In today’s post we are going to show you Step by Step how to connect an Arduino to our platform, thethings.iO. You will only need:

  • An Arduino or Genuino board.
  • Ethernet, Wi-Fi (or Yún or an ESP8266, for the cheaper version) or GSM shield.

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.

Step 1: Preparing the environment

First you need the Arduino software installed. Afterthat, download the thethings.iO Arduino library in our github. Extract the thethingsiO from the .zip file and install it by copying the folder to your Arduino library folder.

The default path for the libraries is:

  • Linux: /Home/your-username/Documents/arduino/libraries
  • Mac: /Users/your-username/Documents/Arduino/libraries
  • Windows: \My Documents\Arduino\libraries

Now you can use the classes and functions described in the reference part of the repository.

Step 2: Sending Values

Now you need to open the Arduino software. Navigate to Examples > thethingsiO. Choose a protocol (if you are a beginner we recommend you to choose http) and then choose your shield (Ethernet, Wifi or GSM). Next, choose Send Values. An already “done” code will appear.
Now we need to make sure that we correctly initialize our Shield. For every shield there’s a method that does the previous action.

For the Ethernet shield, we need to provide the mac address of the shield (located below the shield):


void startEthernet() {
Serial.println("Connecting Arduino to network...");

// Local Network Settings

byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; // Must be unique on local network

// Connect to network amd obtain an IP address using DHCP

while (Ethernet.begin(mac) == 0) {
Serial.println(“DHCP Failed, retrying”);
}

Serial.println(“Arduino connected to network using DHCP”);
}

For the GSM shield, we need to provide the PIN number and the apn settings for your SIM card:


// PIN Number

#define PINNUMBER “”

// APN data

#define GPRS_APN “”
#define GPRS_LOGIN “”
#define GPRS_PASSWORD “”

For the Wifi Shield, you need to provide the SSID and the password:


#define SSID YOURSSID
#define PASS YOURPASSWORD

//In case that you already activated the token with an activation code and we have the token, use the next code:

thethingsiOEthernet ethernet_thing(TOKEN);
thethingsiOWiFi wifi_thing(TOKEN);

// Choose the one depending of your shield.

thethingsiOGSM gsm_thing(TOKEN);

// If you have the activation code but not the token, add the following code:
thethingsiOEthernet ethernet_thing();
thethingsiOWiFi wifi_thing();

// Choose the one depending of your shield

thethingsiOGSM gsm_thing();
string token = activate(“Your activation code”);

// Insert this and the next line inside the setup method, after the start function of the shield

if (token > “0”) setToken(token); // If the activation code is correct, a token is provided

Now that you have your thing created, it’s time to send values.

void loop() {
thing.addValue("Power", random(1,5)); // Adding a value from a number between  1 and 5 with the identifier "Power"
thing.addValue("Temperature", random(0,40)); // Adding a value from a number between 0 and 40 with the identifier "Temperature"
thing.send(); // For sending the previous values to your dashboard }

Step 3: Arduino Monitoring with thethings.iO

Now it is time to monitor the data. Go to Things Manager and select the thing where you are sending the data, that’s the Thing Details.

Thing details with arduino data

Thing details with arduino data

Step 4: Arduino real-time dashboard

Let’s create a cool dashboard which you will be able to monitor this data in real-time.
First, we go to the thethings.iO dashboard. Here, you have to Add a Widget. You do this by pressing the blue circle in the lower right corner.

Add A Widget

Now, choose the kind of Data Source you want to see on your Dashboard.

Add a Widget_2

And select the Resource.

Add a Widget_3

After that, you have to select the Widget Type you’ll want it to appear on your dashboard. In our case we are choosing ‘Lines’ for ‘Temperature’, and ‘Pie’ for ‘Power’.
Add a Widget_Temperature
Add a Widget_Power

And this is an example of what your dashboard would look like if you added a bar graph and logs as well…

thethingio.dash

 

Start with thethings.iO

And that’s it! Easy, right? Now you have your Arduino connected with thethings.iO. Start connecting things now!

Quick Guide: Connect Your First Thing in 1 Minute

This is a quick guide to connect your first thing using our platform, thethings.iO. thethings.iO is the Internet of Things platform that enables fast and scalable connection of things to the Internet, allowing you to monitor and manage your devices in real time and get flexible analytic reports.

As you will see, it is easy, and you can do it in less than a minute. You just need to follow a few steps we’re going to quickly explain to you in this post. Ready? Let’s start now, then!

Step 0: Signing In at thethings.iO

If you haven’t registered yet, you need to do it. Go to thethings.iO page, and sign in. Remember that you can connect one thing for free, so it is worth it. Once you have done that, you’ll be signed in to your panel.

Sign in

welcome-thethingsio

Step 1: Planning the thing

Before starting with the code, you should have an idea of what you want to connect to the Internet. What kind of data do you want to store and visualize? Is it going to be temperature? Or better humidity? Or other features like strength, noise, light…?

Step 2: Activating your first thing

When you have planned that and you are in your panel, it is time to start with the code. Let’s activate your first thing at thethings.iO! To do that you will need an activation code. You will be redirect to the Things Manager screen, where you will find directly the Activation Code screen.

As you may know, activation codes are needed to activate things. When you activate the thing, you will get something called ‘thingToken’. This Token can be compared to a personal ID but for things. The Token will enable you to make API calls to thethings.iO from your thing.

To activate the code, you just need to click on the Activate More Things. After that, the next window will prompt you to Activate. Click on Activate to activate one of the Activation Codes.

activation-code-thethingsio

activation-code-thethingsio

With all of this done, you will be able to see the thing and the thingToken. You can copy your thingToken, because from now on, all the requests will be done using it. Or you can as easily press Accept and your thing will be activated.

thingtoken-thethingsio

 

Step 3: Coding your thing

Let’s start with the coding. Right now, your thing is capable of performing 3 types of actions: read, write or subscribe. You need to open the Developers Console to see the messages you will post to thethings.iO APIs.

Now let’s see the actions:

  • Write: store one or several key-values pairs.
    To store data, you have to use the next endpoint.
    Advice: only alphanumeric characters and “.”, “-”, “_” symbols are admitted for the resource named “key”.
  • Read: your thing reads the last values for a determined key.
    To read data, use the operation GET/things/ with the thing token and the key that you are using to store the values.
  • Subscribe: subscribes to the real-time streaming channel of your things.
    This last method lets you subscribe to the thing channel and get real-time updates from all the thing’s keys. This way, it is created a streaming channel. If you want to know more about the Keep Alive options, click here.

dev-console-thethingsio

Step 4: Visualizing the data

Right now, you should have your first thing connected. You can see the numeric data you store from thethings.iO Panel. You only need to click at the Things Manager menu and then click on the thing you want to visualize. Check past data on historical tab, or the real-time as the data arrives on the real-time tab.

analytics-thethigsio

 

Step 5: Build your own dashboard

thethings.iO IoT Dashboard is fully customizable with widgets that can show historical or real-time data directly from the dashboard and not going to every thing.

And that’s it! With thethings.iO it’s easy, right?

If you want to learn more about thethings.iO features then you can not miss these posts about Twilio and Sigfox! And make sure you follow us on Twitter to keep you posted about the Internet of Things world and thethings.iO latest news!

,

Alternative to Parse IoT: meet thethings.iO

This morning at thethings.iO we woke up to the surprising announcement that Parse, the cloud app platform, will be fully retired within the next year (January 28th, 2017). As you may know, this means its customers and users will need to migrate their applications and hardware to other services, such as the ones we offer at thethings.iO IoT platform. If you want to know more, keep reading…

Parse loves thethings.iO

Parse loves thethings.iO

What Parse used to offer

Parse was focused on the back-end, server maintenance and infrastructure for mobile apps. This way, they offered a solution to all those people who had ideas but lacked the knowledge, time or money to support the costs of a server where to settle down those apps.

It means that Parse offered what they called Core as the main feature. It allowed customers to store and manage data without the need of a server. With its analytics reports, they allowed users to understand how people were using the app: its growth, retention, etc. They easily created Push Notifications across devices and platforms was another of its functionalities.

thethingsiO loves parse

thethingsiO loves parse

Parse used to offer an Internet of Things support as well, allowing users to connect their IoT directly to Parse, as it was tuned to work in hardware environments. Then, Parse could support hardware like Arduino, Intel or Raspberry Pi, among others.

How thethings.iO can help you

thethings.iO is the IoT platform that allows users get fast and scalable connection of your things and products to the Internet. thethings.iO IoT platform also allows you to store relational object-structured data, monitor the connections, OTA push, send an SMS with Twilio through cloud code and manage everything in real time and get flexible analytic reports.

We know it can be hard (considering time or even money) for hardware companies to connect things to the Internet, as you have to build a new server from scratch. We want these companies to focus on their best, build cool things, allowing us focus on what we do best, be their best cloud solution.

thethingsiO customizable dashboard

thethingsiO customizable dashboard

So for all those who decided to use Parse as the Internet of Things cloud solution, we offer you its best alternative to start (or in this case, keep) connecting things easily. thethings.iO IoT platform works with an amount of features that, we are sure, will be of great interest to you, so check our website, sign up and start now!

If you want to migrate your Parse account to thethings.iO send us an e-mail to support (at) thethings.iO and we will help you painlessly get everything up and running .

Quick Guide to Cloud Code

As you know, Internet of Things is the next big thing. Considered the fourth biggest revolution (as important as the industrial and the Internet ones), all the machines connected to the Internet are saving huge amounts of data. But data on its own form does not matter. What is really important is the information we can get from it and services that you can build on top of the information. Here is where thethings.iO can help you make IoT simple!

Cloud Code

Welcome to the new Cloud Code feature. The business logic could not be in your things or Apps but in the Cloud. thethings.iO Cloud Code feature transforms the data from your connected things into information that will be useful to your daily activities.

Nowadays, the Cloud Code is a Javascript runtime programmable tool that enables you to program business logics, artificial intelligence algorithms or others on the top of the data stored. We can find 3 different categories: triggers, jobs and functions. Let’s talk a little bit more about each one. In the future we are going to integrate other languages such as Python, GO or others. What languages would you like to have?

Triggers

Firstly, we find Triggers. A trigger is a piece of code that is executed automatically on our Cloud, after a write command is received. That means that every time a temperature sensor sends the temperature, a trigger is launched in order to convert that data into celsius degrees or launch an alarm if the temperature goes below zero.

A typical use of a trigger is to create an alert. You can code the trigger in a way that when an alert condition happens, you can send an email, send an SMS and make a call with Twilio or tweet a message. And of course, store an event to build reports later. The execution of a trigger is limited to 2 seconds.

Following the previous example, if you have a temperature sensor you can build a Javascript code with the logics of the trigger to alert you when the temperature is higher than X value. When it happens, a message is sent (SMS, e-mail or tweet) to your smartphone or tablet to notify you about the condition. Additionally, if you store an event, later via Jobs, you can generate a report that shows how many times in one day this event get triggered.

Jobs

The Jobs is Javascript code that can be executed once every hour or once a day. The Jobs allow you to set up long running tasks. The execution of a job is limited to 10 minutes. Jobs lets you create map-reduce functions, reports and analytics aggregating the data from the events that your triggers or functions generate.

Current examples of the Jobs are related with mathematical functions or artificial intelligence and predictive maintenance scenarios. For example, a job synchronized with a trigger can help you to predict malfunctions every hour. Another example is a Job that analyzes how your customers use their devices and sends a daily report to the marketing people of your company.

Functions

Finally, we have Functions. Functions are algorithms that could be executed when they are needed. Functions can be called by triggers or jobs and even from outside thethings.iO via an API REST endpoint. Jobs encapsulate business logic that you don’t want to couple into a trigger or a job and of course not into the devices or mobile apps. The execution of a Function is limited to 20 seconds.

If you are using Sigfox, the functions are the place where you need to code the Sigfox payload parser in order to visualize the Sigfox data at thethings.iO.

All Cloud Code plugins

These are thethings.iO Cloud Code plugins:

  • emailing: it sends emails.
  • httpRequest: it sends an http request.
  • console: logs in your code.
  • analytics.events: allows to create and retrieve events.
  • analytics.kpis: to create metrics to be displayed on your dashboard.
  • thethingsAPI: allows to read and write on a device resource.
  • DataSet: represents the data returned from analytics.events.getByName.
  • Twilio: it sends SMS or phone calls. In case you missed it, read the post about Twilio here.
  • Geolib: Integrates Geolib library to provide basic geospatial operations like distance calculation, conversion of decimal coordinates to sexagesimal and vice versa, etc.
  • Twitter.

You can find more information on thethings.iO documentation site.

Know how our Cloud Code works

Do you want to see how it works? Discover how easy it is to use thethings.iO’s Cloud Code! We have created a thing which measures temperature. The next screenshot shows how our Dashboard looks like, with the ‘Thermostat Alerts’ graphic.

In this second screenshot, we see the Job code. In this case, the job get all the Alarm events of the day and store a KPI with the total events. This KPI is consumed by the dashboard widget ‘Thermostat Alerts’ to generate the graphic.

And finally, we see the screenshot of the Trigger code. In this case, we wanted to be notified with an alarm in case the sensor gets a temperature of 50ºC or above. We also store the event ‘Alarm’, which is later consumed by the previous Job.

If you want to learn more about thethings.iO features then you can not miss these posts about Twilio and Sigfox! And make sure you follow us on Twitter to keep you posted about the Internet of Things world and thethings.iO latest news!

Firmware Upgrade Step by Step

Firmware Upgrade Step by Step

Firmware Upgrade Step by Step

Firmware upgrade Over-the-Air

At thethings.iO, we take care of all the Internet of Things workflow. One of the most important parts is the firmware that runs on the hardware. Upgrading the firmware through OTA PUSH is needed in all the use cases related with the Internet of Things.

thethings.iO IoT platform offers OTA (over-the-air) firmware upgrade support. As you may know, OTA is a standard that allows users to transmit and receive information in wireless communication systems. It means that by using thethings.iO you will be able to update the firmware version of all devices you are selling in a rapid and easy way.

The OTA PUSH ‘Step by Step’ video

In the following video we’ll show you how the firmware upgrade feature works in our platform step by step.

thethings.iO allows you to distribute your firmware to all of your devices over Wi-Fi, Bluetooth or mobile broadband (GPRS, 2G, 3G or 4G). Let’s imagine a situation: some of the devices you are selling have a software error. Using your firmware in our dashboard, you just need to update the version your devices have by changing or improving what was wrong. With thethings.iO you can do it remotely, so you do not need to go to the place where each device is physically placed; you only need to use our API to make it work via Wi-Fi.

Firmware upgrade features

By using the firmware manager (located in the panel and Things Manager), users can manage and publish their firmware upgrades for their thing model and microcontroller unit (MCU). The available features of thethings.iO are:

  • To create, manage and upload new firmware versions.
  • To list all available versions.
  • To delete firmware versions.

Keep IoT Simple, Stupid!

Innovation brings enthusiasm when you are making a product. Launching a connected device is hard and expensive. 2015 has been amazing at thethings.iO; we worked together with great projects and awesome people. The most valuable thing we discovered is that things must be more simple, from the UX to the most technological part of the projects.

Inspired by the KISS principle (“Keep It Simple, Stupid”), thethings.iO would like to advocate towards the “Keep IoT Simple, Stupid”!

The “Keep It Simple, Stupid” principle states that the most basic rule in every design is to make it simple rather than complex. That means that simplicity should be more important in design and unnecessary complexity should be avoided. The Internet of Things is a complex scenario and simplicity is much needed, so unnecessary complexity shouldn’t be made.

At thethings.iO IoT platform we have grasped this concept in the essence of our system. Among the connected product and the mobile application, there are hundreds of things to worry about: electronics, mechanicals, manufacturing, packaging, logistics, data security, cloud storage, mobile applications, interoperability with other things, among dozens more.

Simply put the “Keep IoT Simple, Stupid” principle in your project. We suggest that companies focus on what they do best. Some companies are very good at design, other very good with electronics and others with algorithms. How can they bring a connected device into the market faster? The answer is by looking for partners who can make the process less complex. The best projects we worked on 2015 were projects where the consortium of companies that joined the founder team was fantastic. Don’t waste your time and money reinventing the wheel! It’s 2016!

Everyday it becomes easier and easier to connect things to the Internet. This is the main reason why the number of companies building new connected devices in China, Europe, United States or Latam has been on the rise. So, “Keep IoT Simple, Stupid”!

What is thethings.iO’s main role here?

thethings.iO IoT platform

thethings.iO IoT platform

Under this concept of keeping things simple, thethings.iO IoT platform wants to offer a solution to all IoT and digital companies, helping them into the connection, storage, monitoring and data analysis of their cool new devices and products. Outsourcing IoT platform cloud service results in a faster implementation and reduced time to market for the new launches on the IoT landscape. Our advice is to consider taking the “simple, stupid” way to connect your product to IoT: it will be a smart choice.

Hardware companies should focus on building things. At the same time, thethings.iO makes the connectivity development from the prototyping phase until the certification and massive production. thethings.iO offers:

  • IoT Back-End solution to store data that can be accessible in real-time.
  • Customizable front-end user interface with your brand and under your URL.
  • Real-time data analysis with AI and data mining algorithms.
  • Security, Scalability and Data Privacy.
  • Interoperability with the majority of the IoT available.

Yes, it is better when you Keep IoT simple have you not seen it yet?

,

SMS & Voice Calls from Twilio meet thethings.iO

Internet of Things is about monitoring, alarms, notifications, among other, then it’s important to get real-time updates and the best way to get informed it’s probably through phone calls and SMSs. The IoT platform thethings.iO integrated Twilio, the communication platform that leads the voice and messaging applications.

Twilio with thethings.iO

Twilio with thethings.iO

Send SMS and make voice calls from your things with thethings.iO and Twilio

thethings.iO offers notifications (SMS and Voice calls) for your things through cloud code. This feature allows you to receive voice calls, SMS (with Twilio), emails, and tweets (with Twitter), whenever you trigger these messages from your networked products.

Recently, we have integrated Twilio on our Cloud Code feature. This allows our customers to easily program business logics on the top of connected devices and send SMS messages or make a scripted voice calls when needed. In this post I’m going to go through how to integrate Twilio on your IoT solution with a simple example.

Set up Twilio at thethings.iO

To start working with Twilio on thethings.iO IoT platform, you need an account on Twilio, because you need to introduce your Twilio credentials at thethings.iO. Don’t worry if you don’t have an account on Twilio, it’s free to create one and you get a phone number to start playing.

After that, you need a thethings.iO account to start sending data from your devices to our IoT platform. It’s very simple! Register here at thethings.iO follow the configuration step by step. And when you are ready, find some examples from some of the most famous IoT hardware platforms here, such as Arduino, ESP8266, Atmel, Electric Imp and other on our github account. An account on thethings.iO is free and simple to use. You can follow our getting started document and be ready in 1 minute.

Now that your thethings.iO and Twilio accounts are created and configured, you are ready to try the Cloud Code example that sends SMS when the temperature is too high.

Receive an SMS when the temperature of your device is too high

First, go to the Cloud Code feature clicking on the ‘Cloud code’ link at the left sidebar.

Cloud code main view

Create a trigger at the ‘Add Trigger‘ button. A form to create a trigger will appear. You have to name the trigger, link it to a product and insert the Javascript code that will be executed.

Triggers are executed when an event occurs like a thingWrite (when your thing post a value). So, we are going to code a script that sends an SMS when the temperature of a thing is up to 50. Here there is the JS code:

function trigger(params, callback){
  console.log('trigger triggered!!')
  //ignore non write events
  if(params.action !== 'write') return callback()</code>

  var values = params.values
  var thingToken = params.thingToken

  //iterate over the values of the write
  for(var i=0; i<values.length; ++i){     
    if(values[i].key === 'temperature' && values[i].value > 50){
      console.log('omg too hot')
      var telf = '+346661199991111'

      var message = 'Master, it’s too hot here! Device: ' + thingToken

      var twilio = new Twilio(
        'YOUR Twilio AccountSid',
        'YOU Twilio AuthToken'
      )

      twilio.sendMessage({
          to: telf, // Any number Twilio can deliver to
          from: '+346660099991111', // A number you bought from Twilio and can use for outbound communication
          body: message // body of the SMS message
        },
        callback
      )
    }
  }
  //end the trigger
  callback()
}

Now, every time that the temperature of all the devices from the product are up to 50, you’ll receive an SMS alerting you in real-time. And all you need to include to enjoy this feature are 32 lines of JS on your thethings.iO cloud code feature.

If you prefer to receive a voice call instead an SMS, you only have to change the twilio.sendMessage to twilio.makeCall as in the following example:

  twilio.makeCall({
    to: telf,
    from: '+346660099991111',
    url: url_call // A URL that produces an XML document (TwiML) which contains instructions for the call
  },
    callback
  )

Further reading

Introducing the new thethings.iO

Meet the newest thethings.iO

Ch-ch-ch-changes…

It is as they say: the only constant in life is change.

This is true in the technologized world we live in, and it is even more true when running a startup. If you want to change the world, you better listen to how the world wants to be changed. And as we’re on the cusp of the digital revolution merging into the analog world via the Internet of Things, that change is only going to accelerate.

We have seen plenty of changes on thethings.iO in the last twelve months. We’ve seen our team grow, we signed up new customers and partners and couldn’t be happier about them, and we’ve seen a lot of really cool projects happen in the Internet of Things.

We’ve started to work with Telefonica and SigFox, for instance, to give their customers access to our dashboards to more efficiently manage their fleet of devices in the field. We have also further deepened our work with Atmel, Electric Imp and Econais.

Nevertheless what we find the most exciting in this massive change of the Internet of Things are the ingenious applications from makers and developers come up with the freemium accounts that we launched last time. Some of the examples are below:


And so we’ve decided to relaunch thethings.iO site to make it even easier for developers – and we’re talking about you here, whether you’re a maker looking to connect your first project with an Arduino, ESP8266, Electric Imp, Atmel WINC1500 or Raspberry Pi to the Internet, a creative technologist, bringing your latest prototype to life, an enterprise launching their first IoT project, or a professional thinking about how your products can become part of the Internet of Things – to connect their things.
For as little as € 1 per year, your things can become part of the IoT. You build fantastic products, and we connect them. So what are you waiting for? Head over to theThings.iO and start connecting.