This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Adding functionality to nRF Connect Desktop Bluetooth Low Energy App

Hello,

Currently I would like to add a functionality to Bluetooth Low Energy App (BLE). I have a bluetooth slave device that require a specific sequence of sending string and receiving notification string to setup. I use a nRF52840 USB Dongle as an adapter to connect to those slave devices.

I would like to add a button/option to the red area above to automate the configuration sequence. This includes sending a byte to specific service, receive notification from specific service. Where should I start? The examples on the nRF Connect Desktop app development page didn't help, and the documentation is not enough.

Thank you.

Parents
  • Thanks everyone.

    I looked at the writeCharacteristic function and noticed that it already have dispatch() in there, so I'm thinking it is called just like a regular function when needed, and it will dispatch the appropriate action accordingly. I think my problem is maybe I'm using the wrong function to do what I want.

    And regarding states and reducers, for this app, what do I need to keep track of in the state?

    Sorry for asking many questions. There isn't much documentation for nrf connect apps that I can find.

    This is the writeCharacteristic I'm talking about, located in deviceDetailsActions.js

    export function writeCharacteristic(characteristic, value) {
        return (dispatch, getState) => (
            new Promise((resolve, reject) => {
                const adapterToUse = getState().app.adapter.bleDriver.adapter;
    
                if (adapterToUse === null) {
                    reject(new Error('No adapter selected'));
                    return;
                }
    
                const ack = !characteristic.properties.writeWoResp;
    
                adapterToUse.writeCharacteristicValue(characteristic.instanceId, value, ack, error => {
                    if (error) {
                        dispatch(completedWritingAttributeAction(characteristic, null, error));
                        reject(new Error(error.message));
                        return;
                    }
                    dispatch(completedWritingAttributeAction(characteristic, value));
                    resolve();
                });
            }).catch(error => {
                dispatch(showErrorDialog(error));
            })
        );
    }

Reply
  • Thanks everyone.

    I looked at the writeCharacteristic function and noticed that it already have dispatch() in there, so I'm thinking it is called just like a regular function when needed, and it will dispatch the appropriate action accordingly. I think my problem is maybe I'm using the wrong function to do what I want.

    And regarding states and reducers, for this app, what do I need to keep track of in the state?

    Sorry for asking many questions. There isn't much documentation for nrf connect apps that I can find.

    This is the writeCharacteristic I'm talking about, located in deviceDetailsActions.js

    export function writeCharacteristic(characteristic, value) {
        return (dispatch, getState) => (
            new Promise((resolve, reject) => {
                const adapterToUse = getState().app.adapter.bleDriver.adapter;
    
                if (adapterToUse === null) {
                    reject(new Error('No adapter selected'));
                    return;
                }
    
                const ack = !characteristic.properties.writeWoResp;
    
                adapterToUse.writeCharacteristicValue(characteristic.instanceId, value, ack, error => {
                    if (error) {
                        dispatch(completedWritingAttributeAction(characteristic, null, error));
                        reject(new Error(error.message));
                        return;
                    }
                    dispatch(completedWritingAttributeAction(characteristic, value));
                    resolve();
                });
            }).catch(error => {
                dispatch(showErrorDialog(error));
            })
        );
    }

Children
No Data
Related