Reading BLE speed and cadence sensor data

337 views
Skip to first unread message

Fatih Elitas

unread,
Nov 11, 2020, 6:02:27 PM11/11/20
to DroidScript
Hello guys.
I'm trying to read data from the speed and cadence sensor for my bike.
I can read the number of revolutions from the sensor, but I cannot get hardware information such as (manufacturer name) or battery information.

Nothing happens even though I type the UUID numbers from the nrf connect application.

eg characteristic and service id for wheel speed. works.
svcId = 00001816-0000-1000-8000-00805f9b34fb
charId = 00002a5b-0000-1000-8000-00805f9b34fb

But for hardware info, I can't read manufacturer info and battery info.
svcId = 0000180A-0000-1000-8000-00805f9b34fb
charId = 00002A29-0000-1000-8000-00805f9b34fb

Where am I doing wrong?
Thank you for your help.


app.LoadPlugin( "BluetoothLE" );

var cadns;

function OnStart()
{
    if( !app.IsBluetoothEnabled() ) 
    {
        app.SetBluetoothEnabled( true );
        app.ShowPopup("Bluetooth açılıyor")
        
        do app.Wait( 0.3 );
        while ( !app.IsBluetoothOn() ) scan()
    }
    else scan()
}

function scan()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
    
    lst = app.CreateList( "", 0.6, 0.4, "fontawesome");
    lst.SetOnTouch(function( title, body, type, index )
    {
        ble.Connect( body );
    })
    lst.SetBackColor("#11ffffff");
    lay.AddChild( lst );
    
    app.DiscoverBtDevices( "", OnFound );
      
    txt = app.CreateText( "" );
    txt.SetTextSize( 22 );
    lay.AddChild( txt );
    
    btn3 = app.CreateButton( "Tara", 0.4, 0.1 );
    btn3.SetOnTouch( function()
    {
        lst.RemoveAll()
        app.DiscoverBtDevices( "", OnFound );
    })
    lay.AddChild( btn3 );

    app.AddLayout( lay );

    ble = app.CreateBluetoothLE();
    ble.SetOnConnect( OnConnect );
}

function OnFound( name, address)
{
    lst.AddItem( name, address,"[fa-bluetooth]" );
}

function OnConnect()
{
    app.Alert( "Kadans sensörü Bağlandı!" );

    var svcId = "00001816-0000-1000-8000-00805f9b34fb";
    var charId = "00002a5b-0000-1000-8000-00805f9b34fb";
    ble.WatchValue( svcId, charId, "array", OnValue );
}

function OnValue( svcId, charId, val )
{
    cad =  val[6]+val[7]+val[8]+val[9] ;
    cadns = parseInt(cad, 16);
    
    txt.SetText(cadns)
}

Screenshot_2020-11-12-01-55-27.png

Dave

unread,
Nov 16, 2020, 11:22:16 AM11/16/20
to DroidScript
Hi,

You can't use the WatchValue for information that is not changing.  Use the ReadValue() method with the 'string' type instead.

(You will need at least version 1.06 of the BLE plugin for that)

Reply all
Reply to author
Forward
0 new messages