DFRobot / BlunoBasicDemo

The basic demo for bluno
GNU General Public License v3.0
166 stars 233 forks source link

Writing to the Bluno : Null error #22

Open AudeGr opened 4 years ago

AudeGr commented 4 years ago

I want to add to my android project a ble bluno connection ( target sdk : 26, min sdk : 21, compile sdk : 28). I followed the demo but i had a problem with the scan (obselete?) so i found a solution, i connected directly with a paired device using the "connect" function. But now i want to write something to the bluno using the "serialSend" function and it says : "serialSend: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattCharacteristic.setValue(java.lang.String)' on a null object reference"

my SerialSend function : ` public void serialSend(String theString){

    if (mConnectionState == connectionStateEnum.isConnected) {

        try{

            mSCharacteristic.setValue(theString);
            mBluetoothLeService.writeCharacteristic(mSCharacteristic);

        }catch (Exception e){

            Log.d(TAG, "serialSend: "+e.getMessage());

        }

    }

}`

The characteristic i want to write in is null and the BroadcastReceiver is never used, in my opinion the characteristic is instanced in this receiver. the BroadcastReceiver is called after the broadcastUpdate but i enter well in the 'update' function and dont in the receiver. private void broadcastUpdate(final String action) { final Intent intent = new Intent(action.toLowerCase()); sendBroadcast(intent); }

Is it because i dont used the scan to connect my bluno or there is a problem with version or there is an other problem?

Waiting for an answer, thank you.