---
# System prepended metadata

title: EdgeX Setting

---

# EdgeX Setting

## MQTT device service
### Topic Setting
```
root@pe100a: cd /etc/EdgeX/res/mqtt-device
root@pe100a: vim ./configuration.toml

---configuration.toml---

[MQTTBrokerInfo]
...
# Comment out/remove when using multi-level topics
IncomingTopic = "F0B5D1A49D180000/STREAMING" #default "IncomingTopic" EdgeX sub IncomingTopic 接收資料
ResponseTopic = "ResponseTopic" #EdgeX sub ResponseTopic 接收下完Command後的回傳的資料

```

* Command Topic
    EdgeX Pub Command Topic 對 Sensor 下指令
* 設定方法有兩種
    1.透過 UI ：
    EdgeX service開啟,透過瀏覽器輸入 `http://{PE100A IP}:4000/#/metadata/device-center/device-list`,勾選 device並且按下 "Edit"
    ![](https://i.imgur.com/PeSjqVQ.png)
    
    PropertyValue:填入你要更改的Command(beandevice: {deviceid}/OTAC)
    ![](https://i.imgur.com/frCpwXC.png)


    2.Confing.toml
    ```
    root@pe100a: cd /etc/EdgeX/custom-config/devices
    root@pe100a: vim ./my.custom.device.config.toml
    
    ---my.custom.device.config.toml---
    
    # Pre-define Devices
    [[DeviceList]]
      Name = "my-custom-device"
      ProfileName = "my-custom-device-profile"
      Description = "MQTT device is created for test purpose"
      Labels = [ "MQTT", "test" ]
      [DeviceList.Protocols]
        [DeviceList.Protocols.mqtt]
           CommandTopic = "CommandTopic" #填入你要更改的Command(beandevice: {deviceid}/OTAC)
       
    ```
* 除了 UI , 只要有動到config檔，記得重啟service
```
root@pe100a: systemctl restart EdgeX

```

### IP Setting
* mqtt broker IP 依據 PE100A 的 Local IP
* pub sample code for python
```
import paho.mqtt.client as mqtt
import json  


# 連線設定
# 初始化地端程式
client = mqtt.Client()

# 設定登入帳號密碼
#client.username_pw_set("try","xxxx")

# 設定連線資訊(IP, Port, 連線時間) 記得更改local ip
client.connect("192.168.1.101", 1883, 60)

payload = {'name' : "my-custom-device" , 'cmd' : "randnum" , 'randnum' : 1.2}

# #要發布的主題和內容
client.publish("IncomingTopic", json.dumps(payload))

```
* 若pub成功,可以在 UI 看到資料,點選 Events,進入後按下 "Start"

![](https://i.imgur.com/eBNHqal.png)


## Check docker ps
* 確認 EdgeX service 是否都有啟動,正確啟動如下:
```
root@pe100a: docker ps
```
![](https://i.imgur.com/i1q1wqy.png)
* 若沒有出現,可能的問題:
    * docker 沒有啟動 docker-compose: 啟動 service
        `
        root@pe100a: systemctl start EdgeX
        `
        `
        root@pe100a: systemctl status EdgeX #確認是否有在 running
        `
    * docker container 沒有啟動: 查看 log
        `
        root@pe100a: docker ps -a #確認docker container 沒有啟動
        `
        `
        root@pe100a: docker logs edgex-mqtt-broker(更換要查詢的container)
        `
## Schedule 
* 為了防止core data資料無限肥大,要在EdgeX設定排程固定時間清理資料


## SSH PE100A
* 目前 PE100A 都能透過 SSH remote
```
# ssh root@{PE100A IP} 
密碼: asus
```
> [提供ssh 設定網址](https://serverpilot.io/docs/how-to-enable-ssh-password-authentication/)