I'm trying to read a characteristic that sends a JSON string as the value, this string is larger than 185 bytes, which is not a problem when testing it on an Android device but it's being cut off when I read it in iOS.

Steps to Reproduce

  1. Scan for devices.
  2. connect to device
  3. Discover all services and characteristics for device.
  4. send write characteristic with response for device logging into the device with a username and password.
  5. send a read characteristic for device (both read and write use the same service and characteristic).
  6. when I read the value, it's cut off and repeated 3 times.

the correct response that I get with Android:

Base 64:

eyJqc29ucnBjIjoiMi4wIiwicmVzdWx0IjpbMCx7InVidXNfcnBjX3Nlc3Npb24iOiJ4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eCIsInRpbWVvdXQiOjMwMCwiZXhwaXJlcyI6Mjk5LCJhY2xzIjp7ImFjY2Vzcy1ncm91cCI6eyJ4eHh4eC11c2VyIjpbInJlYWQiLCJ3cml0ZSJdfSwidWJ1cyI6eyJmd21hbiI6WyIqIl0sInh4eHh4LmFjcyI6WyJyZWJ1aWxkX3h4eHhfcHJvZmlsZXMiXSwieHh4eHguYXBwIjpbIioiXSwibmV0d29yayI6WyJyZWxvYWQiXSwibmV0d29yay5pbnRlcmZhY2UueHh4IjpbInN0YXR1cyJdLCJuZXR3b3JrLmludGVyZmFjZS54eHgiOlsic3RhdHVzIl0sInVjaSI6WyIqIl19LCJ1Y2kiOnsiKiI6WyJyZWFkIiwid3JpdGUiXX19LCJkYXRhIjp7InVzZXJuYW1lIjoieHh4eHgifX1dLCJpZCI6MX0=

JSON string:

{"jsonrpc":"2.0","result":[0,{"ubus_rpc_session":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","timeout":300,"expires":299,"acls":{"access-group":{"xxxxx-user":["read","write"]},"ubus":{"fwman":["*"],"xxxxx.acs":["rebuild_xxxx_profiles"],"xxxxx.app":["*"],"network":["reload"],"network.interface.xxx":["status"],"network.interface.xxx":["status"],"uci":["*"]},"uci":{"*":["read","write"]}},"data":{"username":"xxxxx"}}],"id":1}

the response that I get with iOS:

Base 64:

eyJqc29ucnBjIjoiMi4wIiwicmVzdWx0IjpbMCx7InVidXNfcnBjX3Nlc3Npb24iOiJ4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eCIsInRpbWVvdXQiOjMwMCwiZXhwaXJlcyI6Mjk5LCJhY2xzIjp7ImFjY2Vzcy1ncm91cCI6eyJ4eHh4eC11c2VyIjpbInJlYWQiLCJ3cml0ZSJdfSwidWJ1cyI6eyJmd21hbiI6W3sianNvbnJwYyI6IjIuMCIsInJlc3VsdCI6WzAseyJ1YnVzX3JwY19zZXNzaW9uIjoieHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHgiLCJ0aW1lb3V0IjozMDAsImV4cGlyZXMiOjI5OSwiYWNscyI6eyJhY2Nlc3MtZ3JvdXAiOnsieHh4eHgtdXNlciI6WyJyZWFkIiwid3JpdGUiXX0sInVidXMiOnsiZndtYW4iOlt7Impzb25ycGMiOiIyLjAiLCJyZXN1bHQiOlswLHsidWJ1c19ycGNfc2Vzc2lvbiI6Inh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4IiwidGltZW91dCI6MzAwLCJleHBpcmVzIjoyOTksImFjbHMiOnsiYWNjZXNzLWdyb3VwIjp7Inh4eHh4LXVzZXIiOlsicmVhZCIsIndyaXRlIl19LCJ1YnVzIjp7ImZ3bWFuIjpb

JSON string:

{"jsonrpc":"2.0","result":[0,{"ubus_rpc_session":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","timeout":300,"expires":299,"acls":{"access-group":{"xxxxx-user":["read","write"]},"ubus":{"fwman":[{"jsonrpc":"2.0","result":[0,{"ubus_rpc_session":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","timeout":300,"expires":299,"acls":{"access-group":{"xxxxx-user":["read","write"]},"ubus":{"fwman":[{"jsonrpc":"2.0","result":[0,{"ubus_rpc_session":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","timeout":300,"expires":299,"acls":{"access-group":{"xxxxx-user":["read","write"]},"ubus":{"fwman":[

  • Library version: react-native-BLE-PLX v.1.1.0
  • Platform: iOS 11.4.1.
  • Platform logs XCode:
[RxBLEKit|VERB|15:55:51.878]: CentralManager(7522903616) didDiscover(peripheral: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")),
rssi: -53)
[RxBLEKit|DEBG|15:55:52.126]: CentralManager(7522903616) stopScan()
[RxBLEKit|DEBG|15:55:52.128]: CentralManager(7522903616) retrievePeripherals(
withIdentifiers: [A0AA0000-000A-00AA-AAAA-AA000AA00A00])
[RxBLEKit|DEBG|15:55:52.137]: CentralManager(7522903616) connect(
peripheral: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")),
options: nil)
[RxBLEKit|DEBG|15:55:53.288]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) discoverServices(
serviceUUIDs: nil)
[RxBLEKit|DEBG|15:55:53.925]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) didDiscoverServices(services
: Optional("[Service(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, id: 7520873408)]"),
error: nil)
[RxBLEKit|DEBG|15:55:53.928]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) discoverCharacteristics(
characteristicUUIDs: nil,
for: Service(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, id: 7520873408))
[RxBLEKit|DEBG|15:55:53.985]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) didDiscoverCharacteristicsFor(for:
Service(uuid: B5DF559F-F530-4661-84C6-F3B9D5F76985, id: 7520873408), characteristics:
Optional("[Characteristic(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, id: 7584057696)]"),
error: nil)
[RxBLEKit|DEBG|15:55:53.987]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) discoverDescriptors(
for: Characteristic(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, id: 7584057696))
[RxBLEKit|DEBG|15:55:53.992]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) didDiscoverDescriptorsFor
(for:Characteristic(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, id: 7584057696), descriptors:
Optional("[]"),
error: nil)
[RxBLEKit|DEBG|15:55:54.570]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) writeValue(
data: 7b226a736f6e727063223a22322e30222c226964223a312c226d6574686f64223a2263616c6c222c22706172616d73223a5b223030303030303030303030303030303030303030303030303030303030303030222c2273657373696f6e222c226c6f67696e222c7b22757365726e616d65223a227878787878222c2270617373776f7264223a22303030303030227d5d7d,
for: Characteristic(uuid:A0AA0000-000A-00AA-AAAA-AA000AA00A00, id: 7584057696),
type: withResponse)
[RxBLEKit|DEBG|15:55:54.644]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) didWriteValueFor(for:Characteristic(uuid:A0AA0000-000A-00AA-AAAA-AA000AA00A00, id: 7584057696),
value: nil,
error: nil)
[RxBLEKit|DEBG|15:55:54.661]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) readValue(
for: Characteristic(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, id: 7584057696))
[RxBLEKit|DEBG|15:55:54.889]: Peripheral(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, name: Optional("BlueZ 5.49")) didUpdateValueFor(for:Characteristic(uuid: A0AA0000-000A-00AA-AAAA-AA000AA00A00, id: 7584057696),
value: Optional("227b6a736f6e727063223a22322e30222c22726573756c74223a5b302c7b22756275735f7270635f73657373696f6e223a227878787878787878787878787878787878787878787878787878787878787878222c2274696d656f7574223a3330302c2265787069726573223a3239392c2261636c73223a7b226163636573732d67726f7570223a7b2278787878782d75736572223a5b2272656164222c227772697465225d7d2c2275627573223a7b2266776d616e223a5b7b226a736f6e727063223a22322e30222c22726573756c74223a5b302c7b22756275735f7270635f73657373696f6e223a227878787878787878787878787878787878787878787878787878787878787878222c2274696d656f7574223a3330302c2265787069726573223a3239392c2261636c73223a7b226163636573732d67726f7570223a7b2278787878782d75736572223a5b2272656164222c227772697465225d7d2c2275627573223a7b2266776d616e223a5b7b226a736f6e727063223a22322e30222c22726573756c74223a5b302c7b22756275735f7270635f73657373696f6e223a227878787878787878787878787878787878787878787878787878787878787878222c2274696d656f7574223a3330302c2265787069726573223a3239392c2261636c73223a7b226163636573732d67726f7570223a7b2278787878782d75736572223a5b2272656164222c227772697465225d7d2c2275627573223a7b2266776d616e223a5b"),
error: nil)
  • Sample code:
  const bluetooth = () => {
    const deviceUUID =
      Platform.OS === 'ios'
        ? 'A0AA0000-000A-00AA-AAAA-AA000AA00A00'
        : 'A0:00:0A:00:A0:00'
    manager.startDeviceScan(null, null, async (error, device) => {
      if (error) {
        console.error(error)
        manager.cancelDeviceConnection(deviceUUID)
      }
      console.log(device)
      if (device && device.localName === 'Device XX-00') {
        const jsonDataServiceUUID = 'A0AA0000-000A-00AA-AAAA-AA000AA00A00'

        const jsonFormattedCharacteristicUUID =
          'A0AA0000-000A-00AA-AAAA-AA000AA00A00'

        manager.stopDeviceScan()
        await manager.connectToDevice(deviceUUID)

        await manager.discoverAllServicesAndCharacteristicsForDevice(deviceUUID)
        let write
        try {
          write = await manager.writeCharacteristicWithResponseForDevice(
            deviceUUID,
            jsonDataServiceUUID,
            jsonFormattedCharacteristicUUID,
            Buffer.from(
              JSON.stringify({
                jsonrpc: '2.0',
                id: 1,
                method: 'call',
                params: [
                  '00000000000000000000000000000000',
                  'session',
                  'login',
                  {
                    username: 'xxxxx',
                    password: '000000',
                  },
                ],
              }),
            ).toString('base64'),
          )
        } catch (err) {
          console.error(err)
        }
        console.log({ write })

        const read = await manager.readCharacteristicForDevice(
          deviceUUID,
          jsonDataServiceUUID,
          jsonFormattedCharacteristicUUID,
        )
        if (read.value) {
          console.log(read)
          const responseJson = Buffer.from(read.value, 'base64').toString()
          console.log(responseJson)
        }
      }
    })
  }
  bluetooth()

Related posts

Recent Viewed