React Native app cannot detect simulated BLE device, how can I test functionality?

71 views Asked by At

I've been hired to create a React Native app that detects specific BLE devices (Arduinos that receive data from the app) and gives users the option to connect to one, and then send a value to it. The Arduinos have a name with the same prefix, and a custom id (eg. BLE App Reciever <id>). To ensure that users can only select these specific devices, I filter the list of available devices to only show those that have the prefix "BLE App Reciever" in their name. I can use (and have used) dummy data to test that part. However, when a user selects one of the devices, the app connects to it, and once they select a value, I use the writeCharacteristicWithoutResponseForService function to send the value to the connected device. That part cannot be done with my dummy data.

The issue? I don't have one of the Arduino devices to test with. I figured that I could use a simulated peripheral on my computer, but after trying LightBlue and BlueSim I'm stuck. Both softwares allow me to customize the broadcasted name so I can ensure it meets the requirement of BLE App Reciever <id>, yet no device with that name is actually detected. Even when I search specifically for the device id provided by LightBlue or BlueSim, there is no device with that id detected. I am using react-native-ble-plx.

I think the code works but I'm not comfortable delivering the product without testing it first, especially because this is my first time using BLE. Please let me know any ideas you have on how I can test the functionality that is described in the first paragraph and shown in the code below. Maybe there is a better way to simulate peripherals.

Get all available devices and filter them:

    manager.startDeviceScan(null, null, (error, scannedDevice) => {
      console.log(scannedDevice?.id); // This is how I know the simulated peripherals are not detected
      if (
        scannedDevice &&
        scannedDevice.id &&
        scannedDevice.name &&
        devices.filter((device) => device.id === scannedDevice.id).length === 0 &&
        scannedDevice.name.includes("BLE App Reciever ")
      ) {
        devices.push({ id: scannedDevice.id, name: scannedDevice.name });
      }
    });

On device selected:

    manager.connectToDevice(id).then((device) => {
      const obj = {};

      // @ts-expect-error
      navigation.navigate("NextScreen", {
        obj: obj,
        device: device,
      });
    });

On value selected:

    const SERVICE_UUID = "5f3759ad-6a5a-4b43-90d5-99e8d5f0c6a7"; // Example value
    const CHARACTERISTIC_UUID = "8c18a8b0-5713-42e9-baf4-56224f0106b5"; // Example value

    const encodeStringToBase64 = (value: string) => {
      console.log(Buffer.from(value).toString("base64"));
      return Buffer.from(value).toString("base64");
    };

    device.writeCharacteristicWithoutResponseForService(
      SERVICE_UUID,
      CHARACTERISTIC_UUID,
      encodeStringToBase64(value)
    );
0

There are 0 answers