Not receiving the battery status form the Battery server

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RaSa_4767806
Level 3
Level 3
10 replies posted 10 questions asked 5 replies posted

Hello,

I have flashed the battery server example code from WICED studio 6.4 to CYBT 423028 Eval board, and battery client code to another board.

Not getting response from server.

I want to get the battery status periodically from battery server.

I have created periodic timer (5 Sec ) in Battery Client  and in that timer I am calling wiced_bt_mesh_create_event by passing the element index as 0, default Vendor Compony ID and Vendor Model ID, dst as 0, and app_key_idx as 0xffff. Event is getting created I believe, as  wiced_bt_mesh_create_event not returning NULL.

Once the event is created I am passing this event to wiced_bt_mesh_battery_client_send_get as an argument, it returns 8019 code.

On server side could not see request is getting received.

Both battery client and server are provisioned through Mehs_Lighting android Mobile application.

Is there any thing I am missing or doing wrong ?

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hi,

Unfortunately I couldn't reproduce the issue. In my testing, I could successfully sent GET command to the server from the client on a button press and could get the battery status back. I am attaching the battery client code herewith. Please try to test with it.

Please let me know whether you are trying to do something else also.

The steps what I followed.

  • Provision battery_client and battery_server applications on two boards using MeshClient.
  • Press the user button on the battery_client device. : - This will publish a GET message.
  • Check the serial traces on both the devices.

You should use wiced_bt_mesh_create_event() for creating mesh event for unsolicited message. Setting destination address=0 will make the device fetch the configured publication for the model for all publication. You can later change it using the provisioner.

Please note: I have tested it using the CYW920719Q40EVB_01 (CYBT_423028_EVAL has the same chip).

Thanks,

-Dheeraj

View solution in original post

0 Likes
13 Replies
RaSa_4767806
Level 3
Level 3
10 replies posted 10 questions asked 5 replies posted

Small correction:- Event is not getting created as wiced_bt_mesh_create_event  is returning NULL.

what is missing in creating event ?

0 Likes

Hi,

Could you please try using app_key_idx = 0.

Could you please share your code?

Thanks,

-Dheeraj

0 Likes
RaSa_4767806
Level 3
Level 3
10 replies posted 10 questions asked 5 replies posted

Hello DheerajP_41​,

After suing app_key_idx = 0, and dst as non 0 value wiced_bt_mesh_create_event not returning the NULL value. if i put dst as 0 its returning NULL.

Even after event creation still not getting the response from battery server. 

after event creation i am calling wiced_bt_mesh_battery_client_send_get with created event as an argument, this API is returning 8109. as per my understanding after calling API wiced_bt_mesh_battery_client_send_get attest i should receive WICED_BT_MESH_TX_COMPLETE event, but not getting this event.

Following the code:- (Part which is in Bold is modified)

wiced_bt_mesh_app_func_table_t wiced_bt_mesh_app_func_table =

{

    mesh_app_init,          // application initialization

    mesh_app_hardware_init,                   // Default SDK platform button processing

    NULL,                   // GATT connection status

    NULL,                   // attention processing

    NULL,                   // notify period set

    NULL,

//    mesh_app_proc_rx_cmd,   // WICED HCI command

    NULL,                   // LPN sleep

    NULL                    // factory reset

};

/******************************************************

*               Function Definitions

******************************************************/

void mesh_app_init(wiced_bool_t is_provisioned)

{

#if 0

    extern uint8_t wiced_bt_mesh_model_trace_enabled;

    wiced_bt_mesh_model_trace_enabled = WICED_TRUE;

#endif

    wiced_set_debug_uart(WICED_ROUTE_DEBUG_TO_PUART);

    wiced_bt_cfg_settings.device_name = (uint8_t *)"Battery_Client";

    wiced_bt_cfg_settings.gatt_cfg.appearance = APPEARANCE_GENERIC_TAG;

    // Adv Data is fixed. Spec allows to put URI, Name, Appearance and Tx Power in the Scan Response Data.

    if (!is_provisioned)

    {

        wiced_bt_ble_advert_elem_t  adv_elem[3];

        uint8_t                     buf[2];

        uint8_t                     num_elem = 0;

        adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_NAME_COMPLETE;

        adv_elem[num_elem].len = (uint16_t)strlen((const char*)wiced_bt_cfg_settings.device_name);

        adv_elem[num_elem].p_data = wiced_bt_cfg_settings.device_name;

        num_elem++;

        adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_APPEARANCE;

        adv_elem[num_elem].len = 2;

        buf[0] = (uint8_t)wiced_bt_cfg_settings.gatt_cfg.appearance;

        buf[1] = (uint8_t)(wiced_bt_cfg_settings.gatt_cfg.appearance >> 8);

        adv_elem[num_elem].p_data = buf;

        num_elem++;

        wiced_bt_mesh_set_raw_scan_response_data(num_elem, adv_elem);

    }

    // register with the library to receive parsed data

    wiced_bt_mesh_model_battery_client_init(mesh_battery_client_message_handler, is_provisioned);

}

/*

* Process event received from the Battery Server.

*/

void mesh_battery_client_message_handler(uint16_t event, wiced_bt_mesh_event_t *p_event, mesh_battery_event_t *p_data)

{

#if defined HCI_CONTROL

    wiced_bt_mesh_hci_event_t *p_hci_event;

#endif

    WICED_BT_TRACE("battery clt msg:%d\n", event);

    switch (event)

    {

    case WICED_BT_MESH_TX_COMPLETE:

        WICED_BT_TRACE("tx complete status:%d\n", p_event->tx_status);

#if defined HCI_CONTROL

        if ((p_hci_event = wiced_bt_mesh_create_hci_event(p_event)) != NULL)

            wiced_bt_mesh_send_hci_tx_complete(p_hci_event, p_event);

#endif

        break;

    case WICED_BT_MESH_BATTERY_STATUS:

        WICED_BT_TRACE("Battery level:%d time discharge:%d charge:%d flags %d %d %d %d\n",

                p_data->battery_level, p_data->time_to_discharge, p_data->time_to_charge,

                p_data->presence, p_data->charging, p_data->level_inidicator, p_data->servicability);

#if defined HCI_CONTROL

        if ((p_hci_event = wiced_bt_mesh_create_hci_event(p_event)) != NULL)

            mesh_battery_hci_event_send(p_hci_event, p_data);

#endif

        break;

    default:

        WICED_BT_TRACE("unknown\n");

        break;

    }

    wiced_bt_mesh_release_event(p_event);

}

/*

* In 2 chip solutions MCU can send commands to change battery state.

*/

uint32_t mesh_app_proc_rx_cmd(uint16_t opcode, uint8_t *p_data, uint32_t length)

{

    wiced_bt_mesh_event_t *p_event;

    WICED_BT_TRACE("[%s] cmd_opcode 0x%02x\n", __FUNCTION__, opcode);

    switch (opcode)

    {

    case HCI_CONTROL_MESH_COMMAND_BATTERY_GET:

        p_event = wiced_bt_mesh_create_event_from_wiced_hci(opcode, MESH_COMPANY_ID_BT_SIG, WICED_BT_MESH_CORE_MODEL_ID_GENERIC_BATTERY_CLNT, &p_data, &length);

        if (p_event == NULL)

        {

            WICED_BT_TRACE("bad hdr\n");

            break;

        }

        wiced_bt_mesh_battery_client_send_get(p_event);

        break;

    default:

        WICED_BT_TRACE("unknown\n");

        return WICED_FALSE;

    }

    return WICED_TRUE;

}

#ifdef HCI_CONTROL

/*

* Send Battery Get event over transport

*/

void mesh_battery_hci_event_send(wiced_bt_mesh_hci_event_t *p_hci_event, mesh_battery_event_t *p_data)

{

    uint8_t *p = p_hci_event->data;

    UINT8_TO_STREAM(p, p_data->battery_level);

    UINT24_TO_STREAM(p, p_data->time_to_discharge);

    UINT24_TO_STREAM(p, p_data->time_to_charge);

    UINT8_TO_STREAM(p, p_data->presence);

    UINT8_TO_STREAM(p, p_data->charging);

    UINT8_TO_STREAM(p, p_data->level_inidicator);

    UINT8_TO_STREAM(p, p_data->servicability);

    mesh_transport_send_data(HCI_CONTROL_MESH_EVENT_BATTERY_STATUS, (uint8_t *)p_hci_event, (uint16_t)(p - (uint8_t *)p_hci_event));

}

#endif

void hal_gpio_app_interrrupt_handler(void* data, uint8_t pin)

{

    static uint8_t  toggle = 0;

    WICED_BT_TRACE("Button Intterup");

    static uint32_t value;

    value = wiced_hal_gpio_get_pin_input_status(pin);

    WICED_BT_TRACE("interrupt_handler:pin:%d\n", pin);

    if(toggle == 1)

    {

        wiced_hal_gpio_configure_pin(WICED_GPIO_PIN_LED_2, GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_HIGH);

        toggle = 0;

    }

    else

    {

        wiced_hal_gpio_configure_pin(WICED_GPIO_PIN_LED_2, GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_LOW);

        toggle = 1;

    }

    wiced_hal_gpio_clear_pin_interrupt_status(pin);

}

void mesh_app_hardware_init(void)

{

    WICED_BT_TRACE("hardware INit");

    wiced_hal_gpio_register_pin_for_interrupt(WICED_GPIO_PIN_BUTTON_1, hal_gpio_app_interrrupt_handler, NULL);

    wiced_hal_gpio_configure_pin(WICED_GPIO_PIN_BUTTON_1, WICED_GPIO_BUTTON_SETTINGS(GPIO_EN_INT_RISING_EDGE), GPIO_PIN_OUTPUT_LOW);

    wiced_hal_gpio_configure_pin(WICED_GPIO_PIN_LED_2, GPIO_OUTPUT_ENABLE, GPIO_PIN_OUTPUT_HIGH);

    if(wiced_init_timer(&hal_gpio_app_timer, &hal_gpio_app_timer_cb, 0, WICED_SECONDS_PERIODIC_TIMER) == WICED_SUCCESS)

    {

        WICED_BT_TRACE("Timer Init Success");

    }

    wiced_start_timer(&hal_gpio_app_timer, LED_BLINK_FREQ_B_IN_SECONDS);

}

void hal_gpio_app_timer_cb(uint32_t arg)

{

    static uint32_t wiced_seconds = 0; /* number of seconds elapsed */

    uint8_t index = 0;

    wiced_bt_mesh_event_t *p_event;

    wiced_result_t reasult;

    p_event = wiced_bt_mesh_create_event(MESH_BATTERY_CLIENT_ELEMENT_INDEX, MESH_VENDOR_COMPANY_ID, MESH_VENDOR_MODEL_ID, 0, 0);

    if(p_event == NULL)

    {

        WICED_BT_TRACE("Bad_Event\n");

    }

    reasult = wiced_bt_mesh_battery_client_send_get(p_event);

    WICED_BT_TRACE("reasuly %d\n", reasult);

    if(reasult == WICED_BT_SUCCESS)

    {

        WICED_BT_TRACE("Sucess");

    }

}

0 Likes

Hi,

When i pass dst and Appkey both as 0xffff then create event is not returning NULL also wiced_bt_mesh_battery_client_send_get returning WICED_BT_SUCCESS but not getting WICED_BT_MESH_TX_COMPLETE .

One More Observation (I know this should not be the issue):- when i provision Battery client through MeshLighting mobile app i dont see provision complete message but on Putty terminal i can see its getting provisioned but for Battery Server i can see provision complete message on MeshLighting App.

0 Likes

Hi DheerajP_41

Now i Could able to get the status from battery server.

From Mesh Client windows app provisioned the devices and from the trace of Mesh Client  app_key_idx, model ID, and dst values are passed manually to create wiced_bt_mesh_create_event. By this way I could able get the status of 3 battery server status individually.

Now to move further I would like to know on how to implement following scenarios:-

scenario 1:-

I want broadcast get status request from client to all battery server same time, is it possible to do so, if possible what should be    passed to wiced_bt_mesh_create_event ? (i.e. app_key_idx, dst, Model_Id etc.) or is there any other way to do so ?

scenario 2:-

Consider the case, I have 3 battery server BS1, BS2, BS3 which are sending status to battery client periodically, with time interval of 10 sec. Suppose if due to some exception in BS2 server, BS2 wants to update the status to client immediately, while doing so BS1 and BS3 should stop their status update.

Question is how to inform BS1 and BS3 to terminate their status update. And again resume their status update when BS2 has done its communication with client ?

0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

Some functionality was missing in the mesh_client library for battery client and server support. Could you please try the experiment using the attached MeshClient ( works on windows OS ).

Keeping dst and app_key_idx as (0, 0) in wiced_bt_mesh_create_event() will use configured publication to send the message.

For example:

void button_interrupt_handler(void* data, uint8_t pin)

{

    wiced_bt_mesh_event_t *p_event;

    wiced_result_t result;

    p_event = wiced_bt_mesh_create_event(0, MESH_COMPANY_ID_BT_SIG, WICED_BT_MESH_CORE_MODEL_ID_GENERIC_BATTERY_CLNT, 0, 0);

if(p_event == NULL)

{

WICED_BT_TRACE("Bad_Event\n");

}

result = wiced_bt_mesh_battery_client_send_get(p_event);

WICED_BT_TRACE("result %d\n", result);

    wiced_hal_gpio_clear_pin_interrupt_status(pin);

}

The libraries will be updated with the fix in next release. Please let us know if you are facing any difficulty.

Thanks,

-Dheeraj

0 Likes

This post seems like the same problem I'm having: [CYBT-423028] wiced_bt_mesh_create_event returns NULL in WICED Studio v6.2.1

I will also try the attached Mesh Client and report back with results. I also want to mention that I had the same problem with onoff_client and level_client, using WICED Studio 6.2.1 and 6.6.0.

Thanks for the help, Dheeraj!

0 Likes

Hi,

Yes. maybe.

Please try with the attached MeshClient in my previous comment. Let me know what is your observation and test results.

Thanks,

-Dheeraj

0 Likes

Hi Dheeraj,

I thought I would respond here instead of the other thread to keep everything in the same place and maybe my results could help RaSa, but please tell me if you would rather keep the threads seperate.

I tried provisioning the devices with the MeshClient you attached and tried setting the company ID to 0xFFFF and 0x0000: in the other thread you said 0xFFFF could be worth a try but MESH_COMPANY_ID_BT_SIG is actually defined as 0x0000 so I tried both. I also tried changing the company ID in the mesh configurations of the devices, tried both 0x1000 and 0x1001 for the model ID(onoff client and server) of the event and even tried setting the destination to the unicast address I knew the server would have(0x0002).

The provisioning works with no problem as usual but unfortunately I still wasn't able to send a message. Setting the company ID to 0xFFFF makes wiced_bt_mesh_create_event() return something that isn't NULL(this is defined as a special case in wiced_bt_mesh_create_event) but still the server doesn't receive anything. I also tried switching between WICED Studio 6.2.1 and 6.6.0, that didn't help either.

I noticed that wiced_bt_mesh_create_event defines MESH_NODE_ID_INVALID as 0 and returns NULL when dst is equal to this value, but setting dst to a non-zero value still returned NULL. Setting the company ID to 0xFFFF means that part isn't executed, but it also means that dst is never changed from zero which is the initialization value.

Thanks,

Tim

0 Likes

Hi Dheeraj and RaSa,

First of all DheerajP_41​ were you able to reproduce the issue? I'm wondering how things worked out on your end.

I was able to send a message which was received by the onoff_server. My client crashes as soon as the message is sent, but I don't know if it's caused by the same thing or if it's a separate issue. I will open a new thread about that.

Instead of calling wiced_bt_mesh_create_event() I'm creating an event myself and filling in all data fields manually. This is the only combination where the server received a message:

    wiced_bt_mesh_event_t event;

    event.opcode = WICED_BT_MESH_OPCODE_GEN_ONOFF_SET;

    event.element_idx = 0;

    event.company_id = MESH_COMPANY_ID_BT_SIG;

    event.model_id = WICED_BT_MESH_CORE_MODEL_ID_GENERIC_ONOFF_CLNT;

    event.dst = 2;

    event.ttl = 63; // DEFAULT_TTL

    event.credential_flag = 0;

    event.retrans_time = 0;

    event.retrans_cnt = 0; // DEFAULT_RETRANSMISSION is 0x41

    event.src = 0;

    event.app_key_idx = 3241;

    event.reply = 0;

    wiced_bt_mesh_event_t *p_event = &event;

  • opcode: WICED_BT_MESH_OPCODE_UNKNOWN -> no message received, client crashes instantly
  • company_id: Both devices have the company ID in their mesh configuration: MESH_COMPANY_ID_BT_SIG which is defined as 0x0000.
    • company_id set to 0x1234(just a random number), client and server mesh config set to MESH_COMPANY_ID_BT_SIG -> no message received, client crashes instantly
    • company_id set to 0xFFFF, client and server mesh config set to MESH_COMPANY_ID_BT_SIG -> no message received, client crashes after second transmission attempt
    • company_id and client mesh config set to 0x1234, server mesh config set to MESH_COMPANY_ID_BT_SIG -> no message received, client crashes instantly
    • company_id and server mesh config set to MESH_COMPANY_ID_BT_SIG, client mesh config set to 0x1234 -> no message received, client crashes instantly
    • All company IDs(client mesh config, server mesh config, event company ID) set to 0x1234 -> no message received, client crashes instantly
    • All company IDs set to MESH_COMPANY_ID_CYPRESS(defined as 0x0131) -> no message received, client crashes instantly
    • All company IDs set to 0xFFFF -> no message received, client crashes after second transmission attempt
  • model_id set to WICED_BT_MESH_CORE_MODEL_ID_GENERIC_ONOFF_SRV -> no message received, client crashes instantly
  • dst: the server is provisioned first so it has the unicast address 0x0002. The client gets the unicast address 0x0003. A group is created and selected as current group before provisioning the devices.
    • set to 0xC000(the group address which both devices are provisioned into) -> no message received, client crashes instantly
    • set to 0 -> no message received, client crashes after second transmission attempt
    • set to 1 -> no message received, client crashes after second transmission attempt
    • set to 3(client's unicast address) -> client receives the message, client crashes after second transmission attempt
    • set to 5(unused unicast address) -> no message received, client crashes instantly
  • src set to 3(client's unicast address) -> no message received, client crashes instantly
  • app_key_idx: 3241 is the Generic app key which can be found in the .json file created by MeshClient
    • set to 0 -> no message received, client crashes after second transmission attempt
  • reply set to 1 -> no message received, client crashes instantly
  • ttl: in wiced_mesh_api.c, where wiced_bt_mesh_create_event() is defined, DEFAULT_TTL is defined as 63 and DEFAULT_RETRANSMISSION(used for retrans_cnt) is defined as 0x41
  • retrans_cnt set to 0x41-> no message received, client crashes instantly

Best regards,

Tim

0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

Unfortunately I couldn't reproduce the issue. In my testing, I could successfully sent GET command to the server from the client on a button press and could get the battery status back. I am attaching the battery client code herewith. Please try to test with it.

Please let me know whether you are trying to do something else also.

The steps what I followed.

  • Provision battery_client and battery_server applications on two boards using MeshClient.
  • Press the user button on the battery_client device. : - This will publish a GET message.
  • Check the serial traces on both the devices.

You should use wiced_bt_mesh_create_event() for creating mesh event for unsolicited message. Setting destination address=0 will make the device fetch the configured publication for the model for all publication. You can later change it using the provisioner.

Please note: I have tested it using the CYW920719Q40EVB_01 (CYBT_423028_EVAL has the same chip).

Thanks,

-Dheeraj

0 Likes

Hello Dheeraj,

I'm having trouble getting the code you sent working. Can you please share the makefile and any other files in the project? I'm getting errors when I try to compile the code.

Regards,

Tim

0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

Please find it here.

I have tested it in WICED 6.4.

Eg. Make target: test.test_mesh_battery_client-CYBT_423028_EVAL download

Thanks,

-Dheeraj

0 Likes