This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Button click to fast to Send Information

Im working with a nRF51422 EK. So, there is an android application with 2 buttons. Each of them can Set a LED. It will be set as long as the button is pressed on the application. When I release the button on the application the LED state should be low. The problem is: if I click and release to fast, it will send a high for the click but it wont send a low for release. This problem I only have when click and release to fast. Is it possible to solve this problem with a notification?

Because I will need an Information from my nRF51422 to Android Device that the information is recieved.

static void led_write_handler(ble_lbs_t * p_lbs, uint8_t led_state) {

	switch (led_state){
		case 0: nrf_gpio_pin_clear(LEDBUTTON_LED_PIN_NO);
						nrf_gpio_pin_clear(AUF);
				break;
		case 1: nrf_gpio_pin_set(LEDBUTTON_LED_PIN_NO);
						nrf_gpio_pin_set(AUF);
				break;
		case 2:	nrf_gpio_pin_clear(LEDBUTTON_LED1_PIN_NO);
						nrf_gpio_pin_clear(AB);
				break;
		case 3: nrf_gpio_pin_set(LEDBUTTON_LED1_PIN_NO);
						nrf_gpio_pin_set(AB);
				break;
	}

Regards,

Inspectron AG

  • Notifications are used for the server role. With client role you'll use the write command.

    Using write without response (write command) allows for faster throughput and queuing of packets in tx buffer . However, the likely problem here is that the android application doesn't actually send any packet when the button is released too fast. This can be verified by using our sniffer application.

    I'm guessing that the application has not acked the previous packet, hence failing to send the second packet indicating that the button is released. The send function in android should then return the status of the write. If it's not GATT_SUCCESS, you should do a re-transmit when the pending packet is acked at application level.

    Note that write command is considered to be a reliable link and is acked at the link layer. Write commands are easier to implement as it automatically queues and acks packets.

    Link to Android callback: developer.android.com/.../BluetoothGattCallback.html

    EDIT: fixed link to Android callback

  • Do I have to send a GATT_SUCCESS when the led_state is changed or is this done automaticly?

  • On the Android side, GATT_SUCCESS means that the write operation was successful. Description about the callback onCharacteristicWrite: "Callback indicating the result of a characteristic write operation. If this callback is invoked while a reliable write transaction is in progress, the value of the characteristic represents the value reported by the remote device. An application should compare this value to the desired value to be written. If the values don't match, the application must abort the reliable write transaction."

  • But on the side of the nRf51422, how I can send a notification to my android application with the information that the onCharacteristicWrite was successful?

  • You could add an additional service/characteristic on the peripheral notifying the central when the packet was received. However, I think it makes more sense to check the status of the onCharacteristicWrite on the android side. When the returned status is GATT_SUCCESS you'll know that it has been sent. You will then end up with link loss after x number of re-transmissions ( defined by supervisor timout) if the transmitted packet is never received. So I think the proper way of doing this is to wait for the callback with GATT_SUCCESS before sending the next write.

Related