0

I am working on a Project, and I am new to BLE, I have got problem with writing value to BLE characteristic (run command on BLE device).

The characteristic take these values:

0x04 0x01 – Lock mode is on

0x04 0x02 – Lock mode is off

My method to read, notify and write from/to characteristic:

  async readWriteNotifyCharacteristics(serviceUuid, characteristicUuid, access, command, handel) {

            try {
          
                const service = await this.server?.getPrimaryService(serviceUuid);
                const characteristic = await service?.getCharacteristic(characteristicUuid);
                switch(access) {
                    case 'R':
                        return characteristic.readValue()

                    case 'N':
                        return characteristic.startNotifications()
                            .then(() => {
                              characteristic.addEventListener('characteristicvaluechanged', handel);
                            });

                    case 'W':
                            characteristic.writeValue(command);
                        break;

                    default:
                        console.log('could not conenct');

                }
            }catch (error) {
                console.log('error', error);
            }
        },

I try to write to characteristic with :

 async readWriteNotifyCharacteristics() {
        const buffer = new Uint16Array([0x06 , 0x02 ])
        await this.cacheCharacteristics(
            'f1196f20-qea4-00e6-bdh89-65790865c9a98',
            'f1196f22-qea4-00e6-bdh89-65790865c9a98',
            'W',
            buffer
        );


        const command = await this.cacheCharacteristics(
            'f1196f20-qea4-00e6-bdh89-65790865c9a98',
            'f1196f22-qea4-00e6-bdh89-65790865c9a98',
            'R'
        );

        },

Everything works fine connection, read from characteristic but nothing happen on the device when I try to write (command) on it. Any idea what I'm doing wrong? Thanks in advance:)

3
  • Maybe this is just a typo but in your question you state you need to send 0x04 0x02 but in your code you send 0x06 0x02. have you tried using a generic BLE scnaner app such as nRF Connect to write the values to the device and see if anything happens? Commented Oct 10, 2022 at 6:39
  • Thanks Michael, I have already tried many values but unfortunately without success. the write to device is done successfully when I tried to read the same characteristic but no change in device (no on / off ). I use the code in os app based on electron js and Vue2 Commented Oct 10, 2022 at 7:07
  • Without documentation, this is a painstaking process of try-and-error with different values. If the device (a lock I assume) comes with an official app you could try to sniff the correct values, but I would imagine a lock to use some kind of encryption. Please try using nRF Connect to experiment further Commented Oct 10, 2022 at 7:14

1 Answer 1

0

Thanks to Michael Kotzjan, With his suggestion of using nRF Connect, I was able to test many inputs and outputs and see the exact logic of device

Sign up to request clarification or add additional context in comments.

1 Comment

Can you explain a little more about how nRF Connect helped you? Comments are ephemeral, so anything in a comment that helped you should be quoted in your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.