GATT services and characteristic declaration error

These are customized UUIDS declared by me 

/* Custom Service Variables */
#define BT_UUID_CUSTOM_SERVICE_VAL  BT_UUID_128_ENCODE(0x821675c3, 0x4046, 0x45f9, 0xb8df, 0xcdc9da1c71a7)

#define CUSTOM_EMG_UUID BT_UUID_128_ENCODE(0x30645c07,0x5a3c,0x4f2d,0xbee5,0x7eafcbf0c790)
#define CUSTOM_BATTERY_UUID BT_UUID_128_ENCODE(0xd7b5a586,0x6191,0x4c0f,0x93e0,0xc2fa666d5ca3)

#define BT_UUID_EMG_DEV BT_UUID_DECLARE_128(BT_UUID_CUSTOM_SERVICE_VAL)
#define BT_UUID_BAT     BT_UUID_DECLARE_128(CUSTOM_BATTERY_UUID)
#define BT_UUID_EMG     BT_UUID_DECLARE_128(CUSTOM_EMG_UUID)
I call this UUIDs to define services and characteristics as follows 
BT_GATT_SERVICE_DEFINE(custom_svc,
BT_GATT_PRIMARY_SERVICE(BT_UUID_EMG_DEV),

BT_GATT_CHARACTERISTIC(BT_UUID_BAT,
                       BT_GATT_CHRC_READ,
                       BT_GATT_PERM_READ,
                       read_battery,NULL,&battery_value),        
                       
BT_GATT_CHARACTERISTIC(BT_UUID_EMG,
                  BT_GATT_CHRC_READ,
                  BT_GATT_PERM_READ,
                  read_emg,NULL,&emg_value)
);
But I am encountering errors such as expecting a comma even if I have put a comma.
error: expected expression before ',' token
110 | read_str, NULL, BT_DIS_MODEL_REF),
| ^
error: expected expression before ',' token
75 | BT_GATT_PERM_NONE, NULL, NULL, NULL),
| ^
error: expected expression before ',' token
55 | &battery_level),
| ^
error: expected expression before ',' token
244 | read_name, write_name, bt_dev.name),
| ^
Could any one please figure me out how to solve this errors.
Parents
  • Hi Vivek, 

    The error complains were not about your declaration but the declaration for DIS service. You may need to check what inside \zephyr\subsys\bluetooth\services\dis.c 
    Please show the whole log. 
    Also please try to test with peripheral_lbs or peripheral_uart . These examples do pretty much what you are trying to do. 
    In case you are not aware, we have a Dev Academy course that can help you to get familiar with Nordic BLE stack. 

Reply
  • Hi Vivek, 

    The error complains were not about your declaration but the declaration for DIS service. You may need to check what inside \zephyr\subsys\bluetooth\services\dis.c 
    Please show the whole log. 
    Also please try to test with peripheral_lbs or peripheral_uart . These examples do pretty much what you are trying to do. 
    In case you are not aware, we have a Dev Academy course that can help you to get familiar with Nordic BLE stack. 

Children
  • iam having the same issue,can u provide me the sample code as iam new to nrf.

  • The code I have developed works fine and can be used as a sample but the code is long enough, it may not fit here. If you are able to provide your mail ID , I will mail it.

  • Hi Vivek, 
    You can attach a file by Insert -> Image/video/file. 
    If you attach a whole project, pleas remove the build folder it will make the .zip file much smaller. 

  • //Function definitions of BLE
    #include "ble_config.h"
    
    ssize_t read_battery(struct bt_conn *conn, const struct bt_gatt_attr *attr,void *buf,uint16_t len,uint16_t offset)
    {
      const char *value= battery_value;
      return bt_gatt_attr_read(conn,attr,buf,len,offset,value,strlen(value));
    }
    
    ssize_t read_emg(struct bt_conn *conn,const struct bt_gatt_attr *attr,void *buf,uint16_t len,uint16_t offset)
    {
       const char *emg_buffer[20];
       snprintf(emg_buffer,sizeof(emg_buffer),"%s,%s",emg_value[0],emg_value[1]);
       return bt_gatt_attr_read(conn,attr,buf,len,offset,emg_buffer,strlen(emg_buffer));
    }
    
    const struct  bt_data ad[]={
       BT_DATA_BYTES(BT_DATA_FLAGS,(BT_LE_AD_GENERAL|BT_LE_AD_NO_BREDR)),
       BT_DATA(BT_DATA_NAME_COMPLETE,DEVICE_NAME,DEVICE_NAME_LEN),
    };
    
    const struct bt_data sd[] = {
    	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_CUSTOM_SERVICE_VAL),
    };
    
    /*
    @ref about advertising intervals
    800 - Min Advertising Interval 500ms (800*0.625ms)
    801 - Max Advertising Interval 500.625ms (801*0.625ms)
    NULL - Indicates undirected advertising
    */
    struct bt_le_adv_param *adv_pram = BT_LE_ADV_PARAM((BT_LE_ADV_OPT_CONNECTABLE|BT_LE_ADV_OPT_USE_IDENTITY),
                                                              800,801,NULL);
    
    /*
    static void update_phy(struct bt_conn *conn)
    {
            int err;
            const struct bt_conn_le_phy_param preferred_phy = {
                    .options = BT_CONN_LE_PHY_OPT_NONE,
                    .pref_rx_phy = BT_GAP_LE_PHY_2M,
                    .pref_tx_phy = BT_GAP_LE_PHY_2M,
            };
            err = bt_conn_le_phy_update(conn,&preferred_phy);
            if(err)
            {
                    LOG_ERR("bt_conn_le_phy_update() returned %d",err);
            }
    }
    */
    
    struct bt_conn *my_conn = NULL;
    
    void on_connected(struct bt_conn *conn,uint8_t err)
    {
            if(err)
            {
                    printk("Connection error %d",err);
                    return;
            }
            printk("Connected");
            my_conn = bt_conn_ref(conn);
            struct bt_conn_info info;
            err = bt_conn_get_info(conn,&info);
            if(!err)
            {
            double connection_interval = info.le.interval*1.25;//in ms
            uint32_t supervision_timeout = info.le.timeout*10;//in ms
            printk("Connection parameters: interval %.2f ms, latency %d intervals,timeout %d ms",connection_interval,info.le.latency,supervision_timeout);
            }
           // update_phy(my_conn);
    }
    void on_disconnected(struct bt_conn *conn, uint8_t reason)
    {
       printk("Disconnected. Reason %d",reason);
       bt_conn_unref(my_conn);
    }
    struct bt_conn_cb connection_callbacks = {
            .connected = on_connected,
            .disconnected = on_disconnected,
    };
    
    
    void bt_ready(void)
    {
            int err;
            err=bt_enable(NULL);
            printk("Bluetooth Intialied\n");
    
            err=bt_le_adv_start(adv_pram,ad,ARRAY_SIZE(ad),sd,ARRAY_SIZE(sd));
    
            if (err) {
    		printk("Advertising failed to start (err %d)\n", err);
    		return;
    	}
            printk("Advertising successfully started\n");
    }
    
    ble_config.h

Related