We have already informed our readers that IBM Watson IoT platform will be discontinued sooner. We will gradually port our snippets for ESP32/Arduino to a generic MQTT platform to avoid this kind of issue in future.
As a user of the Watson IoT Platform (or as a new user) you need to know only two things to run on your server – Mosquitto and Node-RED. Thankfully a lot of work was done by IBM for MQTT. As we will use the server for production/final thing, we need to use a sub-domain, configure DNS and install a cert bot. Instead of Raspberry Pi, we are using the server:
Issue the following commands to get started :
---
1 2 3 4 5 6 7 8 9 10 | apt update -y && apt upgrade -y sudo add-apt-repository ppa:certbot/certbot sudo apt install certbot mosquitto mosquitto-clients # if ufw is installed then run these commands sudo ufw allow 80 sudo ufw allow 8883 sudo ufw allow 8083 sudo ufw allow 1880 # change the domain name sudo certbot certonly --standalone --preferred-challenges http -d mqtt.example.com |
I guess, you can follow the instructions to complete the certbot installation. Point DNS towards the server. Make sure that the name resolves. It may take 12 hours to 2 days to complete propagation (depending upon your location).
Proceed with the installation and configure Mosquitto MQTT :
1 2 3 | sudo mosquitto_passwd -c /etc/mosquitto/passwd your-username # enter password nano /etc/mosquitto/conf.d/default.conf |
Use this kind of configuration :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | allow_anonymousfalse password_file /etc/mosquitto/passwd listener 1883 localhost listener 8883 certfile /etc/letsencrypt/live/mqtt.example.com/cert.pem cafile /etc/letsencrypt/live/mqtt.example.com/chain.pem keyfile /etc/letsencrypt/live/mqtt.example.com/privkey.pem listener 8083 protocol websockets certfile /etc/letsencrypt/live/mqtt.example.com/cert.pem cafile /etc/letsencrypt/live/mqtt.example.com/chain.pem keyfile /etc/letsencrypt/live/mqtt.example.com/privkey.pem |
Restart the service, check it and set certificate renewal:
1 2 3 4 5 6 7 8 9 | systemctl restart mosquitto systemctl status mosquitto tail /var/log/mosquitto/mosquitto.log nano /etc/letsencrypt/renewal/mqtt.example.com.conf # add it renew_hook = systemctl restart mosquitto # check for errors certbot renew --dry-run |
Next, install the Paho javascript client or an Android app to check whether MQTT is working. Now install Node-RED:
1 2 3 | bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) # wait till installation completes node-red admin init |
Visit mqtt.example.com:1880 in a web browser to open and log in to the Node-RED admin panel. The above things were used on the IBM Watson IoT platform.