---
# System prepended metadata

title: BLE Device Service
tags: [Edgex]

---

# BLE Device Service
[TOC]
### 用戶的角度
1. 設定需要拿到資料的時間 ex: AM8.00 - PM8.00 其餘時間不收資料
2. 設定config
3. Read device data
4. 知道data所代表的欄位


#### 流程

在UI上設定好device的config -> 開啟device service -> 讀到想要的data

### 開發的角度
### Library
[go-bluetooth](https://github.com/muka/go-bluetooth)

#### 流程
在UI設定好device的config -> Service Start -> 讀config -> Scan Device -> 收data -> 讀取data欄位 -> 上傳資料 -> Service Stop
#### Device Service 功能
1. Start
2. Stop
3. Collect Data
4. Save Data to Core-data
6. Read Config from consul
7. Scan Device
8. Trigger Device
9. Data Process to each column

#### Configuration
MAC address
scan interval time
upload data frequency


## Application Service

1. read config
2. according config set pipeline function
3. listen to event from message bus ( or Core data)
4. data process to expected payload
5. upload data to cloud
6. send monitor event to agent


### Config
upload frequency
upload size per packet
resource url (/event/resource)
resource column
cloud database endpoint


## 程式

用 application template or not?
優缺點
大致上可以沿用 除了input的部分 原本是從messageBus 變成ble

driver.go
#### Application Template
proccessor :
    input -> cache -> process
    
input : poll subscribe
process : immediate, interval
    
![image](https://hackmd.io/_uploads/SJrkH1H9p.png)




### BLE Device Service Configuration

1. protocol ble : Macaddress
2. ble profile : including manufacturerData's symbol offset
3. autoevent time
4. bluetooth scan interval time


device.yaml : macaddress, profileName, autoEvents
profile.yaml : resourceName, RW, dataType
configuration : bluetooth scan interval time