How can I modify my board so that my iPhone automatically connects to it

I'm testing my code based on nrf5SDK v17.0.0 with nrf52832 board.

By nrf connect application,I can see the broadcast packet from my board.It looks something like this.

Some of my hypothetical users are iPhone users.Then I  test my board with iphone.

It is OK when I use iphone to connect,pair and bond with my board.

But when I restart the bluetooth on iphone or reenter Bluetooth broadcast range of my board, iphone will not connect to it automatically.But Android phone can connect to it automatically.

Besides,I tried the example that hid_mouse,The example can achieve this effect,but it seem based on whitelist.But I want to support multiple phones to connect and support them reconnect automatically at the same time.

  • Hi,

    At present, it is necessary to manually connect the iPhone to NRF52832, but I hope that the iPhone can automatically connect after bonding.

    The screenshot is to show the services defined in 52832, so there is no bonding.

    I did an experiment, after the iPhone scanned and bond 52832 in the Settings -> Bluetooth interface, turned off the Bluetooth switch and restarted, 52832 always showed no connection, just like the video below:

    As you can see, I had to manually tap after the Bluetooth restarted to trigger the phone's connection to the 52832(Bluetooth name is Anny_ETC_1961).

  • Hi,

    There is unfortunately not much we can do about iOS behaviour as that is controlled by Apple, but I am a bit suprised about this. What happens if you insteead of toggling Bluetooth off and on again on the phone resets the nRF devices? Does the phone re-connect automatically then?

  • Hi,

    When I instead of toggling Bluetooth off and on again on the phone resets the nRF devices,the result is same as above.

    I'm not sure if you noticed that I uploaded the project files earlier. If yes, I hope you can give me some suggestions for improvement according to the code.

    而不是切换蓝牙开关手机重置nRF设备

  • Hi,

    I have looked at your project, and I don't see anything that sticks out. It includes a HID mouse service with a standard UUID as far as I can see, and just has an additional NUS service. I am not able to build your Keil project, but can you test on your end to see if for instance removing the NUS service makes a difference? Or if not, backtrack and see how much and what you need to remove to get the same behaviour as with the HID mouse sample (that iOS automatically reconnects)?

    This is a bit of trial and error, as we do not know what happend internally in iOS and why it decides to not reconnect.

  • Hi,

    Thanks for your suggestion.I found the cause of the problem.

    As you can see from the file, the Bluetooth name is written this way:

    char * namecat(void)
    {
    	ble_gap_addr_t addr;
    	sd_ble_gap_addr_get(&addr);
    	NRF_LOG_HEXDUMP_INFO(addr.addr,BLE_GAP_ADDR_LEN);
    	static char name[13] = DEVICE_NAME;
    	char addr_name[4];
    	for(uint8_t i = 0; i < 2;i++)
    	{
    		addr_name[2*i] = num_to_char((addr.addr[i])/16);
    		addr_name[2*i+1] = num_to_char((addr.addr[i])%16);
    	}
    	strcat(name,addr_name);
    	name[13] = '\0';
    	return name;
    }

    After the modification, the Bluetooth name is written like this:

    static char name[14] = DEVICE_NAME;
    
    char * namecat(void)
    {
    	ble_gap_addr_t addr;
    	sd_ble_gap_addr_get(&addr);
    	NRF_LOG_HEXDUMP_INFO(addr.addr,BLE_GAP_ADDR_LEN);
    	char addr_name[5];
    	for(uint8_t i = 0; i < 2;i++)
    	{
    		addr_name[2*i] = num_to_char((addr.addr[i])/16);
    		addr_name[2*i+1] = num_to_char((addr.addr[i])%16);
    	}
        addr_name[4] = '\0';
    	//strcat(name,addr_name);
        memcpy(&name[9],addr_name,5);
    	return name;
    }
    
    /**@brief Function for the GAP initialization.
     *
     * @details This function sets up all the necessary GAP (Generic Access Profile) parameters of the
     *          device including the device name, appearance, and the preferred connection parameters.
     */
    static void gap_params_init(void)
    {
        ret_code_t              err_code;
        ble_gap_conn_params_t   gap_conn_params;
        ble_gap_conn_sec_mode_t sec_mode;
    
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
    
        //char *name = namecat();
        namecat();
    
        err_code = sd_ble_gap_device_name_set(&sec_mode,
                                              (const uint8_t *)name/*DEVICE_NAME*/,
                                              strlen(name/*DEVICE_NAME*/));
        APP_ERROR_CHECK(err_code);

    Although the problem has been solved, what puzzles me is why these two approaches lead to different results.

Related