Which APIs ared used to send msg by ble?

Hiii,

I have added BLE from peripheral_hids_keyboard to Peripherial_Uart,and now my PC and mobile (Android) can connect with DK(nrf52833) and can regard it as a HID,but cant receive data sent by DK.I wonder which APIs are needed to send data via ble?

Best regards,

Martin

Parents
  • Hi,

    • What SDK (and version) are you using?
    • Did you test with the unmodified HIDS Keyboard sample first, to confirm that one works on its own?

    Regards,
    Terje

  • Hi,

    • I use nfr connect SDKV 2.6.0 running on nrf52833DK.
    • I have tested this two sample,and peripheral_uart can send data from uart and peripheral_hids_keyboard can send data by pressing button and PC or Mobile can receive data from a HID(keyboard).
    • And now I have ported a part code of peripheral_hids_keyboard into peripheral_uart and can connect with mobile regarded as HID,but mobile cant receive data from DK.

    Regards,

    Martin

  • And peripheral_uart can send data via bt_nus_send(),does peripheral_hids_keyboard have the similar one?

  • Hi,

    With the HID Service library you can send HID reports. It is not intended for sending pure characters, but rather to send HID reports (which in the case of a HID keyboard report contains key presses - which are close to characters but not exactly the same as characters.) Using the HID Service library, HID reports can be sent using bt_hids_inp_rep_send() or bt_hids_boot_kb_inp_rep_send().

    Regards,
    Terje

  • Hi,

    Ive tried bt_hids_inp_rep_send() that you mentioned and it succed but something unexpected appear.

    The first is that I can only send no more than six word at one time,do there any ideas to expand this?

    The other one is that the data can only be sent the first one if not change the first one word in the second time.

    For example:

    At the first time I send "04 05 06 07 08 09" and I receive "a b c d e f",and the second time I send the same data as the first time I just receive "a".

    And if I send data that is larger than 6Byte,It will only receive the first 6Byte.

    my report map is as follows.

    	static const uint8_t report_map[] = {
    		0x05, 0x01,       /* Usage Page (Generic Desktop) */
    		0x09, 0x06,       /* Usage (Keyboard) */
    		0xA1, 0x01,       /* Collection (Application) */
    
    		/* Keys */
    #if INPUT_REP_KEYS_REF_ID
    		0x85, INPUT_REP_KEYS_REF_ID,
    #endif
    		0x05, 0x07,       /* Usage Page (Key Codes) */
    		0x19, 0xe0,       /* Usage Minimum (224) */
    		0x29, 0xe7,       /* Usage Maximum (231) */
    		0x15, 0x00,       /* Logical Minimum (0) */
    		0x25, 0x01,       /* Logical Maximum (1) */
    		0x75, 0x01,       /* Report Size (1) */
    		0x95, 0x08,       /* Report Count (8) */
    		0x81, 0x02,       /* Input (Data, Variable, Absolute) */
    
    		0x95, 0x01,       /* Report Count (1) */
    		0x75, 0x08,       /* Report Size (8) */
    		0x81, 0x01,       /* Input (Constant) reserved byte(1) */
    
    		0x95, 0x06,       /* Report Count (6) */
    		0x75, 0x08,       /* Report Size (8) */
    		0x15, 0x00,       /* Logical Minimum (0) */
    		0x25, 0x65,       /* Logical Maximum (101) */
    		0x05, 0x07,       /* Usage Page (Key codes) */
    		0x19, 0x00,       /* Usage Minimum (0) */
    		0x29, 0x65,       /* Usage Maximum (101) */
    		0x81, 0x00,       /* Input (Data, Array) Key array(6 bytes) */
    
    		/* LED */
    #if OUTPUT_REP_KEYS_REF_ID
    		0x85, OUTPUT_REP_KEYS_REF_ID,
    #endif
    		0x95, 0x05,       /* Report Count (5) */
    		0x75, 0x01,       /* Report Size (1) */
    		0x05, 0x08,       /* Usage Page (Page# for LEDs) */
    		0x19, 0x01,       /* Usage Minimum (1) */
    		0x29, 0x05,       /* Usage Maximum (5) */
    		0x91, 0x02,       /* Output (Data, Variable, Absolute), */
    				  /* Led report */
    		0x95, 0x01,       /* Report Count (1) */
    		0x75, 0x03,       /* Report Size (3) */
    		0x91, 0x01,       /* Output (Data, Variable, Absolute), */
    				  /* Led report padding */
    
    		0xC0              /* End Collection (Application) */
    	};
    

    And my code getting data from uart and sending them to ble.

    static void data_send_proc(void)
    {
    	int err;
    	int buf_size = 8;
    	uint8_t buffer[UART_BUF_SIZE] = {0,0};
    	
    	struct uart_data_cmd_t *buf = k_fifo_get(&fifo_uart_rx_data,
    						     K_FOREVER);
    	
    	if(buf->len != 0){
    		printk("buf->len is %d\n",buf->len);
    		
    		memcpy(buffer+2,buf->data,buf->len-2);
    		k_free(buf);
    
    		for (size_t i = 0; i < CONFIG_BT_HIDS_MAX_CLIENT_COUNT; i++) {
    			if (conn_mode[i].conn) {
    				err = bt_hids_inp_rep_send(&hids_obj, conn_mode[i].conn,
    									INPUT_REP_KEYS_IDX,buffer,
    									buf_size, NULL);
    			}
    		}
    
    	}
    	
    }
    

    Hope your reply

    Regards,

    Martin

Reply
  • Hi,

    Ive tried bt_hids_inp_rep_send() that you mentioned and it succed but something unexpected appear.

    The first is that I can only send no more than six word at one time,do there any ideas to expand this?

    The other one is that the data can only be sent the first one if not change the first one word in the second time.

    For example:

    At the first time I send "04 05 06 07 08 09" and I receive "a b c d e f",and the second time I send the same data as the first time I just receive "a".

    And if I send data that is larger than 6Byte,It will only receive the first 6Byte.

    my report map is as follows.

    	static const uint8_t report_map[] = {
    		0x05, 0x01,       /* Usage Page (Generic Desktop) */
    		0x09, 0x06,       /* Usage (Keyboard) */
    		0xA1, 0x01,       /* Collection (Application) */
    
    		/* Keys */
    #if INPUT_REP_KEYS_REF_ID
    		0x85, INPUT_REP_KEYS_REF_ID,
    #endif
    		0x05, 0x07,       /* Usage Page (Key Codes) */
    		0x19, 0xe0,       /* Usage Minimum (224) */
    		0x29, 0xe7,       /* Usage Maximum (231) */
    		0x15, 0x00,       /* Logical Minimum (0) */
    		0x25, 0x01,       /* Logical Maximum (1) */
    		0x75, 0x01,       /* Report Size (1) */
    		0x95, 0x08,       /* Report Count (8) */
    		0x81, 0x02,       /* Input (Data, Variable, Absolute) */
    
    		0x95, 0x01,       /* Report Count (1) */
    		0x75, 0x08,       /* Report Size (8) */
    		0x81, 0x01,       /* Input (Constant) reserved byte(1) */
    
    		0x95, 0x06,       /* Report Count (6) */
    		0x75, 0x08,       /* Report Size (8) */
    		0x15, 0x00,       /* Logical Minimum (0) */
    		0x25, 0x65,       /* Logical Maximum (101) */
    		0x05, 0x07,       /* Usage Page (Key codes) */
    		0x19, 0x00,       /* Usage Minimum (0) */
    		0x29, 0x65,       /* Usage Maximum (101) */
    		0x81, 0x00,       /* Input (Data, Array) Key array(6 bytes) */
    
    		/* LED */
    #if OUTPUT_REP_KEYS_REF_ID
    		0x85, OUTPUT_REP_KEYS_REF_ID,
    #endif
    		0x95, 0x05,       /* Report Count (5) */
    		0x75, 0x01,       /* Report Size (1) */
    		0x05, 0x08,       /* Usage Page (Page# for LEDs) */
    		0x19, 0x01,       /* Usage Minimum (1) */
    		0x29, 0x05,       /* Usage Maximum (5) */
    		0x91, 0x02,       /* Output (Data, Variable, Absolute), */
    				  /* Led report */
    		0x95, 0x01,       /* Report Count (1) */
    		0x75, 0x03,       /* Report Size (3) */
    		0x91, 0x01,       /* Output (Data, Variable, Absolute), */
    				  /* Led report padding */
    
    		0xC0              /* End Collection (Application) */
    	};
    

    And my code getting data from uart and sending them to ble.

    static void data_send_proc(void)
    {
    	int err;
    	int buf_size = 8;
    	uint8_t buffer[UART_BUF_SIZE] = {0,0};
    	
    	struct uart_data_cmd_t *buf = k_fifo_get(&fifo_uart_rx_data,
    						     K_FOREVER);
    	
    	if(buf->len != 0){
    		printk("buf->len is %d\n",buf->len);
    		
    		memcpy(buffer+2,buf->data,buf->len-2);
    		k_free(buf);
    
    		for (size_t i = 0; i < CONFIG_BT_HIDS_MAX_CLIENT_COUNT; i++) {
    			if (conn_mode[i].conn) {
    				err = bt_hids_inp_rep_send(&hids_obj, conn_mode[i].conn,
    									INPUT_REP_KEYS_IDX,buffer,
    									buf_size, NULL);
    			}
    		}
    
    	}
    	
    }
    

    Hope your reply

    Regards,

    Martin

Children
No Data
Related