Skip to content

Instantly share code, notes, and snippets.

@conoro
Created August 20, 2017 17:42
Show Gist options
  • Save conoro/5f0713a5d2b62d41dd34fcb20e4c86eb to your computer and use it in GitHub Desktop.
Save conoro/5f0713a5d2b62d41dd34fcb20e4c86eb to your computer and use it in GitHub Desktop.
Using Puck.js with the KuLight RGB Bluetooth Lightbulb
// See https://conoroneill.net/using-puck-js-with-kulight-rgb-bluetooth-lightbulb/
// and https://www.espruino.com/Puck.js+and+Bluetooth+Lightbulbs
/*
On = 0x02, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Off = 0x32, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Red = 0x02, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Orange = 0x02, 0xff, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Yellow = 0x02, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Green = 0x02, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Cyan = 0x02, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Blue = 0x02, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Pink = 0x02, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
*/
function setLight(isOn) {
var gatt;
NRF.connect("e1:fb:c1:6b:81:6f random").then(function(g) {
console.log("Connected");
gatt = g;
return gatt.getPrimaryService("8d96a001-0002-64c2-0001-9acc4838521c");
}).then(function(service) {
return service.getCharacteristic("8d96b002-0002-64c2-0001-9acc4838521c");
}).then(function(characteristic) {
if (isOn){
return characteristic.writeValue([ 0x02, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
} else {
return characteristic.writeValue([ 0x32, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
}
}).then(function() {
gatt.disconnect();
console.log("Done!");
});
}
var on = true;
setWatch(function() {
on = !on;
setLight(on);
}, BTN, { repeat:true, edge:"rising", debounce:50 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment