Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan BLE devices results in "XPC connection invalid" #84

Closed
jay-k98 opened this issue Nov 19, 2024 · 4 comments
Closed

Scan BLE devices results in "XPC connection invalid" #84

jay-k98 opened this issue Nov 19, 2024 · 4 comments

Comments

@jay-k98
Copy link

jay-k98 commented Nov 19, 2024

Description

When trying to scan for ESP32 devices I always receive the error "The operation couldn't be completed (ESPProvision.ESPDeviceCSSError error 6.)". In Xcode on the console this error appears: "XPC connection invalid".

I added every bluetooth related permission to Info.plist and the Example App of this repo is working just fine with the same phone and ESP32.

This is the code i am using:

import Foundation
import ESPProvision

class ProvisioningManager: ObservableObject {
    @Published var devices: [ESPDevice] = []
    @Published var errorMessage: String? = nil
    
    func searchForESPDevices() {
        ESPProvisionManager.shared.searchESPDevices(devicePrefix: "ESP", transport: .ble, security: .secure) { deviceList, error in
            if let error = error {
                self.errorMessage = "Error during device search: \(error.localizedDescription)"
                return
            }
            
            guard let devices = deviceList else {
                self.errorMessage = "No devices found."
                return
            }
            
            self.devices = devices
        }
    }
}

struct ContentView: View {
    @StateObject var bluetoothManager = BluetoothManager()
    @State private var selectedDevice: ESPDevice?

    var body: some View {
        VStack {
            if let errorMessage = bluetoothManager.errorMessage {
                Text("Error: \(errorMessage)")
                    .foregroundColor(.red)
            }

            Button("Search for Devices") {
                bluetoothManager.searchForESPDevices()
            }
            .padding()

            List(bluetoothManager.devices, id: \.name) { device in
                Button(action: {
                    selectedDevice = device
                }) {
                    Text(device.name)
                }
            }
        }
        .padding()
    }
}

To Reproduce
Steps to reproduce the behavior:

  1. Run the app
  2. Tap on 'Search for Devices'
    ...

Frequency
Every time you tap on 'Search for Devices'

Expected behavior
BLE devices are scanned successfully and a list of devices is displayed.

Screenshots
Screenshot 2024-11-19 at 18 35 42

ESP Device Information:

  • Board type: ESP32

iOS information:

  • Device type: iPhone
  • iOS version: iPhone 14
  • App version: 3.0.1 (?)

Provisioning information:

  • ESPProvision iOS SDK version: 3.0.1
  • Device type: BLE
  • Security: Secure

ESP Device logs:
n/a

Additional context
n/a

@jay-k98 jay-k98 changed the title Scan BLE devices not working with SwiftUI Scan BLE devices results in "XPC connection invalid" Nov 19, 2024
@ajay-gantayet
Copy link
Contributor

Hi @jay-k98 , could you please provide the following information to help us in debugging and quickly resolving the issue:

  • The esp-idf version
  • The firmware example
  • Firmware logs

You can also check if you are using the correct device prefix while initiating the device search.
You could also check with our App Store ESP BLE Provisioning app and see if you are observing the same behaviour with that app: https://apps.apple.com/us/app/esp-ble-provisioning/id1473590141.

@jay-k98
Copy link
Author

jay-k98 commented Nov 21, 2024

Hi @ajay-gantayet :) Thanks for answering!

ESP-IDF version: 5.3.1
Firmware Example: wifi_prov_mgr
Firmware logs: Don't have any since the device didn't connect. It is running just fine and working with both the ESP BLE Provisioning app from App Store and the Example

@ajay-gantayet
Copy link
Contributor

Hi @jay-k98 , thanks for the reply.
Could you please check what the device name prefix for this firmware is?
Also in this API call:
ESPProvisionManager.shared.searchESPDevices(devicePrefix: "ESP", transport: .ble, security: .secure) , you could replace the "ESP" provided for the devicePrefix with empty string or "PROV". You should be able to see your device listed there.

@jay-k98
Copy link
Author

jay-k98 commented Nov 26, 2024

My prefix was ESP (full name ESP32_jay). Changing the device prefix to an empty string fixed it. Thank you for helping me out @ajay-gantayet 👍

@jay-k98 jay-k98 closed this as completed Nov 26, 2024
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

No branches or pull requests

2 participants