Reader small image

You're reading from  Internet of Things with Arduino Cookbook

Product typeBook
Published inSep 2016
PublisherPackt
ISBN-139781785286582
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Marco Schwartz
Marco Schwartz
author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz

Right arrow

Chapter 3. Interacting with Web Services

In this chapter, we will cover:

  • Discovering the Temboo platform

  • Tweeting from an Arduino board

  • Posting updates on Facebook

  • Storing data on Google Drive

  • Automation with IFTTT

  • Sending push notifications

  • Sending text message notifications

  • Troubleshooting usual issues with web services

Introduction


Having an Arduino board that can easily be connected to the Internet allows many exciting applications, for example, by making the board communicate with existing web services.

In this chapter, we are going to learn how to use existing web services to really build amazing Internet of Things projects with our Arduino board. We'll, for example, use it to post on Facebook or Twitter, and to send automated notifications based on data measured by the board.

Discovering the Temboo platform


To interact with web services from the Arduino MKR1000 board, the easiest thing to do is to use a platform that will make the connection between the board and the web services themselves.

The first platform of this kind that we are going to use in this chapter is the Temboo platform, which was the platform recommended by Arduino when their first IoT product (the Arduino Yun) came out. We'll see how easy it is to create an account there and how to use it to connect to a lot of web services.

Getting ready

  1. The first step is to create a Temboo account. To do so, simply visit https://temboo.com/.

  2. You should then be able to create an account and log in:

  3. After that, you will be able to explore the Temboo libraries to interact with other web services, which are called Choreos:

  4. You can now click on a given Choreo to see what kinds of interactions are available. For example, this is the Disqus Choreo:

  5. For example, this is what you will see if you click on one possible interaction...

Tweeting from an Arduino board


In this recipe, we are going to learn how to use Temboo to tweet a message from your Arduino board. We are going to create an app on Twitter, and then see how to configure your Arduino board to send tweets from it.

Getting ready

  1. The first step is to create a Twitter account if that's not done yet, and then log in with this account at https://apps.twitter.com/.

  2. You will then be able to create a Twitter application:

  3. What matters is to get the application API key and app secret:

  4. You will also have to get the app access token and token secret:

How to do it...

Let's now see how to configure the Arduino board. You have two choices here: either do it from the Temboo interface, or simply grab the sketch from the GitHub repository of the project.

As Temboo does not officially support the MKR1000 board at the time of writing, I recommend getting the code from the GitHub repository of this book.

The Choreo we are going to use here is called statusesUpdate:

Let's now see how to...

Posting updates on Facebook


In this recipe, we are going to learn how to use Temboo again, this time to post an update on your Facebook feed.

Getting ready

  1. The first step is to create a Facebook application. To do so, go to https://developers.facebook.com/.

  2. You will then be able to name your app:

  3. Then you need to add the following line inside the settings of your app, replacing account_name with the name of your Temboo account:

  4. Now we need to authorize the use of this application by the Temboo servers. To do so, visit https://temboo.com/library/Library/Facebook/OAuth/InitializeOAuth/.

  5. Here you will need to insert the application ID, which can be found on the Facebook app page:

  6. Once that's done, you will need to visit a URL to authorize the app:

  7. Finally, after following all the steps from the Temboo website, you will be given your access token that will be used by the Arduino board to post on Facebook:

How to do it...

For the rest of this recipe, we'll use the Choreo at https://temboo.com/library/Library...

Automation with IFTTT


In the next few recipes of this book, we are going to use another website to interact with web services: IFTTT. We'll see how IFTTT will allow you to quickly define powerful automation rules and actions that can be triggered by the Arduino board.

Getting ready

The first step for all the remaining recipes of this chapter is to create an IFTTT account at https://ifttt.com.

From there, you will be able to explore the first important part of IFTTT: channels. Channels are all the web services or triggers that you can use within IFTTT, for example, Gmail, Twitter, Pushover, and so on. You can quickly have an overview of the available channels:

For example, if you type Weather, you can quickly add the weather channel, allowing you to trigger actions depending on the weather:

The next important part of IFTTT is recipes. Recipes allow the user to create an action (on a given channel) when a trigger is called (on another channel). This is really the core of IFTTT. You can also quickly...

Sending push notifications


In this recipe, we are going to see how to send push notifications from your Arduino boards, via IFTTT. As we are slowly discovering the IFTTT service, we are only going to build a simple alert system here.

Getting ready

To start, you need to connect to the Pushover channel, which is a service to send notifications to your mobile device. If you don't have a Pushover account yet, create one by downloading the app on your mobile device.

Then, add the channel inside IFTTT:

Next, we are going to need some sensors connected to your Arduino board. Please see the previous chapter to see how to connect a photocell and the DHT11 sensor to your Arduino board.

How to do it...

We are now going to create our first IFTTT recipe:

  1. Create a new recipe, and select the Maker channel as the trigger:

  2. Name the event alert:

  3. Next, select Pushover as the action channel:

  4. As for the notification, we'll simply name it Alert, and write the following message:

  5. You can now create the recipe that will appear...

Sending text message notifications


In this recipe, we'll continue using IFTTT, but this time we are going to see how to send data along with the trigger coming from the board. This will allow us to actually send data via IFTTT. To illustrate this, we'll send data right on your phone via text messages.

Getting ready

For this recipe, you will need to have your board connected to sensors just like in the previous recipe. You will also need to connect the SMS channel to your IFTTT account:

  1. Create a new recipe, and name the event text_data:

  2. After that, select SMS as the action channel:

  3. This time, we are actually going to send data with the request, and this data is available as Value1, Value2, and so on. Therefore, this is the message we are going to use:

  4. This is how the final recipe should look like:

How to do it...

Now, let's see how to configure the Arduino board. As the code is very similar to the one from the last recipe, I will only highlight the changes here.

Same as before, you need to enter your...

Storing data on Google Drive


In this last recipe of this chapter, we are going to see how to use our Arduino board and IFTTT to log measured data right on a Google Drive spreadsheet, so it can be accessed from anywhere in the world.

Getting ready

Before building this recipe, we need to connect the Google Drive channel to your account:

  1. You will simply need to log in to your Google account from IFTTT, authorize the app, and then you'll be able to see the Google Drive channel inside your IFTTT account:

  2. Now, create a new recipe, use the Maker channel as the trigger, and name the event google_data:

  3. As the action channel, choose Google Drive, and then select the Add row to spreadsheet action:

  4. Next, leave it as it is for the row to be appended to the spreadsheet, as it already contains all the data that we want to log:

  5. Finally, create the recipe, and check that it is activated.

How to do it...

We are now going to configure our Arduino board for this project. Again, as it is really similar to the last recipe...

Troubleshooting issues with web services


In this part of the chapter, we are going to see what can go wrong when using your Arduino board to interact with web services. Indeed, some of the steps involved here are quite complex and many things can go differently than expected.

Updates

The first thing that can happen is incorrectly entering your Twitter API keys or Facebook access token inside the Arduino sketch. Also make sure that you correctly entered the callback URL inside the Facebook app settings. Finally, make sure that you didn't reach the calls limit on Temboo.

No notifications are triggered

If you don't receive any notifications from IFTTT, either via push notifications or text messages, first check that you entered the correct Maker key for IFTTT inside the sketch, as well as the correct event name. Also check that the recipe is still marked as active on IFTTT. Finally, make sure that you are connected to the Internet with your Arduino board, and that the sensors connected to the board...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Internet of Things with Arduino Cookbook
Published in: Sep 2016Publisher: PacktISBN-13: 9781785286582
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz