Some LED bulbs on the market can change colors and make sounds via Bluetooth. Normally, it is controlled from the attached smartphone application, but I challenged the control from the microcomputer (Intel Edison).
At the end of last year, I participated in the IT development contest Mashup Awards. This time, the second time I participated, I made and applied for an IoT toilet system using AI (chatbot) and sensors (Related article ). One of the functions of the system is the "watching" function, and if the toilet is too long, the bot will ask "Is it okay?", And if the lid is left open, "Isn't it left empty?" I will urge you.
In order to realize this voice guidance function, we used an LED bulb with a speaker function instead of a single-function Bluetooth speaker, but said that "it makes it easier to handle the power supply" and "it can be installed on the ceiling of the toilet and the sound can easily pass through". In addition to the merits, I was able to use it in an interesting way, such as "changing the color according to the spoken language (example: yellow when calling attention)".
Philips Hue comes to the forefront when it comes to controllable LED bulbs, but for Hue, which can only control light, Bluetooth connection type LED bulbs that can control both sound and light may be used more interestingly than art. I thought, so I decided to summarize the control method here.
--1st step: Control by typing a command from the microcomputer --2nd step: Control by running a program on the microcomputer
In this article, we will write up to the 1st step first, and in the following articles, we will write the 2nd step.
I used Mi Pow PLAYBULB as an LED bulb (the model name BT100 is printed on the main body). Actually, I tried several other models of Bluetooth-controlled LED bulbs, but I couldn't analyze the communication protocol and couldn't control them.
As a microcomputer, I used Intel Edison, which can be powered by a USB battery and is easy to handle. I haven't tried it, but I think that the same control can be realized with Raspberry Pi 3 and PC.
It is assumed that Intel Edison's Wifi etc. have already been set up (if you like, you can also set here). The firmware version is as follows.
root@edison:~# uname -a
Linux edison 3.10.98-poky-edison+ #1 SMP PREEMPT Mon Jun 6 14:32:08 PDT 2016 i686 GNU/Linux
At the same time, enable Bluetooth. If you restart Edison, it will be disabled again, so I set it to be automatically enabled at startup by referring to this.
root@edison:~# rfkill unblock bluetooth
root@edison:~# rfkill list
...
2: bcm43xx Bluetooth: bluetooth
Soft blocked: no
Hard blocked: no
It is assumed that the LED bulb is inserted into the socket and the color can be changed from the PLAYBULB dedicated control app for smartphones. First, check if you can see PLAYBULB from the Intel Edison console.
root@edison:~# bluetoothctl
[NEW] Controller 98:4F:EE:04:28:48 edison [default]
[bluetooth]# scan on
Discovery started
[CHG] Controller 98:4F:EE:04:28:48 Discovering: yes
[NEW] Device DB:22:4B:13:AC:E6 PLAYBULB COLOUR LED <--LED bulb function
[NEW] Device AC:E6:4B:13:E4:9F PLAYBULB COLOUR <--Speaker function
Since PLAYBULB has two functions, an LED bulb and a speaker, you can check two as a Device. Make a note of the address on the LED bulb side.
Next, install the tools (gatttools) required for control on Intel Edison.
Bluetooth has profiles for various devices (HID profile for mouse and keyboard, A2DP profile for voice, etc.), but PLAYBULB has a standard profile for Bluetooth LE, Generic Attribute Profile (GATT). ) Is used for control. [Explanatory article on using gatttools on Intel Edison](https://software.intel.com/en-us/articles/using-the-generic-attribute-profile-gatt-in-bluetooth-low-energy-with- your-intel-edison) is on the official website, so there is no problem with this street. For reference, I will post the command at hand.
root@edison: wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.43.tar.xz
root@edison: tar -xf bluez-5.43.tar.xz
root@edison: cd bluez-5.43
root@edison: ./configure --prefix=/usr/local --disable-systemd -disable-udev
root@edison: make
root@edison: make install
root@edison: cp ./attrib/gatttool /usr/local/bin
root@edison: export PATH=$PATH:/usr/local/bin
root@edison: gatttool
Usage:
gatttool [OPTION...]
...
I will use it frequently in the future, so I copied it to / usr / local / bin and put it in the path.
About device control with Bluetooth LE GATT profile
--For a specific handle (like an address called Attribute Handle) --Write / read specific control data
I think of it as an image. First, let's change the color of the light bulb.
After gatttool -b
, specify the address on the LED bulb side that was checked with bluetoothctl
earlier.
root@edison:~# gatttool -b DB:22:4B:13:AC:E6 -I
[DB:22:4B:13:AC:E6][LE]> connect
Attempting to connect to DB:22:4B:13:AC:E6
Connection successful
[DB:22:4B:13:AC:E6][LE]> char-write-cmd 0x001b 00ff0000 <--Red
[DB:22:4B:13:AC:E6][LE]> char-write-cmd 0x001b 0000ff00 <--Green
[DB:22:4B:13:AC:E6][LE]> char-write-cmd 0x001b 000000ff <--Blue
...
Did the color change? In the above, control is performed by writing 4 bytes of data to the handle (0x001b) that controls color, but you can also specify blinking patterns, etc. The correspondence table is shown below.
Byte | Effect |
---|---|
0 | White level |
1 | Red level |
2 | Green level |
3 | Blue level |
Byte | Effect |
---|---|
0 | Reserve? |
1 | Red level (in single color) |
2 | Green level (single color) |
3 | Blue level (single color) |
4 | 0x00 :Single color flashing 0x01 :Monochromatic fade 0x02 :Rainbow flashing 0x03 :Rainbow fade |
5 | Reserve? |
6 | Effect speed(0x00 fastest) |
7 | Reserve? |
** Caution **: This correspondence table is not officially distributed, but is calculated by analyzing it independently, so it may be incorrect or may change depending on the model. In addition, there is a possibility of damaging the product by setting parameters not intended by the manufacturer. Please do it at your own risk.
The LED bulb (PLAYBULB) can now be controlled from the microcomputer (Intel Edison) by sending a control command according to the Bluetooth LE GATT profile.
However, the above method cannot be applied because it is necessary to issue commands for control. Next, we will challenge control using a programming language (Python).
Recommended Posts