Software apps and online services
Hand tools and fabrication machines
Life gets harder when someone grows old. Imagine an elderly person searching for a light switch in the dark but struggling to locate it. Why something so simple have to become so difficult ?
Not anymore, because with the evolving world of motion technology and inter-connected wireless devices, lighting solutions can be made simplified for not only for senior persons but for everyone.
In this project, I am going to present interconnected lighting and switching system to address this problem.
Features of this solution
- Multiway Wireless On/Off Switches
- Motion Sensed Timer Lighting
- Scalable for Additional Lights/Switches/Sensors
- Reconfigurable Bluetooth Mesh Network
- Android App Controllable
Bluetooth mesh enables larger network of connected devices to solve the problems of fixed positioned lights/switches. Depending on the network configuration and firmware, multiple wireless switches can control multiple lights at once. Can't locate wireless switch points in the dark ? No worries, motion sensor can light up the nearest light for you !
Long hallway or corridor with lots of light ? Not a problem in mesh connected wireless lamps, push one switch at the entry point to turn on all the lights and another switch to at the exit point to turn off all at once.
Bluetooth (LPN) low power node based switch can run for years on a CR2032 or 2 AA batteries. An elderly person can have a wireless bed switch for his/her lights ! One push in the middle of the night and the entire house lights up !Demo
Following video shows both motion sensed and multiway mesh switches to control all the lights.
- Motion sensed only turns on local light for 15 seconds and then turns off.
- Multiway switches turns all lights until turned off
- Multiway switched on lights ignore motion sense and stays on
- Blue status LED means motion sensed, 15 sec timer for light
- Green status LED means local/remote switch toggled
- Cyan status LED means motion timer ignored, light always on
I am going to use 4 CYBT-213043-Mesh development boards to demonstrate this solution.
These kits are prefect for wireless mesh connected lighting and switching because all the necessary hardware like motion sensor, ambient light sensor, switch and GPIO pins are available to control external LED lamp or electromagnetic relay for mains load.
3 white LED boards will be used for the lights. These external LEDs will be controlled over GPIO P12, which will drive the base of S8050 NPN transistor (through 1 k resistor) to switch power to these LEDs
As for powering each set of hardware, 2 AA will provide power through CR2032 power traces.
Above hardware setup is suitable for testing range and stability of the lighting network. But it is just a prototype setup, actual product will use AC to DC power supply for the Bluetooth Hardware and Sensors. For the lights, relay or AC LED driver circuits may be necessaryBluetooth Mesh Basics
Bluetooth Mesh is many to many communication network of large number of devices (nodes), where each device can play different kind of roles. Here is a very brief introduction to Bluetooth Mesh :-
- Standard Node: Every node in a mesh network with the ability to both send and receive mesh messages
- Relay Node: Receive mesh messages and re-transmit for network range extension. To avoid re-transmission of same message, relay node caches messages to prevent looping
- Low Power Node: Battery powered and usually sleeps/stays in low power mode most of the time, then wakes periodically, sends message (e.g. sensor data) and goes back to sleep again. Low power nodes must have a friend node with in it's range to do other stuffs.
- Friend Node: Friend nodes are necessary for Low Power Nodes (LPN) to receive messages while sleeping. A Friend node can keep messages for their adjacent LPNs, when LPN wakes up, it asks its friend node to provide messages addressed toward it.
- GATT Proxy Node: BLE and Bluetooth Classic devices can not directly interact with Bluetooth Mesh Nodes. Since, most phones and laptops are BLE devices, there is no direct way to interact with a mesh network. This is where GATT Proxy comes in, it allows BLE devices to talk with other mesh nodes through GATT Proxy node. A node can act as GATT proxy (dual mode Bluetooth) translating BLE to MESH communication.
In the sersor_motion.c file following code makes every node used in this project a combination of Relay, Friend and GATT proxy
.features = WICED_BT_MESH_CORE_FEATURE_BIT_FRIEND | WICED_BT_MESH_CORE_FEATURE_BIT_RELAY | WICED_BT_MESH_CORE_FEATURE_BIT_GATT_PROXY_SERVER
Client, Server and Control Models
- Server: Sends/Changes data based on Clients GET/SET requests.
- Clients: Send GET/SET requests to Server
- Control: Acts both as a Client and a Server.
This project is a control model, because every light is a switch to itself and other lights in the network.
wiced_bt_mesh_core_config_model_t mesh_element1_models =
Advertising and Provisioning
Mesh device(node) that is not part of any network, will keep advertising it's name, UUID, device type icon like a BLE Beacon.
A provisioning device running a provisioning app will scan and make a BLE GATT connection to provision the rouge device(node) with the network information.
The provisioning process assigns the netkey and the unicast/group address of the primary element.
Once the device is provisioned it will be able to receive and decode BLE Mesh packets. Then the provisioning application will to send the rest of the configuration information like group subscriptions, application keys. Now the device will become a part of that mesh network
Once multiple devices are provisioned to the same mesh network, each node can communicate with other nodes through mesh messaging.Programming, Flashing Firmware & Provisioning
Bluetooth Mesh development with ModusToolbox is highly abstracted away, so the low level hardware details are not exposed. Using APIs and Element Models with the help of example codes, firmware development can be done relatively easily.
Following video shows how to add drivers, snip codes and example project for CYBT213043 Mesh kit :
Programming Steps (above video)
- Install and Run ModusToolbox 2.0
- Name a new Workspace and chose folder location
- Click New Application > CYBT213043-MESH >Next
- Now select wiced_btsdk first ( this order is important) >Next >Finish
- Then select Mesh-Snip-213043MESH > Next > Finish (optional)
- Finally select Mesh-Demo-213043MESH >Next > Finish
- In the project explorer (left corner) all the examples will be available
This project is a combination of following 3 example projects and some of my own code :
copy "led_control.c" & "led_control.h" files into the MESH_sensor_motion folder as shown in the video.
Now copy the codes attached below this page
(code section) and replace the original example codes with my modified codes.
Copy codes from modified "led_control.c" into original "led_control.c"
Copy codes from modified "led_control.h" into original "led_control.h"
Copy codes of modified "sensor_motion.c" into original "sensor_motion.c"
Flash/Upload same code to all the kits one by one
The next video shows how compile+flashing and then provisioning is done:
Mesh_Client.exe is a Windows application that comes with ModusToolbox, which is used to provision mesh devices to a network. It can be found in this location:-
RunMesh_Client.exe in Windows 10 machine
- Type a Network name (1st time) and click create network
- Click "Open" (wait till 'done' msg on Trace window [below])
- Click "Scan Unprovisioned" and wait
- Click "Stop Scan" when unprovision devices UUID shows with names
- Click " Provision and Configure"
wait till 'done' msg on Trace window
- Click "Close" to save network configuration to saved inside device
Note: Clicking randomly on mesh client app might hang the app, be patient, provisioning takes nearly a minute or so !External References