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
Node.js package for the Xiaomi Mi Flora Plant Sensor built on top of [noble](https://github.com/noble/noble) and [ES6 promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises).
3
+
Node.js package for the Xiaomi Mi Flora Plant Sensor built on top of [noble](https://github.com/noble/noble).
Have a look in the [Wiki](https://github.com/ChrisScheffler/miflora/wiki) for more information on the sensor.
16
13
17
14
---
18
15
16
+
## Prerequisites
17
+
18
+
Please see [the Prerequisites section for noble](https://github.com/noble/noble#prerequisites).
19
+
19
20
## Install
20
21
21
22
```sh
@@ -24,64 +25,92 @@ npm install miflora
24
25
25
26
## Usage
26
27
28
+
The library uses [async/await](https://javascript.info/async-await) code syntax instead of [Promises chaining](https://javascript.info/promise-chaining) in order to execute asynchronous code sequentially. Since all internal code is based on [Promises](https://javascript.info/promise-basics) you still can use the `method().then().catch()`-pattern regardless.
This time we listen for 60000 milliseconds (60 seconds) **or** until all devices from given `opts.addresses` have been discovered and print out the number of detected devices.
53
+
54
+
### Query device information
55
+
56
+
All query methods implicitly initiate a connection if none exists. You can call `device.connect()` explicitly if you like nevertheless.
57
+
58
+
The library however **doesn't** perform a disconnect implicitly. You can call `device.disconnect()` when you have finished you queries or let you disconnect automatically from the device after 10 seconds.
59
+
60
+
#### Firmaware & Battery
61
+
62
+
```javascript
63
+
constdata=awaitdevice.queryFirmwareInfo();
64
+
console.log(data);
65
+
```
66
+
67
+
Example output:
68
+
27
69
```javascript
28
-
constmiflora=require('miflora');
29
-
30
-
miflora.discover().then(devices=> {
31
-
devices.forEach(device=> {
32
-
miflora.queryDevice(device).then(data=> {
33
-
console.log(JSON.stringify(data, null, 2));
34
-
}).catch(err=> {
35
-
console.error('error while querying device', device, ':', err);
36
-
});
37
-
});
38
-
}).catch(err=> {
39
-
console.error('well, something went wrong:', err);
0 commit comments