zkiiito / node-sbrick-protocol

SBrick protocol implementation in node.js
MIT License
8 stars 0 forks source link

SBrick.js #1

Open 360fun opened 7 years ago

360fun commented 7 years ago

Hi! ;)

I think you will find my project interesting: https://360fun.github.io/sbrick.js/

I think would be great if we could join them together somehow: in my project I used a separate class to communicate through Web Bluetooth. Maybe you can also separate the Node.js Bluetooth API so we can maintain a unique JavaScript library to manage the SBrick! :D

Let me know: francesco@360fun.net

zkiiito commented 7 years ago

hey!

thanks for contacting! I'll look into your project in the following days, and will msg you!

360fun commented 7 years ago

Great, take your time! ;)

zkiiito commented 7 years ago

I've looked into noble, and it has basic support for web bluetooth, so I've modified my package to use that, you can see it in the https://github.com/zkiiito/node-sbrick-protocol/tree/webbluetooth branch. I also had to add some functionality to noble, because it did not support optionalServices, but now it does, see https://github.com/zkiiito/noble/tree/webbluetooth-optionalservices, I'll create a PR later. so, webpack created the sbrick.webbluetooth.js file, and you can use it the same way you do server-side. I have to fix winston, because it's not really good with webpack, so for now I've replaced all winston calls with console.log.

360fun commented 7 years ago

Great! I didn't know that node could work with Web Bluetooth: I will look into it! ;) Anyway join the two projects together sounds pretty complicated...

zkiiito commented 7 years ago

node can not work with web bluetooth, but with webpack I've created a file - sbrick.webbluetooth.js - which bundles together everything for the browser.

so, if you embed that in a webpage, you can just create an SBrick instance, like this:

var sbrick = new SBrick('webbluetooth');
sbrick.connect()
.then(function() {
sbrick.start();
}).then(function() {
sbrick.channels[0].pwm = 255;
}).catch(console.log);
360fun commented 7 years ago

Cool, I will try it! :D In the meanwhile I got the chance to start playing with the SBrick Plus, but I'm having problems in reading the sensors data...did you start working on that?