Enable BLE FOTA DFU MCUBOOT in Zephyr only on button press

Greetings,

I would like to enable triggered firmware update option (dfu icon to be shown and to work) in NRF Connect android app on button press or uart. I followed the nordic academy example about  ble dfu update but i want to enable it only on button press. Where can i follow an example for this ?

Best regards.

Parents
  • mcumgr with zephyr uses BLE GATT services to communicate and update firmware You may add callback functions for GATT write/read and block reading/writing mcumgr attributes if button is not pressed.

    Following code always authorizes requests, but you can return false in write_authorize/read_authorize (using bt_uuid_cmp to check if it is OTA attribute read/write or just block all GATT attributes if that's ok for you) and OTA will be blocked.

    bool write_authorize (struct bt_conn *conn, const struct bt_gatt_attr *attr) {
      return true;
    }
    
    bool read_authorize (struct bt_conn *conn, const struct bt_gatt_attr *attr) {
      return true;
    }
    
    static const struct bt_gatt_authorization_cb auth_callbacks = {
      .read_authorize = read_authorize,
      .write_authorize = write_authorize,
    };
    
    
    ...
      err = bt_gatt_authorization_cb_register(&auth_callbacks);
      if (err) {
        printk("Error at setting auth callbacks (err %d), probably already set\n", err);
      }
    ...

Reply
  • mcumgr with zephyr uses BLE GATT services to communicate and update firmware You may add callback functions for GATT write/read and block reading/writing mcumgr attributes if button is not pressed.

    Following code always authorizes requests, but you can return false in write_authorize/read_authorize (using bt_uuid_cmp to check if it is OTA attribute read/write or just block all GATT attributes if that's ok for you) and OTA will be blocked.

    bool write_authorize (struct bt_conn *conn, const struct bt_gatt_attr *attr) {
      return true;
    }
    
    bool read_authorize (struct bt_conn *conn, const struct bt_gatt_attr *attr) {
      return true;
    }
    
    static const struct bt_gatt_authorization_cb auth_callbacks = {
      .read_authorize = read_authorize,
      .write_authorize = write_authorize,
    };
    
    
    ...
      err = bt_gatt_authorization_cb_register(&auth_callbacks);
      if (err) {
        printk("Error at setting auth callbacks (err %d), probably already set\n", err);
      }
    ...

Children
No Data
Related