RAK11720 RUI3 V4.1.1 bluetooth register callback

I Am trying to register bluetooth callback with RUI3 API but the callback never call what doing wrong?
the idea is, if device connect to RAK11720 call the bleCallback

void bleCallback(Event event)

{

    Serial.printf(" Bluetooth testing callBack... %c \r\n", event);

}

void setup()

// Start BLE UART advertisement for ever

api.ble.settings.blemode(RAK_BLE_UART_MODE);

api.ble.advertise.start(0);

api.ble.registerCallback(BLE_CONNECTED,  (BLE_HANDLER) bleCallback);

What RUI3 version are you using?

I tried the latest staging RUI3 V4.1.1 with this code in setup():

	MYLOG("SETUP", "Starting BLE");
	Serial6.begin(115200, RAK_AT_MODE);
	api.ble.advertise.start(30);
	api.ble.registerCallback(BLE_CONNECTED, (BLE_HANDLER)bleCallback);

with the callback

void bleCallback(void)
{
	MYLOG("BLE-CB","Bluetooth testing callBack... ");
}

My log shows the callback

Interesting here is that event is 0, but it should be 1. Need to check with R&D.

And the BLE callback handler is defined as void bleCallback(void) Seems the event is not forwarded to the callback. Another thing to check with R&D

Figured it out.

Two callbacks required, one for connect, one for disconnect. I found if I use Serial.print() in the callback, I am getting code crashes. So I am calling another function with a timer to announce the event.

uint8_t event;

void ble_con_cb(void)
{
	event = BLE_CONNECTED;
	api.system.timer.start(RAK_TIMER_1, 100, &event);
}

void ble_dis_cb(void)
{
	event = BLE_DISCONNECTED;
	api.system.timer.start(RAK_TIMER_1, 100, &event);
}

void setup(void)
{
	MYLOG("SETUP", "Starting BLE");
	Serial6.begin(115200, RAK_AT_MODE);
	api.ble.advertise.start(30);
	api.ble.registerCallback(BLE_CONNECTED, (BLE_HANDLER)ble_con_cb);
	api.ble.registerCallback(BLE_DISCONNECTED, (BLE_HANDLER)ble_dis_cb);
	api.system.timer.create(RAK_TIMER_1, connection_handler, RAK_TIMER_ONESHOT);
}

void connection_handler(void *event)
{
	uint8_t *reason = (uint8_t *)event;
	if (reason != NULL)
	{
		if (reason[0] == BLE_CONNECTED)
		{
			MYLOG("BLE-CB", "Bluetooth connected...");
		}
		if (reason[0] == BLE_DISCONNECTED)
		{
			MYLOG("BLE-CB", "Bluetooth disconnected...");
		}
		return;
	}
}

Works for me.

Hi Beegee

It works! fine thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.