void main(void) { struct device *ipm; int rc; uint32_t value32; rc = bt_enable(bt_ready); if (rc) { printk("Bluetooth init failed (err %d)\n", rc); return; } bt_conn_cb_register(&conn_callbacks); bt_conn_auth_cb_register(&auth_cb_display); ipm = device_get_binding("power_ipm"); ipm_register_callback(ipm, sensor_ipm_callback, NULL); ipm_set_enabled(ipm, 1); while (1) { if (default_conn) { value32 = sys_cpu_to_le32(consumption_value); bt_gatt_notify(default_conn, &attrs[2], &value32, sizeof(value32)); k_sleep(INTERVAL); value32 = sys_cpu_to_le32(solar_value); bt_gatt_notify(default_conn, &attrs[6], &value32, sizeof(value32)); } k_sleep(INTERVAL); } }
void main(void) { int err; err = bt_enable(bt_ready); if (err) { printk("Bluetooth init failed (err %d)\n", err); return; } bt_conn_cb_register(&conn_callbacks); bt_conn_auth_cb_register(&auth_cb_display); /* Implement notification. At the moment there is no suitable way * of starting delayed work so we do it here */ while (1) { k_sleep(MSEC_PER_SEC); /* Heartrate measurements simulation */ hrs_notify(); /* Battery level simulation */ bas_notify(); } }
void main(void) { int err; err = bt_enable(NULL); if (err) { printk("Bluetooth init failed (err %d)\n", err); return; } printk("Bluetooth initialized\n"); gap_init(DEVICE_NAME, APPEARANCE); bt_conn_auth_cb_register(&auth_cb_display); bt_conn_cb_register(&conn_callbacks); err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)); if (err) { printk("Advertising failed to start (err %d)\n", err); return; } printk("Advertising successfully started\n"); }
static void set_io_cap(const uint8_t *data, uint16_t len) { const struct gap_set_io_cap_cmd *cmd = (void *) data; uint8_t status; /* Reset io cap requirements */ memset(&cb, 0, sizeof(cb)); bt_conn_auth_cb_register(NULL); switch (cmd->io_cap) { case GAP_IO_CAP_DISPLAY_ONLY: cb.cancel = auth_cancel; cb.passkey_display = auth_passkey_display; break; case GAP_IO_CAP_KEYBOARD_DISPLAY: cb.cancel = auth_cancel; cb.passkey_display = auth_passkey_display; cb.passkey_entry = auth_passkey_entry; break; case GAP_IO_CAP_NO_INPUT_OUTPUT: cb.cancel = auth_cancel; break; case GAP_IO_CAP_KEYBOARD_ONLY: cb.cancel = auth_cancel; cb.passkey_entry = auth_passkey_entry; break; case GAP_IO_CAP_DISPLAY_YESNO: default: status = BTP_STATUS_FAILED; goto rsp; } if (bt_conn_auth_cb_register(&cb)) { status = BTP_STATUS_FAILED; goto rsp; } status = BTP_STATUS_SUCCESS; rsp: tester_rsp(BTP_SERVICE_ID_GAP, GAP_SET_IO_CAP, CONTROLLER_INDEX, status); }
void main(void) { int err; err = bt_enable(bt_ready); if (err) { printk("Bluetooth init failed (err %d)\n", err); return; } bt_conn_cb_register(&conn_callbacks); bt_conn_auth_cb_register(&auth_cb_display); }
void main(void) { int err; err = bt_enable(bt_ready); if (err) { printk("Bluetooth init failed (err %d)\n", err); return; } bt_conn_cb_register(&conn_callbacks); bt_conn_auth_cb_register(&auth_cb_display); /* Implement notification. At the moment there is no suitable way * of starting delayed work so we do it here */ while (1) { task_sleep(sys_clock_ticks_per_sec); /* Current Time Service updates only when time is changed */ cts_notify(); /* Heartrate measurements simulation */ hrs_notify(); /* Battery level simulation */ bas_notify(); /* Vendor indication simulation */ if (simulate_vnd) { if (indicating) { continue; } ind_params.attr = &vnd_attrs[2]; ind_params.func = indicate_cb; ind_params.data = &indicating; ind_params.len = sizeof(indicating); if (bt_gatt_indicate(NULL, &ind_params) == 0) { indicating = 1; } } } }
void main(void) { struct device *ipm; int rc; uint16_t value16; uint32_t value32; rc = bt_enable(bt_ready); if (rc) { printk("Bluetooth init failed (err %d)\n", rc); return; } bt_conn_cb_register(&conn_callbacks); bt_conn_auth_cb_register(&auth_cb_display); ipm = device_get_binding("ess_ipm"); ipm_register_callback(ipm, sensor_ipm_callback, NULL); ipm_set_enabled(ipm, 1); while (1) { /* Notify value changes via BLE here so that the notification intervals can be controlled. */ if (default_conn) { value16 = sys_cpu_to_le16(temp_value); bt_gatt_notify(default_conn, &attrs[2], &value16, sizeof(value16)); k_sleep(INTERVAL); value16 = sys_cpu_to_le16(humidity_value); bt_gatt_notify(default_conn, &attrs[6], &value16, sizeof(value16)); k_sleep(INTERVAL); value32 = sys_cpu_to_le32(pressure_value); bt_gatt_notify(default_conn, &attrs[10], &value32, sizeof(value32)); k_sleep(INTERVAL); value16 = sys_cpu_to_le16(uv_index_value); bt_gatt_notify(default_conn, &attrs[14], &uv_index_value, sizeof(uv_index_value)); } k_sleep(INTERVAL); } }