randdusing / cordova-plugin-bluetoothle

Bluetooth Low Energy Phonegap Plugin
803 stars 353 forks source link

sending more than 20 byte #324

Open mjseyyedi opened 8 years ago

mjseyyedi commented 8 years ago

I tried writeQ function to send more than 20 bytes but it didn't work for me. of course I think i did sth wrong; here is my send function:

$scope.sendText = function (inputText) {
        var bytes = bluetoothle.stringToBytes(inputText);
        var encodedString = bluetoothle.bytesToEncodedString(bytes);
        if (inputText.length < 20) {
          bluetoothle.write(
            function (result) {
              alert("data transmitted" + JSON.stringify(result));
            },
            function (error) {
              alert("data transmission failed" + JSON.stringify(error));
            },
            {
              value: encodedString,
              service: $scope.sendCharService.serviceId,
              characteristic: $scope.sendCharService.uuid,
              type: "noResponse",
              address: $scope.deviceId
            }
          );
        }
        else {
          bluetoothle.writeQ(
            function (result) {
              alert("data transmitted" + JSON.stringify(result));
            },
            function (error) {
              alert("data transmission failed" + JSON.stringify(error));
            },
            {
              value: encodedString,
              service: $scope.sendCharService.serviceId,
              characteristic: $scope.sendCharService.uuid,
              type: "noResponse",
              address: $scope.deviceId
            }
          );
        }
      }

the if statement block works perfectly but the else no! what am I missing?

randdusing commented 8 years ago

Looks fine to me, are you receiving any callbacks?

mjseyyedi commented 8 years ago

@randdusing yes , "data transmitted" shows up. means worked perfectly

randdusing commented 8 years ago

Not sure if I follow. It's working for write but not writeQ. The writeQ callbacks are never called?

mjseyyedi commented 8 years ago

the writeQ callback calls correctly , but in bluetooth I don't receive more than 20 bytes

randdusing commented 8 years ago

On the peripheral side, only 20 bytes show up?