Skip to content

TruGanic/ble-native-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“‘ BLE Sensor Simulator β€” Android Native

A native Android application that transforms any phone into a Bluetooth Low Energy (BLE) Peripheral, simulating a smart logistics sensor. It broadcasts real-world cold chain & supply chain data over BLE β€” no physical sensor hardware required.

This is the mobile companion to the PC-based BLE Sensor Simulator (Node.js/bleno). Both simulators share identical UUIDs, payload formats, and BLE protocol behavior, making them fully interchangeable.


🎯 What It Does

The app acts as a BLE GATT Server (Peripheral) that:

  1. πŸ“‚ Loads 1,000 rows of logistics sensor data from a bundled CSV dataset
  2. πŸ“» Advertises as LogisticsSim over Bluetooth Low Energy
  3. πŸ”„ Cycles through data rows every 2 seconds
  4. πŸ“€ Broadcasts each row as a UTF-8 string via Read and Notify characteristics
  5. πŸ“Š Displays a real-time dashboard with live payload, sensor values, and event log

A separate device (phone, tablet, or PC) running a BLE client/scanner can discover, connect, and receive the streaming data.


πŸ“Έ App Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     πŸš› BLE Sensor Simulator         β”‚
β”‚       Logistics & Cold Chain         β”‚
β”‚                                      β”‚
β”‚  β”Œβ”€ SERVICE STATUS ────────────────┐ β”‚
β”‚  β”‚ 🟒 Advertising... Waiting       β”‚ β”‚
β”‚  β”‚    No connections                β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                      β”‚
β”‚  β”Œβ”€ BLE CONFIGURATION ────────────┐ β”‚
β”‚  β”‚ Device Name: LogisticsSim       β”‚ β”‚
β”‚  β”‚ Service:  A07498CA-AD5B-...     β”‚ β”‚
β”‚  β”‚ Char:     51FF12BB-3ED8-...     β”‚ β”‚
β”‚  β”‚ Properties: Read | Notify       β”‚ β”‚
β”‚  β”‚ Interval: 2000ms                β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                      β”‚
β”‚  β”Œβ”€ CURRENT DATA ──── Row: 42/1000 ┐ β”‚
β”‚  β”‚ BLE Payload:                     β”‚ β”‚
β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
β”‚  β”‚ β”‚ Truck_7,27.0,67.8,Delayed   β”‚ β”‚ β”‚
β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
β”‚  β”‚ 🚚 Truck_7      πŸ“¦ Delayed      β”‚ β”‚
β”‚  β”‚ 🌑️ 27.0Β°C       πŸ’§ 67.8%       β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                      β”‚
β”‚  β”Œβ”€ EVENT LOG ─────────────────────┐ β”‚
β”‚  β”‚ [15:30:01] Simulator started    β”‚ β”‚
β”‚  β”‚ [15:30:01] Advertising...       β”‚ β”‚
β”‚  β”‚ [15:30:05] Device connected     β”‚ β”‚
β”‚  β”‚ [15:30:05] Client subscribed    β”‚ β”‚
β”‚  β”‚ [15:30:07] Broadcasting: ...    β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚     ⏹  STOP SIMULATOR           β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                      β”‚
β”‚    Dataset: sensor_data.csv (1000)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ BLE Protocol Specification

This app implements the exact same BLE protocol as the PC simulator:

Parameter Value
Advertising Name LogisticsSim
Service UUID A07498CA-AD5B-474E-940D-16F1FBE7E8CD
Characteristic UUID 51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B
CCCD (Descriptor) 00002902-0000-1000-8000-00805f9b34fb
Properties Read, Notify
Encoding UTF-8 String
Update Interval 2000ms
Payload Format AssetID,Temperature,Humidity,ShipmentStatus

Example Payloads

Truck_7,27.0,67.8,Delayed
Truck_6,22.5,54.3,In Transit
Truck_10,25.2,62.2,In Transit
Truck_9,25.4,52.3,Delivered

πŸ› οΈ Tech Stack

Component Technology
Language Kotlin 1.9.24
Min SDK 26 (Android 8.0 Oreo)
Target SDK 35 (Android 15)
Build System Gradle 8.9 + AGP 8.7.3
Java OpenJDK 17
BLE Stack Android BluetoothLeAdvertiser + BluetoothGattServer
UI Material Components + ViewBinding
Service Foreground Service (connectedDevice type)
Architecture Service ↔ BroadcastReceiver ↔ Activity

πŸ“¦ Installation

Option 1: Download APK (Quick)

  1. Transfer BLE-Sensor-Simulator.apk to your Android phone
  2. Enable "Install from Unknown Sources" in Settings
  3. Open the APK and install

Option 2: Build from Source

Prerequisites:

  • Android SDK (API 35)
  • Java 17+
  • Bluetooth 4.0+ device with BLE Peripheral support
# Clone the repository
git clone https://github.com/TruGanic/ble-native-simulator.git
cd ble-native-simulator

# Build the debug APK
./gradlew assembleDebug

# Install via ADB
adb install app/build/outputs/apk/debug/app-debug.apk

πŸš€ Usage

Starting the Simulator

  1. Open BLE Sensor Simulator on your Android phone
  2. Grant Bluetooth and Notification permissions when prompted
  3. Tap β–Ά START SIMULATOR
  4. The status will show "Advertising... Waiting for connections"

Connecting a Client

On a separate device, use any BLE client:

Client Platform
nRF Connect Android / iOS
BLE Scanner Android
LightBlue iOS
Your React Native / Flutter app Any
PC with noble / bleak Linux / macOS / Windows

Steps:

  1. Scan for BLE devices
  2. Connect to "LogisticsSim"
  3. Find Service A07498CA-...
  4. Open Characteristic 51FF12BB-...
  5. Enable Notifications (or do a Read)
  6. Data streams every 2 seconds βœ“

⚠️ Important: The simulator and scanner must run on separate physical devices. A single phone cannot be both the BLE Peripheral and Central simultaneously for the same service.


πŸ“Š Dataset

The bundled sensor_data.csv contains 1,000 rows of simulated logistics & cold chain data.

Source: Smart Logistics Supply Chain Dataset by ziya07 on Kaggle.

Field Example Used in BLE Payload
Timestamp 2024-03-20 00:11:14
Asset_ID Truck_7 βœ…
Latitude -65.7383
Longitude 11.2497
Inventory_Level 390
Shipment_Status Delayed βœ…
Temperature 27.0 βœ…
Humidity 67.8 βœ…
Traffic_Status Detour
Waiting_Time 38
+ 6 more fields ...

πŸ—οΈ Project Structure

ble-native-simulator/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ build.gradle.kts                  # App-level build config
β”‚   β”œβ”€β”€ proguard-rules.pro
β”‚   └── src/main/
β”‚       β”œβ”€β”€ AndroidManifest.xml            # Permissions & service declaration
β”‚       β”œβ”€β”€ assets/
β”‚       β”‚   └── sensor_data.csv            # Bundled dataset (1000 rows)
β”‚       β”œβ”€β”€ java/com/truganic/blesimulator/
β”‚       β”‚   β”œβ”€β”€ MainActivity.kt            # UI controller, permissions, lifecycle
β”‚       β”‚   β”œβ”€β”€ BleSimulatorService.kt     # Core BLE peripheral (GATT server)
β”‚       β”‚   β”œβ”€β”€ CsvDataManager.kt          # CSV parser & row cycling
β”‚       β”‚   └── LogisticsData.kt           # Data model & payload serializer
β”‚       └── res/
β”‚           β”œβ”€β”€ layout/activity_main.xml   # Dark-themed dashboard layout
β”‚           β”œβ”€β”€ drawable/                  # Status indicators, backgrounds
β”‚           └── values/                    # Colors, strings, themes
β”œβ”€β”€ build.gradle.kts                       # Root build config
β”œβ”€β”€ settings.gradle.kts                    # Project settings
β”œβ”€β”€ gradle.properties                      # Gradle JVM & Android config
β”œβ”€β”€ gradlew                                # Gradle wrapper script
β”œβ”€β”€ gradle/wrapper/
β”‚   └── gradle-wrapper.properties          # Gradle 8.9 distribution
└── sensor_data.csv                        # Source dataset

πŸ”§ How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Android Phone (Peripheral)                    β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  CSV      │───▢│  CsvDataManager  │───▢│  BleSimulator     β”‚  β”‚
β”‚  β”‚  Asset    β”‚    β”‚  Parse & Cycle   β”‚    β”‚  Service          β”‚  β”‚
β”‚  β”‚  Data     β”‚    β”‚  Every 2 sec     β”‚    β”‚                   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚                                          β”‚  β”‚ GATT Server β”‚  β”‚  β”‚
β”‚                                          β”‚  β”‚ Advertiser  │──┼──┼──▢ BLE Radio
β”‚                                          β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚                   β”‚  β”‚
β”‚  β”‚         MainActivity              │◀──│  Broadcasts       β”‚  β”‚
β”‚  β”‚  Live Dashboard + Event Log       β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                      BLE Radio Wave
                           β”‚
                           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Another Device (Central / Scanner)                  β”‚
β”‚                                                                  β”‚
β”‚  nRF Connect / React Native App / Python bleak / etc.           β”‚
β”‚  ──▢ Scan ──▢ Connect ──▢ Subscribe ──▢ Receive Data           β”‚
β”‚                                                                  β”‚
β”‚  Payload: "Truck_7,27.0,67.8,Delayed"                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”€ PC vs Android Simulator

Both simulators are protocol-compatible and interchangeable:

Feature PC Simulator Android Simulator
Language TypeScript / Node.js Kotlin
BLE Library @abandonware/bleno Android BLE API
Platform Linux (BlueZ) Android 8.0+
Service UUID βœ… Identical βœ… Identical
Characteristic UUID βœ… Identical βœ… Identical
Payload Format βœ… Identical βœ… Identical
Update Interval 2000ms 2000ms
Advertising Name LogisticsSim LogisticsSim
Requires Root Yes (sudo) No
Portable ❌ Desktop/RPi only βœ… Any Android phone

πŸ“± Compatibility

Requirements

  • Android 8.0 Oreo (API 26) or higher
  • Bluetooth 4.0+ with BLE Peripheral mode support
  • Most phones manufactured after 2015 support this

Tested On

  • Android 12 (API 31)
  • Android 13 (API 33)
  • Android 14 (API 34)

Permissions Used

Permission Purpose Android Version
BLUETOOTH_ADVERTISE BLE advertising 12+ (API 31+)
BLUETOOTH_CONNECT GATT server connections 12+ (API 31+)
BLUETOOTH Legacy BLE access ≀11 (API ≀30)
BLUETOOTH_ADMIN Legacy BLE admin ≀11 (API ≀30)
ACCESS_FINE_LOCATION Legacy BLE scanning ≀11 (API ≀30)
FOREGROUND_SERVICE Keep service alive 9+ (API 28+)
POST_NOTIFICATIONS Service notification 13+ (API 33+)

πŸ“„ License

ISC


πŸ™ Credits


Built with ❀️ by TruGanic

About

A native Android BLE Peripheral Simulator that transforms any phone into a Smart Logistics Sensor . broadcasting cold chain data (temperature, humidity) over Bluetooth Low Energy in real-time. Mobile companion to the Node.js PC simulator.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages