The widget allowing device configuration through Bluetooth. You can scan for nearby Bluetooth devices, select one of the discovered ones, and then change the characteristics you have defined in the template, for instance, the access to the home WIFI (SSID and password).
Scan for Devices
Select Device
Configure Device
Custom Update Logic
To convert specific configuration needs you can define JavaScript functions that are called during the widget usage.
Writer Function
This JavaScript function is called each time a characteristic must be written. In this way, you can implement your custom write login, for instance by transforming the value to write, or by splitting it among multiple calls.
var bleCustomWrite = function(device, characteristic, value, widget) {
return new Promise((resolve, reject) => {
console.log(device);
console.log(characteristic);
console.log(value);
resolve();
});
};
See the Writer Function property on each characteristic.
Update Callback
This JavaScript function is called after the Update button is pressed, so you can implement you custom post-update logic, for instance by calling an external service API, or by setting another characteristic to reboot the device or similar.
var bleCustomUpdate = function(device, context, widget) {
return new Promise((resolve, reject) => {
console.log("UPDATED");
console.log(device);
resolve();
});
};
See the Update Callback property on the widget.
Template Syntax
Below you can find some examples of how to use the component within a template.
<bluetooth-configuration-widget [title]="'WIFI Configuration'"
[config]="{statusService: '61fe', statusCharacteristic: '03ed06ef', pin: '12345'}">
<property label="WIFI SSID" [config]="{service: '61fe', uuid: '16e009ba', mode: 'WRITE', editable: true}"></property>
<property label="WIFI Password" [config]="{service: '61fe', uuid: '16e009bb', mode: 'WRITE', editable: true}"></property>
<property label="Serial Number" [config]="{service: '61fe', uuid: '16e009aa' mode : 'READ', editable: false"></property>
</bluetooth-configuration-widget>
Component Reference
Here is a comprehensive list of all the elements and properties that can be used to configure the component.
Bluetooth Configuration <bluetooth-configuration-widget> | |
---|---|
PROPERTIES | |
CSS Class | The name(s) of the CSS class used to customize the widget layout. |
Debug Mode | The flag to enable BLE debugging that displays additional icons to access the BLE device and characteristic details of read or write errors. true false
|
PIN | The optional PIN used to access the device. |
Status Characteristic UUID | The UUID of the characteristic that provides the state of the device. |
Status Service UUID | The UUID of the service that provides the device state characteristic. |
Title | The title displayed on the top part of the widget box. |
Update Callback | The name of the JavaScript function to be invoked when the device update is complete. |
Visibility Condition | The expression that allows you to reduce the visibility of the element. |
SUB-ELEMENTS | |
Characteristic | The BLE characteristic to read or write. |
Characteristic <property> | |
---|---|
PROPERTIES | |
Characteristic UUID | The UUID of the characteristic to read or write. |
Editable | The flag indicating whether the value can be changed manually within the widget, in case the characteristic is writable. true false
|
Hidden | The flag that hides the characteristic when it is not editable. true false
|
Id | The symbolic name of the characteristic. |
Input placeholder | The value input placeholder. |
Input Type | The type of the input to be used for the editing. TEXT PASSWORD
|
Label | The label displayed for this characteristic. |
Mode | The way the characteristic is accessed. READ WRITE READ_WRITE
|
Property | The property to be used to write the characteristic. |
Reader Function | The name of the JavaScript function that implements the custom read logic for the characteristic. It is generally used when it is necessary to transform the value after the read. |
Service UUID | The UUID of the service of this characteristic. |
Value | The static value to use as default characteristic value. |
Writer Function | The name of the JavaScript function that implements custom writing logic for the characteristic. It is generally used when it is necessary to transform the value before writing or to divide it among multiple calls. |