Iphone & BLE disconnects

Fugazi
Posts: 42
Joined: Wed Apr 26, 2017 9:05 pm

Iphone & BLE disconnects

Postby Fugazi » Tue Jun 05, 2018 8:16 am

Hi

can anyone get BLE to be stable on the iphone, I have posted this in a few places as I am desparate to get this working, managed to get android stable and to run for 20+ hours now, so thats all good, but the Iphone runs for a minute or so and then disconnects.

This is on the BLE UART example aswell.

Thanks to people for developing these libraries however ! :)


Problem comes :-

W (198098) BT_APPL: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0008
E (198112) BT_APPL: Unknown connection ID: 4 fail sending notification

Tested using an Iphone 4s , the same thing with a hm10 module works great.

Thanks


D (197199) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197207) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197208) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197223) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197223) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197261) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197261) GeneralUtils: 0000 11 .
D (197265) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197273) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197281) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197282) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197297) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197297) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197335) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197335) GeneralUtils: 0000 12 .
D (197339) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197347) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197355) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197356) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197371) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197371) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197409) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197409) GeneralUtils: 0000 13 .
D (197413) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197421) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197429) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197432) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197445) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197445) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197483) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197483) GeneralUtils: 0000 14 .
D (197487) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197495) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197503) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197504) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197519) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197519) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197557) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197557) GeneralUtils: 0000 15 .
D (197561) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197569) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197577) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197578) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197593) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197593) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197631) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197631) GeneralUtils: 0000 16 .
D (197635) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197643) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197651) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197652) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197667) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197667) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197705) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197705) GeneralUtils: 0000 17 .
D (197709) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197717) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197725) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197726) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197741) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197741) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197779) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197779) GeneralUtils: 0000 18 .
D (197783) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197791) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197799) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197800) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197815) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197815) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197853) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197853) GeneralUtils: 0000 19 .
D (197857) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197865) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197873) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197874) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197889) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197889) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (197927) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (197927) GeneralUtils: 0000 1a .
D (197931) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (197939) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197947) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (197948) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (197963) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (197963) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (198001) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (198001) GeneralUtils: 0000 1b .
D (198006) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (198014) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (198021) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
V (198022) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (198037) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (198037) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
D (198075) GeneralUtils: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ----------------
D (198075) GeneralUtils: 0000 1c .
D (198079) FreeRTOS: Semaphore taking: name: ConfEvt (0x3ffe6c2c), owner: <N/A> for notify
D (198087) FreeRTOS: Semaphore taken: name: ConfEvt (0x3ffe6c2c), owner: notify
V (198095) FreeRTOS: >> wait: Semaphore waiting: name: ConfEvt (0x3ffe6c2c), owner: notify for notify
W (198098) BT_APPL: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0008
E (198112) BT_APPL: Unknown connection ID: 4 fail sending notification
V (198118) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe6c2c), owner: notify
V (198125) FreeRTOS: << wait: Semaphore released: name: ConfEvt (0x3ffe6c2c), owner: <N/A>
V (198125) FreeRTOS: Semaphore giving: name: ConfEvt (0x3ffe71c8), owner: <N/A>
start advertising

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Re: Iphone & BLE disconnects

Postby JoaoLopesF » Tue Jun 05, 2018 1:14 pm

Hi,

In my project, I use pcbreflux ble_uart_server and based on Nordic examples, to make the Esp32 firmware and Android and iOS app.

In my case, testing with iPhone 5, it had a higher performance and stability than Android 7.1.

To help you, please give us more details:

- Is your Esp-IDF code based on ?
- Is your iOS code also based on ?
-You can test with latest iPhone, at least iPhone 5, to check if it's something with the iPhone 4?

Fugazi
Posts: 42
Joined: Wed Apr 26, 2017 9:05 pm

Re: Iphone & BLE disconnects

Postby Fugazi » Tue Jun 05, 2018 9:50 pm

Hi

Thanks for the reply, am really stuck on this one.

Latest espidf code and arduino code off the site as of a week ago

Running the BLE UART example from the arduino libaries.

Tried Iphone 4S, 6 and X

Used several different BLE scanners and applications, same in all.

Will try that uart example you mention... if i can get it to compile ;)

Thanks

Fugazi
Posts: 42
Joined: Wed Apr 26, 2017 9:05 pm

Re: Iphone & BLE disconnects

Postby Fugazi » Wed Jun 06, 2018 11:05 am

OK compiles now

I guess I am supposed to send the notifiocations through :-

void char2_notify_handle(esp_gatt_if_t gatts_if, uint16_t conn_id) ?

However not sure where to get the variables esp_gatt_if_t gatts_if, uint16_t conn_id from ?

Any ideas?

Thanks

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Re: Iphone & BLE disconnects

Postby JoaoLopesF » Wed Jun 06, 2018 2:24 pm

Hi,

I suggest the nRF Toolbox App of Nordic to test Ble comunications, especifically UART, its is very good,
and have code in github and an Ble Library to Android and iOS

*** ble_uart_server (by pcbreflux)

*** Send (by esp_ble_gatts_send_indicate)

Code: Select all

esp_ble_gatts_send_indicate(mGatts_if, 0, gl_char[1].char_handle,
			size, (uint8_t*) data, false);
*** Receive (this function I changed)
I use callbacks to C++ class, but I put here a simple call to a function to process the data

Code: Select all


static void char1_write_handler(esp_gatts_cb_event_t event,
		esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param) {
	DEBUG("char1_write_handler %d", param->write.handle);

	if (gl_char[0].char_val != NULL) {
		DEBUG("char1_write_handler char_val %d",param->write.len);
		gl_char[0].char_val->attr_len = param->write.len;
		for (uint32_t pos = 0; pos < param->write.len; pos++) {
			gl_char[0].char_val->attr_value[pos] = param->write.value[pos];
		} DEBUG("char1_write_handler %.*s", gl_char[0].char_val->attr_len, (char*)gl_char[0].char_val->attr_value);
	} DEBUG(" char1_write_handler esp_gatt_rsp_t");
	esp_ble_gatts_send_response(gatts_if, param->write.conn_id,
			param->write.trans_id, ESP_GATT_OK, NULL);

	// Changed -> after send_response

	if (gl_char[0].char_val != NULL && gl_char[0].char_val->attr_len > 0) { // Read ;-)

		// Call function
				
		bleRecData((char*) gl_char[0].char_val->attr_value,
					(uint8_t) gl_char[0].char_val->attr_len);
		
		
	}
}

Code: Select all


static void bleRecData(char *data, uint8_t size) { 

	// Received  data by BLE notification

	char aux[size + 1];
	sprintf(aux, "%.*s", size, data);

	ESP_LOGV(TAG_BLE, "*** BLE receb [%d]:%s", size, aux);

        // Process the data .....

}

I hope this helps you

Fugazi
Posts: 42
Joined: Wed Apr 26, 2017 9:05 pm

Re: Iphone & BLE disconnects

Postby Fugazi » Wed Jun 06, 2018 6:22 pm

Nearly :)

I worked out the receive, the send variables in the send_indicate I am kinda stuck where to get them from?

esp_ble_gatts_send_indicate(mGatts_if, 0, gl_char[1].char_handle,
size, (uint8_t*) data, false);

Where do you get the mGatts_if variable from ?

Something like esp_gatt_if_t gatts_if_for_indicate = ESP_GATT_IF_NONE;?

Is there a full example code anywhere ? :)


thanks again

Fugazi
Posts: 42
Joined: Wed Apr 26, 2017 9:05 pm

Re: Iphone & BLE disconnects

Postby Fugazi » Thu Jun 07, 2018 8:30 am

Cant get anything to notify still

esp_ble_gatts_send_indicate(gl_profile.gatts_if, gl_profile.conn_id, gl_char[1].char_handle,1,&notify_pos,false); ?

Is these the parameters to be used ? thanks

osx1000
Posts: 3
Joined: Tue Jun 05, 2018 2:40 pm

Re: Iphone & BLE disconnects

Postby osx1000 » Thu Jun 07, 2018 10:15 am

Hi, off topic: Are you developing under macOS?

Jörg

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Re: Iphone & BLE disconnects

Postby JoaoLopesF » Thu Jun 07, 2018 9:41 pm

Hi,

I not tested use of gl_profile.gatts_if, maybe works
I use an global variable for it:

Code: Select all

static esp_gatt_if_t mGatts_if = ESP_GATT_IF_NONE;
And change the event:

Code: Select all

case ESP_GATTS_CONNECT_EVT:
		DEBUG("SERVICE_START_EVT, conn_id %d, remote %02x:%02x:%02x:%02x:%02x:%02x:, is_conn %d",
				param->connect.conn_id,
				param->connect.remote_bda[0], param->connect.remote_bda[1], param->connect.remote_bda[2],
				param->connect.remote_bda[3], param->connect.remote_bda[4], param->connect.remote_bda[5],
				param->connect.conn_id);
		gl_profile.conn_id = param->connect.conn_id;

		/// BLE

		mGatts_if = gatts_if;


Fugazi
Posts: 42
Joined: Wed Apr 26, 2017 9:05 pm

Re: Iphone & BLE disconnects

Postby Fugazi » Fri Jun 08, 2018 6:47 am

Hi

Thanks, i just needed to reboot the iphone, it was being daft, it works now, thanks for all the help.

Unfortunately this does exactly the same as the arduino example.

If you have 5 minutes spare try sending one byte every 50ms.... it runs for about one minute and then the iphone disconnects with

(14321) BT_APPL: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0008

So still not working.

:(

Who is online

Users browsing this forum: No registered users and 68 guests