Search for HC-05 Bluetooth device via Bluetooth

Good afternoon guys, I want to create an app that's detects common bluetooth based credit card skimmers predominantly found in gas pumps. The app scans for available bluetooth connections looking for a device with title HC-05. If found, the app will attempt to connect using the default password of 1234. Once connected, the letter 'P' will be sent. If a response of 'M' then there is a very high likelihood there is a skimmer in the bluetooth range of your phone (5 to 15 feet).

I can show you the code I already have:

class ScanViewController: UIViewController, CBPeripheralDelegate, CBCentralManagerDelegate {

    

    // Properties Back-End

        private var centralManager: CBCentralManager!

        private var peripherals: [CBPeripheral] = []

        private var peripheral: CBPeripheral!

   
    override func viewDidLoad() {

        super.viewDidLoad()

        view.backgroundColor = .systemGroupedBackground

        

        centralManager = CBCentralManager(delegate: self, queue: nil)

      
    }

    //MARK: - Back-End

    

    // If we're powered on, start scanning

           func centralManagerDidUpdateState(_ central: CBCentralManager) {

               print("Central state update")

               if central.state != .poweredOn {

                   print("Central is not powered on")

               } else {

                   print("Central scanning for", ParticlePeripheral.skimmerDeviceUUID);

                   centralManager.scanForPeripherals(withServices: [ParticlePeripheral.skimmerDeviceUUID],

                                                     options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])

               }

           }

    

    // Handles the result of the scan

           func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {



               // We've found it so stop scan

               self.centralManager.stopScan()

            print("Stopped to scan")



               // Copy the peripheral instance

               self.peripheral = peripheral

               self.peripheral.delegate = self



               // Connect!

               self.centralManager.connect(self.peripheral, options: nil)

            

           }

    

    // The handler if we do connect succesfully

            func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {

                if peripheral == self.peripheral {

                    print("Connected to Skimmer Scammer")

                    peripheral.discoverServices([ParticlePeripheral.skimmerDeviceUUID])

                }

            }

    

    // Handles discovery event

            func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {

                if let services = peripheral.services {

                    for service in services {

                        if service.uuid == ParticlePeripheral.skimmerDeviceUUID {

                            print("Skimmer Scanner service found")

                            //Now kick off discovery of characteristics

                            peripheral.discoverCharacteristics([...], for: service)

                            return

                        }

                    }

                }

            }


class ParticlePeripheral: NSObject {

        // I think thats the uuid for HC-05

        public static let skimmerDeviceUUID     = CBUUID.init(string: "00001101-0000-1000-8000-00805F9B34FB")

    }

I googled around for hours but I wasn't able to find a solution and I have never worked with Bluetooth connections before, that makes it really difficult but I tried. My questions:

  1. is the code I already have valid?
  2. How to can I connect via pin code? "1234"

I would be so helpful if someone here has some advices for me, thanks in advance!

Answered by Scott J in 704037022

Unfortunately, what you are trying to do won’t work on iOS. Core Bluetooth supports only Bluetooth Low Energy, while the HC-05 module uses Classic Bluetooth, specifically the serial port profile. Those aren’t compatible.

Accepted Answer

Unfortunately, what you are trying to do won’t work on iOS. Core Bluetooth supports only Bluetooth Low Energy, while the HC-05 module uses Classic Bluetooth, specifically the serial port profile. Those aren’t compatible.

Search for HC-05 Bluetooth device via Bluetooth
 
 
Q