參考:NCRL_MQTT
首先查詢自己外網ip,交大都是(140.113.X.X):
$ cd /etc/mosquitto/config.d/
$ sudo vim default.conf
寫完 default.conf 後重啟 mosquitto 服務
$ sudo systemctl restart mosquitto.service
首先查詢內網ip (192.168.X.X):
登入路由器做port fowarding:
設定完路由器設定 mosquitto
$ cd /etc/mosquitto/config.d/
$ sudo vim default.conf
寫完 default.conf 後重啟 mosquitto 服務
$ sudo systemctl restart mosquitto.service
For Linux : $ sudo apt-get install docker.io
For Rpi : $ curl -fsSL https://get.docker.com/ | sh
# 打完下面這行要logout
$ sudo usermod -aG docker ${使用者名稱}
$ 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
$ cd /etc/mosquito
# 新增一個 password file
$ sudo mosquitto_passwd -c <password file name> <name>
# example
$ sudo mosquitto_passwd -c password ncqq
# 打密碼和確認密碼
$ vim password
# username:log
$ sudo vim acl
$ sudo service mosquitto restart
$ cd ws/src/mqtt_client/config
$ vim params.yaml
# 在 broker 下面新增 user: <name> 和 pass: <password>並打上
帳號密碼要用在broker設定好的
以下為實驗室例子:
啟動mqtt_client以讀取數據,每個client都要打
$ roslaunch mqtt_client standalone.launch
可以用以下方式檢查是否能成功讀取
ROS Input | MQTT | ROS Output |
---|---|---|
/ping/ros | pingpong/ros | /pong/ros |
$ rostopic pub -r 1 /ping/ros geometry_msgs/Point "x: 3.0
y: 3.0
z: 3.0"
$ rostopic echo /pong/ros
我們的樹梅派連接dongle,因為要再不同網域下ssh連到樹梅派有點麻煩,所以使用較簡單的方法,在開啟時同時啟動mqtt和mavros
$ cd catkin_ws/src/mqtt_client/launch
$ vim launch_both.launch
$ sudo apt install ros-noetic-robot-upstart
$ rosrun robot_upstart install --master "http://localhost:11311" --setup /home/ubuntu/formation_ws/devel/setup.bash mqtt_client/launch/launch_both.launch --job upstart_test --symlink
設定MQTT參數:
$ cd catkin_ws/src/mqtt_client
$ vim parmas.yaml
可以選其他topic與mqtt連接
重啟mqtt_client服務:
$ sudo service upstart_test restart
設定MQTT參數:
$ cd catkin_ws/src/mqtt_client
$ vim parmas.yaml
啟動mqtt_client以讀取數據
$ roslaunch mqtt_client standalone.launch
在終端機開啟其他分頁,並輸入想要看得topic,例如:
$ rostopic echo /mavros/state
將mqtt與ros的橋架好後即可做數值讀取, 飛控
部分文章直接引用實驗室內容 https://hackmd.io/_ktvIEz5S4-YAGB62iy8Yw?view
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing