# NCRL_MQTT [TOC] ## Server - Follow https://www.vultr.com/docs/install-mosquitto-mqtt-broker-on-ubuntu-20-04-server/ - Make IP open for everyone ```bash= $ cd /etc/mosquitto $ vim mosquitto.conf # 修改完後,重起服務 $ sudo systemctl status mosquitto ``` ![](https://i.imgur.com/TcaltVH.png =500x300) ## Client ### Client OS ubuntu 20.04 - Follow https://github.com/ika-rwth-aachen/mqtt_client ### Client OS not ubuntu 20.04 #### 1. Prerequisites - install docker ([reference](https://blog.gtwang.org/virtualization/ubuntu-linux-install-docker-tutorial/)) ```bash= For Linux : $ sudo apt-get install docker.io For Rpi : $ curl -fsSL https://get.docker.com/ | sh # 打完下面這行要logout $ sudo usermod -aG docker ${使用者名稱} ``` - download ncrl_mqtt repo ```bash= $ cd # download repo for docker usage $ git clone https://github.com/leeandy0822/ncrl_mqtt.git $ cd ncrl_mqtt # run docker $ source docker_run.sh #catkin_make and load env parameters $ source env.sh ``` ![](https://i.imgur.com/kMD5Y24.png) #### 2. 更改 broker host IP ```bash= $ roscd mqtt_client $ cd launch $ vim params.yaml ``` ![](https://i.imgur.com/Hpk3uPn.png =300x300) #### 3. Enable the mqtt_ros service ```bash= $ roslaunch mqtt_client standalone.launch ``` ![](https://i.imgur.com/OybHaeU.png) #### 4. Check the ros topics ![](https://i.imgur.com/hy7efYj.png =400x250) | ROS Input | MQTT | ROS_Output | | -------- | -------- | -------- | | /ping/ros | /pingpong/ros | /pong/ros | | /ping/primitive | /pingpong/primitive |/pong/primitive | ![](https://i.imgur.com/k3dDL9J.png) ## Authorization #### 1. broker 端新增 password file - move to /etc/mosquito ```bash= $ cd /etc/mosquito # 新增一個 password file $ sudo mosquitto_passwd -c <password file name> <name> # example $ sudo mosquitto_passwd -c password ncqq # 打密碼和確認密碼(這裡設定ee405423) $ vim password # username:log ``` ![](https://i.imgur.com/QQXcMoX.png) #### 2. 重啟 broker 端 server ```bash= $ sudo service mosquitto restart ``` #### 3. 所有 client 都要新增 password 設定 - 開啟 mqtt_client/launch/params.yaml ```bash= $ cd ws/src/mqtt_client/launch $ vim params.yaml # 在 broker 下面新增 user: 和 pass: # 帳號密碼要與上面password file 一致 ``` ![](https://i.imgur.com/byP0DmT.png =200x100)