Bluetooth Serial Listing Problem


#1

I m using ionic latest version (1.3.19) and ngCordova. I want to use Bluetooth Serial. I write this in my app.js . Bluetooth Enable or Disable works great but .I cant learn Bluetooth list. Where is my wrong ?

// Ionic Starter App

   // angular.module is a global place for creating, registering and retrieving Angular modules
 // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
   // the 2nd parameter is an array of 'requires'
   angular.module('starter', ['ionic','ngCordova'])

  .run(function($ionicPlatform) {
   $ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
  StatusBar.styleDefault();
}
 });
 }).controller("MainCtrl",function($scope,$ionicPlatform,$cordovaBluetoothSerial){
    $scope.bluetoothEnable="";


        $cordovaBluetoothSerial.isEnabled().then(function(){
            $scope.bluetoothEnable="Bluetooth Enable";

        },
        function() {
            $scope.bluetoothEnable="Bluetooth Disable";


        });
       $scope.liste=function()
       {
           $cordovaBluetoothSerial.list().then(function(result){
           $scope.btlist=result;

       },
           function(error){
            console.log(error)   ;
           });


       }
        $scope.undiscoverdliste=function()
        {
            $cordovaBluetoothSerial.discoverUnpaired(event).then(function(result){
                $scope.btlist=result;
            },function(error){
                console.log("Err");
                $scope.btlist=error;
            });

        }






});

#2

I’m also using a this plugin and I think it’s due to the structure of the function

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic','ngCordova'])



.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
     }
     if(window.StatusBar) {
      StatusBar.styleDefault();
     }
     });
     }).controller("MainCtrl",function($scope,$ionicPlatform,$cordovaBluetoothSerial){
       
 $scope.bluetoothEnable="";

bluetoothSerial.isEnabled(
        function() {
          $scope.bluetoothEnable="Bluetooth Enable";
        },
        function() {
          $scope.bluetoothEnable="Bluetooth Disable";
        }
    );

   $scope.liste=function()
   {
       bluetoothSerial.list(
        function(paireddevices) {
            angular.forEach(paireddevices, function(paireddev){
               $scope.btlist.push(paireddev);
            });
        },
        function(){
            console.log('error')   ;
    });

   };

    $scope.undiscoverdliste=function()
    {
    bluetoothSerial.discoverUnpaired(
        function(undevices) {
            angular.forEach(undevices, function(device){
                $scope.btlist.push(device);
            });
        },
        function(){
            console.log("Err");
    });

    };

Hope that helps / works :wink:


#3

Hey Matthew ,Thanks for help but its not working I tried samsung S4 mini . only "Bluetooth Enable " works. :slight_smile:


#4

Guys, how do you get $cordovaBluetoothSerial to work? The moment I put “$cordovaBluetoothSerial” in my controller, everything stops working. I’ve added ngcordova.js before cordova.js in my index.html and added ngcordova.js under lib folder. I’ve added BluetoothSerial plugin using “ionic plugin add com.megster.cordova.bluetoothserial” command. My code is identical to the one above. I’m out of ideas. Please help.


#5

Up for this topic ! :smile:


#6

iam using this plugin. Iam able to connect to the bluetooth printer also. But when i write hello world data to the printer, iam unable to print. help me guys. After connecting to device iam directly writing data to printer is it correct or else i need to subscribe the device thereafter should i write data . Please share the example wih code.