diff --git a/firmware/app/prj.conf b/firmware/app/prj.conf index f0121be..6078c4b 100644 --- a/firmware/app/prj.conf +++ b/firmware/app/prj.conf @@ -23,6 +23,7 @@ CONFIG_BT_SMP=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_GATT_CLIENT=y CONFIG_BT_DEVICE_NAME="Mellifera" +CONFIG_BT_BAS=y CONFIG_BT_BUF_ACL_RX_SIZE=255 CONFIG_BT_BUF_ACL_TX_SIZE=251 diff --git a/firmware/app/src/main.c b/firmware/app/src/main.c index 2e3f2c3..282df25 100644 --- a/firmware/app/src/main.c +++ b/firmware/app/src/main.c @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -312,7 +313,11 @@ int thread_sensors(void) LOG_ERR("Could not get sample"); } - sprintf(str_v, "V :%7.5f", voltage.val1 + voltage.val2 * 1e-6); + double vbat = voltage.val1 + voltage.val2 * 1e-6; + uint8_t pct_bat = 100.0 * (vbat - 3.3) / (4.2 - 3.3); + bt_bas_set_battery_level(pct_bat); + + sprintf(str_v, "V :%7.5f", vbat); sprintf(str_i, "I :%7.5f", current.val1 + current.val2 * 1e-6); sprintf(str_p, "P :%7.4f", pressure.val1 + pressure.val2 * 1e-6); sprintf(str_t, "T :%7.4f", temperature.val1 + temperature.val2 * 1e-6); diff --git a/firmware/app/src/peripheral_gatt_write.c b/firmware/app/src/peripheral_gatt_write.c index 987ed70..be59ef9 100644 --- a/firmware/app/src/peripheral_gatt_write.c +++ b/firmware/app/src/peripheral_gatt_write.c @@ -11,6 +11,7 @@ #include #include #include +#include extern int mtu_exchange(struct bt_conn *conn); extern int write_cmd(struct bt_conn *conn); @@ -19,6 +20,9 @@ extern uint32_t last_write_rate; static const struct bt_data ad[] = { BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), + BT_DATA_BYTES(BT_DATA_UUID16_ALL, + BT_UUID_16_ENCODE(BT_UUID_BAS_VAL), // battery service + ), BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1), // -1 to strip \0 };