Publishing for Bluetooth Asia 2018 developer session: mesh session. This repo is for GenericOnOff client side firmware.

EULA

PLEASE READ MESH_DEMO_TUTORIAL_EULA.TXT BEFORE START DEVELOPMENT.

Overview

This sample demonstrates Bluetooth Mesh functionality on micro:bit. It doesn't need provisioning because all the credential material (DevKey, NetKey, AppKey, Key Index, IVI and Unicast address) is pre-configured. This sample work as a GenericOnOff client:

  • Pressing Button A on micro:bit will send GenericOnOffSet access message with on or off state alternatively and specific group address;
  • Pressing Button B on micro:bit will switch the group address from 0xC000 to 0xC003 and back to 0xC000 again like round robin;

Requirements

micro:bit board

Building and Running

0. Download source code, it's zip file, the link is on this page, Download repository.

1. Following below link to set the development environment up on your Windows computer. http://docs.zephyrproject.org/getting_started/installation_win.html . Please make sure git checkout this commit, commit: 88dfd399f480b1593a8e13f5a68d512921a55502 , the detail is here, https://github.com/zephyrproject-rtos/zephyr/commit/88dfd399f480b1593a8e13f5a68d512921a55502

2. copy zip file into ./zephyr/sample/ in the Zephyr tree.

3. unzip the file by "Extract Here".

3. access into the extracted folder and rename prj_bbc_microbit.txt to prj_bbc_microbit.conf

4. if adopting Windows Command Prompt, use it to access into the unzip folder and type following commands on the console:

mkdir build & cd build

cmake -GNinja -DBOARD=bbc_microbit ..

ninja

if adopting MSYS2, use it to access into the unzip folder and type following commands on the console:

mkdir build & cd build

cmake -GNinja -DBOARD=bbc_microbit ..

ninja

5. connect micro:bit with your computer by USB cable, the board will be enumerated as a massive storage device;

6. drag the hex file (which is in ./zephyr/sample/[unzip folder]/build/zephyr/zephyr.hex) into Microbit massive storage device to flash the firmware;

7. micro:bit is ready to work as a GenericOnOff client.

Committer:
krenbluetoothsig
Date:
Sun May 27 12:30:57 2018 +0000
Revision:
10:f83347affca6
Parent:
9:ba6d8314dbb0
Child:
11:4d9f3f506c13
client; 1. CHG: add some comments for client firmware.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krenbluetoothsig 0:876e59f87d50 1 /*
krenbluetoothsig 1:fb4893064dd4 2 * Copyright (c) 2018 Bluetooth SIG
krenbluetoothsig 0:876e59f87d50 3 *
krenbluetoothsig 0:876e59f87d50 4 * SPDX-License-Identifier: Apache-2.0
krenbluetoothsig 10:f83347affca6 5 * Client firmware.
krenbluetoothsig 0:876e59f87d50 6 */
krenbluetoothsig 0:876e59f87d50 7
krenbluetoothsig 0:876e59f87d50 8 #include <misc/printk.h>
krenbluetoothsig 0:876e59f87d50 9
krenbluetoothsig 0:876e59f87d50 10 #include <bluetooth/bluetooth.h>
krenbluetoothsig 0:876e59f87d50 11 #include <bluetooth/mesh.h>
krenbluetoothsig 1:fb4893064dd4 12 #include <gpio.h>
krenbluetoothsig 1:fb4893064dd4 13 #include <board.h>
krenbluetoothsig 1:fb4893064dd4 14 #include <soc.h>
krenbluetoothsig 1:fb4893064dd4 15 #include <misc/printk.h>
krenbluetoothsig 7:6512e150f5f6 16 #include <settings/settings.h>
krenbluetoothsig 1:fb4893064dd4 17 #include <ctype.h>
krenbluetoothsig 1:fb4893064dd4 18 #include <flash.h>
krenbluetoothsig 1:fb4893064dd4 19 #include <gpio.h>
krenbluetoothsig 1:fb4893064dd4 20 #include <pwm.h>
krenbluetoothsig 1:fb4893064dd4 21
krenbluetoothsig 0:876e59f87d50 22 #include <display/mb_display.h>
krenbluetoothsig 0:876e59f87d50 23
krenbluetoothsig 1:fb4893064dd4 24 #include <bluetooth/mesh.h>
krenbluetoothsig 0:876e59f87d50 25
krenbluetoothsig 1:fb4893064dd4 26 #if !defined(NODE_ADDR)
krenbluetoothsig 1:fb4893064dd4 27 #define NODE_ADDR 0x0b02
krenbluetoothsig 1:fb4893064dd4 28 #endif
krenbluetoothsig 0:876e59f87d50 29
krenbluetoothsig 1:fb4893064dd4 30 #define CID_INTEL 0x0002
krenbluetoothsig 1:fb4893064dd4 31 #define MOD_INTEL 0x0000
krenbluetoothsig 1:fb4893064dd4 32 #define GROUP_ADDR 0xc000
krenbluetoothsig 1:fb4893064dd4 33 #define PUBLISHER_ADDR 0x000f
krenbluetoothsig 1:fb4893064dd4 34
krenbluetoothsig 1:fb4893064dd4 35 /* Model Operation Codes */
krenbluetoothsig 0:876e59f87d50 36 #define BT_MESH_MODEL_OP_GEN_ONOFF_GET BT_MESH_MODEL_OP_2(0x82, 0x01)
krenbluetoothsig 0:876e59f87d50 37 #define BT_MESH_MODEL_OP_GEN_ONOFF_SET BT_MESH_MODEL_OP_2(0x82, 0x02)
krenbluetoothsig 0:876e59f87d50 38 #define BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x03)
krenbluetoothsig 0:876e59f87d50 39 #define BT_MESH_MODEL_OP_GEN_ONOFF_STATUS BT_MESH_MODEL_OP_2(0x82, 0x04)
krenbluetoothsig 0:876e59f87d50 40
krenbluetoothsig 1:fb4893064dd4 41 /* Publication Declarations */
krenbluetoothsig 1:fb4893064dd4 42 BT_MESH_HEALTH_PUB_DEFINE(health_pub, 0);
krenbluetoothsig 0:876e59f87d50 43 BT_MESH_MODEL_PUB_DEFINE(gen_onoff_pub_cli, NULL, 2 + 2);
krenbluetoothsig 0:876e59f87d50 44
krenbluetoothsig 1:fb4893064dd4 45 /* Button debounce timeout */
krenbluetoothsig 1:fb4893064dd4 46 #define BUTTON_DEBOUNCE_DELAY_MS 250
krenbluetoothsig 0:876e59f87d50 47
krenbluetoothsig 1:fb4893064dd4 48 /* LED matrix scroll speed */
krenbluetoothsig 1:fb4893064dd4 49 #define SCROLL_SPEED K_MSEC(500)
krenbluetoothsig 1:fb4893064dd4 50
krenbluetoothsig 1:fb4893064dd4 51 /* Buzzer definition, no used in this example. */
krenbluetoothsig 1:fb4893064dd4 52 #define BUZZER_PIN EXT_P0_GPIO_PIN
krenbluetoothsig 1:fb4893064dd4 53 #define BEEP_DURATION K_MSEC(60)
krenbluetoothsig 0:876e59f87d50 54
krenbluetoothsig 1:fb4893064dd4 55 /* Key definition, it's pre-configured, not need to do provisioning. */
krenbluetoothsig 1:fb4893064dd4 56 static const u8_t net_key[16] = {
krenbluetoothsig 1:fb4893064dd4 57 0xf1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
krenbluetoothsig 1:fb4893064dd4 58 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
krenbluetoothsig 1:fb4893064dd4 59 };
krenbluetoothsig 1:fb4893064dd4 60 static const u8_t dev_key[16] = {
krenbluetoothsig 1:fb4893064dd4 61 0xf1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
krenbluetoothsig 1:fb4893064dd4 62 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
krenbluetoothsig 1:fb4893064dd4 63 };
krenbluetoothsig 1:fb4893064dd4 64 static const u8_t app_key[16] = {
krenbluetoothsig 1:fb4893064dd4 65 0xf1, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
krenbluetoothsig 1:fb4893064dd4 66 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
krenbluetoothsig 0:876e59f87d50 67 };
krenbluetoothsig 0:876e59f87d50 68
krenbluetoothsig 0:876e59f87d50 69
krenbluetoothsig 1:fb4893064dd4 70 /* group address string. */
krenbluetoothsig 1:fb4893064dd4 71 const char *groupAddress2String[] = {
krenbluetoothsig 1:fb4893064dd4 72 "Bedroom",
krenbluetoothsig 1:fb4893064dd4 73 "Living",
krenbluetoothsig 1:fb4893064dd4 74 "Dining",
krenbluetoothsig 1:fb4893064dd4 75 "Garage"
krenbluetoothsig 0:876e59f87d50 76 };
krenbluetoothsig 0:876e59f87d50 77
krenbluetoothsig 1:fb4893064dd4 78 static struct device *gpio;
krenbluetoothsig 1:fb4893064dd4 79 static struct device *nvm;
krenbluetoothsig 1:fb4893064dd4 80 static struct device *pwm;
krenbluetoothsig 1:fb4893064dd4 81
krenbluetoothsig 1:fb4893064dd4 82 static struct k_work button_work;
krenbluetoothsig 1:fb4893064dd4 83 static u32_t time, last_time;
krenbluetoothsig 1:fb4893064dd4 84
krenbluetoothsig 1:fb4893064dd4 85 const u16_t net_idx;
krenbluetoothsig 1:fb4893064dd4 86 const u16_t app_idx;
krenbluetoothsig 1:fb4893064dd4 87 const u32_t iv_index;
krenbluetoothsig 1:fb4893064dd4 88 u8_t flags;
krenbluetoothsig 1:fb4893064dd4 89 u16_t addr = NODE_ADDR;
krenbluetoothsig 1:fb4893064dd4 90 u16_t groupAddress = GROUP_ADDR;
krenbluetoothsig 0:876e59f87d50 91
krenbluetoothsig 1:fb4893064dd4 92 /* Transaction ID for Generic OnOff Set */
krenbluetoothsig 1:fb4893064dd4 93 static u8_t trans_ID = 0;
krenbluetoothsig 1:fb4893064dd4 94
krenbluetoothsig 1:fb4893064dd4 95 /* GenericOnOffSet state */
krenbluetoothsig 1:fb4893064dd4 96 u8_t OnOff_Value = 0;
krenbluetoothsig 1:fb4893064dd4 97
krenbluetoothsig 1:fb4893064dd4 98 /* Model Operation decleration */
krenbluetoothsig 1:fb4893064dd4 99 static void gen_onoff_set(struct bt_mesh_model *model,
krenbluetoothsig 1:fb4893064dd4 100 struct bt_mesh_msg_ctx *ctx,
krenbluetoothsig 1:fb4893064dd4 101 struct net_buf_simple *buf);
krenbluetoothsig 1:fb4893064dd4 102
krenbluetoothsig 1:fb4893064dd4 103 static void gen_onoff_set_unack(struct bt_mesh_model *model,
krenbluetoothsig 1:fb4893064dd4 104 struct bt_mesh_msg_ctx *ctx,
krenbluetoothsig 1:fb4893064dd4 105 struct net_buf_simple *buf);
krenbluetoothsig 1:fb4893064dd4 106
krenbluetoothsig 1:fb4893064dd4 107 static void gen_onoff_get(struct bt_mesh_model *model,
krenbluetoothsig 1:fb4893064dd4 108 struct bt_mesh_msg_ctx *ctx,
krenbluetoothsig 1:fb4893064dd4 109 struct net_buf_simple *buf);
krenbluetoothsig 0:876e59f87d50 110
krenbluetoothsig 1:fb4893064dd4 111 static void gen_onoff_status(struct bt_mesh_model *model,
krenbluetoothsig 1:fb4893064dd4 112 struct bt_mesh_msg_ctx *ctx,
krenbluetoothsig 1:fb4893064dd4 113 struct net_buf_simple *buf);
krenbluetoothsig 1:fb4893064dd4 114 static void genericOnOffSet(void);
krenbluetoothsig 1:fb4893064dd4 115
krenbluetoothsig 0:876e59f87d50 116
krenbluetoothsig 1:fb4893064dd4 117 /* switch group address like round robin. */
krenbluetoothsig 1:fb4893064dd4 118 u16_t board_set_target(void)
krenbluetoothsig 0:876e59f87d50 119 {
krenbluetoothsig 1:fb4893064dd4 120 switch (groupAddress) {
krenbluetoothsig 1:fb4893064dd4 121 case GROUP_ADDR:
krenbluetoothsig 1:fb4893064dd4 122 groupAddress++;
krenbluetoothsig 1:fb4893064dd4 123 break;
krenbluetoothsig 1:fb4893064dd4 124 case (GROUP_ADDR + 3):
krenbluetoothsig 1:fb4893064dd4 125 groupAddress = GROUP_ADDR;
krenbluetoothsig 1:fb4893064dd4 126 break;
krenbluetoothsig 1:fb4893064dd4 127 default:
krenbluetoothsig 1:fb4893064dd4 128 groupAddress++;
krenbluetoothsig 1:fb4893064dd4 129 break;
krenbluetoothsig 1:fb4893064dd4 130 }
krenbluetoothsig 0:876e59f87d50 131
krenbluetoothsig 1:fb4893064dd4 132 return groupAddress;
krenbluetoothsig 1:fb4893064dd4 133 }
krenbluetoothsig 1:fb4893064dd4 134
krenbluetoothsig 1:fb4893064dd4 135 /* Callback function for button B pressed, it's scheduled by OS, out of interrupt routine
krenbluetoothsig 1:fb4893064dd4 136 * it's safe to stay here longer. */
krenbluetoothsig 1:fb4893064dd4 137 static void button_send_pressed(struct k_work *work)
krenbluetoothsig 1:fb4893064dd4 138 {
krenbluetoothsig 1:fb4893064dd4 139 struct mb_display *disp = mb_display_get();
krenbluetoothsig 1:fb4893064dd4 140
krenbluetoothsig 1:fb4893064dd4 141 printk("button_send_pressed()\n");
krenbluetoothsig 1:fb4893064dd4 142 if(OnOff_Value % 2) {
krenbluetoothsig 1:fb4893064dd4 143 mb_display_print(disp, MB_DISPLAY_MODE_SINGLE, 100000,
krenbluetoothsig 1:fb4893064dd4 144 "%s", groupAddress2String[groupAddress - GROUP_ADDR]);
krenbluetoothsig 1:fb4893064dd4 145 }
krenbluetoothsig 1:fb4893064dd4 146 else
krenbluetoothsig 1:fb4893064dd4 147 {
krenbluetoothsig 1:fb4893064dd4 148 mb_display_print(disp, MB_DISPLAY_MODE_SINGLE, 100000,
krenbluetoothsig 1:fb4893064dd4 149 "%s", " ");
krenbluetoothsig 1:fb4893064dd4 150 }
krenbluetoothsig 1:fb4893064dd4 151 genericOnOffSet();
krenbluetoothsig 1:fb4893064dd4 152 }
krenbluetoothsig 1:fb4893064dd4 153
krenbluetoothsig 1:fb4893064dd4 154 /* button B callback, direct invoke by interrupt routine, need to be out of this callback ASAP. */
krenbluetoothsig 1:fb4893064dd4 155 static void button_pressed(struct device *dev, struct gpio_callback *cb,
krenbluetoothsig 0:876e59f87d50 156 uint32_t pins)
krenbluetoothsig 0:876e59f87d50 157 {
krenbluetoothsig 1:fb4893064dd4 158 struct mb_display *disp = mb_display_get();
krenbluetoothsig 1:fb4893064dd4 159
krenbluetoothsig 0:876e59f87d50 160 /*
krenbluetoothsig 0:876e59f87d50 161 * One button press within a 1 second interval sends an on message
krenbluetoothsig 0:876e59f87d50 162 * More than one button press sends an off message
krenbluetoothsig 0:876e59f87d50 163 */
krenbluetoothsig 0:876e59f87d50 164 time = k_uptime_get_32();
krenbluetoothsig 0:876e59f87d50 165
krenbluetoothsig 0:876e59f87d50 166 /* debounce the switch */
krenbluetoothsig 0:876e59f87d50 167 if (time < last_time + BUTTON_DEBOUNCE_DELAY_MS) {
krenbluetoothsig 0:876e59f87d50 168 last_time = time;
krenbluetoothsig 0:876e59f87d50 169 return;
krenbluetoothsig 0:876e59f87d50 170 }
krenbluetoothsig 0:876e59f87d50 171
krenbluetoothsig 0:876e59f87d50 172 if (pins & BIT(SW0_GPIO_PIN)) {
krenbluetoothsig 1:fb4893064dd4 173 k_work_submit(&button_work);
krenbluetoothsig 1:fb4893064dd4 174 }
krenbluetoothsig 1:fb4893064dd4 175 else {
krenbluetoothsig 1:fb4893064dd4 176 board_set_target();
krenbluetoothsig 1:fb4893064dd4 177
krenbluetoothsig 1:fb4893064dd4 178 mb_display_print(disp, MB_DISPLAY_MODE_DEFAULT, SCROLL_SPEED,
krenbluetoothsig 1:fb4893064dd4 179 "%s", groupAddress2String[groupAddress - GROUP_ADDR]);
krenbluetoothsig 0:876e59f87d50 180 }
krenbluetoothsig 1:fb4893064dd4 181 last_time = time;
krenbluetoothsig 1:fb4893064dd4 182 }
krenbluetoothsig 1:fb4893064dd4 183
krenbluetoothsig 1:fb4893064dd4 184 static const struct {
krenbluetoothsig 1:fb4893064dd4 185 char note;
krenbluetoothsig 1:fb4893064dd4 186 u32_t period;
krenbluetoothsig 1:fb4893064dd4 187 u32_t sharp;
krenbluetoothsig 1:fb4893064dd4 188 } period_map[] = {
krenbluetoothsig 1:fb4893064dd4 189 { 'C', 3822, 3608 },
krenbluetoothsig 1:fb4893064dd4 190 { 'D', 3405, 3214 },
krenbluetoothsig 1:fb4893064dd4 191 { 'E', 3034, 3034 },
krenbluetoothsig 1:fb4893064dd4 192 { 'F', 2863, 2703 },
krenbluetoothsig 1:fb4893064dd4 193 { 'G', 2551, 2407 },
krenbluetoothsig 1:fb4893064dd4 194 { 'A', 2273, 2145 },
krenbluetoothsig 1:fb4893064dd4 195 { 'B', 2025, 2025 },
krenbluetoothsig 1:fb4893064dd4 196 };
krenbluetoothsig 1:fb4893064dd4 197
krenbluetoothsig 1:fb4893064dd4 198 static u32_t get_period(char note, bool sharp)
krenbluetoothsig 1:fb4893064dd4 199 {
krenbluetoothsig 1:fb4893064dd4 200 int i;
krenbluetoothsig 1:fb4893064dd4 201
krenbluetoothsig 1:fb4893064dd4 202 if (note == ' ') {
krenbluetoothsig 1:fb4893064dd4 203 return 0;
krenbluetoothsig 0:876e59f87d50 204 }
krenbluetoothsig 0:876e59f87d50 205
krenbluetoothsig 1:fb4893064dd4 206 for (i = 0; i < ARRAY_SIZE(period_map); i++) {
krenbluetoothsig 1:fb4893064dd4 207 if (period_map[i].note != note) {
krenbluetoothsig 1:fb4893064dd4 208 continue;
krenbluetoothsig 1:fb4893064dd4 209 }
krenbluetoothsig 0:876e59f87d50 210
krenbluetoothsig 1:fb4893064dd4 211 if (sharp) {
krenbluetoothsig 1:fb4893064dd4 212 return period_map[i].sharp;
krenbluetoothsig 1:fb4893064dd4 213 } else {
krenbluetoothsig 1:fb4893064dd4 214 return period_map[i].period;
krenbluetoothsig 1:fb4893064dd4 215 }
krenbluetoothsig 1:fb4893064dd4 216 }
krenbluetoothsig 1:fb4893064dd4 217
krenbluetoothsig 1:fb4893064dd4 218 return 1500;
krenbluetoothsig 0:876e59f87d50 219 }
krenbluetoothsig 0:876e59f87d50 220
krenbluetoothsig 0:876e59f87d50 221
krenbluetoothsig 1:fb4893064dd4 222 void board_heartbeat(u8_t hops, u16_t feat)
krenbluetoothsig 0:876e59f87d50 223 {
krenbluetoothsig 0:876e59f87d50 224 struct mb_display *disp = mb_display_get();
krenbluetoothsig 1:fb4893064dd4 225 const struct mb_image hops_img[] = {
krenbluetoothsig 1:fb4893064dd4 226 MB_IMAGE({ 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 227 { 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 228 { 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 229 { 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 230 { 1, 1, 1, 1, 1 }),
krenbluetoothsig 1:fb4893064dd4 231 MB_IMAGE({ 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 232 { 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 233 { 1, 1, 0, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 234 { 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 235 { 1, 1, 1, 1, 1 }),
krenbluetoothsig 1:fb4893064dd4 236 MB_IMAGE({ 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 237 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 238 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 239 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 240 { 1, 1, 1, 1, 1 }),
krenbluetoothsig 1:fb4893064dd4 241 MB_IMAGE({ 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 242 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 243 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 244 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 245 { 1, 1, 1, 1, 1 }),
krenbluetoothsig 1:fb4893064dd4 246 MB_IMAGE({ 1, 0, 1, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 247 { 0, 0, 0, 0, 0 },
krenbluetoothsig 1:fb4893064dd4 248 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 249 { 0, 0, 0, 0, 0 },
krenbluetoothsig 1:fb4893064dd4 250 { 1, 0, 1, 0, 1 })
krenbluetoothsig 1:fb4893064dd4 251 };
krenbluetoothsig 0:876e59f87d50 252
krenbluetoothsig 1:fb4893064dd4 253 printk("%u hops\n", hops);
krenbluetoothsig 0:876e59f87d50 254
krenbluetoothsig 1:fb4893064dd4 255 if (hops) {
krenbluetoothsig 1:fb4893064dd4 256 hops = min(hops, ARRAY_SIZE(hops_img));
krenbluetoothsig 1:fb4893064dd4 257 mb_display_image(disp, MB_DISPLAY_MODE_SINGLE, K_SECONDS(2),
krenbluetoothsig 1:fb4893064dd4 258 &hops_img[hops - 1], 1);
krenbluetoothsig 1:fb4893064dd4 259 }
krenbluetoothsig 0:876e59f87d50 260 }
krenbluetoothsig 0:876e59f87d50 261
krenbluetoothsig 1:fb4893064dd4 262 void board_attention(bool attention)
krenbluetoothsig 0:876e59f87d50 263 {
krenbluetoothsig 1:fb4893064dd4 264 struct mb_display *disp = mb_display_get();
krenbluetoothsig 1:fb4893064dd4 265 static const struct mb_image attn_img[] = {
krenbluetoothsig 1:fb4893064dd4 266 MB_IMAGE({ 0, 0, 0, 0, 0 },
krenbluetoothsig 1:fb4893064dd4 267 { 0, 0, 0, 0, 0 },
krenbluetoothsig 1:fb4893064dd4 268 { 0, 0, 1, 0, 0 },
krenbluetoothsig 1:fb4893064dd4 269 { 0, 0, 0, 0, 0 },
krenbluetoothsig 1:fb4893064dd4 270 { 0, 0, 0, 0, 0 }),
krenbluetoothsig 1:fb4893064dd4 271 MB_IMAGE({ 0, 0, 0, 0, 0 },
krenbluetoothsig 1:fb4893064dd4 272 { 0, 1, 1, 1, 0 },
krenbluetoothsig 1:fb4893064dd4 273 { 0, 1, 1, 1, 0 },
krenbluetoothsig 1:fb4893064dd4 274 { 0, 1, 1, 1, 0 },
krenbluetoothsig 1:fb4893064dd4 275 { 0, 0, 0, 0, 0 }),
krenbluetoothsig 1:fb4893064dd4 276 MB_IMAGE({ 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 277 { 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 278 { 1, 1, 0, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 279 { 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 280 { 1, 1, 1, 1, 1 }),
krenbluetoothsig 1:fb4893064dd4 281 MB_IMAGE({ 1, 1, 1, 1, 1 },
krenbluetoothsig 1:fb4893064dd4 282 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 283 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 284 { 1, 0, 0, 0, 1 },
krenbluetoothsig 1:fb4893064dd4 285 { 1, 1, 1, 1, 1 }),
krenbluetoothsig 1:fb4893064dd4 286 };
krenbluetoothsig 0:876e59f87d50 287
krenbluetoothsig 1:fb4893064dd4 288 if (attention) {
krenbluetoothsig 1:fb4893064dd4 289 mb_display_image(disp,
krenbluetoothsig 1:fb4893064dd4 290 MB_DISPLAY_MODE_DEFAULT | MB_DISPLAY_FLAG_LOOP,
krenbluetoothsig 1:fb4893064dd4 291 K_MSEC(150), attn_img, ARRAY_SIZE(attn_img));
krenbluetoothsig 1:fb4893064dd4 292 } else {
krenbluetoothsig 1:fb4893064dd4 293 mb_display_stop(disp);
krenbluetoothsig 1:fb4893064dd4 294 }
krenbluetoothsig 1:fb4893064dd4 295 }
krenbluetoothsig 0:876e59f87d50 296
krenbluetoothsig 0:876e59f87d50 297 static void configure_button(void)
krenbluetoothsig 0:876e59f87d50 298 {
krenbluetoothsig 0:876e59f87d50 299 static struct gpio_callback button_cb;
krenbluetoothsig 0:876e59f87d50 300
krenbluetoothsig 0:876e59f87d50 301 /* Initialize the button debouncer */
krenbluetoothsig 0:876e59f87d50 302 last_time = k_uptime_get_32();
krenbluetoothsig 0:876e59f87d50 303
krenbluetoothsig 0:876e59f87d50 304 k_work_init(&button_work, button_send_pressed);
krenbluetoothsig 0:876e59f87d50 305
krenbluetoothsig 0:876e59f87d50 306 gpio = device_get_binding(SW0_GPIO_NAME);
krenbluetoothsig 0:876e59f87d50 307
krenbluetoothsig 0:876e59f87d50 308 gpio_pin_configure(gpio, SW0_GPIO_PIN,
krenbluetoothsig 0:876e59f87d50 309 (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
krenbluetoothsig 0:876e59f87d50 310 GPIO_INT_ACTIVE_LOW));
krenbluetoothsig 1:fb4893064dd4 311 gpio_pin_configure(gpio, SW1_GPIO_PIN,
krenbluetoothsig 1:fb4893064dd4 312 (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
krenbluetoothsig 1:fb4893064dd4 313 GPIO_INT_ACTIVE_LOW));
krenbluetoothsig 0:876e59f87d50 314
krenbluetoothsig 0:876e59f87d50 315 gpio_init_callback(&button_cb, button_pressed,
krenbluetoothsig 1:fb4893064dd4 316 BIT(SW0_GPIO_PIN) | BIT(SW1_GPIO_PIN));
krenbluetoothsig 0:876e59f87d50 317 gpio_add_callback(gpio, &button_cb);
krenbluetoothsig 0:876e59f87d50 318
krenbluetoothsig 0:876e59f87d50 319 gpio_pin_enable_callback(gpio, SW0_GPIO_PIN);
krenbluetoothsig 0:876e59f87d50 320 gpio_pin_enable_callback(gpio, SW1_GPIO_PIN);
krenbluetoothsig 0:876e59f87d50 321 }
krenbluetoothsig 0:876e59f87d50 322
krenbluetoothsig 7:6512e150f5f6 323 void board_init(u16_t *addr)
krenbluetoothsig 0:876e59f87d50 324 {
krenbluetoothsig 1:fb4893064dd4 325 struct mb_display *disp = mb_display_get();
krenbluetoothsig 1:fb4893064dd4 326
krenbluetoothsig 1:fb4893064dd4 327 nvm = device_get_binding(FLASH_DEV_NAME);
krenbluetoothsig 1:fb4893064dd4 328 pwm = device_get_binding(CONFIG_PWM_NRF5_SW_0_DEV_NAME);
krenbluetoothsig 1:fb4893064dd4 329
krenbluetoothsig 1:fb4893064dd4 330 *addr = ( (u16_t)NRF_FICR->DEVICEADDR[0] ) & 0x7fff;
krenbluetoothsig 1:fb4893064dd4 331 printk("FICR 0x%02x\n", *addr);
krenbluetoothsig 1:fb4893064dd4 332
krenbluetoothsig 1:fb4893064dd4 333 mb_display_print(disp, MB_DISPLAY_MODE_DEFAULT, SCROLL_SPEED,
krenbluetoothsig 1:fb4893064dd4 334 "%s %s", "Client", groupAddress2String[groupAddress - GROUP_ADDR]);
krenbluetoothsig 0:876e59f87d50 335
krenbluetoothsig 0:876e59f87d50 336 configure_button();
krenbluetoothsig 0:876e59f87d50 337 }
krenbluetoothsig 0:876e59f87d50 338
krenbluetoothsig 1:fb4893064dd4 339 static void heartbeat(u8_t hops, u16_t feat)
krenbluetoothsig 1:fb4893064dd4 340 {
krenbluetoothsig 1:fb4893064dd4 341 board_heartbeat(hops, feat);
krenbluetoothsig 1:fb4893064dd4 342 }
krenbluetoothsig 1:fb4893064dd4 343
krenbluetoothsig 1:fb4893064dd4 344 static struct bt_mesh_cfg_srv cfg_srv = {
krenbluetoothsig 1:fb4893064dd4 345 #if defined(CONFIG_BOARD_BBC_MICROBIT)
krenbluetoothsig 1:fb4893064dd4 346 .relay = BT_MESH_RELAY_ENABLED,
krenbluetoothsig 1:fb4893064dd4 347 .beacon = BT_MESH_BEACON_DISABLED,
krenbluetoothsig 1:fb4893064dd4 348 #else
krenbluetoothsig 1:fb4893064dd4 349 .relay = BT_MESH_RELAY_ENABLED,
krenbluetoothsig 1:fb4893064dd4 350 .beacon = BT_MESH_BEACON_ENABLED,
krenbluetoothsig 1:fb4893064dd4 351 #endif
krenbluetoothsig 1:fb4893064dd4 352 .frnd = BT_MESH_FRIEND_NOT_SUPPORTED,
krenbluetoothsig 1:fb4893064dd4 353 .default_ttl = 7,
krenbluetoothsig 1:fb4893064dd4 354
krenbluetoothsig 1:fb4893064dd4 355 /* 3 transmissions with 20ms interval */
krenbluetoothsig 1:fb4893064dd4 356 .net_transmit = BT_MESH_TRANSMIT(2, 20),
krenbluetoothsig 1:fb4893064dd4 357 .relay_retransmit = BT_MESH_TRANSMIT(3, 20),
krenbluetoothsig 1:fb4893064dd4 358
krenbluetoothsig 1:fb4893064dd4 359 .hb_sub.func = heartbeat,
krenbluetoothsig 1:fb4893064dd4 360 };
krenbluetoothsig 1:fb4893064dd4 361
krenbluetoothsig 1:fb4893064dd4 362 static struct bt_mesh_cfg_cli cfg_cli = {
krenbluetoothsig 1:fb4893064dd4 363 };
krenbluetoothsig 1:fb4893064dd4 364
krenbluetoothsig 1:fb4893064dd4 365
krenbluetoothsig 1:fb4893064dd4 366 static void attention_on(struct bt_mesh_model *model)
krenbluetoothsig 1:fb4893064dd4 367 {
krenbluetoothsig 1:fb4893064dd4 368 printk("attention_on()\n");
krenbluetoothsig 1:fb4893064dd4 369 board_attention(true);
krenbluetoothsig 1:fb4893064dd4 370 }
krenbluetoothsig 1:fb4893064dd4 371
krenbluetoothsig 1:fb4893064dd4 372 static void attention_off(struct bt_mesh_model *model)
krenbluetoothsig 1:fb4893064dd4 373 {
krenbluetoothsig 1:fb4893064dd4 374 printk("attention_off()\n");
krenbluetoothsig 1:fb4893064dd4 375 board_attention(false);
krenbluetoothsig 1:fb4893064dd4 376 }
krenbluetoothsig 1:fb4893064dd4 377
krenbluetoothsig 1:fb4893064dd4 378 static const struct bt_mesh_health_srv_cb health_srv_cb = {
krenbluetoothsig 1:fb4893064dd4 379 .attn_on = attention_on,
krenbluetoothsig 1:fb4893064dd4 380 .attn_off = attention_off,
krenbluetoothsig 1:fb4893064dd4 381 };
krenbluetoothsig 1:fb4893064dd4 382
krenbluetoothsig 1:fb4893064dd4 383 static struct bt_mesh_health_srv health_srv = {
krenbluetoothsig 1:fb4893064dd4 384 .cb = &health_srv_cb,
krenbluetoothsig 1:fb4893064dd4 385 };
krenbluetoothsig 1:fb4893064dd4 386
krenbluetoothsig 1:fb4893064dd4 387 /*
krenbluetoothsig 1:fb4893064dd4 388 * OnOff Model Client Op Dispatch Table
krenbluetoothsig 1:fb4893064dd4 389 */
krenbluetoothsig 1:fb4893064dd4 390
krenbluetoothsig 1:fb4893064dd4 391 static const struct bt_mesh_model_op gen_onoff_cli_op[] = {
krenbluetoothsig 1:fb4893064dd4 392 { BT_MESH_MODEL_OP_GEN_ONOFF_STATUS, 1, gen_onoff_status },
krenbluetoothsig 1:fb4893064dd4 393 BT_MESH_MODEL_OP_END,
krenbluetoothsig 1:fb4893064dd4 394 };
krenbluetoothsig 1:fb4893064dd4 395
krenbluetoothsig 1:fb4893064dd4 396 static struct bt_mesh_model root_models[] = {
krenbluetoothsig 1:fb4893064dd4 397 BT_MESH_MODEL_CFG_SRV(&cfg_srv),
krenbluetoothsig 1:fb4893064dd4 398 BT_MESH_MODEL_CFG_CLI(&cfg_cli),
krenbluetoothsig 1:fb4893064dd4 399 BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub),
krenbluetoothsig 1:fb4893064dd4 400 BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_ONOFF_CLI, gen_onoff_cli_op,
krenbluetoothsig 1:fb4893064dd4 401 &gen_onoff_pub_cli, NULL),
krenbluetoothsig 1:fb4893064dd4 402 };
krenbluetoothsig 1:fb4893064dd4 403
krenbluetoothsig 1:fb4893064dd4 404 static struct bt_mesh_elem elements[] = {
krenbluetoothsig 1:fb4893064dd4 405 BT_MESH_ELEM(0, root_models, /* vnd_models */ BT_MESH_MODEL_NONE),
krenbluetoothsig 1:fb4893064dd4 406 };
krenbluetoothsig 1:fb4893064dd4 407
krenbluetoothsig 1:fb4893064dd4 408 static const struct bt_mesh_comp comp = {
krenbluetoothsig 1:fb4893064dd4 409 .cid = BT_COMP_ID_LF,
krenbluetoothsig 1:fb4893064dd4 410 .elem = elements,
krenbluetoothsig 1:fb4893064dd4 411 .elem_count = ARRAY_SIZE(elements),
krenbluetoothsig 1:fb4893064dd4 412 };
krenbluetoothsig 1:fb4893064dd4 413
krenbluetoothsig 1:fb4893064dd4 414 /*
krenbluetoothsig 1:fb4893064dd4 415 * Generic OnOff Model Server Message Handlers
krenbluetoothsig 1:fb4893064dd4 416 *
krenbluetoothsig 1:fb4893064dd4 417 * Mesh Model Specification 3.1.1
krenbluetoothsig 1:fb4893064dd4 418 *
krenbluetoothsig 1:fb4893064dd4 419 */
krenbluetoothsig 1:fb4893064dd4 420
krenbluetoothsig 1:fb4893064dd4 421 static void gen_onoff_get(struct bt_mesh_model *model,
krenbluetoothsig 1:fb4893064dd4 422 struct bt_mesh_msg_ctx *ctx,
krenbluetoothsig 1:fb4893064dd4 423 struct net_buf_simple *buf)
krenbluetoothsig 1:fb4893064dd4 424 {
krenbluetoothsig 1:fb4893064dd4 425 printk("gen_onoff_get...\n");
krenbluetoothsig 1:fb4893064dd4 426 }
krenbluetoothsig 1:fb4893064dd4 427
krenbluetoothsig 1:fb4893064dd4 428 static void gen_onoff_set_unack(struct bt_mesh_model *model,
krenbluetoothsig 1:fb4893064dd4 429 struct bt_mesh_msg_ctx *ctx,
krenbluetoothsig 1:fb4893064dd4 430 struct net_buf_simple *buf)
krenbluetoothsig 1:fb4893064dd4 431 {
krenbluetoothsig 1:fb4893064dd4 432 printk("gen_onoff_set_unack...\n");
krenbluetoothsig 1:fb4893064dd4 433 }
krenbluetoothsig 1:fb4893064dd4 434
krenbluetoothsig 1:fb4893064dd4 435 static void gen_onoff_set(struct bt_mesh_model *model,
krenbluetoothsig 1:fb4893064dd4 436 struct bt_mesh_msg_ctx *ctx,
krenbluetoothsig 1:fb4893064dd4 437 struct net_buf_simple *buf)
krenbluetoothsig 1:fb4893064dd4 438 {
krenbluetoothsig 1:fb4893064dd4 439 printk("gen_onoff_set...\n");
krenbluetoothsig 1:fb4893064dd4 440
krenbluetoothsig 1:fb4893064dd4 441 }
krenbluetoothsig 1:fb4893064dd4 442
krenbluetoothsig 1:fb4893064dd4 443 static void gen_onoff_status(struct bt_mesh_model *model,
krenbluetoothsig 1:fb4893064dd4 444 struct bt_mesh_msg_ctx *ctx,
krenbluetoothsig 1:fb4893064dd4 445 struct net_buf_simple *buf)
krenbluetoothsig 1:fb4893064dd4 446 {
krenbluetoothsig 1:fb4893064dd4 447 printk("gen_onoff_status...\n");
krenbluetoothsig 1:fb4893064dd4 448 }
krenbluetoothsig 1:fb4893064dd4 449
krenbluetoothsig 1:fb4893064dd4 450 static void configure(void)
krenbluetoothsig 1:fb4893064dd4 451 {
krenbluetoothsig 1:fb4893064dd4 452 int status;
krenbluetoothsig 1:fb4893064dd4 453
krenbluetoothsig 1:fb4893064dd4 454 printk("Configuring...\n");
krenbluetoothsig 1:fb4893064dd4 455
krenbluetoothsig 1:fb4893064dd4 456 /* Add Application Key */
krenbluetoothsig 1:fb4893064dd4 457 status = bt_mesh_cfg_app_key_add(net_idx, addr, net_idx, app_idx, app_key, NULL);
krenbluetoothsig 1:fb4893064dd4 458 printk("bt_mesh_cfg_app_key_add = %d \n", status);
krenbluetoothsig 1:fb4893064dd4 459
krenbluetoothsig 1:fb4893064dd4 460
krenbluetoothsig 1:fb4893064dd4 461 /* Bind to Generic on/off client model */
krenbluetoothsig 1:fb4893064dd4 462 status = bt_mesh_cfg_mod_app_bind(net_idx, addr, addr, app_idx,
krenbluetoothsig 1:fb4893064dd4 463 BT_MESH_MODEL_ID_GEN_ONOFF_CLI, NULL);
krenbluetoothsig 1:fb4893064dd4 464 printk("bt_mesh_cfg_mod_app_bind = %d \n", status);
krenbluetoothsig 1:fb4893064dd4 465
krenbluetoothsig 1:fb4893064dd4 466 status = bt_mesh_cfg_mod_sub_add(net_idx, addr, addr,
krenbluetoothsig 1:fb4893064dd4 467 GROUP_ADDR, BT_MESH_MODEL_ID_GEN_ONOFF_CLI, NULL);
krenbluetoothsig 1:fb4893064dd4 468 printk("bt_mesh_cfg_mod_sub_add = %d \n", status);
krenbluetoothsig 1:fb4893064dd4 469
krenbluetoothsig 1:fb4893064dd4 470
krenbluetoothsig 1:fb4893064dd4 471 struct bt_mesh_cfg_hb_sub sub = {
krenbluetoothsig 1:fb4893064dd4 472 .src = PUBLISHER_ADDR,
krenbluetoothsig 1:fb4893064dd4 473 .dst = GROUP_ADDR,
krenbluetoothsig 1:fb4893064dd4 474 .period = 0x10,
krenbluetoothsig 1:fb4893064dd4 475 };
krenbluetoothsig 1:fb4893064dd4 476
krenbluetoothsig 1:fb4893064dd4 477 bt_mesh_cfg_hb_sub_set(net_idx, addr, &sub, NULL);
krenbluetoothsig 1:fb4893064dd4 478 printk("Subscribing to heartbeat messages\n");
krenbluetoothsig 1:fb4893064dd4 479
krenbluetoothsig 1:fb4893064dd4 480
krenbluetoothsig 1:fb4893064dd4 481 printk("Configuration complete\n");
krenbluetoothsig 1:fb4893064dd4 482
krenbluetoothsig 1:fb4893064dd4 483 }
krenbluetoothsig 1:fb4893064dd4 484
krenbluetoothsig 1:fb4893064dd4 485 static const u8_t dev_uuid[16] = { 0xdd, 0xdd };
krenbluetoothsig 1:fb4893064dd4 486
krenbluetoothsig 1:fb4893064dd4 487 static const struct bt_mesh_prov prov = {
krenbluetoothsig 1:fb4893064dd4 488 .uuid = dev_uuid,
krenbluetoothsig 1:fb4893064dd4 489 };
krenbluetoothsig 1:fb4893064dd4 490
krenbluetoothsig 0:876e59f87d50 491 static void bt_ready(int err)
krenbluetoothsig 0:876e59f87d50 492 {
krenbluetoothsig 0:876e59f87d50 493 if (err) {
krenbluetoothsig 0:876e59f87d50 494 printk("Bluetooth init failed (err %d)\n", err);
krenbluetoothsig 0:876e59f87d50 495 return;
krenbluetoothsig 0:876e59f87d50 496 }
krenbluetoothsig 0:876e59f87d50 497
krenbluetoothsig 0:876e59f87d50 498 printk("Bluetooth initialized\n");
krenbluetoothsig 0:876e59f87d50 499
krenbluetoothsig 0:876e59f87d50 500 err = bt_mesh_init(&prov, &comp);
krenbluetoothsig 0:876e59f87d50 501 if (err) {
krenbluetoothsig 0:876e59f87d50 502 printk("Initializing mesh failed (err %d)\n", err);
krenbluetoothsig 0:876e59f87d50 503 return;
krenbluetoothsig 0:876e59f87d50 504 }
krenbluetoothsig 0:876e59f87d50 505
krenbluetoothsig 1:fb4893064dd4 506 printk("Mesh initialized\n");
krenbluetoothsig 0:876e59f87d50 507
krenbluetoothsig 7:6512e150f5f6 508 if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
krenbluetoothsig 7:6512e150f5f6 509 printk("Loading stored settings\n");
krenbluetoothsig 7:6512e150f5f6 510 settings_load();
krenbluetoothsig 7:6512e150f5f6 511 }
krenbluetoothsig 7:6512e150f5f6 512
krenbluetoothsig 7:6512e150f5f6 513 err = bt_mesh_provision(net_key, net_idx, flags, iv_index, addr,
krenbluetoothsig 1:fb4893064dd4 514 dev_key);
krenbluetoothsig 7:6512e150f5f6 515
krenbluetoothsig 7:6512e150f5f6 516 if (err == -EALREADY) {
krenbluetoothsig 7:6512e150f5f6 517 printk("Using stored settings\n");
krenbluetoothsig 7:6512e150f5f6 518 } else if (err) {
krenbluetoothsig 1:fb4893064dd4 519 printk("Provisioning failed (err %d)\n", err);
krenbluetoothsig 1:fb4893064dd4 520 return;
krenbluetoothsig 7:6512e150f5f6 521 } else {
krenbluetoothsig 7:6512e150f5f6 522 printk("Provisioning completed\n");
krenbluetoothsig 7:6512e150f5f6 523 configure();
krenbluetoothsig 1:fb4893064dd4 524 }
krenbluetoothsig 1:fb4893064dd4 525
krenbluetoothsig 1:fb4893064dd4 526 printk("Provisioning completed\n");
krenbluetoothsig 1:fb4893064dd4 527
krenbluetoothsig 1:fb4893064dd4 528 configure();
krenbluetoothsig 0:876e59f87d50 529 }
krenbluetoothsig 0:876e59f87d50 530
krenbluetoothsig 1:fb4893064dd4 531 static void genericOnOffSet(void)
krenbluetoothsig 0:876e59f87d50 532 {
krenbluetoothsig 1:fb4893064dd4 533 NET_BUF_SIMPLE_DEFINE(msg, 2 + 2 + 4);
krenbluetoothsig 1:fb4893064dd4 534 struct bt_mesh_msg_ctx ctx = {
krenbluetoothsig 1:fb4893064dd4 535 .net_idx = net_idx,
krenbluetoothsig 1:fb4893064dd4 536 .app_idx = app_idx,
krenbluetoothsig 1:fb4893064dd4 537 .addr = groupAddress,
krenbluetoothsig 1:fb4893064dd4 538 .send_ttl = BT_MESH_TTL_DEFAULT,
krenbluetoothsig 1:fb4893064dd4 539 };
krenbluetoothsig 1:fb4893064dd4 540
krenbluetoothsig 1:fb4893064dd4 541 /* Bind to Generic OnOff Model */
krenbluetoothsig 1:fb4893064dd4 542 bt_mesh_model_msg_init(&msg, BT_MESH_MODEL_OP_GEN_ONOFF_SET );
krenbluetoothsig 1:fb4893064dd4 543
krenbluetoothsig 1:fb4893064dd4 544 net_buf_simple_add_u8(&msg, OnOff_Value % 2);
krenbluetoothsig 1:fb4893064dd4 545 OnOff_Value++;
krenbluetoothsig 1:fb4893064dd4 546 net_buf_simple_add_u8(&msg, trans_ID++);
krenbluetoothsig 1:fb4893064dd4 547
krenbluetoothsig 1:fb4893064dd4 548 if (bt_mesh_model_send(&root_models[3], &ctx, &msg, NULL, NULL)) {
krenbluetoothsig 1:fb4893064dd4 549 printk("Unable to send Vendor Button message\n");
krenbluetoothsig 1:fb4893064dd4 550 }
krenbluetoothsig 1:fb4893064dd4 551
krenbluetoothsig 1:fb4893064dd4 552 printk("Button message sent with addr 0x%04x\n", groupAddress);
krenbluetoothsig 0:876e59f87d50 553 }
krenbluetoothsig 0:876e59f87d50 554
krenbluetoothsig 0:876e59f87d50 555 void main(void)
krenbluetoothsig 0:876e59f87d50 556 {
krenbluetoothsig 0:876e59f87d50 557 int err;
krenbluetoothsig 1:fb4893064dd4 558
krenbluetoothsig 1:fb4893064dd4 559 printk("Initializing...\n");
krenbluetoothsig 0:876e59f87d50 560
krenbluetoothsig 7:6512e150f5f6 561 board_init(&addr);
krenbluetoothsig 0:876e59f87d50 562
krenbluetoothsig 7:6512e150f5f6 563 printk("Unicast address: 0x%04x, name: %s\n", addr, groupAddress2String[groupAddress - GROUP_ADDR]);
krenbluetoothsig 0:876e59f87d50 564
krenbluetoothsig 0:876e59f87d50 565 /* Initialize the Bluetooth Subsystem */
krenbluetoothsig 0:876e59f87d50 566 err = bt_enable(bt_ready);
krenbluetoothsig 0:876e59f87d50 567 if (err) {
krenbluetoothsig 0:876e59f87d50 568 printk("Bluetooth init failed (err %d)\n", err);
krenbluetoothsig 0:876e59f87d50 569 }
krenbluetoothsig 1:fb4893064dd4 570
krenbluetoothsig 1:fb4893064dd4 571 while (1) {
krenbluetoothsig 1:fb4893064dd4 572
krenbluetoothsig 1:fb4893064dd4 573 }
krenbluetoothsig 1:fb4893064dd4 574
krenbluetoothsig 0:876e59f87d50 575 }