Skip to content

Commit

Permalink
Protection from error "Peripheral already connected"
Browse files Browse the repository at this point in the history
  • Loading branch information
b108@volgograd committed May 3, 2020
1 parent f74b245 commit a607db9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions xiaomi-ble.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ module.exports = function(RED) {
peripheral.once('disconnect', send);
var disconnectTimeout = setTimeout(send, 30000);

peripheral.connect(function(error) {
var connectCallback = function(error) {
if (error != null) {
node.status({fill:"red", shape:"dot", text:"cannot connect: " + error});
node.requestActive = false;
Expand All @@ -160,7 +160,9 @@ module.exports = function(RED) {
} else {
mijiaTemperatureRead(peripheral, msg, send);
}
});
};

(peripheral.state !== 'connected') ? peripheral.connect(connectCallback) : connectCallback();
}

node.on('input', function(msg) {
Expand Down

1 comment on commit a607db9

@eschava
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've integrated this commit to the main repository if you don't mind

Please sign in to comment.