• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » How to Run Your Own IoT Cloud on a VPS

By Abhishek Ghosh March 25, 2021 10:03 am Updated on March 25, 2021

How to Run Your Own IoT Cloud on a VPS

Advertisement

There are many reasons why some of the users do not like commercial IoT platforms such as IBM Watson IoT for simple works like that of controlling light, motor and other simple electrical devices. If we take IBM Watson IoT as an example commercial platform, just to use ESP32 Arduino, you have to depend on the peoples of the community like us. You have to check our sample projects such as ESP32-IBM-Watson-IoT-Example and adapt for your need. Unlike the vanilla MQTT installation, you are restricted to easily use any Android app for the MQTT dashboard. Unfortunately, there are too many commercial IoT platforms and the number of makers for the IoT segment is not huge in number. Official documentation of IBM Watson IoT is not easy to understand after reading once by a newbie. The second problem is the cost. Commercial IoT platforms are great within the free usage tier. They are super costly when you want to implement your system for your whole house. Keep in mind, IBM uses mostly open-source things. The situation goes worse with many other platforms.

So, for making a bunch of switches smart, you probably should run an MQTT broker on a VPS. If your code once, you’ll not need to modify the code for many years. I must warn you – this is not easy work. As we have mentioned before on this website, on lowendbox.com you’ll get reviews of low-cost Virtual Private Servers with 64MB or more RAM at less than $1/month running cost. You’ll get free domain name somewhere on this internet (or just use a sub-domain of your existing TLD), free Let’s Encrypt is more than enough to secure the connection.

You can use the original Mosquitto, Mosquitto client, Paho for web GUI, Node-RED for simplified flow-based programming. These are the basic packages behind IBM Watson IoT.

Advertisement

---

In this article, we are providing you with the basic steps to install Mosquitto and Mosquitto client. Installation is just easy :

Vim
1
sudo apt-get install mosquitto mosquitto-clients

Test it by publishing a message :

Vim
1
mosquitto_pub -h localhost -t test -m "hello world"

Subscribe has a similar command :

Vim
1
mosquitto_sub -h localhost -t test

We have to create a default configuration file. As the first step, create a user with a password :

Vim
1
sudo mosquitto_passwd -c /etc/mosquitto/passwd abhishek

Now, create the configuration file :

Vim
1
sudo nano /etc/mosquitto/conf.d/default.conf

Paste these three lines :

Vim
1
2
3
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883

Save it and reload Mosquitto :

Vim
1
sudo systemctl restart mosquitto

Now, if you run the above command to publish a message, it will be rejected :

Vim
1
mosquitto_pub -h localhost -t test -m "hello world"

You have to run the command with username and password (P is capital) :

Vim
1
mosquitto_pub -h ip.address -t "test" -m "hello world" -u "abhishek" -P "password"

If you can run the above command without facing an error, you are done completing a basic setup.

How to Run Your Own IoT Cloud on a VPS

Here is a sample sketch for ESP32 Arduino to test the thing :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <WiFi.h>
#include <PubSubClient.h>
 
 
// Update these with values suitable for your network.
const char* ssid = "paste-here";
const char* password = "paste-here";
const char* mqtt_server = "paste-here";
#define mqtt_port 1883
#define MQTT_USER "abhishek"
#define MQTT_PASSWORD "password"
#define MQTT_SERIAL_PUBLISH_CH "/example/ESP32/serialdata/tx"
#define MQTT_SERIAL_RECEIVER_CH "/example/ESP32/serialdata/rx"
 
WiFiClient wifiClient;
 
PubSubClient client(wifiClient);
 
void setup_wifi() {
    delay(10);
    // We start by connecting to a WiFi network
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }
    randomSeed(micros());
    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
}
 
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "ESP32Client-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
    if (client.connect(clientId.c_str(),MQTT_USER,MQTT_PASSWORD)) {
      Serial.println("connected");
      //Once connected, publish an announcement...
      client.publish("/example/ESP32/serialdata/messages", "hello world");
      // ... and resubscribe
      client.subscribe(MQTT_SERIAL_RECEIVER_CH);
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}
 
void callback(char* topic, byte *payload, unsigned int length) {
    Serial.println("-------new message from broker-----");
    Serial.print("channel:");
    Serial.println(topic);
    Serial.print("data:");  
    Serial.write(payload, length);
    Serial.println();
}
 
void setup() {
  Serial.begin(115200);
  Serial.setTimeout(500);// Set time out for
  setup_wifi();
  client.setServer(mqtt_server, mqtt_port);
  client.setCallback(callback);
  reconnect();
}
 
void publishSerialData(char *serialData){
  if (!client.connected()) {
    reconnect();
  }
  client.publish(MQTT_SERIAL_PUBLISH_CH, serialData);
}
void loop() {
   client.loop();
   if (Serial.available() > 0) {
     char mun[501];
     memset(mun,0, 501);
     Serial.readBytesUntil( '\n',mun,500);
     publishSerialData(mun);
   }
}

If you complete the total thing without facing any error, then try some MQTT Dashboard App for Android. You have to read the MQTT documentation for commands, install a web GUI like Paho.

Tagged With vps netcup howto language:en

This Article Has Been Shared 399 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to How to Run Your Own IoT Cloud on a VPS

  • Cisco Cloud Services : Solutions and Deployment

    Cisco Cloud Services has taken the way of its family of telecommunication services, large companies and retailers to help them deliver solutions as a service.

  • Installing WordPress on Debian Rackspace Cloud Server

    Installing WordPress on Debian Rackspace Cloud Server is a detailed text plus video guide explaining the commands for each steps and the advantage of symlinks.

  • Enable Nginx PHP-FPM Status Page (Ubuntu, HP Cloud)

    Here is How To Enable Nginx PHP-FPM Status Page on Ubuntu Server Instance Running on HP Cloud. Enabling Ping Has Difference With Enabling Status.

  • What is iPaaS?

    What is iPaaS We Recently Read About? iPaaS is special group of cloud service for the delivery of systems integration to address SOA, EAI, Data and more.

  • HP Cloud Automation Services on HP Helion Public Cloud

    HP Helion Cloud is Not Limited By Launching Instances. Here is Introduction to Integrate the HP Cloud Automation Services via Various Images.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is ChatGPT? February 3, 2023
  • Zebronics Pixaplay 16 : Entry Level Movie Projector Review February 2, 2023
  • What is Voice User Interface (VUI) January 31, 2023
  • Proxy Server: Design Pattern in Programming January 30, 2023
  • Cyberpunk Aesthetics: What’s in it Special January 27, 2023

About This Article

Cite this article as: Abhishek Ghosh, "How to Run Your Own IoT Cloud on a VPS," in The Customize Windows, March 25, 2021, February 5, 2023, https://thecustomizewindows.com/2021/03/how-to-run-your-own-iot-cloud-on-a-vps/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT