Skip to content

[Feat] ESP32와의 BLE 통신 구현#7

Merged
ParkSeongGeun merged 3 commits intodevfrom
feat/ble-esp32-settings
Oct 18, 2025
Merged

[Feat] ESP32와의 BLE 통신 구현#7
ParkSeongGeun merged 3 commits intodevfrom
feat/ble-esp32-settings

Conversation

@ParkSeongGeun
Copy link
Copy Markdown
Contributor

@ParkSeongGeun ParkSeongGeun commented Oct 18, 2025

개요

ESP32 모듈과의 블루투스 연결을 확인하고, 필터링을 통해 특정 디바이스와의 연결을 구현하였습니다.

스크린샷

ScreenRecording_10-18-2025.16-04-33_1.MP4
아두이노 Serial Monitor 도움말 누른 상태
image 스크린샷 2025-10-18 오후 4 05 13
IMG.0386.mp4

수정사항

  1. BluetoothConfig 추가 (BluetoothConfig.swift)
  • ESP32 BLE 통신에 필요한 UUID 및 설정값을 Info.plist에서 안전하게 관리
  • Service UUID, Characteristic UUID (RX/TX), 디바이스 이름 패턴 등 중앙화된 설정 관리
  • 버스 번호 파싱 및 디바이스 이름 생성 유틸리티 메서드 제공
  • 스캔 타임아웃(10초) 등 BLE 통신 파라미터 정의
  1. BluetoothManager 리팩토링 (BluetoothManager.swift)
  • 서비스 UUID 기반 스캔: Service UUID로 버스 기기만 필터링하여 스캔 (scanForPeripherals(withServices:))
  • 버스 번호 검증: Advertisement Data의 디바이스 이름에서 버스 번호를 추출하여 사용자가 선택한 버스와 매칭
  • 실제 데이터 전송 구현:
    • Service Discovery → Characteristic Discovery → Write 전체 플로우 구현
    • RX Characteristic을 통해 배려석 알림 메시지 전송
    • Write 응답 확인 후 성공/실패 콜백 처리
  1. Info.plist BLE 설정 추가
  • BLE UUID 설정값 추가:
    • BUS_SERVICE_UUID: 버스 기기 식별용 Service UUID
    • RX_CHARACTERISTIC_UUID: 데이터 전송용 Characteristic UUID
    • TX_CHARACTERISTIC_UUID: 데이터 수신용 Characteristic UUID
  • 디바이스 식별 설정:
    • DEVICE_NAME_PREFIX: 버스 기기 이름 패턴 (예: "BUS_")
    • COURTESY_SEAT_MESSAGE: 배려석 알림 메시지
  • 블루투스 권한 설명 추가: NSBluetoothAlwaysUsageDescription

변경된 파일

  • BluetoothConfig.swift (신규): BLE 설정 중앙 관리
  • BluetoothManager.swift (리팩토링): 임시 구현에서 실제 BLE 통신으로 전환
  • Info.plist: BLE UUID 및 설정값 추가
  • project.pbxproj: Config 경로 업데이트

주요 개선사항

이전:

  • 모든 BLE 기기 무차별 스캔
  • 첫 번째 발견 기기에 무조건 연결
  • 실제 데이터 전송 없이 연결 성공만으로 처리
  • TODO 주석으로 구현 필요 항목 명시

현재:

  • Service UUID로 버스 기기만 필터링
  • 버스 번호 검증 후 목표 기기에만 연결
  • Characteristic 발견 → 데이터 전송 → 응답 확인 완전 구현
  • 설정값 Info.plist 수정

ESP32 연동 준비사항

현재 구현은 ESP32 모듈 설정을 위한 준비가 완료된 상태입니다. ESP32 측에서 필요한 사항:

  1. Service UUID를 BUS_SERVICE_UUID 값으로 설정
  2. RX/TX Characteristic UUID를 각각 RX_CHARACTERISTIC_UUID, TX_CHARACTERISTIC_UUID 값으로 설정
  3. 디바이스 이름을 {DEVICE_NAME_PREFIX}{버스번호} 형식으로 설정 (예: "BUS_101")
  4. RX Characteristic으로 수신한 데이터를 파싱하여 배려석 알림 처리

TODO

  • ESP32-C6 모듈 여러개를 사용한 검증
  • 다수의 블루투스 연결이 가능한지 확인
  • 거리 측정

Summary by CodeRabbit

  • New Features

    • Added Bluetooth connectivity to send notifications on buses
    • Display real-time bus arrival information
    • Locate and show nearest bus stop based on user location
    • Added help screen interface
  • Updates

    • Refreshed app styling with new color scheme
    • Updated app icons and image assets
  • Tests

    • Added unit test coverage for core features

@ParkSeongGeun ParkSeongGeun self-assigned this Oct 18, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 18, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This PR introduces a comprehensive bus information system to the ComfortableMove app, including Bluetooth-based courtesy-seat notifications, location tracking, real-time bus arrival API integration, bus stop geolocation, and a redesigned home screen. It adds configuration management, multiple data models, supporting services, and unit tests.

Changes

Cohort / File(s) Summary
Project Configuration
.gitignore, ComfortableMove/.gitignore, ComfortableMove/Info.plist
Adds ignore patterns for Xcode config (.xcconfig), macOS artifacts, build artifacts, and dependency directories. Updates Info.plist with API keys and UUIDs for Bluetooth/API services, location and Bluetooth permission strings, and network transport security settings.
Build Target & Project Setup
ComfortableMove/ComfortableMove.xcodeproj/project.pbxproj
Introduces a new ComfortableMoveTest unit test target with dedicated build phases, configurations, and dependencies linked to the main target.
Asset Catalogs
ComfortableMove/ComfortableMove/App/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json, Image/HelpImage.imageset/Contents.json, Image/HomeTitle.imageset/Contents.json, Image/buttonImage.imageset/Contents.json
Updates app icon filenames (AppLogo.pngapp_logo.png) and adds dark/tinted variants. Introduces new image sets for help, home title, and button assets with multi-scale support (1x/2x/3x).
Configuration & Managers
AppConfig.swift, APIManager.swift (scaffold)
Loads API_KEY from Info.plist with nil-coalescing default. Creates APIManager skeleton for future API operations.
Bluetooth Integration
Core/Manager/Bluetooth/BluetoothConfig.swift, Core/Manager/Bluetooth/BluetoothManager.swift
BluetoothConfig centralizes Bluetooth UUIDs and device naming from Info.plist with helper methods for bus number parsing. BluetoothManager orchestrates CoreBluetooth scanning, peripheral connection, service/characteristic discovery, and sends courtesy-seat messages to a target bus.
Bus Arrival & Location Services
Core/Manager/BusArrivalService.swift, Core/Manager/LocationManager.swift, Core/Manager/BusStopManager.swift
BusArrivalService fetches real-time bus arrival data from external API and parses XML responses. LocationManager wraps CLLocationManager for location tracking with permission handling and callback support. BusStopManager loads and parses CSV bus stop data, groups stops, and computes nearest stop to a given coordinate.
Data Models
Core/Model/BusArrivalResponse.swift, Core/Model/BusStop.swift, Core/Model/StopWithRoutes.swift
Introduces BusArrivalResponse hierarchy for API response decoding, BusStop with distance computation, and StopWithRoutes aggregating stop and route information.
UI Views
Core/Presentation/Home/HomeView.swift (new), Core/Presentation/Help/HelpPageView.swift, Core/Presentation/Help/InfoView.swift
Adds comprehensive HomeView managing bus selection, arrival refresh, location-based stop detection, and Bluetooth notification sending. Introduces HelpPageView for help overlay and placeholder InfoView. Updates splash/onboarding background color reference from PrimaryColor to BFPrimaryColor.
Deleted
Core/Home/HomeView.swift (old)
Removes previous HomeView implementation.
Unit Tests
ComfortableMoveTest/BusStopManagerTests.swift, ComfortableMoveTest/LocationManagerTests.swift
Adds comprehensive test suites validating BusStopManager nearest-stop logic, loading state, and performance; and LocationManager location updates, permission handling, refresh behavior, and error handling.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant HomeView
    participant LocationManager
    participant BusStopManager
    participant BusArrivalService
    participant BluetoothManager

    User->>HomeView: Tap refresh button
    activate HomeView
    HomeView->>LocationManager: Request current location
    activate LocationManager
    LocationManager-->>HomeView: currentLocation
    deactivate LocationManager
    
    HomeView->>BusStopManager: findNearestStop(location)
    activate BusStopManager
    BusStopManager-->>HomeView: nearestStop + routes
    deactivate BusStopManager
    
    HomeView->>BusArrivalService: getArrivalInfo for each route
    activate BusArrivalService
    BusArrivalService-->>HomeView: arrival messages
    deactivate BusArrivalService
    deactivate HomeView
    
    User->>HomeView: Select route & confirm notification
    activate HomeView
    HomeView->>BluetoothManager: sendCourtesySeatNotification(busNumber)
    activate BluetoothManager
    BluetoothManager->>BluetoothManager: Scan → Connect → Discover → Write
    BluetoothManager-->>HomeView: success/failure
    deactivate BluetoothManager
    HomeView->>HomeView: Show alert
    deactivate HomeView
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Rationale: The PR introduces significant heterogeneous architectural components—Bluetooth state management with CoreBluetooth delegates, CSV parsing with geolocation computation, network API integration with XML parsing, location services with permission handling, and complex UI state orchestration. Each domain requires separate reasoning despite some repetitive test patterns. The logic density is moderate-to-high (Bluetooth scanning/connection, coordinate distance calculations, async task coordination). File spread is substantial (~25 modified/added files across multiple domains).

Possibly related PRs

Poem

🐰 A bus app hops into place,
With Bluetooth, maps, and network grace,
Stop data parsed, locations found,
Courtesy seats come round and round!
Tests ensure each hop is true,
Comfortable moves in every queue. 🚌✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.29% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "[Feat] ESP32와의 BLE 통신 구현" (Implementing BLE Communication with ESP32) directly corresponds to the primary objective stated in the PR description: "adds BLE configuration and end-to-end ESP32 BLE communication support and refactors the Bluetooth manager." The core changes include the new BluetoothConfig.swift and refactored BluetoothManager.swift that implement filtered scanning, bus number verification, service/characteristic discovery, and data transmission to ESP32 devices. While the PR also includes supporting infrastructure (bus arrival service, location manager, UI views, models), these are supplementary components enabling the primary BLE communication feature. The title is clear, concise, and accurately captures the main change from the developer's perspective.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ParkSeongGeun ParkSeongGeun changed the title Feat/ble esp32 settings [Feat] ESP32와의 BLE 통신 구현 Oct 18, 2025
@ParkSeongGeun ParkSeongGeun changed the base branch from main to dev October 18, 2025 07:21
@jinny3824
Copy link
Copy Markdown

블루투스 통신 구현이 원활히 되는 것 확인했고, 디자인도 준수하여 거의 완벽하게 UI개발해주신 것 같습니다. 고생하셨습니다! 세세한건 직접 확인해봐야할 것 같습니다.
애니메이션 관련해선 좀 더 자세하게 명세해봐야할 것 같습니다.

@ParkSeongGeun ParkSeongGeun merged commit deefbbc into dev Oct 18, 2025
2 checks passed
@ParkSeongGeun ParkSeongGeun deleted the feat/ble-esp32-settings branch October 18, 2025 12:27
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