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

I am a beginner for BLE. I want my ble to communicate with my nrf android app.

I am using Keil uvision. Working with example codes, with uart example I got the code to send a data to mobile app through ble. But I cannot find code for receiving a data by ble which is send from the mobile app. Please help me. I need a code, such that when I send a data (let it be "ON") from my mobile to the connected ble , a led must ON. And similarly when I send "OFF" the led must OFF.

Parents Reply Children
  • I got the answer. I am now able to send data (string) from my mobile to BLE device.

    In the main loop I didn't write any code. In main() function there are some function call statements as it is in the BLE UART example pgm.

    while(1)
    	 {
    		 if(i==500)
    		 {
    		  i=0;
    		 }
    		power_manage();
    	 }

    But I coded inside the nus_data_handler() function.

    static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
    {
    
    	uint8_t k=0;
    	if (strstr((char*)(p_data), "on")) {
        nrf_gpio_pin_write(1,1);
    		printf("ON");
      }
    	
    	else if (strstr((char*)(p_data), "off")) {
        nrf_gpio_pin_write(1,0);
    		printf("OFF");
      }
    	
    	else if(strstr((char*)(p_data), "toggle")) {
    		while(k<10){
    		nrf_gpio_pin_toggle(1);
    		printf("TOGGLE");
    			Delay_ms(100);
    			k++;
    		}
      }
    	
    }

    When I send "on" from my mobile, then the GPIO pin 1 will become high.

    And when I send "off" , the GPIO pin 1 will set low.

    And at last, when I send "toggle", the pin 1 will start toggle for 10 times, as I coded.

Related