mirror of
https://github.com/morgan9e/SensorReader
synced 2026-04-14 16:37:20 +09:00
.
This commit is contained in:
@@ -7,6 +7,8 @@ class BLEManager: NSObject, ObservableObject {
|
|||||||
@Published var isScanning = false
|
@Published var isScanning = false
|
||||||
@Published var bluetoothState: CBManagerState = .unknown
|
@Published var bluetoothState: CBManagerState = .unknown
|
||||||
@Published var discoveredDevices: Set<String> = []
|
@Published var discoveredDevices: Set<String> = []
|
||||||
|
@Published var allowedUUIDs: Set<String> = []
|
||||||
|
@Published var discoveryMode = false
|
||||||
|
|
||||||
private var centralManager: CBCentralManager!
|
private var centralManager: CBCentralManager!
|
||||||
private var seenNonces: Set<String> = []
|
private var seenNonces: Set<String> = []
|
||||||
@@ -14,13 +16,6 @@ class BLEManager: NSObject, ObservableObject {
|
|||||||
// Configuration
|
// Configuration
|
||||||
private let companyID: UInt16 = 0xFFFF
|
private let companyID: UInt16 = 0xFFFF
|
||||||
|
|
||||||
// Optional: Set specific UUIDs to filter. Empty = accept all devices with correct company ID
|
|
||||||
// Example: ["12345678-1234-1234-1234-123456789ABC"]
|
|
||||||
var allowedUUIDs: Set<String> = []
|
|
||||||
|
|
||||||
// Set to true to show all devices regardless of company ID (for discovery)
|
|
||||||
var discoveryMode = false
|
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
centralManager = CBCentralManager(delegate: self, queue: nil)
|
centralManager = CBCentralManager(delegate: self, queue: nil)
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ struct ContentView: View {
|
|||||||
SensorReadingRow(reading: reading)
|
SensorReadingRow(reading: reading)
|
||||||
}
|
}
|
||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
|
.background(Color(.systemGroupedBackground))
|
||||||
|
.scrollContentBackground(.hidden)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start/Stop button
|
// Start/Stop button
|
||||||
@@ -63,6 +65,7 @@ struct ContentView: View {
|
|||||||
.padding()
|
.padding()
|
||||||
.disabled(bleManager.bluetoothState != .poweredOn)
|
.disabled(bleManager.bluetoothState != .poweredOn)
|
||||||
}
|
}
|
||||||
|
.background(Color(.systemGroupedBackground))
|
||||||
.navigationTitle("EnvSensor Reader")
|
.navigationTitle("EnvSensor Reader")
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
@@ -234,7 +237,21 @@ struct SensorReadingRow: View {
|
|||||||
.font(.system(.body, design: .monospaced))
|
.font(.system(.body, design: .monospaced))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.vertical, 8)
|
.padding()
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 12)
|
||||||
|
.fill(Color(.secondarySystemGroupedBackground))
|
||||||
|
)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 12)
|
||||||
|
.strokeBorder(Color.blue.opacity(0.4), lineWidth: 2.5)
|
||||||
|
)
|
||||||
|
.shadow(color: Color.black.opacity(0.15), radius: 5, x: 0, y: 3)
|
||||||
|
.padding(.vertical, 6)
|
||||||
|
.padding(.horizontal, 12)
|
||||||
|
.listRowInsets(EdgeInsets())
|
||||||
|
.listRowSeparator(.hidden)
|
||||||
|
.listRowBackground(Color.clear)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func rssiColor(_ rssi: Int) -> Color {
|
private func rssiColor(_ rssi: Int) -> Color {
|
||||||
|
|||||||
41
README.md
41
README.md
@@ -4,18 +4,29 @@ An iOS application for scanning and reading environmental sensor data from BLE d
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Real-time BLE scanning for EnvSensor devices
|
- **Real-time BLE scanning** for EnvSensor devices
|
||||||
- Displays environmental readings:
|
- **Environmental readings display:**
|
||||||
- Temperature (°C)
|
- Temperature (°C)
|
||||||
- Humidity (%)
|
- Humidity (%)
|
||||||
- Pressure (hPa)
|
- Pressure (hPa)
|
||||||
- Displays power metrics:
|
- **Power metrics display:**
|
||||||
- Voltage (V)
|
- Voltage (V)
|
||||||
- Current (mA)
|
- Current (mA)
|
||||||
- Power (mW)
|
- Power (mW)
|
||||||
- Shows signal strength (RSSI in dBm)
|
- **Device Management:**
|
||||||
- Automatic deduplication of readings based on nonce
|
- UUID-based device filtering (iOS doesn't expose MAC addresses)
|
||||||
- Clean, modern SwiftUI interface
|
- Discovered devices list
|
||||||
|
- Optional device whitelist
|
||||||
|
- Discovery mode for debugging
|
||||||
|
- **Visual Features:**
|
||||||
|
- Signal strength indicator (RSSI in dBm)
|
||||||
|
- Color-coded RSSI display
|
||||||
|
- Card-based UI with borders and shadows
|
||||||
|
- Dark/Light mode support
|
||||||
|
- **Smart Features:**
|
||||||
|
- Automatic deduplication of readings based on nonce
|
||||||
|
- Keeps last 100 readings
|
||||||
|
- Company ID filtering (0xFFFF)
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
@@ -23,12 +34,26 @@ An iOS application for scanning and reading environmental sensor data from BLE d
|
|||||||
- iPhone or iPad with Bluetooth LE support
|
- iPhone or iPad with Bluetooth LE support
|
||||||
- Xcode 15.0 or later (for building)
|
- Xcode 15.0 or later (for building)
|
||||||
|
|
||||||
|
## Device Filtering
|
||||||
|
|
||||||
|
**Note:** iOS does not expose Bluetooth MAC addresses for privacy reasons. Instead, the app uses device UUIDs which are assigned by iOS.
|
||||||
|
|
||||||
|
### How to Filter Devices
|
||||||
|
|
||||||
|
1. **Start scanning** - The app will show all devices with Company ID `0xFFFF`
|
||||||
|
2. **Open Settings** - Tap the gear icon in the top-right
|
||||||
|
3. **View discovered devices** - All found devices are listed with their UUIDs
|
||||||
|
4. **Add to filter** - Tap "Add" next to any device to whitelist it
|
||||||
|
5. **Manual entry** - You can also manually enter UUIDs in the format `12345678-1234-1234-1234-123456789ABC`
|
||||||
|
|
||||||
|
When the whitelist is empty, all devices with the correct Company ID are shown. When you add devices to the whitelist, only those specific devices will display readings.
|
||||||
|
|
||||||
## BLE Protocol
|
## BLE Protocol
|
||||||
|
|
||||||
The app scans for BLE devices with the following characteristics:
|
The app scans for BLE devices with the following characteristics:
|
||||||
|
|
||||||
- **Device Name**: `EnvSensor`
|
- **Company ID**: `0xFFFF` (required)
|
||||||
- **Company ID**: `0xFFFF`
|
- **Device Name**: Optional, not used for filtering
|
||||||
- **Data Format** (16 bytes, little-endian):
|
- **Data Format** (16 bytes, little-endian):
|
||||||
- Bytes 0-1: Nonce (UInt16)
|
- Bytes 0-1: Nonce (UInt16)
|
||||||
- Bytes 2-3: Temperature (Int16, divide by 100 for °C)
|
- Bytes 2-3: Temperature (Int16, divide by 100 for °C)
|
||||||
|
|||||||
Reference in New Issue
Block a user