We've been building a set of creator client apps to take to the Embedded World 2017 show in a couple of weeks, we've written a component to control a BLE bulb which is a useful creator IoT framework example so I figured I'd run through it in a forum post.
We picked up a set ChiChinLighting 7watt muliti-colour BLE bulbs of bulbs from Amazon which we sniffed to learn the commands to connect to the bulb and set specific colours. Having learnt the BLE commands we put a C app together that makes an IPSO object for a colour string available and waits for the specific strings "red", "blue", "green", or "yellow" to be written to the object. When one of these strings is seen in the IPSO object then the bulb controller app sends the appropriate colour command to the bulb by BLE.
The repo for this project is https://github.com/CreatorDev/Ci40-ew17-bulb, you can build this with the creator-sdk for ci40 openwrt by first compiling the dependencies (libffi, glib2, expat, dbus, libical, and bluez) and then the bulb controller application.
The steps below cover the stages of deploying the bulb controller application on the Creator Ci40.
- If you don't already have a Creator Device Server account then register at https://console.creatordev.io
- Connect your Ci40 to your network and onboard it to your Creator Device Server account, take a look workshop 1 if you need more information on this process
- While you're on the console then use the device keys area to grab a PSK identity and secret to use with this app
- On the Ci40 use the awa_clientd command with your PSK identidy and secret to create a client to use with the bulb controller
awa_clientd -b coaps://deviceserver.creatordev.io:15684 --endPointName Bulbcontroller -s --pskIdentity PSK-IDENTIFY --pskKey PSK_KEY --ipcPort 12345 -d
This will create an endpoint call BulbController on your Ci40 on the internal port 12345.
- Find the MAC address for your bulb using the hcitool included in the bluez package
If the bluez package is not already installed on your Ci40 then install it using
opkg update && opkg install bluez-utils
- Install the bulb controller application using the ipk that you've built
- Start the bulb controller using the MAC address of your bulb
bulb_controller -t AA:BB:CC:DD:EE:FF &
The bulb_controller app will attempt to connect to the bulb, if there's an error then the application will give output in the Ci40 console window.
When you go back to the Creator Device Server console and select the devices option you'll now see your Ci40 listed, click on the Ci40 and you'll see the objects available, the object 3311 will show the string shown for the existing colour of the bulb. Use the pen icon to edit this value to one of the predefined strings in the bulb_controller app.
The Device Server will update the object value on the Ci40 which in turn will be picked up by the bulb_controller application and the appropriate bulb colour set command will be sent to the bulb using BLE.
All of the actions possible with the Creator Device Server console are also available using the developer API. If you want to build an IoT system around bulb control, or you want to include bulb control in an existing IoT system, then you can set the value of the 3311 colour object's string and let the Creator IoT framework and the bulb_controller application complete the process for you. Take a look at workshop 4 for an example of a Node.js webapp that uses our creator-js-client to access and use the Creator Device Server REST API.