Avatar for user154849

user154849

Member since Mar 2023 • Last active Apr 2023
  • 2 conversations
  • 3 comments

Most recent activity

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user154849

    Hi, im kinda struggling again using react-native-ble-plx

    I try to recognize when the button was pressed, i tried different things, my last approach was to add a characteristic and monitor this in my react native application, but the characteristic just wont show up, any ideas?

    NRF.setServices({
      '6e400001-b5a3-f393-e0a9-e50e24dcca9e': {
        '6e400004-b5a3-f393-e0a9-e50e24dcca9e': {
          value: 1,
          writable: false,
          notify: true,
          description: 'Button Characteristic',
          onSubscribe: function() {
            setWatch(function() {
              NRF.updateServices({
               '6e400001-b5a3-f393-e0a9-e50e24dcca9e': {
                 '6e400004-b5a3-f393-e0a9-e50e24dcca9e': {
                    value: 1,
                    notify: true
                  }
                }
              });
            }, BTN, {repeat: true, edge: 'rising', debounce: 50});
          }
        }
      }
    });
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for user154849

    Hi, thanks, now it works :)

    Here is the working code :)
    I fixed the uuid part and also the command was wrong :)

      return new Promise<string>((resolve, reject) => {
                return Ble.startDeviceScan(null, null, async (error, device) => {
                    if (error) {
                        console.log(error.message);
                        if (typeof error.message === 'string') {
                            //show error
                        }
                        reject(false);
                        return;
                    }
    
                    console.log(device?.name);
    
                    if (device?.name?.trim().startsWith('Puck.js')) {
                        try {
                            if (device) {
                                Ble.stopDeviceScan();
    
                                const discoverAndWrite = async () => {
                                    await device.discoverAllServicesAndCharacteristics();
                                    const result2 = await device.services();
                                    result2.forEach(async (service) => {
                                        const charList = await service.characteristics();
                                        charList.forEach(async (characteristic) => {
                                            if (characteristic.uuid === '6e400002-b5a3-f393-e0a9-e50e24dcca9e') {
                                                const data = Buffer.from('LED.toggle();\n').toString('base64');
                                                characteristic
                                                    .writeWithResponse(data)
                                                    .then((val) => console.log('value', val))
                                                    .catch((reason) => console.log('reason', reason));
                                            }
                                            if (characteristic.uuid === '6e400003-b5a3-f393-e0a9-e50e24dcca9e') {
                                                characteristic.monitor((error, newCharacteristic) => {
                                                    console.log('monitor', error, newCharacteristic);
                                                });
                                            }
                                        });
                                    });
                                };
    
                                const connected = await device.isConnected();
    
                                if (!connected) {
                                    await device.connect();
                                }
    
                                await discoverAndWrite();
    
                                resolve(device.id);
                            }
                        } catch (err: any) {
                            console.log('errMessage', err);
                            if (typeof err.message === 'string') {
                                // show error
                            }
    
                            reject(err.message);
                        }
                    }
                });
            });
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for user154849

    Hi :)

    Im working on integrating the Puck.js into my react native application using react-native-ble-plx
    Everything is working fine, but when i try to write some data, i just get this message

    [BleError: Characteristic 6e400002-b5a3-f393-e0a9-e50e24dcca9e notify change failed for device 1E986C85-8037-E56E-A18D-0F38826AAB12 and service 6e400001-b5a3-f393-e0a9-e50e24dcca9e]

    Thats my code :)

    return new Promise<string>((resolve, reject) => {
                return Ble.startDeviceScan(null, null, async (error, device) => {
                    if (error) {
                        console.log(error.message);
                        if (typeof error.message === 'string') {
                            //show error
                        }
                        reject(false);
                        return;
                    }
    
                    console.log(device?.name);
    
                    if (device?.name?.trim().startsWith('Puck.js')) {
                        try {
                            if (device) {
                                Ble.stopDeviceScan();
                                const connected = await device.isConnected();
    
                                if (!connected) {
                                    await device.connect();
                                    await device.discoverAllServicesAndCharacteristics();
                                    const result2 = await device.services();
                                    result2.forEach(async (service) => {
                                        const charLit = await service.characteristics();
                                        charLit.forEach(async (chari) => {
                                            console.log('carhi', chari);
                                            if (chari.uuid === '6e400002-b5a3-f393-e0a9-e50e24dcca9e') {
                                                chari.monitor((error, char) => {
                                                    console.log('monitor,', error, char !== undefined);
                                                });
    
                                                const data = Buffer.from(['LED1.set();/n']).toString('base64');
                                                chari
                                                    .writeWithResponse(data)
                                                    .then((val) => console.log('val', val))
                                                    .catch((reason) => console.log('reson', reason));
                                            }
                                        });
                                    });
                                }
    
                                resolve(device.id);
                            }
                        } catch (err: any) {
                            console.log('errMessage', err);
                            if (typeof err.message === 'string') {
                                // show error
                            }
    
                            reject(err.message);
                        }
                    }
                });
            });
    

    I would be greatful for any help :)

Actions