<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Update BLE Characteristic from ENUM</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57970/update-ble-characteristic-from-enum</link><description>Hi 
 I would like to use an ENUM and STUCT within my application to maintain device state (IDLE, RUNNING etc). This state needs to update a BLE Characteristic. I have the BLE Service and Characteristic running but am struggling to send the ENUM as a single</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 26 Feb 2020 15:25:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57970/update-ble-characteristic-from-enum" /><item><title>RE: Update BLE Characteristic from ENUM</title><link>https://devzone.nordicsemi.com/thread/236621?ContentTypeID=1</link><pubDate>Wed, 26 Feb 2020 15:25:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3190a402-9502-4bcc-812f-f2b2ec3e3b4f</guid><dc:creator>aplatts</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I have looked at my code and carried out a few modifications and have a better understand how the SoftDevice works.&lt;br /&gt;&lt;br /&gt;The following is working, on the following event, it calls handle_ble_char:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;case BLE_SRVC_OPT_EVT_CONNECTED:
        t_value = SET;
        handle_ble_char(p_cus_service, &amp;amp;p_cus_service-&amp;gt;status_char_handles , &amp;amp;t_value);
        break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The structure of&amp;nbsp;&lt;span&gt;handle_ble_char is as follows:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void handle_ble_char (ble_srvc_opt_t *p_service, ble_gatts_char_handles_t *p_char_handle, m_setget *p_type) {

    uint32_t err_code;
    ble_gatts_value_t	t_value;

    //Get &amp;amp; Set for ble_src_opt - Char - Status
    if (p_char_handle-&amp;gt;value_handle == m_cus.status_char_handles.value_handle) {
        
        t_value.p_value = &amp;amp;m_srm_state.evt_type;
	    t_value.len      = 1;
	    t_value.offset   = 0;

        switch (*p_type)
        {
        case SET:
            err_code = sd_ble_gatts_value_set(p_service-&amp;gt;conn_handle, p_char_handle-&amp;gt;value_handle, &amp;amp;t_value);
    	    APP_ERROR_CHECK(err_code);
            break;
        case GET:
            err_code = sd_ble_gatts_value_get(p_service-&amp;gt;conn_handle, p_char_handle-&amp;gt;value_handle, &amp;amp;t_value);
    	    APP_ERROR_CHECK(err_code);
            break;
        default:
            break;
        }
    }

}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This is a universal bit of code which allows me to tell it which service and characteristic to set or get.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It is working as planned now...thanks for the help on this one.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update BLE Characteristic from ENUM</title><link>https://devzone.nordicsemi.com/thread/236310?ContentTypeID=1</link><pubDate>Tue, 25 Feb 2020 15:03:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:488838bd-6986-426c-ad87-9554d83b0b5e</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Did you try the workaround suggest in the linked case in the previous reply?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You could try setting&amp;nbsp;err_code =sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0)&amp;nbsp; before you call&amp;nbsp; ble_srvc_opt_custom_value_update(). And you should make sure that notifications is enabled.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update BLE Characteristic from ENUM</title><link>https://devzone.nordicsemi.com/thread/236030?ContentTypeID=1</link><pubDate>Mon, 24 Feb 2020 15:08:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d91ed8da-8486-4bd2-a30d-d2c046e33473</guid><dc:creator>aplatts</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I think the issue is that I am attempting to send a Characteristic Value before it being ready (i.e. I&amp;#39;m sending as soon as&amp;nbsp;BLE_SRVC_OPT_EVT_CONNECTED). As this is at the Service level, I assume that the Characteristic could still be being negotiated.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Would this make sense?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update BLE Characteristic from ENUM</title><link>https://devzone.nordicsemi.com/thread/235708?ContentTypeID=1</link><pubDate>Fri, 21 Feb 2020 12:31:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:959cf117-f76e-441b-b660-72a55b139611</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;ERROR 13313 is a&amp;nbsp;&lt;span&gt;BLE_ERROR_GATTS_SYS_ATTR_MISSING which is returned by&amp;nbsp;sd_ble_gatts_hvx(). Could you try the solution proposed&amp;nbsp;in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/32024/error-code-13313-0x3401-returned-by-ble_nus_string_send/124935#124935"&gt;this case&lt;/a&gt;.&amp;nbsp; Also I can&amp;#39;t see that value is a struct member from your definition of the struct&amp;nbsp;m_srm_state. It seems that the struct member is called&amp;nbsp;evt_type.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update BLE Characteristic from ENUM</title><link>https://devzone.nordicsemi.com/thread/235467?ContentTypeID=1</link><pubDate>Thu, 20 Feb 2020 13:26:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a88bb48-f5fb-448b-97d8-185a1800cd8e</guid><dc:creator>aplatts</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The code won&amp;#39;t compile as is, but if I replace the ENUM var with a simple byte of 01 -&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;ret_code_t err_code;
uint8_t value            = 0;
err_code = ble_srvc_opt_custom_value_update(&amp;amp;m_cus, value);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;This code is initiated as soon as the following criteria is met within&amp;nbsp; this static void -&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_srvc_opt_evt(ble_srvc_opt_t     * p_cus_service,
                       ble_srvc_opt_evt_t * p_evt)
{

    ret_code_t err_code;
    uint8_t value            = 0;
    
    switch(p_evt-&amp;gt;evt_type)
    {

        case BLE_SRVC_OPT_EVT_NOTIFICATION_ENABLED:
            break;

        case BLE_SRVC_OPT_EVT_NOTIFICATION_DISABLED:
            break;

        case BLE_SRVC_OPT_EVT_CONNECTED:
            //Set BLE Characteristics on connection
            err_code = ble_srvc_opt_custom_value_update(&amp;amp;m_cus, value);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_SRVC_OPT_EVT_DISCONNECTED:
            break;

        default:
            // No implementation needed.
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;I get the following crash:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Fast advertising.

&amp;lt;info&amp;gt; app: ble_srvc_data Custom Characteristic - BLE_GAP_EVT_CONNECTED

&amp;lt;info&amp;gt; app: ble_srvc_opt Custom Characteristic - BLE_GAP_EVT_CONNECTED

&amp;lt;info&amp;gt; app: In ble_srvc_opt_custom_value_update. 

&amp;lt;error&amp;gt; app: ERROR 13313 [Unknown error code] at ../../../main.c:206

PC at: 0x0002D141

&amp;lt;error&amp;gt; app: End of error report&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Lines 205 and 206 in main.c are:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;err_code = ble_srvc_opt_custom_value_update(&amp;amp;m_cus, value);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Value Update Code:-&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint32_t ble_srvc_opt_custom_value_update(ble_srvc_opt_t * p_cus, uint8_t custom_value)
{
    NRF_LOG_INFO(&amp;quot;In ble_srvc_opt_custom_value_update. \r\n&amp;quot;); 
    if (p_cus == NULL)
    {
        return NRF_ERROR_NULL;
    }

    uint32_t err_code = NRF_SUCCESS;
    ble_gatts_value_t gatts_value;

    // Initialize value struct.
    memset(&amp;amp;gatts_value, 0, sizeof(gatts_value));

    gatts_value.len     = sizeof(uint8_t);
    gatts_value.offset  = 0;
    gatts_value.p_value = &amp;amp;custom_value;

    // Update database.
    err_code = sd_ble_gatts_value_set(p_cus-&amp;gt;conn_handle,
                                      p_cus-&amp;gt;custom_value_handles.value_handle,
                                      &amp;amp;gatts_value);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Send value if connected and notifying.
    if ((p_cus-&amp;gt;conn_handle != BLE_CONN_HANDLE_INVALID)) 
    {
        ble_gatts_hvx_params_t hvx_params;

        memset(&amp;amp;hvx_params, 0, sizeof(hvx_params));

        hvx_params.handle = p_cus-&amp;gt;custom_value_handles.value_handle;
        hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
        hvx_params.offset = gatts_value.offset;
        hvx_params.p_len  = &amp;amp;gatts_value.len;
        hvx_params.p_data = gatts_value.p_value;

        err_code = sd_ble_gatts_hvx(p_cus-&amp;gt;conn_handle, &amp;amp;hvx_params);
    }
    else
    {
        err_code = NRF_ERROR_INVALID_STATE;
    }


    return err_code;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Update BLE Characteristic from ENUM</title><link>https://devzone.nordicsemi.com/thread/235440?ContentTypeID=1</link><pubDate>Thu, 20 Feb 2020 12:16:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08851466-065a-4297-a7eb-d240d3a1b4e2</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m interested in seeing more of your code, specifically the initialization of the service and the&amp;nbsp;ble_srvc_opt_custom_value_update(). Also&lt;/p&gt;
[quote user=""]I have the BLE Service and Characteristic running but am struggling to send the ENUM as a single byte (uint8_t).[/quote]
&lt;p&gt;&amp;nbsp;What exactly happens when you run the application? Are you getting any errors? Have you tried &lt;a href="https://www.youtube.com/watch?v=uP8RYgYGRvI"&gt;debugging &lt;/a&gt;your application?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>