Setting up a Low Cost SMQ IoT Broker

(How To Set Up an Environmentally Friendly IoT Solution)

Are you ready to build your own IoT cloud solution and connect thousands of devices? Our hands-on tutorial makes it easy to get started. While we tested this on a 64 MB Virtual Private Server (VPS), this low-end configuration is no longer available. However, the same principles apply to other VPS options, and you can easily scale up by selecting a VPS with more memory. In our tests, we successfully connected 10,000 devices using a 64 MB server, showcasing how efficient and scalable this solution can be, using fewer resources and helping to save the planet.

If you're familiar with connecting to a VPS using SSH and you're ready to get started installing your IoT cloud solution, feel free to scroll down to the script we have prepared that automates the process. However, if you're new to this process or you want a step-by-step guide, be sure to check out the video below. It will walk you through the process of setting up your IoT cloud solution and help you get up and running in no time.


Video 1: How to Install the IoT Solution on an Online VPS and How to use a Domain Name with the VPS

Note: The video above uses berry.pw as the VPS provider. Berry is no longer in business. See Beginner's Guide to VPS below for details.

Beginner's Guide to VPS

Setting up your own Virtual Private Server (VPS) may sound complicated and expensive, but the reality is that setting up a VPS is very easy and the cost can be minimal. Note that we are not affiliated with any VPS service provider. We only provide recommendations on how to install the server solution online. If you are new to VPS or if you want to know about alternatives, read the following section:

The following is meant to be a quick introduction and not an exhaustive guide to VPS technology. There are several types of VPN technology; the most common are KVM and OpenVZ. A KVM is full hardware virtualization, and you can run almost any operating system on a KVM, including Windows. A KVM is technically more difficult and challenging to set up than OpenVZ. A KVM also takes considerably longer to set up since the OS must be installed just as you would do on a regular computer. Our recommendation is to use OpenVZ since it is so easy to set up, it literary only takes seconds to set up an OpenVZ instance. OpenVZ supports Linux only, which just happens to be the best OS for the Mako Server when it comes to managing many (IoT) connections. OpenVZ functions similarly to container technology such as Docker, and the provider installs the kernel. You do not have the option of using your own selected kernel version when using OpenVZ.

Both KVM and OpenVZ share the same hardware. It is up to the discretion of the VPS service provider when it comes to how many instances they install on the actual hardware. Unfortunately, some providers tend to overstock the hardware, resulting in intermittent sluggishness or downtime. This is especially true of low-end providers. In most cases, a so called low end VPS is more than sufficient for running the Mako Server, but you need to make sure you select a provider that both looks to stay in business and does not overstock the hardware. You may select any VPS provider, and if you are looking for a budget VPS, you may be interested in joining LowEndSpirit.com, a community-driven site with information on how to use budget VPS providers successfully. However, keep in mind that many providers overstock the physical hardware. We have had great success with securedragon. For example, the SMQ High Availability IoT Cluster Example runs on two O64 OpenVZ powered securedragon powered VPSs.

KVM is best for professional use; OpenVZ is best for learning purposes.

Another factor to keep in mind is that KVM and OpenVZ instances are running on blade servers installed in large data centers. These data centers may host both budget VPS providers and much more expensive VPS providers. What we have observed is that if/when a VPS goes offline, it is in most cases not the VPS that went down but the datacenter's network that went down. That means if you select a more expensive provider, the VPS will still go offline if the data center's network goes down.

New to Linux?

If you're new to Linux and feel intimidated, don't worry! An online OpenVZ-powered VPS is the perfect place to learn the command line. Even if you make mistakes or get your VPS into a state that you can't recover from, the easy-to-use web-based VPS control interface allows you to restore the VPS to its original configuration with just the click of a button. This means you can safely play around and learn at your own pace without worrying about permanently damaging your VPS. If you do get stuck, just log into the VPS web control panel and click the re-install button - a fresh Linux VPS will be available within one to two minutes, giving you a chance to start over. So don't be afraid to dive in and start learning - an online VPS is a great way to get comfortable with command-line Linux.

Top VPS providers:

The web site LowEndSpirit.com is a great place to ask questions on (budget) VPSs.

Amazon, Google Cloud, Microsoft Azure, etc.

You may opt to install the IoT solution (using our installation script) on providers such as Amazon (AWS), Google Cloud, and Microsoft Azure. These providers provide free trial periods. However, note that setting up a VPS on these providers is technically much more challenging than setting up an OpenVZ VPS on providers listed on LowEndSpirit, such as securedragon. Both AWS and Google Cloud tout free lightweight tiers, and this may be an option since Mako Server is super light on resources. However, figuring out if the service can be free is difficult. In any event, you must provide credit card information when signing up, even for the free trial.

Getting Started

As mentioned earlier, you can set up a free test VPS using Amazon, Google Cloud, or Microsoft Azure. However, configuring these services can be more complex than using basic VPS providers. If you're looking for a free server, we recommend following our Oracle Free Tier Mako Server Tutorial, which provides a detailed guide on installing the server, but note that this is more complicated than the instructions provided below.

For a simpler, low-cost VPS setup, refer to the instructions below:

  1. Navigate to securedragon.net, click OpenVZ VPS, and select 256MB by clicking the Order Now button. Alternatively, select a VPS provider from the community rated list. You can sometimes get great deals.
  2. On the next page in the Wizard, select Billing Cycle, select VPS location, and select Debian or Ubuntu as the operating system.
  3. Complete the wizard.

You will receive an email sometime after signing up. The following shows an excerpt from such an email with details that you will need when configuring and installing software on the VPS.

Server Details ============================= Server Plan: O64 Main IP: 162.253.179.15 Root Password: https://securedragon.net/xxxxxx

Use the "Root Password" link to retrieve the VPS root password. You will need this password when connecting using SSH (explained below).

Setting up a Domain Name

When you sign up for a VPS service, you are assigned a dedicated IP address that uniquely identifies your online server. While you can access your VPS using this IP address, using a domain name is far more convenient and professional. In this guide, we’ll walk you through the steps to connect a domain name to your VPS’s IP address.

Tip: Freenom offers free domain names, but opting for a paid domain name is often more reliable and secure. If you already own a domain, you can use it or create a subdomain instead.

Freenom is a good choice if you are setting up a server for learning purposes. If you want to use Freenom, navigate to http://www.freenom.com, sign up, and select one of the free domain names. During the registration process, select Use DNS and enter the VPS IP address in the two fields. Select 12 month period and click Continue. Your VPS should now be accessible via the domain name you registered. Note that it may take up to 48 hours before it works.

If you did not set the DNS during the registration, do as follows:

  1. In the control panel, click Domain -> My Domains.
  2. Click on your domain and click Manage Domain
  3. Click Manage Freenom DNS. You should see the page below (Figure 2).
  4. Leave the name field blank and enter the IP address in the Target. 
  5. If you also want the server to be accessible as http://www.your-domain-name, go to the "Add Record" and add www in the Name field and the IP address in the Target field.

Figure 2: The two name records that make the server accessible with or without the www prefix

Installing the Mako Server

The Mako Server must be installed from a Linux console, and your VPS should be accessible via Secure Shell (SSH). To log in to the VPS, use the credentials provided in the email you received when signing up for the VPS service. If you're using Windows as your host operating system, you can install the Putty SSH client, but a better option is to utilize the Windows Subsystem for Linux (WSL) for a more seamless Linux experience.

Using SSH, enter the server's IP address (from the email you received). You can also use the new domain name if the DNS is ready. You can test this by pinging your domain name. If the DNS is ready, the ping command should respond with your server's IP address.

Figure 3: Running Putty on Windows and connecting to online VPS using the domain name simplemq.tk

At the login prompt, enter the username 'root' and the password you set for your VPS. Once logged in, you can proceed with installing the Mako Server. Before starting the installation, run the following commands to update your Linux system and install the necessary tools:

apt update
apt upgrade
apt install git lsof zip

The Mako Server and the SMQ LED example can be installed in two ways: automatically (by using a script we have prepared) or manually.

Installing Mako Server Automatically

The following script downloads and installs the Mako Server as a Linux Daemon. The script also downloads and installs the Xedge IDE for Mako Server and the SMQ LED Example's server-side code.

Note: The following command and script are tailored for Debian-based systems, such as Debian and Ubuntu. It uses package management commands that are incompatible with Red Hat-based systems like CentOS or Fedora. For Red Hat-based systems, consider following the manual installation instructions below.

Copy the following and paste it into the Linux console (Putty)

wget http://makoserver.net/install/brokerX86/install.sh; chmod +x install.sh; ./install.sh

Follow the installation prompts:

  • Select n when asked: Do you want to minify the JS and CSS files?

  • Enter a username and password for the server login.

  • Select y to install the Let's Encrypt plugin.

  • Enter the domain name you configured for your VPS and an email address as required by Let's Encrypt.

The server will be running when the installation script completes. Proceed by making sure everything is working.

Manual Installation

Installing the server manually will give you a deeper understanding of managing and installing software on an online VPS. Note that the following instructions do not include installation of the Xedge IDE, which is installed when using the automatic installation option above.

To manually install the Mako Server and configure the Mako Server, proceed to the tutorial Installing Mako Server as a Service on Linux and navigate back to this tutorial when you have completed the installation process.

When the server is installed, enter the following commands (or copy and paste) into the SSH terminal window (you must be running as root):

su mako; cd; cd www; wget http://makoserver.net/download/IoT-LED-Broker.tar.gz; tar xvzf IoT-LED-Broker.tar.gz; rm IoT-LED-Broker.tar.gz; exit; /etc/init.d/mako.sh restart;

The above commands download a prepackaged SMQ IoT Example Broker Setup (IoT-LED-Broker.tar.gz) and install the package in the 'www' directory.

Configuring and Testing the Online Server

After installing the server, navigate to the domain name you configured for the VPS's public IP address. You should see a link to the Xedge IDE if you selected the automatic installation option. Click this link and log in using the credentials you set during the server installation.

The next step is to create the SMQ IoT Example Broker Setup. The screenshot in the video below demonstrates how to create and configure this application. Click the video button below to watch a short introduction to the Xedge IDE.

To create the SMQ IoT Example Broker Setup, follow these steps:

  1. In the left pane, expand 'home', right-click 'www' , and select 'New App'.
  2. In the Application Configuration window:
    • Check 'Running', 'Auto Start', and 'LSP App'.
    • Clear the 'Directory Name' field and leave it blank to create an LSP root application.
  3. Click the 'Save' button.

The SMQ IoT Example Broker should now start and be ready to accept SMQ connections from devices. You can navigate to the root of your domain name (e.g., https://your-domain-name/) to access the SMQ LED user interface.

Tip: You may navigate back to the Xedge IDE's user interface by using any nonexisting URL. The Xedge IDE traps all non-existent access by installing a 404-not-found hook. Click any link to log in and log in using the credentials you set when installing the server.

Mount The Server as a Network Drive:

You should be able to directly work on the server's 'www' directory from your own computer as soon as the online server is installed.

Video 2: Mounting your online server as a network drive.

Your Web File Manager and WebDAV server URL: http://server-address/fs/


Connecting Edge Nodes (devices) to the SMQ Broker

We also recommend downloading the SMQ C client stack and LED example code from GitHub; then modify the example's C source code URL to point to your own domain name, compiling the example, and making sure you can connect the edge node example to your own server/broker.

Using the ESP32 Microcontroller as an Edge Device

If you prefer working with C code for your edge device, consider using the user-friendly SharkSSL IDE for ESP32 to connect your ESP32-powered devices to your cloud server. For those who aren’t C coders or want an even simpler way to get started, check out the tutorial Your First IoT Edge Device Project. This step-by-step guide walks you through setting up an ESP32 device using the Lua language, making it easier than ever to run device code and connect to your cloud server.

The tutorial Your First IoT Edge Device Project offers the simplest and most straightforward way to connect your devices to your cloud server.

See the SMQ source code page for additional language support, including Java and JavaScript.

Related SMQ IoT Articles

Posted in SimpleMQ

Seeking an Engineering Boost?

Don't let networking, security, and device management hold you back! Let Real Time Logic help your business, development team, or customers save time and money by handling these complex tasks for you.

With a wealth of experience creating IoT solutions and embedded device interfaces, we're well-equipped to dramatically improve your products and how you build them. And if you prefer to tackle things on your own, check out our extensive list of embedded web server and IoT tutorials.

Whether you choose to work with us or take the DIY route, we're here to help you succeed. Let's team up and make your vision a reality!



OPC-UA

OPC-UA Client & Server

An easy to use OPC UA stack that enables bridging of OPC-UA enabled industrial products with cloud services, IT, and HTML5 user interfaces.

Edge Controller

Edge Controller

Use our user programmable Edge-Controller as a tool to accelerate development of the next generation industrial edge products and to facilitate rapid IoT and IIoT development.

On-Premises IoT

On-Premises IoT Platform

Learn how to use the Barracuda App Server as your On-Premises IoT Foundation.

Embedded Web Server

Barracuda Embedded Web Server

The compact Web Server C library is included in the Barracuda App Server protocol suite but can also be used standalone.

WebSocket Server

Microcontroller Friendly

The tiny Minnow Server enables modern web server user interfaces to be used as the graphical front end for tiny microcontrollers. Make sure to check out the reference design and the Minnow Server design guide.

WebDAV Server

Network File System

Why use FTP when you can use your device as a secure network drive.

HTTP Client

Secure HTTP Client Library

PikeHTTP is a compact and secure HTTP client C library that greatly simplifies the design of HTTP/REST style apps in C or C++.

WebSocket Client

Microcontroller Friendly

The embedded WebSocket C library lets developers design tiny and secure IoT applications based on the WebSocket protocol.

SMTP Client

Secure Embedded SMTP Library

Send alarms and other notifications from any microcontroller powered product.

Crypto Library

RayCrypto C Library

The RayCrypto engine is an extremely small and fast embedded crypto library designed specifically for embedded resource-constrained devices.

Embedded PKI Service

Automatic SSL Certificate Management for Devices

Real Time Logic's SharkTrust™ service is an automatic Public Key Infrastructure (PKI) solution for products containing an Embedded Web Server.

Modbus

Modbus TCP client

The Modbus client enables bridging of Modbus enabled industrial products with modern IoT devices and HTML5 powered HMIs.