gatt-srv.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. /*
  2. * Copyright (C) 2019 Freie Universität Berlin
  3. *
  4. * This file is subject to the terms and conditions of the GNU Lesser
  5. * General Public License v2.1. See the file LICENSE in the top level
  6. * directory for more details.
  7. */
  8. /**
  9. * @ingroup examples
  10. * @{
  11. *
  12. * @file
  13. * @brief (Mock-up) BLE heart rate sensor example
  14. *
  15. * @author Hauke Petersen <hauke.petersen@fu-berlin.de>
  16. *
  17. * @}
  18. */
  19. #include <stdio.h>
  20. #include <stdint.h>
  21. #include "assert.h"
  22. #include "event/timeout.h"
  23. #include "nimble_riot.h"
  24. #include "net/bluetil/ad.h"
  25. #include "periph/gpio.h"
  26. #include "timex.h"
  27. #include "roomba.h"
  28. #include "board.h"
  29. #include "host/ble_hs.h"
  30. #include "host/ble_gatt.h"
  31. #include "services/gap/ble_svc_gap.h"
  32. #include "services/gatt/ble_svc_gatt.h"
  33. #define BLE_GATT_SVC_IPS 0x1821
  34. #define BLE_GATT_CHAR_IPS_CONFIG 0x2AAD
  35. #define BLE_GATT_CHAR_LATITUDE 0x2AAE
  36. #define BLE_GATT_CHAR_LONGITUDE 0x2AAF
  37. #define BLE_GATT_CHAR_LOCAL_NORTH 0x2AB0
  38. #define BLE_GATT_CHAR_LOCAL_EAST 0x2AB1
  39. #define BLE_GATT_CHAR_FLOOR_N 0x2AB2
  40. #define BLE_GATT_CHAR_ALTITUDE 0x2AB3
  41. #define BLE_GATT_CHAR_UNCERTAIN 0x2AB4
  42. #define BLE_GATT_CHAR_LOC_NAME 0x2AB4
  43. #define IPS_CONFIG_COORD_PRESENT (1 << 0)
  44. #define IPS_CONFIG_COORD_IN_ADV (1 << 1)
  45. #define IPS_CONFIG_TXP_IN_ADV (1 << 2)
  46. #define IPS_CONFIG_ALT_IN_ADV (1 << 3)
  47. #define IPS_CONFIG_FLOOR_IN_ADV (1 << 4)
  48. #define IPS_CONFIG_UNCE_IN_ADV (1 << 5)
  49. #define IPS_CONFIG_LOC_NAME_AVAIL (1 << 6)
  50. static const char *_device_name = "ROOMBAHAHAHACKED";
  51. static const char *_manufacturer_name = "Insane adding machines";
  52. static const char *_model_number = "2X";
  53. static const char *_serial_number = "a8b302c7f3-29183-x8";
  54. static const char *_fw_ver = "1.0.0";
  55. static const char *_hw_ver = "1.0";
  56. static event_queue_t _eq;
  57. static event_t _update_evt;
  58. static event_timeout_t _update_timeout_evt;
  59. static uint16_t _conn_handle;
  60. static uint16_t _ips_val_handle;
  61. static uint16_t _sensors_val_handle;
  62. static int _ips_handler(uint16_t conn_handle, uint16_t attr_handle,
  63. struct ble_gatt_access_ctxt *ctxt, void *arg);
  64. static int _devinfo_handler(uint16_t conn_handle, uint16_t attr_handle,
  65. struct ble_gatt_access_ctxt *ctxt, void *arg);
  66. static int _roomba_ctrl_handler(uint16_t conn_handle, uint16_t attr_handle,
  67. struct ble_gatt_access_ctxt *ctxt, void *arg);
  68. static int _roomba_sensors_handler(uint16_t conn_handle, uint16_t attr_handle,
  69. struct ble_gatt_access_ctxt *ctxt, void *arg);
  70. static int _bas_handler(uint16_t conn_handle, uint16_t attr_handle,
  71. struct ble_gatt_access_ctxt *ctxt, void *arg);
  72. static void _start_advertising(void);
  73. /* UUID = 35f28386-3070-4f3b-ba38-27507e991760 */
  74. static const ble_uuid128_t gatt_svr_svc_roomba = BLE_UUID128_INIT(
  75. 0x60, 0x17, 0x99, 0x7e, 0x50, 0x27, 0x38, 0xba,
  76. 0x3b, 0x4f, 0x70, 0x30, 0x86, 0x83, 0xf2, 0x35
  77. );
  78. /* UUID = 35f28386-3070-4f3b-ba38-27507e991762 */
  79. static const ble_uuid128_t gatt_svr_chr_roomba_ctl = BLE_UUID128_INIT(
  80. 0x62, 0x17, 0x99, 0x7e, 0x50, 0x27, 0x38, 0xba,
  81. 0x3b, 0x4f, 0x70, 0x30, 0x86, 0x83, 0xf2, 0x35
  82. );
  83. /* UUID = 35f28386-3070-4f3b-ba38-27507e991764 */
  84. static const ble_uuid128_t gatt_svr_chr_roomba_sensors = BLE_UUID128_INIT(
  85. 0x64, 0x17, 0x99, 0x7e, 0x50, 0x27, 0x38, 0xba,
  86. 0x3b, 0x4f, 0x70, 0x30, 0x86, 0x83, 0xf2, 0x35
  87. );
  88. /* UUID = 35f28386-3070-4f3b-ba38-27507e991766 */
  89. static const ble_uuid128_t gatt_svr_chr_roomba_sensors_notify = BLE_UUID128_INIT(
  90. 0x66, 0x17, 0x99, 0x7e, 0x50, 0x27, 0x38, 0xba,
  91. 0x3b, 0x4f, 0x70, 0x30, 0x86, 0x83, 0xf2, 0x35
  92. );
  93. /* GATT service definitions */
  94. static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
  95. {
  96. /* Indoor positioning service */
  97. .type = BLE_GATT_SVC_TYPE_PRIMARY,
  98. .uuid = BLE_UUID16_DECLARE(BLE_GATT_SVC_IPS),
  99. .characteristics = (struct ble_gatt_chr_def[]) { {
  100. .uuid = BLE_UUID16_DECLARE(BLE_GATT_CHAR_IPS_CONFIG),
  101. .access_cb = _ips_handler,
  102. .val_handle = &_ips_val_handle,
  103. .flags = BLE_GATT_CHR_F_NOTIFY,
  104. }, {
  105. .uuid = BLE_UUID16_DECLARE(BLE_GATT_CHAR_LATITUDE),
  106. .access_cb = _ips_handler,
  107. .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
  108. }, {
  109. .uuid = BLE_UUID16_DECLARE(BLE_GATT_CHAR_LONGITUDE),
  110. .access_cb = _ips_handler,
  111. .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
  112. }, {
  113. 0, /* no more characteristics in this service */
  114. }, }
  115. },
  116. {
  117. /* Roomba controls */
  118. .type = BLE_GATT_SVC_TYPE_PRIMARY,
  119. .uuid = (ble_uuid_t*) &gatt_svr_svc_roomba.u,
  120. .characteristics = (struct ble_gatt_chr_def[]) { {
  121. /* Characteristic: ROOMBA CTRL */
  122. .uuid = (ble_uuid_t*) &gatt_svr_chr_roomba_ctl.u,
  123. .access_cb = _roomba_ctrl_handler,
  124. .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
  125. }, {
  126. /* Characteristic: ROOMBA sensors read/notify */
  127. .uuid = (ble_uuid_t*) &gatt_svr_chr_roomba_sensors.u,
  128. .access_cb = _roomba_sensors_handler,
  129. .flags = BLE_GATT_CHR_F_READ,
  130. }, {
  131. .uuid = (ble_uuid_t*) &gatt_svr_chr_roomba_sensors_notify.u,
  132. .access_cb = _roomba_sensors_handler,
  133. .val_handle = &_sensors_val_handle,
  134. .flags = BLE_GATT_CHR_F_NOTIFY,
  135. }, {
  136. 0, /* no more characteristics in this service */
  137. }, }
  138. },
  139. {
  140. /* Device Information Service */
  141. .type = BLE_GATT_SVC_TYPE_PRIMARY,
  142. .uuid = BLE_UUID16_DECLARE(BLE_GATT_SVC_DEVINFO),
  143. .characteristics = (struct ble_gatt_chr_def[]) { {
  144. .uuid = BLE_UUID16_DECLARE(BLE_GATT_CHAR_MANUFACTURER_NAME),
  145. .access_cb = _devinfo_handler,
  146. .flags = BLE_GATT_CHR_F_READ,
  147. }, {
  148. .uuid = BLE_UUID16_DECLARE(BLE_GATT_CHAR_MODEL_NUMBER_STR),
  149. .access_cb = _devinfo_handler,
  150. .flags = BLE_GATT_CHR_F_READ,
  151. }, {
  152. .uuid = BLE_UUID16_DECLARE(BLE_GATT_CHAR_SERIAL_NUMBER_STR),
  153. .access_cb = _devinfo_handler,
  154. .flags = BLE_GATT_CHR_F_READ,
  155. }, {
  156. .uuid = BLE_UUID16_DECLARE(BLE_GATT_CHAR_FW_REV_STR),
  157. .access_cb = _devinfo_handler,
  158. .flags = BLE_GATT_CHR_F_READ,
  159. }, {
  160. .uuid = BLE_UUID16_DECLARE(BLE_GATT_CHAR_HW_REV_STR),
  161. .access_cb = _devinfo_handler,
  162. .flags = BLE_GATT_CHR_F_READ,
  163. }, {
  164. 0, /* no more characteristics in this service */
  165. }, }
  166. },
  167. {
  168. /* Battery Level Service */
  169. .type = BLE_GATT_SVC_TYPE_PRIMARY,
  170. .uuid = BLE_UUID16_DECLARE(BLE_GATT_SVC_BAS),
  171. .characteristics = (struct ble_gatt_chr_def[]) { {
  172. .uuid = BLE_UUID16_DECLARE(BLE_GATT_CHAR_BATTERY_LEVEL),
  173. .access_cb = _bas_handler,
  174. .flags = BLE_GATT_CHR_F_READ,
  175. }, {
  176. 0, /* no more characteristics in this service */
  177. }, }
  178. },
  179. {
  180. 0, /* no more services */
  181. },
  182. };
  183. int cmd_mode(int argc, char **argv);
  184. uint8_t get_mode(void);
  185. int switch_mode(int newmode);
  186. static uint8_t cmd_buf[20];
  187. static int cmd_buf_off = 0;
  188. static int cmd_buf_exp_len = 0;
  189. void order66(void);
  190. static void parse_bt_char(uint8_t c)
  191. {
  192. uint8_t mode;
  193. if (cmd_buf_off == 0) {
  194. switch (c) {
  195. case 'M':
  196. cmd_buf_exp_len = 2;
  197. break;
  198. case 'D':
  199. cmd_buf_exp_len = 5;
  200. break;
  201. case 'C':
  202. cmd_buf_exp_len = 4;
  203. break;
  204. case 'S':
  205. motors_stop();
  206. return;
  207. default:
  208. printf("Unknown command %02x\n", cmd_buf[0]);
  209. return;
  210. }
  211. }
  212. cmd_buf[cmd_buf_off++] = c;
  213. if (cmd_buf_off >= cmd_buf_exp_len) {
  214. int len = cmd_buf_exp_len;
  215. cmd_buf_off = 0;
  216. cmd_buf_exp_len = 0;
  217. switch (cmd_buf[0]) {
  218. case 'M':
  219. mode = cmd_buf[1];
  220. if (len != 2)
  221. return;
  222. printf("Mode switch: %d\n", mode);
  223. if ((mode <= ROOMBA_MODE_DOCK) || (mode == 66)) {
  224. switch_mode(mode);
  225. }
  226. break;
  227. case 'D':
  228. {
  229. int16_t speed, radius;
  230. if (len != 5)
  231. return;
  232. memcpy(&speed, cmd_buf + 1, 2);
  233. memcpy(&radius, cmd_buf + 3, 2);
  234. printf("Drive %hd %hd\n", speed, radius);
  235. motors_drive(speed, radius);
  236. }
  237. break;
  238. case 'C':
  239. {
  240. if (len != 4)
  241. return;
  242. printf("Clean brushes/vac/sidebrush: %d %d %d\n", cmd_buf[1], cmd_buf[2], cmd_buf[3]);
  243. motors_clean_set(cmd_buf[1], cmd_buf[2], cmd_buf[3]);
  244. }
  245. break;
  246. default:
  247. printf("Unknown command %02x\n", cmd_buf[0]);
  248. }
  249. }
  250. }
  251. static int _roomba_sensors_handler(
  252. uint16_t conn_handle, uint16_t attr_handle,
  253. struct ble_gatt_access_ctxt *ctxt, void *arg)
  254. {
  255. int rc = 0;
  256. uint16_t om_len;
  257. ble_uuid_t* read_uuid = (ble_uuid_t*) &gatt_svr_chr_roomba_sensors.u;
  258. static uint8_t ch;
  259. struct roomba_sensors_data *bt_sensors;
  260. puts("[BT] Sensor command");
  261. (void) conn_handle;
  262. (void) attr_handle;
  263. (void) arg;
  264. bt_sensors = roomba_sensors();
  265. printf("bt_sensors.valid = %s\n", bt_sensors->valid?"yes":"no");
  266. if (ble_uuid_cmp(ctxt->chr->uuid, read_uuid) == 0) {
  267. puts("access to characteristic 'roomba sensors'");
  268. rc = os_mbuf_append(ctxt->om, bt_sensors, sizeof(struct roomba_sensors_data));
  269. puts("");
  270. return rc;
  271. }
  272. puts("unhandled uuid!");
  273. return 1;
  274. }
  275. static int _roomba_ctrl_handler(
  276. uint16_t conn_handle, uint16_t attr_handle,
  277. struct ble_gatt_access_ctxt *ctxt, void *arg)
  278. {
  279. int rc = 0;
  280. uint16_t om_len;
  281. ble_uuid_t* write_uuid = (ble_uuid_t*) &gatt_svr_chr_roomba_ctl.u;
  282. static uint8_t ch;
  283. puts("[BT] Command");
  284. (void) conn_handle;
  285. (void) attr_handle;
  286. (void) arg;
  287. int mode = get_mode();
  288. if (ble_uuid_cmp(ctxt->chr->uuid, write_uuid) == 0) {
  289. puts("access to characteristic 'roomba ctl'");
  290. switch (ctxt->op) {
  291. case BLE_GATT_ACCESS_OP_READ_CHR:
  292. puts("read mode");
  293. /* send given data to the client */
  294. rc = os_mbuf_append(ctxt->om, &mode, sizeof(unsigned int));
  295. break;
  296. case BLE_GATT_ACCESS_OP_WRITE_CHR:
  297. rc = ble_hs_mbuf_to_flat(ctxt->om, &ch, 1, &om_len);
  298. printf("om_len = %d, char: %02x\n", om_len, ch);
  299. parse_bt_char(ch);
  300. break;
  301. case BLE_GATT_ACCESS_OP_READ_DSC:
  302. puts("read from descriptor");
  303. break;
  304. case BLE_GATT_ACCESS_OP_WRITE_DSC:
  305. puts("write to descriptor");
  306. break;
  307. default:
  308. puts("unhandled operation!");
  309. rc = 1;
  310. break;
  311. }
  312. puts("");
  313. return rc;
  314. }
  315. puts("unhandled uuid!");
  316. return 1;
  317. }
  318. static int _ips_handler(uint16_t conn_handle, uint16_t attr_handle,
  319. struct ble_gatt_access_ctxt *ctxt, void *arg)
  320. {
  321. (void)conn_handle;
  322. (void)attr_handle;
  323. (void)arg;
  324. int res;
  325. static uint32_t lat = 0x01020304, lon = 0x05060708;
  326. puts("[ACCESS] indoor positioning value");
  327. if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
  328. printf("[READ] ");
  329. if (ble_uuid_u16(ctxt->chr->uuid) == BLE_GATT_CHAR_LATITUDE) {
  330. printf("LAT\n");
  331. res = os_mbuf_append(ctxt->om, &lat, sizeof(lat));
  332. return (res == 0)? res: BLE_ATT_ERR_INSUFFICIENT_RES;
  333. }
  334. if (ble_uuid_u16(ctxt->chr->uuid) == BLE_GATT_CHAR_LONGITUDE) {
  335. printf("LON\n");
  336. res = os_mbuf_append(ctxt->om, &lon, sizeof(lon));
  337. return (res == 0)? res: BLE_ATT_ERR_INSUFFICIENT_RES;
  338. }
  339. } else if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
  340. printf("[WRITE] ");
  341. if (ble_uuid_u16(ctxt->chr->uuid) == BLE_GATT_CHAR_LATITUDE) {
  342. printf("LAT\n");
  343. memcpy(&lat, ctxt->om->om_databuf, sizeof(lat));
  344. res = os_mbuf_append(ctxt->om, &lat, sizeof(lat));
  345. return (res == 0)? res: BLE_ATT_ERR_INSUFFICIENT_RES;
  346. }
  347. if (ble_uuid_u16(ctxt->chr->uuid) == BLE_GATT_CHAR_LONGITUDE) {
  348. printf("LON\n");
  349. printf("%08x\n", *((unsigned int *)(ctxt->om->om_databuf)));
  350. printf("%08x\n", *((unsigned int *)(ctxt->om->om_databuf + 4)));
  351. memcpy(&lon, ctxt->om->om_databuf, sizeof(lon));
  352. res = os_mbuf_append(ctxt->om, &lon, sizeof(lon));
  353. return (res == 0)? res: BLE_ATT_ERR_INSUFFICIENT_RES;
  354. }
  355. }
  356. return BLE_ATT_ERR_INSUFFICIENT_RES;
  357. }
  358. static int _devinfo_handler(uint16_t conn_handle, uint16_t attr_handle,
  359. struct ble_gatt_access_ctxt *ctxt, void *arg)
  360. {
  361. (void)conn_handle;
  362. (void)attr_handle;
  363. (void)arg;
  364. const char *str;
  365. switch (ble_uuid_u16(ctxt->chr->uuid)) {
  366. case BLE_GATT_CHAR_MANUFACTURER_NAME:
  367. puts("[READ] device information service: manufacturer name value");
  368. str = _manufacturer_name;
  369. break;
  370. case BLE_GATT_CHAR_MODEL_NUMBER_STR:
  371. puts("[READ] device information service: model number value");
  372. str = _model_number;
  373. break;
  374. case BLE_GATT_CHAR_SERIAL_NUMBER_STR:
  375. puts("[READ] device information service: serial number value");
  376. str = _serial_number;
  377. break;
  378. case BLE_GATT_CHAR_FW_REV_STR:
  379. puts("[READ] device information service: firmware revision value");
  380. str = _fw_ver;
  381. break;
  382. case BLE_GATT_CHAR_HW_REV_STR:
  383. puts("[READ] device information service: hardware revision value");
  384. str = _hw_ver;
  385. break;
  386. default:
  387. return BLE_ATT_ERR_UNLIKELY;
  388. }
  389. int res = os_mbuf_append(ctxt->om, str, strlen(str));
  390. return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
  391. }
  392. static int _bas_handler(uint16_t conn_handle, uint16_t attr_handle,
  393. struct ble_gatt_access_ctxt *ctxt, void *arg)
  394. {
  395. (void)conn_handle;
  396. (void)attr_handle;
  397. (void)arg;
  398. puts("[READ] battery level service: battery level value");
  399. uint8_t level = 50; /* this battery will never drain :-) */
  400. int res = os_mbuf_append(ctxt->om, &level, sizeof(level));
  401. return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
  402. }
  403. static int gap_event_cb(struct ble_gap_event *event, void *arg)
  404. {
  405. (void)arg;
  406. switch (event->type) {
  407. case BLE_GAP_EVENT_CONNECT:
  408. printf("Ev: connect, Status: %d\n", event->connect.status);
  409. if (event->connect.status) {
  410. _start_advertising();
  411. LED2_OFF;
  412. return 0;
  413. }
  414. LED2_ON;
  415. _conn_handle = event->connect.conn_handle;
  416. break;
  417. case BLE_GAP_EVENT_DISCONNECT:
  418. _start_advertising();
  419. break;
  420. case BLE_GAP_EVENT_SUBSCRIBE:
  421. if (event->subscribe.attr_handle == _ips_val_handle) {
  422. if (event->subscribe.cur_notify == 1) {
  423. }
  424. else {
  425. }
  426. }
  427. break;
  428. }
  429. return 0;
  430. }
  431. static void _start_advertising(void)
  432. {
  433. struct ble_gap_adv_params advp;
  434. int res;
  435. memset(&advp, 0, sizeof advp);
  436. advp.conn_mode = BLE_GAP_CONN_MODE_UND;
  437. advp.disc_mode = BLE_GAP_DISC_MODE_GEN;
  438. advp.itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
  439. advp.itvl_max = BLE_GAP_ADV_FAST_INTERVAL1_MAX;
  440. res = ble_gap_adv_start(nimble_riot_own_addr_type, NULL, BLE_HS_FOREVER,
  441. &advp, gap_event_cb, NULL);
  442. assert(res == 0);
  443. (void)res;
  444. }
  445. static void update_sensors(void)
  446. {
  447. struct os_mbuf *om;
  448. struct roomba_sensors_data *sens;
  449. printf("[GATT] Sensor values changed\n");
  450. sens = roomba_sensors();
  451. /* send data notification to GATT client */
  452. om = ble_hs_mbuf_from_flat(sens, sizeof(struct roomba_sensors_data));
  453. if (!om) {
  454. printf("[GATT] Error incapsulating sensor data in frame \n");
  455. return;
  456. }
  457. ble_gattc_notify_custom(_conn_handle, _sensors_val_handle, om);
  458. }
  459. void *gatt_srv(void *arg)
  460. {
  461. puts("NimBLE GATT server starting");
  462. int res = 0;
  463. msg_t msg;
  464. (void)res;
  465. /* setup local event queue (for handling heart rate updates) */
  466. /* verify and add our custom services */
  467. res = ble_gatts_count_cfg(gatt_svr_svcs);
  468. assert(res == 0);
  469. res = ble_gatts_add_svcs(gatt_svr_svcs);
  470. assert(res == 0);
  471. /* set the device name */
  472. ble_svc_gap_device_name_set(_device_name);
  473. /* reload the GATT server to link our added services */
  474. ble_gatts_start();
  475. /* configure and set the advertising data */
  476. uint8_t buf[BLE_HS_ADV_MAX_SZ];
  477. bluetil_ad_t ad;
  478. bluetil_ad_init_with_flags(&ad, buf, sizeof(buf), BLUETIL_AD_FLAGS_DEFAULT);
  479. uint16_t ips_uuid = BLE_GATT_SVC_IPS;
  480. bluetil_ad_add(&ad, BLE_GAP_AD_UUID16_INCOMP, &ips_uuid, sizeof(ips_uuid));
  481. bluetil_ad_add_name(&ad, _device_name);
  482. ble_gap_adv_set_data(ad.buf, ad.pos);
  483. /* start to advertise this node */
  484. _start_advertising();
  485. while (1) {
  486. if (msg_receive(&msg) >= 0) {
  487. (void)msg;
  488. update_sensors();
  489. }
  490. }
  491. return 0;
  492. }