You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the code snippet above, the variable `switchbot` is an `SwitchBotBLE` object. The `SwitchBotBLE` object has a lot of methods as described in sections below.
@@ -119,7 +119,7 @@ The `discover` method finds devices. This method returns a `Promise` object. Thi
119
119
In the code snippet below, no parameter is passed to the method:
120
120
121
121
```Typescript
122
-
switchbotBLE.discover().then((device_list) => {
122
+
switchBotBLE.discover().then((device_list) => {
123
123
// Do something...
124
124
}).catch((error) => {
125
125
console.error(error);
@@ -131,7 +131,7 @@ If no parameter is passed to the method as the code above, an `Array` object wil
131
131
If you want a quick response, you can set the `quick` property to `true`.
132
132
133
133
```Typescript
134
-
switchbotBLE.discover({
134
+
switchBotBLE.discover({
135
135
duration: 5000,
136
136
quick: true
137
137
}).then((device_list) => {
@@ -148,11 +148,11 @@ As the `quick` property is set to `true`, the `resolve()` function will be calle
148
148
The `ondiscover` property on the [`Switchbot`](#Switchbot-object) object is an event handler called whenever a device is newly found in the discovery process. A [`SwitchbotDevice`](#SwitchbotDevice-object) object is passed to the callback function set to the `ondiscover` property.
149
149
150
150
```Typescript
151
-
switchbotBLE.ondiscover= (device) => {
151
+
switchBotBLE.ondiscover= (device) => {
152
152
console.log(device.id+' ('+device.modelName+')');
153
153
};
154
154
155
-
switchbotBLE.discover().then(() => {
155
+
switchBotBLE.discover().then(() => {
156
156
console.log('The discovery process was finished.');
157
157
}).catch((error) => {
158
158
console.error(error);
@@ -180,19 +180,19 @@ Whenever a packet is received, the callback function set to the [`onadvertisemen
180
180
181
181
```Typescript
182
182
// Set a callback function called when a packet is received
183
-
switchbotBLE.onadvertisement= (ad) => {
183
+
switchBotBLE.onadvertisement= (ad) => {
184
184
console.log(ad);
185
185
};
186
186
187
187
// Start to scan advertising packets
188
-
switchbotBLE.startScan({
188
+
switchBotBLE.startScan({
189
189
id: 'cb:4e:b9:03:c9:6d',
190
190
}).then(() => {
191
191
// Wait for 30 seconds
192
-
returnswitchbotBLE.wait(30000);
192
+
returnswitchBotBLE.wait(30000);
193
193
}).then(() => {
194
194
// Stop to scan
195
-
switchbotBLE.stopScan();
195
+
switchBotBLE.stopScan();
196
196
process.exit();
197
197
}).catch((error) => {
198
198
console.error(error);
@@ -226,7 +226,7 @@ The `serviceData` property depends on the model of the device. See the section "
226
226
If a callback function is set to the `onadvertisement` property, the callback function will be called whenever an advertising packet is received from a device during the scan is active (from the moment when the [`startScan()`](#startscan-method) method is called, to the moment when the [`stopScan()`](#Switchbot-stopScan-method) method is called).
@@ -243,7 +243,7 @@ The `stopScan()` method stops to scan advertising packets coming from devices. T
243
243
244
244
```typescript
245
245
try {
246
-
switchbotBLE.stopScan()
246
+
switchBotBLE.stopScan()
247
247
console.log('Stopped BLE scanning to close listening.')
248
248
} catch (e:any) {
249
249
console.error(`Failed to stop BLE scanning, error:${e.message}`)
@@ -257,12 +257,12 @@ The `wait()` method waits for the specified milliseconds. This method takes an i
257
257
This method has nothing to do with Switchbot devices. It's just a utility method. See the section "[Quick Start](#Quick-Start)" for details of the usage of this method.
258
258
259
259
```typescript
260
-
awaitswitchbotBLE.wait(1000)
260
+
awaitswitchBotBLE.wait(1000)
261
261
```
262
262
263
263
### `SwitchBotDevice` Object
264
264
265
-
The `SwitchbotDevice` object represents a Switchbot device (Bot, Meter, Curtain, Contact or Motion), which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
265
+
The `SwitchbotDevice` object represents a Switchbot device (Bot, Meter, Curtain, Contact or Motion), which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
266
266
267
267
Actually, the `SwitchbotDevice` object is a super class of the [`WoHand`](#SwitchbotDeviceWoHand-object) and `WoSensorTH` objects. The [`WoHand`](#SwitchbotDeviceWoHand-object) object represents a Bot, the `WoSensorTH` object represents a Meter.
268
268
@@ -367,7 +367,7 @@ switchbot
367
367
})
368
368
.then(() => {
369
369
console.log("Waiting for 5 seconds...");
370
-
returnswitchbotBLE.wait(5000);
370
+
returnswitchBotBLE.wait(5000);
371
371
})
372
372
.then(() => {
373
373
console.log("Putting the arm up...");
@@ -461,7 +461,7 @@ The `ondisconnect` event handler will be called when the connection with the dev
461
461
462
462
### `WoHand` Object
463
463
464
-
The `WoHand` object represents a Bot, which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
464
+
The `WoHand` object represents a Bot, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
465
465
466
466
Actually, the `WoHand` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
467
467
@@ -589,7 +589,7 @@ switchbot
589
589
590
590
### `WoCurtain` Object
591
591
592
-
The `WoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
592
+
The `WoCurtain` object represents a Curtain, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
593
593
594
594
Actually, the `WoCurtain` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
595
595
@@ -698,7 +698,7 @@ switchbot
698
698
699
699
### `WoPlugMini` Object
700
700
701
-
The `WoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
701
+
The `WoPlugMini ` object represents a PlugMini, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
702
702
703
703
Actually, the `WoPlugMini ` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
704
704
@@ -722,7 +722,7 @@ If no connection is established with the device, this method automatically estab
722
722
723
723
### `WoSmartLock` Object
724
724
725
-
The `WoSmartLock ` object represents a SmartLock, which is created through the discovery process triggered by the [`switchbotBLE.discover()`](#Switchbot-discover-method) method.
725
+
The `WoSmartLock ` object represents a SmartLock, which is created through the discovery process triggered by the [`switchBotBLE.discover()`](#discover-method) method.
726
726
727
727
Actually, the `WoSmartLock ` is an object inherited from the [`SwitchbotDevice`](#SwitchbotDevice-object). You can use not only the method described in this section but also the properties and methods implemented in the [`SwitchbotDevice`](#SwitchbotDevice-object) object.
728
728
@@ -769,19 +769,19 @@ After the [`startScan()`](#startscan-method) method is invoked, the [`onadvertis
769
769
// Load the node-switchbot and get a `Switchbot` constructor object
770
770
import { SwitchBotBLE } from'node-switchbot';
771
771
// Create a `Switchbot` object
772
-
constswitchbotBLE=newSwitchBotBLE();
772
+
constswitchBotBLE=newSwitchBotBLE();
773
773
774
774
(async () => {
775
775
// Start to monitor advertisement packets
776
-
awaitswitchbotBLE.startScan();
776
+
awaitswitchBotBLE.startScan();
777
777
// Set an event handler
778
-
switchbotBLE.onadvertisement= (ad) => {
778
+
switchBotBLE.onadvertisement= (ad) => {
779
779
console.log(JSON.stringify(ad, null, ''));
780
780
};
781
781
// Wait 10 seconds
782
-
awaitswitchbotBLE.wait(10000);
782
+
awaitswitchBotBLE.wait(10000);
783
783
// Stop to monitor
784
-
switchbotBLE.stopScan();
784
+
switchBotBLE.stopScan();
785
785
process.exit();
786
786
})();
787
787
```
@@ -1062,11 +1062,11 @@ This sample discovers a Bot (WoHand), then put the Bot's arm down, finally put i
1062
1062
// Load the node-switchbot and get a `Switchbot` constructor object
@@ -1075,14 +1075,14 @@ const switchbotBLE = new SwitchBotBLE();
1075
1075
// Put the Bot's arm down (stretch the arm)
1076
1076
awaitdevice.down();
1077
1077
// Wait for 5 seconds
1078
-
awaitswitchbotBLE.wait(5000);
1078
+
awaitswitchBotBLE.wait(5000);
1079
1079
// Put the Bot's arm up (retract the arm)
1080
1080
awaitdevice.up();
1081
1081
process.exit();
1082
1082
})();
1083
1083
```
1084
1084
1085
-
In order to manipulate the arm of your Bot, you have to discover your Bot using the [`discover()`](#Switchbot-discover-method) method. The object `{ model: 'H' }` passed to the method means that only Bots will be discovered. That is, Meters will be ignored.
1085
+
In order to manipulate the arm of your Bot, you have to discover your Bot using the [`discover()`](#discover-method) method. The object `{ model: 'H' }` passed to the method means that only Bots will be discovered. That is, Meters will be ignored.
1086
1086
1087
1087
In this code, you can get a [`WoHand`](#SwitchbotDeviceWoHand-object) object representing the found Bot. Using the [`down()`](#SwitchbotDeviceWoHand-down-method) and [`up()`](#SwitchbotDeviceWoHand-up-method) methods of the object, you can move the arm. In addition to these methods, you can use the [`press()`](#SwitchbotDeviceWoHand-press-method), [`turnOn()`](#SwitchbotDeviceWoHand-turnOn-method), and [`turnOff()`](#SwitchbotDeviceWoHand-turnOff-method) methods as well.
0 commit comments