Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
feat: add BLE mqtt extension
Browse files Browse the repository at this point in the history
  • Loading branch information
guangbochen authored and Frank Mai committed Jun 22, 2020
1 parent 68b774b commit 7414998
Show file tree
Hide file tree
Showing 10 changed files with 1,243 additions and 50 deletions.
95 changes: 62 additions & 33 deletions adaptors/ble/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,66 @@ Grant permissions to Octopus as below:
bluetoothdevices.devices.edge.cattle.io/status [] [] [get patch update]
```

## BLE Device Parameters
## Example of BLE deviceLink YAML
```YAML
apiVersion: edge.cattle.io/v1alpha1
kind: DeviceLink
metadata:
name: xiaomi-temp-rs2201
spec:
adaptor:
node: edge-worker
name: adaptors.edge.cattle.io/ble
model:
apiVersion: "devices.edge.cattle.io/v1alpha1"
kind: "BluetoothDevice"
template:
metadata:
labels:
device: xiaomi-temp-rs2201
spec:
parameters:
syncInterval: 15s
timeout: 10s
extension:
mqtt:
client:
server: tcp://test.mosquitto.org:1883
message:
topic:
prefix: cattle.io/octopus
with: nn # namespace/name
protocol:
name: "MJ_HT_V1"
macAddress: ""
properties:
- name: data
description: XiaoMi temp sensor with temperature and humidity data
accessMode: NotifyOnly
visitor:
characteristicUUID: 226c000064764566756266734470666d
```
For more BLE deviceLink examples, please refer to the [deploy/e2e](./deploy/e2e/) directory.
## BLE Device Spec
Parameter | Description | Scheme | Required
--- | --- | --- | ---
parameters | Parameter of the opcua device| *[DeviceParamters](#deviceparamters) | false
protocol | Device protocol config | [DeviceProtocol](#deviceprotocol) | true
properties | Device properties | []*[DeviceProperty](#deviceproperty) | false
extension | Integrate with deivce MQTT extension | *[DeviceExtension](#deviceextension) | false
#### DeviceParamters
Parameter | Description | Scheme | Required
--- | --- | --- | ---
syncInterval | Device properties sync interval, default to `15s` | string | false
timeout | Device connection timeout, default to `10s` | string | false

### DeviceProtocol

Parameter | Description | Scheme | Required
--- | --- | --- | ---
name | Device name | string | NOT required when the device macAddress is provided
Expand All @@ -64,13 +116,15 @@ accessMode | Property accessMode | *[PropertyAccessMode](#propertyaccessmode) |
visitor | Property visitor | *[PropertyVisitor](#propertyvisitor) | true

### PropertyAccessMode

Parameter | Description | Scheme | Required
--- | --- | --- | ---
ReadOnly | Property access mode is read only | string | false
ReadWrite | Property access mode is read and write | string | false
NotifyOnly | Property access mode is notify only | string | false

### PropertyVisitor

Parameter | Description | Scheme | Required
--- | --- | --- | ---
characteristicUUID | Property UUID | string | true
Expand All @@ -79,6 +133,7 @@ dataWrite | Responsible for converting the data from the string into []byte that
dataConverter | Responsible for converting the data being read from the bluetooth device into string | *[BluetoothDataConverter](#bluetoothdataconverter) | false

### BluetoothDataConverter

Parameter | Description | Scheme | Required
--- | --- | --- | ---
startIndex | Specifies the start index of the incoming byte stream to be converted | int | true
Expand All @@ -88,48 +143,22 @@ shiftRight | Specifies the number of bits to shift right | int | false
orderOfOperations | Specifies in what order the operations | []*[BluetoothOperations](#BluetoothOperations) | false

### BluetoothOperations

Parameter | Description | Scheme | Required
--- | --- | --- | ---
operationType | Specifies the operation to be performed | *[BluetoothArithmeticOperationType](#bluetootharithmeticoperationtype) | true
operationValue | Specifies with what value the operation is to be performed | string | true

### BluetoothArithmeticOperationType

Parameter | Description | Scheme | Required
--- | --- | --- | ---
Add | Arithmetic operation of add | string | false
Subtract | Arithmetic operation of subtract | string | false
Multiply | Arithmetic operation of multiply | string | false
Divide | Arithmetic operation of divide | string | false

## Example of BLE deviceLink YAML
```YAML
apiVersion: edge.cattle.io/v1alpha1
kind: DeviceLink
metadata:
name: xiaomi-temp-rs2200
spec:
adaptor:
node: ubuntu
name: adaptors.edge.cattle.io/ble
parameters:
syncInterval: 30
timeout: 60
model:
apiVersion: "devices.edge.cattle.io/v1alpha1"
kind: "BluetoothDevice"
template:
metadata:
labels:
device: xiaomi-temp-rs2200
spec:
protocol:
name: "MJ_HT_V1"
macAddress: ""
properties:
- name: data
description: XiaoMi temp sensor with temperature and humidity data
accessMode: NotifyOnly
visitor:
characteristicUUID: 226c000064764566756266734470666d
```
For more BLE deviceLink examples, please refer to the [deploy/e2e](./deploy/e2e/) directory.
#### DeviceExtension

- reference the [example YAML](#example-of-ble-devicelink-yaml) of BLE device for MQTT integration.
- check [Integrate with MQTT Documentation](https://github.com/cnrancher/octopus/blob/master/docs/adaptors/integrate_with_mqtt.md) for more details.
26 changes: 22 additions & 4 deletions adaptors/ble/api/v1alpha1/bluetoothdevice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type BluetoothDeviceSpec struct {
// Specifies the properties of the BLE device.
// +optional
Properties []DeviceProperty `json:"properties,omitempty"`

// Specifies the extension of device.
// +optional
Extension *DeviceExtensionSpec `json:"extension,omitempty"`
}

type Parameters struct {
Expand All @@ -32,10 +36,18 @@ type Parameters struct {

// DeviceProperty defines an individual ble device property
type DeviceProperty struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
AccessMode PropertyAccessMode `json:"accessMode"`
Visitor PropertyVisitor `json:"visitor"`
// The device property name.
// +kubebuilder:validation:Required
Name string `json:"name"`
// The device property description.
// +optional
Description string `json:"description,omitempty"`
// Required: The URL for opc-ua server endpoint.
// +kubebuilder:validation:Required
AccessMode PropertyAccessMode `json:"accessMode"`
// PropertyVisitor represents the way to access the property.
// +optional
Visitor PropertyVisitor `json:"visitor"`
}

// DeviceProtocol defines how to connect the BLE device
Expand Down Expand Up @@ -87,6 +99,12 @@ const (

// BluetoothDeviceStatus defines the observed state of BluetoothDevice
type BluetoothDeviceStatus struct {
// Reports the extension of device.
// +optional
Extension *DeviceExtensionStatus `json:"extension,omitempty"`

// Reports the status of the BLE device.
// +optional
Properties []StatusProperties `json:"properties,omitempty"`
}

Expand Down
17 changes: 17 additions & 0 deletions adaptors/ble/api/v1alpha1/extension_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v1alpha1

import "github.com/rancher/octopus/pkg/mqtt/api/v1alpha1"

// DeviceExtensionSpec defines the desired state of device extension.
type DeviceExtensionSpec struct {
// Specifies the MQTT settings.
// +optional
MQTT *v1alpha1.MQTTOptionsSpec `json:"mqtt,omitempty"`
}

// DeviceExtensionStatus defines the observed state of device extension.
type DeviceExtensionStatus struct {
// Reports the MQTT settings.
// +optional
MQTT *v1alpha1.MQTTOptionsStatus `json:"mqtt,omitempty"`
}
51 changes: 51 additions & 0 deletions adaptors/ble/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7414998

Please sign in to comment.