Запускаем MQTT & Node-RED на DigitalOcean VPS (обновлено: 23 Feb 2017, 13:23:44)

Как создать свой собственный облачный сервер с MQTT и Node-RED. 3 месяца за 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
root@178.62.198.242's password: [PASSWORD FROM EMAIL MESSAGE]
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 36-197-190-90.dyn.estpak.ee
Changing password for root.
(current) UNIX password: [PASSWORD FROM EMAIL MESSAGE]
Enter new UNIX password: [YOUR NEW STRONG PASSWORD]
Retype new UNIX password: [YOUR NEW STRONG PASSWORD]
root@debian-512mb-ams3-01:~#
9. Initial work done! Congratulations!
10. Mosquitto MQTT Broker setup: 

DigitalOcean (Debian 8 x86_64)!

root@debian-512mb-ams3-01:~# wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key && apt-key add mosquitto-repo.gpg.key
...
OK
root@debian-512mb-ams3-01:~# cd /etc/apt/sources.list.d/ && wget http://repo.mosquitto.org/debian/mosquitto-jessie.list && cd
root@debian-512mb-ams3-01:~# apt-get update && apt-get install mosquitto
...
Do you want to continue? [Y/n]
[Y]
...
[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
[Note: During the install some errors may be reported, these are typically non-fatal errors]
root@debian-512mb-ams3-01~:# apt-get install npm
root@debian-512mb-ams3-01~:# npm install -g npm@2.x
root@debian-512mb-ams3-01~:# npm install -g node-gyp
root@debian-512mb-ams3-01~:# apt-get install nodejs-legacy
root@debian-512mb-ams3-01~:# npm install -g node-red
root@debian-512mb-ams3-01~:# npm install -g pm2
root@debian-512mb-ams3-01~:# pm2 start /usr/local/bin/node-red -- -v
root@debian-512mb-ams3-01~:# pm2 save
root@debian-512mb-ams3-01~:# pm2 startup

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

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