Running MQTT & Node-RED on DigitalOcean VPS (updated: 23 Feb 2017, 14:23:44)

How to create own server with MQTT and Node-RED. 3 month for 5$

1. Go to DigitalOcean and Sign up for a Digital Ocean account for simply enter your email and password.

2. After registration, login your DigitalOcean account and confirm your email address.
3. Update your billing profile and deposit a $5 via paypal or credit card to your Digital Ocean account, the totally $15 is going to become available and it can be bought a 3 months vps cloud hosting.
4. Now you can create Droplet/Server, click Create Droplet button in the upper right hand corner of the page.

5. Select Debian and size 5$/mo, choose suitable region.

6. Finally click create.

7. After ~55 seconds our new clean VPS ready for use. IP Address/Username/Password will be sent to your email address. After that we need some SSH client (Windows users - PuTTY) for further steps.
8. Connect with SSH Client to the Server
login as: root
You are required to change your password immediately (root enforced)

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Apr 26 11:12:43 2016 from
Changing password for root.
Retype new UNIX password: [YOUR NEW STRONG PASSWORD]
9. Initial work done! Congratulations!
10. Mosquitto MQTT Broker setup: 

DigitalOcean (Debian 8 x86_64)!

root@debian-512mb-ams3-01:~# wget && apt-key add mosquitto-repo.gpg.key
root@debian-512mb-ams3-01:~# cd /etc/apt/sources.list.d/ && wget && cd
root@debian-512mb-ams3-01:~# apt-get update && apt-get install mosquitto
Do you want to continue? [Y/n]
[Mosquitto installed!]
root@debian-512mb-ams3-01:~# cd /etc/mosquitto && nano acl.conf
[Paste this two lines]:
pattern read #
pattern write %u/#
[Click Ctrl + O, Enter, Ctrl + X]

root@debian-512mb-ams3-01:/etc/mosquitto# touch password.conf
root@debian-512mb-ams3-01:/etc/mosquitto# cd conf.d/
root@debian-512mb-ams3-01:/etc/mosquitto/conf.d# nano my.conf
[Paste this]:
acl_file /etc/mosquitto/acl.conf
allow_anonymous false
password_file /etc/mosquitto/password.conf
[Click Ctrl + O, Enter, Ctrl + X]

[username - Your username for authentication on MQTT broker, password - for authentication on MQTT broker]
root@debian-512mb-ams3-01:/etc/mosquitto/conf.d# cd && mosquitto_passwd -b password.conf [username] [password]
root@debian-512mb-ams3-01:/etc/mosquitto# /etc/init.d/mosquitto restart && cd

[Congratulations Mosquitto MQTT broker setup is done and it is ready for use]
[Example commands for publishing and subscribing on your MQTT broker]:

[Subscribe to all topics on broker]:
root@debian-512mb-ams3-01~:# mosquitto_sub -u [user] -P [password] -t '#' -v

[Publishing some message (in another SSH connection), root of the topic must be your username]:
root@debian-512mb-ams3-01~:# mosquitto_pub -t [user]/foo/bar -m 'foobar hello mqtt' -u [user] -P [password]
11. How to use with Wifi-IoT firmware:

Period: 10
Server: [Your DigitalOcean VPS IP Address same as SSH]
Port: 1883
User: [Your MQTT broker username]
Passw: [Your MQTT broker password]

[After ~10 sec you can see in SSH client window where you started "subscribe all topics cmd" messages from your module]

12. Installing Node-RED visual tool for wiring the Internet of Things
curl -sL | sudo -E bash -
apt-get install -y nodejs
npm install -g npm@3.x
hash -r
npm cache clean
npm install -g --unsafe-perm node-red
npm install -g pm2
cd /root
pm2 start /usr/bin/node-red --node-args="--max-old-space-size=128" -- -v
pm2 save
pm2 startup

[Node-RED setup done, open your browser http://[server ip address]:1880/]

Now you can start wiring your Internet of Things! Congratulations!