Items used in this project
Hardware components
Story
This video shows you how to control most types of Bluetooth lightbulb using Puck.js.
The actual code used is:
- function setLight(isOn) {
- var gatt;
- NRF.connect("98:7b:f3:61:1c:22").then(function(g) {
- // ^^^^^^^^^^^^^^^^^ your light's address here
- gatt = g;
- return gatt.getPrimaryService("33160fb9-5b27-4e70-b0f8-ff411e3ae078");
- }).then(function(service) {
- return service.getCharacteristic("217887f8-0af2-4002-9c05-24c9ecf71600");
- }).then(function(characteristic) {
- return characteristic.writeValue(isOn ? 1 : 0);
- }).then(function() {
- gatt.disconnect();
- console.log("Done!");
- });
- }
- var on = false;
- setWatch(function() {
- on = !on;
- setLight(on);
- }, BTN, { repeat:true, edge:"rising", debounce:50 });
But you'll have to change the address to that of your lightbulb!
This code will work with Awox Smartlight C9 and W13 bulbs. For other bulbs you may need to use the steps shown in the video to work out which characteristics were used.
Extras
For the Awox Smartlight W13 you can also change:
- Brightness by writing a value from 0 to 127 to characteristic
d8da934c-3d8f-4bdf-9230-f61295b69570
on servicefff6fe25-469d-42bc-9179-b3a093f19032
- Colour temperature by writing a value from 0 to 127 to characteristic
5b430c99-cb06-4c66-be2c-b538acfd1961
on servicefff6fe25-469d-42bc-9179-b3a093f19032
Buying
You can buy the lights I used here from eBay:
- Awox Smartlight C9 - multicolour
- Awox Smartlight W13 - white, variable temperature
Code
Credits
Espruino
Espruino, Espruino Pico and Puck.js are low-power Microcontrollers that run JavaScript. Espruino is a JavaScript Interpreter for Microcontrollers that is designed to make development quick and easy. The Espruino interpreter is firmware that runs on a variety of different microcontrollers, but we also make Espruino Boards that come with the interpreter pre-installed and are the easiest devices to get started with. However Espruino itself isn't just the interpreter firmware or hardware - there's also the Web IDE, command-line tools, documentation, tutorials, and modules that form a complete solution for embedded software development.
Leave your feedback...