Setting Up Your Own Arduino IoT Cloud Server
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.
Join the DZone community and get the full member experience.Join For Free
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.
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.
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.
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.
The following video shows how to setup an online Linux IoT server.
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.
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:
The following video shows how to compile the code and upload the code to the ESP8266
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 Arduino environment is great for beginners, but Arduino is very limited in it's functionality. Instead of using Arduino you may also use a ready to use FreeRTOS environment called the esp-open-rtos, but don't worry, you do not need to go through the complex esp-open-rtos setup. Instead, you may use a pre-configured and completely ready to use environment with an easy to use web based IDE. The web based IDE is great for Arduino users that are accustomed to the easy to use Arduino IDE.
Navigate to RTL and download the free ESP8266 IDE.
The IDE, which is designed for educational purposes, includes a pre-configured esp-open-rtos bundled with an easy to use web based C source code IDE. The IDE requires VmWare or VirtualBox. I prefer VmWare over VirtualBox, since I find it easier to use. Note that VmWare is free for non commercial use.
The screenshot below shows the virtual machine and the web based IDE connected to the virtual machine. Notice how the virtual machine has taken ownership of the ESP8266 USB connection. The web based IDE detects this and shows the ESP8266 as connected and ready to be flashed with new firmware.
Note that the IP address of your VM will most likely be different than in the above figure. Make sure to click in the virtual machine window for the IP address. If the window is blank, click the window and then press the enter key. You must enter this IP address in your browser to open the web IDE.
Opinions expressed by DZone contributors are their own.