npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@siva7170/ble-connection

v2.0.3

Published

Node.js Bluetooth SPP communication for Windows

Downloads

36

Readme

BLE Connection

This is a node addon api package used for connecting other bluetooth through Bluethooth SPP. IMPORTANT! It supports for Windows platform. For now, we can only connect to other bluetooth spp. It means, this package does not act as server.

Getting Started

This library is developed in C++ and support for Node.js.

Installation

Install this package into your project by below command

npm install @siva7170/ble-connection

Usage

Below code is sample for how to use it. Please see methods and its functionalities below sections.

const bleConnection = require('@siva7170/ble-connection');

const bleConnInstance = new bleConnection.BLEConnection();

Methods

Initiate(successCallback,failureCallback)

  • successCallback:

    • Type: Function
  • failureCallback:

    • Type: Function

It initializes the necessary things.

bleConnInstance.Initiate(()=>{
	console.log("Initiated!");
	// rest of the code
},()=>{
	console.log("Failed to initiate!");
});

Connect(bluetooth_addr, uuid, successCallback,failureCallback)

  • bluetooth_addr:

    • Type: String
  • uuid:

    • Type: String
  • successCallback:

    • Type: Function
  • failureCallback:

    • Type: Function

This method will try to connect to the given bluetooth address and uuid from bluetooth spp server.

// please use valid bluetooth address and UUID
bleConnInstance.Connect("00:00:00:00:00:E0","aaaaaaaa-aaaa-4444-cccc-999888999888",()=>{
	console.log("Connected!");
    // rest of the code
},()=>{
	console.log("Failed to connect!");
});

SendData(data, successCallback, failureCallback) (optional)

  • data:

    • Type: String
  • successCallback:

    • Type: Function
  • failureCallback:

    • Type: Function

With this method, you can send data to client

bleConnInstance.SendData('Hi server!',(res)=>{
	console.log("Data sent: "+sData);
}, (err)=>{

});

OnReceiveData(onDataRecvCallback)

  • onDataRecvCallback:
    • Type: Function

This method will be triggered when the data sent from bluetooth server

bleConnInstance.OnReceiveData((data)=>{
	console.log("Data receivedd: "+data);
});

Full Example

Please find full example of implementation

const bleConnection = require('@siva7170/ble-connection');

const bleConnInstance = new bleConnection.BLEConnection();

try{
    bleConnInstance.Initiate(()=>{
        console.log("Initiated!");

        bleConnInstance.Connect("00:00:00:00:00:E0","aaaaaaaa-aaaa-4444-cccc-999888999888",()=>{
            console.log("Connected!");
            let sData="Hi client";
            bleConnInstance.SendData(sData,(res)=>{
                console.log("Data sent: "+sData);
            }, (err)=>{

            });

            bleConnInstance.OnReceiveData((data)=>{
                console.log("Data receivedd: "+data);
            });
            
            sData="How are you?";
            bleConnInstance.SendData(sData,(res)=>{
                console.log("Data sent: "+sData);
            }, (err)=>{

            });
        },()=>{
            console.log("Failed to connect!");
        });
    },()=>{
        console.log("Failed to initiate!");
    });
}catch(e){
    console.error(e.toString());
}

Version 2

Usage

Below code is sample for how to use it. Please see methods and its functionalities below sections.

const bleConnection = require('@siva7170/ble-connection');

const bleConnInstance = new bleConnection.BLEConnection();

Methods

SetBtInfo(bluetooth_addr, uuid, timeout_for_reconnect, no_of_attempt_to_reconnect)

  • bluetooth_addr:

    • Type: String
  • uuid:

    • Type: String
  • timeout_for_reconnect:

    • Type: Integer
  • no_of_attempt_to_reconnect:

    • Type: Integer

It sets necessary things to BLE Connection before it initialize.

bleConnInstance.SetBtInfo("00:00:00:00:00:E0","aaaaaaaa-aaaa-4444-cccc-999888999888",5000,0);

GetStatus(statusCallback) (optional)

  • statusCallback:
    • Type: Function

This method will give current state of BLE Connection when it is changed from one to another.

bleConnInstance.GetStatus((res)=>{
  console.log("Status: "+res);
});

MakeConnection(successCallback, failureCallback)

  • successCallback:

    • Type: Function
  • failureCallback:

    • Type: Function

It will make connection to device which is defined in SetBtInfo()

bleConnInstance.MakeConnection(()=>{
    console.log("Connected...!");
},
()=>{
    console.log("Failed to connect!");
});

IsConnected(successCallback, failureCallback) (optional)

  • successCallback:

    • Type: Function
  • failureCallback:

    • Type: Function

This method will be triggered when connection made to Bluetooth Server.

    bleConnInstance.IsConnected(()=>{
        console.log("Connection status: Connected!");
    },
    ()=>{
        console.log("Failed to connect!");
    });

SendDataToServer(data, successCallback, failureCallback) (optional)

  • data:

    • Type: String
  • successCallback:

    • Type: Function
  • failureCallback:

    • Type: Function

With this method, you can send data to client

bleConnInstance.SendDataToServer('Hi server!',(res)=>{
	console.log("Data sent: "+sData);
}, (err)=>{

});

OnReceiveDataFromServer(onDataRecvCallback)

  • onDataRecvCallback:
    • Type: Function

This method will be triggered when the data sent from bluetooth server

bleConnInstance.OnReceiveDataFromServer((data)=>{
	console.log("Data receivedd: "+data);
});

Full Example

Please find full example of implementation

const bleConnection = require('@siva7170/ble-connection');

const bleConnInstance = new bleConnection.BLEConnection();

try{
    bleConnInstance.SetBtInfo("00:00:00:00:00:E0","aaaaaaaa-aaaa-4444-cccc-999888999888",5000,0);

    
    bleConnInstance.GetStatus((res)=>{
        console.log("Status: "+res);
    });


    bleConnInstance.MakeConnection(()=>{
        console.log("Connected...!");
    },
    ()=>{
        console.log("Failed to connect!");
    });

    bleConnInstance.IsConnected(()=>{
        console.log("Connection status: Connected!");

       // INITIATE
      bleConnInstance.SendDataToServer("INITIATE",(res)=>{
        console.log("Initiating...!");
      }, (err)=>{

      });

      bleConnInstance.OnReceiveDataFromServer((data)=>{
        bleConnInstance.SendDataToServer("READY_SCAN",(res)=>{
          console.log("Ready scan...!");
        }, (err)=>{
                    
        });
      });
    },
    ()=>{
        console.log("Failed to connect!");
    });

}catch(e){
    console.error(e.toString());
}

TODO

  • [x] Bluetooth SPP Client (Windows)
  • [ ] Bluetooth SPP Client (Other platform)
  • [ ] Bluetooth SPP Server (for all platform)
  • [ ] Modify all code more efficient

Contribution

I created this package for my own usage. I welcome contribution for this package improvement.