Bluetooth LE

347 views
Skip to first unread message

Berni4

unread,
Mar 21, 2017, 4:43:57 PM3/21/17
to DroidScript
Hi,

i have build my first android app wit Droid Script. I use BLE, if i launch my app from the droid script, everything works fine but after build the APK and install the App, in the device list are no BLE devices.

Here is my code:

app.LoadPlugin( "BluetoothLE" );

var count = 0;

  var txt1 = 0;
  var txt2 = 0;
  var txt3 = 0;
  var txt4 = 0;
  var txt5 = 0;
  var txt6 = 0;
  var txt7 = 0;
  var txt8 = 0;
  var txt9 = 0;
  var txt10= 0;
  var txt11= 0;
  var txt12= 0;
 
  var channel = 0;

function OnStart()
{
  lay = app.CreateLayout("Linear","VCenter,FillXY");

  btnConnect = app.CreateButton( "Verbinden", 0.4, 0.1 );
  btnConnect.SetOnTouch( btn_OnTouch );
  lay.AddChild( btnConnect );

  //btnTemp = app.CreateButton( "Temperatur", 0.4, 0.1 );
  //lay.AddChild( btnTemp );

  var value = 0;
 
  txtB  = app.CreateText( "" );
  txtB.SetTextSize(36);
  lay.AddChild( txtB );
 
  txtC  = app.CreateText( "" );
  txtC.SetTextSize(36);
  lay.AddChild( txtC );
 
  txt  = app.CreateText( "" );
  txt.SetTextSize(36);
  lay.AddChild( txt );
 
  txtA  = app.CreateText( "" );
  txtA.SetTextSize(36);
  lay.AddChild( txtA );
 
  txtD  = app.CreateText( "" );
  txtD.SetTextSize(36);
  lay.AddChild( txtD );
 
  skb = app.CreateSeekBar( 0.8 );
  skb.SetRange( 500.0 );
  lay.AddChild( skb );
 
  skb2 = app.CreateSeekBar( 0.8 );
  skb2.SetRange( 500.0 );
  lay.AddChild( skb2 ); 

  app.AddLayout( lay );
 
  ble = app.CreateBluetoothLE();
  ble.SetOnSelect( OnSelect );
  ble.SetOnConnect( OnConnect );
  ble.SetOnUartReceive( OnUartReceive );
}


function btn_OnTouch( isChecked )
{
  ble.Select();
}

function OnSelect( name, address )
{
  ble.Connect( address, "UART" );
}

function OnConnect()
{
  app.ShowPopup( "Verbunden!" );
}

function OnUartReceive( data )
{
 if (data!="+"&&channel==0&&data!=">")
 {
     if(count==0)
     {
        txt1=data;
     }
     else if(count==1)
     {
        txt2=data;
     }
     else if(count==2)
     {
        txt3=data;
     }
     else if(count==3)
     {
        txt4=data;
     }
     else if(count==4)
     {
        txt5=data;
     }
     else if(count==5)
     {
        txt6=data;
        channel=1;
     }
     count++;
 }
 else if (data!=">"&&channel==1)
 {
     if(count==0)
     {
        txt7=data;
     }
     else if(count==1)
     {
        txt8=data;
     }
     else if(count==2)
     {
        txt9=data;
     }
     else if(count==3)
     {
        txt10=data;
     }
     else if(count==4)
     {
        txt11=data;
     }
     //else if(count==5)
     //{
     //   txt12=data;
     //}
     count++;
 }
 else
 {
    //if(count==5){txt6=0;}
    value = txt1 + txt2 + txt3 + txt4 + txt5 + txt6;
    if(value!=0&&txt1!=" "&&txt2!=" "&&txt3!=" "&&txt4!=" "&&txt5!=" "&&txt6!=" ")
    {
        txt.SetText( "Sensor 1:" + value );
        skb.SetValue( value );
    }
    else
    {
        txt.SetText( "Sensor 1: 0" );
        skb.SetValue( value );       
    }
    value = txt7 + txt8 + txt9 + txt10 + txt11 + txt12;
    if(value!=0)
    {
        txtA.SetText( "Sensor 2: " + value );
        skb2.SetValue( value );
    }
    else
    {
        txtA.SetText( "Differenz: 0" );
        skb2.SetValue( value );       
    }
    value = " ";
    txt1 = " ";
    txt2 = " ";
    txt3 = " ";
    txt4 = " ";
    txt5 = " ";
    txt6 = " ";
    txt7 = " ";
    txt8 = " ";
    txt9 = " ";
    txt10 = " ";
    txt11 = " ";
    txt12 = " ";
    count = 0;
    channel = 0;
 }
 
 if(data=="+")
 {
    count=0;    
 }
}

Steve Garman

unread,
Mar 21, 2017, 4:49:46 PM3/21/17
to DroidScript
There was a permissions problem in the BluetoothLE plugin.

I think it has been fixed but I am not sure.

Try reinstalling the plugin and see if that fixes it.

If it does not help, add this line at the top of your code

_AddPermissions("Bluetooth");

Berni4

unread,
Mar 21, 2017, 4:58:14 PM3/21/17
to DroidScript
Hi,

thank you for your quick Answer. With "_AddPremissions(Bluetooth");" it works!

Thank you verry much!


Reply all
Reply to author
Forward
0 new messages