node-mi-flora-classic-updated
v0.2.0
Published
Node package for xiaomi mi flora plant sensor. Version 0.1.1 of original with update to support abandonware version of noble.
Downloads
25
Maintainers
Readme
node-mi-flora
Node package for Xiaomi Mi Flora Plant Sensor
This package is under development. Use it on your own risk until the stable version is out.
Installation
npm install node-mi-flora
Basic Usage
const MiFlora = require('node-mi-flora');
let flora = new MiFlora(); // initialize flora
// start scanning
flora.startScanning();
// set an interval to rescan & get fresh data
setInterval(function () {
console.log('every 15 seconds, rescan devices');
flora.startScanning();
}, 15000);
// stop scanning
flora.stopScanning();
Events
Data
When data available, it publishes DeviceData object which contains temperature, lux, moisture, and fertility.
flora.on('data', function (data) {
console.log('data', data);
// print DeviceData { deviceId: '1111', temperature: 25.2, lux: 5142, moisture: 46, fertility: 0 }
});
Firmware & Battery
When data available, it publishes plain object which contains firmware and battery values.
flora.on('firmware', function (data) {
console.log('firmware', data);
// print { deviceId: '1111', batteryLevel: 82, firmwareVersion: '2.6.2' }
});
Notes
debug mode
DEBUG=miflora node examples/basic.js
if you having trouble running the script on raspberry pi, run
sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)
. This grants thenode
binarycap_net_raw privileges
, so it can start/stop BLE advertising without sudo. sourceuse it with strict mode
node --use_strict examples/basic.js
if your flora's firmware version is older than 2.8.6, please install v0.1.0