Skip to content

Conversation

@tuuhin
Copy link
Owner

@tuuhin tuuhin commented Oct 19, 2025

Bluetooth Low Energy Server and UI/UX improvements
Included a full-featured Bluetooth Low Energy (BLE) server, allowing the app to broadcast services and characteristics to connected clients. It also includes significant UI/UX enhancements, bug fixes, and dependency updates.

Changes

  • Added the ability to start a BLE GATT server with configurable services.
  • Included services for Battery Level, Environmental Sensing (Ambient Light), and Nordic UART (NUS)
  • Implemented a service to send battery level and ambient light change to subscribed clients
  • The server UI displays the list of connected devices and available services

UI/UX improvements

  • A new color scheme has been applied for a more modern and cohesive look.
  • The UI for both BLE client and server has been changed a bit
  • A progress indicator is now shown when connecting to a BLE device.

Fixes and Refactoring

  • Improved the BLE scanning logic to be more reliable.
  • Refactored the codebase for better readability and maintainability,

tuuhin added 11 commits October 11, 2025 22:46
AndroidBLEClientConnector.kt opens the gatt server, configure the services and  starts advertising
BLEServerUUID.kt contains the server services, characteristics uuid
BLEConstructorDSL.kt provides a simple way to configure a service, characteristics or description via the domain based models
BLEServerGattCallback.kt manages the incomming connection read/ write execution its incomplete yet after the nus is ready it can be tested!
BLEServerConnector.kt included flow for is server running and errors flow as there can be some errors while starting the server
BLEServerServiceQueue.kt a queue needed to be maintained as we cannot add service at one go when its added then only the next one can be added
Included a battery service, this can be used to read battery of the mobile via BatteryReader.kt
DeviceModule.kt will contain device specific providers
Converted BLEServerServices values into functions
Separated BLEMessageModel.kt into Echo and NUS message models with tx value in nus message
BatteryReader.kt uses the battery manager to read the charging state and battery level
BLEServerGattCallback.kt changes related to adding new service ,characteristics and descriptor and how to handle each response
Battery Service notify is not ready yet will be adding that next
A new environmental sensing service included to read and notify about the light sensor values
LightSensorReader.kt reads the ambient light
In AndroidBLEServerConnector.kt and BLEServerGattCallback.kt included notifications the values are read and the map is maintained for subscribers according to the last notification client list is made and notified
for notification corrected some portion in AndroidBLEServerConnector::onStartServer
BLEMessageModel.kt updated and for notification we use BLENotificationModel.kt
Included using sensor.light in AndroidManifest.xml
Updating the BLE Client code rename exceptions, included permission checking before calling connect .
In BLE Scan logic the auto cancel before timeout logic updated, using the finally clause the stop is always called in-case the scan is stopped or some error is thrown
Using locks in SampleUUIDReader.kt so that loading the sample uuid's in memory doesn't happen twice
Also made some Ui Changes
Notable changes include adding the service and characteristics count,
Using surface in place of card in BluetoothDeviceCard.kt and BluetoothLEDeviceCard.kt is the device is not paired using a different icon color
BluetoothLEDeviceCard.kt also include a signal indicator based on the rssi values.
In BluetoothPermissionButton.kt checking all the bluetooth based permission include advertise which is used for advertising the server services
User is prompted to start the server with service configuration (yet to build)
On starting the server the services and connected client will be shown the user then can stop the server when done,
Included BLEServer route in Routes.kt
Included BLEServerViewModel.kt in ViewModelModule.kt
Drawer navigation to BLEServer screen
BLEServerServices will handle what services the server should run with, on BLEServerConnector.kt onStart it now need a set of services options, the options will be converted to bleServices via BLEServerServicesToGatt.kt
IN BLEDeviceViewModel.kt add a toast message to show client re-connected
Again some work on the ble server screen and added BLEServerOptionSelectorBottomSheet.kt which will let the user know what services are running or will be ran later
IN BLEServerViewModel.kt handling the screen state via BLEServerScreenState.kt
LightSensorReaderImpl.kt some manufacturer may not actually allow the device to register thus need to check if sensor callback is registered
BLEServerNotificationManager.kt and BLENotificationTypes.kt now manages the logic for clients subscribed to device based notification battery and illuminance
Updated ble_service_uuids.json with new service names
Corrections in BLEServerGattCallback.kt, broadcast receivers are register when client count>0 and unregister if client count ==0
LightSensorReaderImpl.kt can give null value if not registered so its a gatt failure
Using the sample reader to update all the probable names for services and characteristics
AndroidBLEServerConnector.kt the issue that the characteristics change was not notified as the service were not the same, so once the service are registered they are used to set the broadcast channels
Added string resources for most raw strings in ble feature (clients and server)
For client included BLEDeviceScreenContent.kt which shows a connecting progress indicator when the client profile is unavailable.
Changed the color and shape of BLEDeviceProfile.kt.
IN BLEServerOptionSelectorBottomSheet.kt added a checkbox as its tell the user its selected or unselected the color doesn't define that fully
Replaced icons in BTAppNavigationDrawer.kt
Width of the content in Start server box corrected for classic server
THe blue yellow green theming was looking bad as there was no synergy between the colors thus used a sandy yellow color scheme
Removed unwanted resources from the project
Bumped up version no to 1.2.0
Mentioned BLEServer in README.md file
@tuuhin tuuhin merged commit 811315c into main Oct 19, 2025
1 check passed
@tuuhin tuuhin deleted the ble_server branch October 19, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants