BLE GATT services

Hi all, I am working on an application capable of advertising, and an external device can be connected to it to write values to the application. For the application I try to connect through the mobile application of nRF connect, but I'm having problems two things, I do not always appear the device, and when it appears, the service appears but does not allow me to write to it, even when it appears in its characteristics that has permissions to write.

I think the problem can be found in the service declaration. I attach the code

#include <errno.h>
#include <zephyr/init.h>
#include <zephyr/sys/__assert.h>
#include <stdbool.h>
#include <zephyr/types.h>

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/services/bas.h>
/*

static uint16_t ack_package = 0;

static ssize_t write_ack_package(struct bt_conn *conn,
			       const struct bt_gatt_attr *attr,const void *buf,
			       uint16_t len, uint16_t offset, uint8_t flags)
{
	uint8_t *value = attr->user_data;

	if (offset + len > sizeof(ack_package)) {
		return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
	}

	memcpy(value + offset, buf, len);

	return len;
}
BT_GATT_SERVICE_DEFINE(ipg,
	BT_GATT_PRIMARY_SERVICE(BT_UUID_IPG),
	BT_GATT_CHARACTERISTIC(BT_UUID_IPG_ACK_PACKAGE,
			       BT_GATT_CHRC_WRITE_WITHOUT_RESP | BT_GATT_CHRC_WRITE,
			       BT_GATT_PERM_WRITE,NULL,  write_ack_package,
			       &ack_package),
);

uint8_t bt_ipg_get_ack_package(void)
{
	return ack_package;
}

For advertising I use the functions provided by the BLE example pheripheral_hids_keyboard

Related