How to read data from SAE j1939 bus

Asked by At

Here we are trying to read data from J1939 SAE bus devices but seems it not read with iOS we are working with Core bluetooth connectivity we have done in android and in android work fine but same device not read with iOS can any one please help me on that.

Here i am attaching my code snippets

Connecting Bluetooth devices as SEA J1939

var manager:CBCentralManager! 
manager.connect(connectPeripheral, options: nil) 
connectPeripheral.delegate = self

Bluetooth Connection success

func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
         print("Connected!")
         self.showAlertOneButton(withTitle: "", with: key.KBluetoothConnect, firstButton: key.KOk) { (UIAlertAction) in
             self.navigationItem.rightBarButtonItem?.tintColor = UIColor.blue
             self.vwBLTSub.removeFromSuperview()
             //all services
             self.connectPeripheral.discoverServices(nil)
         }
     }

Read Data from device

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService,
                    error: Error?) {
        guard let characteristics = service.characteristics else { return }

        for characteristic in characteristics {
            print(characteristic)
            if characteristic.properties.contains(.read) {
                print("\(characteristic.uuid): properties contains .read")

                peripheral.readValue(for: characteristic)
            }
            if characteristic.properties.contains(.notify) {
                print("\(characteristic.uuid): properties contains .notify")

            }
        }
    }

1 Answers

0
hotpaw2 On

The stock OS on iOS devices block application access to USB and Bluetooth services, except for those clearly documented as whitelisted by Apple, or those devices enrolled in Apple's MFI program (under NDA).

The solution I use it to connect to non-Apple-permitted USB and Bluetooth profile devices with a Raspberry Pi, and then serve the data from the Pi to iOS devices over a network socket (via WiFi, or wired ethernet, which Apple supports on iOS via various dongles), or using Core Bluetooth BLE (which is whitelisted, but much slower).