I have been working on a web service and Device Handler to control the MiPow Playbulb candles with a Chip computer (or Raspberry Pi with Bluetooth Dongle). Everything seems to be working great at this point.
Chip Setup
Note: Run all commands as root or put “sudo” in front of them
Install the following packages:
apt-get install apache2 php5 libapache2-mod-php5
Copy the contents of playbulb.php into a file located in /var/www/html/
vi /var/www/html/playbulb.php
Edit the section under “#### EDIT SETTINGS HERE ####”
You will need to put the MAC address of your Playbulb’s here as well as the handle that controls the color and effect. There is a good chance, that our handles are the same, but I did create a tool to help you figure it out if not.
You can get the MAC address from your Playbulbs by running the following command (make sure your candles are turned on and that you don’t have any phone connected to them):
hcitool lescan
#### EDIT SETTINGS HERE ####
$candles = array(“xx:xx:xx:xx:xx:xx”, “xx:xx:xx:xx:xx:xx”, “xx:xx:xx:xx:xx:xx”);
$color_handle = “0x0019”;
$effect_handle = “0x0017”;
############################
SmartThings Setup
Install the device handler located here:
Create a new device in the IDE and assign the newly created device handler. You can set the Device ID to whatever you want as it will get automatically set when the device type is used.
Open the device on your phone and set the IP address and the port of the Chip, and Device ID of the candle(s) you want to control. The format of the candle Device ID is simply candle where x corresponds to the order of the MAC address that you put in the playbulb.php file. You can also go to http://ipaddressOfChip/playbulb.php?config=true to view the Device IDs. You can place multiple devices by comma separating them. For example, if you want to control candle 1, 2, and 3, you would put “candle1,candle2,candle3” (without quotations - notice NO spaces between as well).
At this point you should be able to control your candles (as long as they are within range of the Chip).
Additional Candles
Because of how SmartThings assigns Device IDs to LAN devices, if you want additional device types for candles, you have to add extra ports to your Apache config on the Chip. So, if you want to have one SmartThings device that controls 3 candles and then 3 individual devices that control the same candles individually, you would need 4 ports.
Add the following to /etc/apache2/ports.conf
vi /etc/apache2/ports.conf
Listen 81
Listen 82
Listen 83
Listen 84
Restart apache
systemctl restart apache2
When creating another MiPow device in SmartThings, just use an unused port. I probably could get around this by creating a “Bridge” type SmartApp, but I haven’t gotten to that point yet.
Finding Bluetooth Handles
On github download the tool that I created called find_handle.sh.
Make it executable and run it against one of your candles and it will give you some possible choices to try for the handlers.
chmod 755 find_handle.sh
./find_handlers.sh xx:xx:xx:xx:xx:xx
Raspberry Pi
To use the Pi, you will need to get a compatible Bluetooth LE dongle. You will also likely need to compile gattool.
Let me know if it gives you any problems and I will help walk you through it.
Raspberry Pi specific instructions:
wget https://www.kernel.org/pub/linux/bluetooth/bluez-5.37.tar.gz
tar -zxf bluez-5.37.tar.gz
cd bluez-5.37
./configure --enable-library
make -j8 && sudo make install
cp attrib/gatttool /usr/local/bin/