Helm alert.7zHello!
I have tried to make a additional custom service with a characteristic to contain data from a sensor value. I want the server to only send the value when it changes (to save battery life). I succeeded it doing this on the server side, but could not make the client module read it when the notification came. By using the master control app, I see that the server is working as intended.
Now instead I'll want to modify the existing characteristic as i know that one works. I'll just change the value that is transmitted. In the original example the server sends a notification with either value 0 or 1 corresponding to a press of a button. The client then gets the notification and toggles an led according to the value received.
Again I have modified the server code, so that the example characteristic sends the sensor value only when the value changes instead of a button press. According to the master controll app this works.
So to my question. How do I modify the client code so that it reads the value of the sensor and saves it in a variable? My initial though was that this would be simple, but apparently I was wrong....
I changed this code:
static void on_evt_hvx(ble_evt_t * p_ble_evt, client_t * p_client, uint32_t index)
if ((p_client != NULL) && (p_client->state == STATE_RUNNING))
{
if (
(
p_ble_evt->evt.gattc_evt.params.hvx.handle
==
p_client->srv_db.services[0].charateristics[p_client->char_index].characteristic.handle_value
)
&&
(p_ble_evt->evt.gattc_evt.params.hvx.len == 1)
)
{
if(index < LEDS_NUMBER)
{
uint8_t leds[] = LEDS_LIST;
if (p_ble_evt->evt.gattc_evt.params.hvx.data[0] == 0)
{
LEDS_OFF(1<<leds[index]);
}
else
{
LEDS_ON(1<<leds[index]);
}
}
}
}
}
To this:
static void on_evt_hvx(ble_evt_t * p_ble_evt, client_t * p_client, uint32_t index)
if ((p_client != NULL) && (p_client->state == STATE_RUNNING))
{
if (p_ble_evt->evt.gattc_evt.params.hvx.handle
==
p_client->srv_db.services[0].charateristics[p_client->char_index].characteristic.handle_value)
{
z_value=p_ble_evt->evt.gattc_evt.params.hvx.data[0];
}
}
, where "z_value" is a uint8_t.
Any help would be appreciated!
/Christian