Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Setting Up Your Own Arduino IoT Cloud Server

DZone's Guide to

Setting Up Your Own Arduino IoT Cloud Server

Want to get your IoT project working in the cloud? Not a problem. Follow along this guide to get your own virtual private server up and running to support your IoT work.

· IoT Zone
Free Resource

If you have had a chance to play around with some of the new Arduino-enabled hardware platforms such as the ESP8266 Wi-Fi SoC, you may already have used an online IoT service for your project. In this article, we will show you how to setup your own online service by setting up a Virtual Private Server (VPS) and server software for your Arduino IoT project.

In addition to setting up your own VPS, we will show you how to install a simple example that lets you control LEDs, lights, etc., by using a browser. The following figure shows how any number of devices can be controlled in real time by navigating to your own VPS using a browser. The online VPS functions as a proxy and makes it possible for any number of users to control the devices via the online server.

VPS for Arduino

Some of the benefits of using an online server and operating it as a proxy for routing messages between users and the devices are:

  • Enables users on one network to control devices on another network. For example, a device connected to a home network can be controlled via a Smartphone connected to the cellular network.

  • Devices operate as network (TCP/IP) clients, thus no router port forwarding or other tricks are required for gaining access to the devices via the online server.

  • Devices acting as network clients operate in stealth mode, thus greatly improving the security of the devices. We will get more into security later.

  • Small devices typically do not have the resources for providing a direct web interface. The online server manages all the heavy lifting of providing a web interface for the devices, thus greatly minimizing the code complexity in the devices.

Virtual Private Server

Setting up your own VPS may sound complicated and expensive, but the reality is that setting up a VPS is very easy and the cost can be minimal. It is possible to find VPS services as low as $8 a year. My favorite site for shopping for a budget VPS is lowendbox.com and one of my favorite VPS providers is securedragon, where you can get a three-month lease for less than $6 and a yearly lease for $12.

Memory Limitation

A limitation with a budget VPS is the amount of memory available. The budget VPS we are using in this article has only 64Mbyte of memory, thus limiting the selection of IoT server solutions that can be used. The IoT solution we will use in this article is an application server framework that includes an IoT protocol, a web server, a server side scripting language, and a database in one unit. This software package can easily run on a budget VPS, and in my test environment, I was able to connect 10,000 devices to the online server. I performed the test by using a number of additional Virtual Private Servers, where I ran a number of simulated devices.

Linux

A budget VPS will be running Linux. If you have never used Linux, you may think that this is not for you; however, nothing can be further from the truth. An online VPS is the best starting point for anyone new to learning command line Linux because no matter what you do with the VPS, an easy to use web based VPS control interface will let you restore the VPS to its original configuration by a button click. For this reason, playing around with an online VPS is a great way to learn command line Linux. If you get your Linux VPS into a state where you are unable to recover it, log into the VPS web control panel and click the re-install button. A fresh Linux VPS will then be available in one to two minutes, and you can start over.

Remote Login via SSH

An online VPS enables you to remotely login by using SSH (Secure Shell). If your own computer is running Windows, download the SSH client Putty, and start the executable from any directory. Mac and Windows computers typically include a command line SSH client, thus you can simply type ssh in a command line on Linux and Mac.

When you sign up for a VPS service, such as the budget securedragon VPS (O64), you will receive an email with instructions for how to remotely log into your VPS by using SSH. The instructions include the IP address of your new VPS and the root (admin) password. The following figure shows how to enter the IP address in Putty and how to login as user root in the command line window.

SSH VPS

At this point, feel free to try a few Linux commands. Don't worry about corrupting the VPS since a simple button click in the VPS control panel will re-install the Linux operating system.

Installing the IoT Server

Before installing the server software, I recommend re-installing the Linux operating system by using the VPS control panel if you have made any modifications to the Linux operating system running on the VPS.

To install the server software and the example program, copy all of the following and paste the commands into the SSH console window.

 source <(wget -q -O- http://makoserver.net/install/brokerX86/install.sh) 

The following short video shows the complete installation sequence, from logging into the VPS, installing the software, and verifying that it works by using a browser. 

Downloading and Compiling the Arduino Sketch

The Arduino example has been tested on an Arduino compatible ESP8266 WiFi. However, you should be able to use any Arduino with only minor changes to the startup code.

Download and unpack the Arduino Sketch in any directory https://simplemq.com/downloads/SMQ-Arduino.zip

Open the sketch file SMQ.ino in your Arduino IDE and scroll down until you see:

#error REMOVE THIS LINE AND SET THE TWO VARIABLES BELOW
static const char* ssid = "";
static const char* password = "";

Remove the first line above and set variable 'ssid' to your wireless network ID and 'password' to your wireless password.

Open the file led-example.cpp and scroll down until you see:

#define SIMPLEMQ_DOMAIN "http://simplemq.com"

Change the domain name "simplemq.com" to the IP address of your VPS.

Compile and upload the sketch file to your Arduino board. If everything goes as it should, the Arduino device should show up in the web interface. You get to the web interface by using a browser and navigating to your VPS IP address.

The following video shows how to compile the Arduino sketch, how to upload the sketch to the Arduino board, and how to control the board using a web browser.

The above is all you need for setting up an online server that you can use for controlling your Arduino devices in real time by using a browser. The complete application can be used "as is" for controlling anything that provides an on/off state such as LEDs, lights, motors, etc.. The complete application consists of two parts: (1) A JavaScript powered web application running in your browser and that is connected to the online server. (2) the Arduino code running on the Arduino board and that is also connected to the online server. The online server acts as a generic proxy and routes messages between devices and browsers.

The IoT protocol used in this application is called SMQ, which provides one-to-one communication (via the online proxy) in addition to the publish/subscribe pattern. The publish/subscribe (pub/sub) feature in SMQ is similar to other pub/sub protocols such as MQTT and AMQP. An online proxy server is typically referred to as a broker when using pub/sub protocols. The broker is in charge of routing messages between publishers and subscribers. A detailed explanation of how the JavaScript application and the Arduino code work can be found here.

IoT Security

I recently published an article on IoT security that includes security related to pub/sub protocols, such as the SMQ protocol. I recommend reading this article since some pub/sub protocols can be risky to use in their default state. Although the LED/Light-Controller application used in this article does not use password authentication, it is still fairly secure since the SMQ broker cannot easily be detected and SMQ does not allow wildcard subscription. See the IoT security article for details. As a coding exercise, you may add authentication to the LED/Light-Controller app.

Topics:
arduino ,iot app development ,vps ,iot

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}