Android Question iTAG BLE Button now is not working

Discussion in 'Android Questions' started by Daniel-White, Jun 30, 2019.

  1. Daniel-White

    Daniel-White Active Member Licensed User

    Hi, folks. Please help me with your wisdom :D

    I developed years ago an App to work with the button of iTAG, but apparently, something is different with the new iTags.

    For troubleshooting, I used the nRF Connect App. and I noticed I need to send a command or similar to the iTAG to enable the feature of the button. my old iTAGs work without need to write or send something to them. But these new ones are weirds.

    the New iTAG and nRF Connect. The new iTAG is connected
    Take a look at "Notification and Indication disable"
    if I press the button in the iTAG the nRF does not detect it.


    upload_2019-6-30_20-42-23.png


    So, to put to work the button of the iTAG I did this:
    Pressed the button (I showed in blue circle).
    and look now the value to "Notification Enable"

    upload_2019-6-30_20-45-37.png


    So, Now when I press the iTAG button the nRF connect App receive the value take a look the green circle the value is correct (0x)01 exactly the same with my old iTAGs

    upload_2019-6-30_20-48-3.png


    My understanding, apparently, I need now with those new iTags send a manager.write or manager.notify to enable or turn on the flag indicating the iTAG to send the value 0x01 ??? with the old iTAG I only need read never send a command. :eek:

    Code:
    Sub Manager_DataAvailable (ServiceId As String, Characteristics As Map)
     
    'iTags only
        Dim Valread As String = ""
        
    For Each id As String In Characteristics.Keys
            
    Dim data() As Byte
            data = Characteristics.Get(
    id)
            Valread  = 
    BytesToString(data, 0, data.Length, "UTF8")
              
            
    Select id
                
    Case findmeCharacteristic    'FIND_ME_CHARACTERISTIC     
                    BotoniTAGapretado = data(0)   '1   = Button Pressed    0 = No button pressed.
    Where
    Dim findmeCharacteristic As String = "0000ffe1-0000-1000-8000-00805f9b34fb"
    Dim findmeService As String = "0000ffe0-0000-1000-8000-00805f9b34fb"

    That code works great with my old iTags, but give this error with the new ones.

    Found: ITAG, FC:58:FA:04:03:DB, RSSI = -64, (MyMap) {1=[B@424587b, 10=[B@915698, 2=[B@7d45ef1, 9=[B@9c00ad6, 0=[B@1960157}
    ITAG ENCONTRADO
    Discovering services.
    Discovering services.
    Discovering services.
    id =00002a05-0000-1000-8000-00805f9b34fbCaracteristica =[B@cd395c8
    id =00002a06-0000-1000-8000-00805f9b34fbCaracteristica =[B@e69e661
    id =0000ffe1-0000-1000-8000-00805f9b34fbCaracteristica =[B@74ed586
    nucleo_manager_dataavailable (B4A line: 207)
    BotoniTAGapretado = data(0) '1 = Button Pressed
    java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
    at cpn.dgcop.nucleo5._manager_dataavailable(nucleo5.java:344)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7045)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)


    The problematic code is this:
    BotoniTAGapretado = data(0) '1 = Button Pressed 0 = No button pressed

    I am thinking, I am close to the solution but :confused:

    Thanks for any light.

    Daniel W
     
    Last edited: Jun 30, 2019
  2. emexes

    emexes Well-Known Member Licensed User

    I do love those iTags, especially now that they're like a buck each, but I too noticed that they are not identical.

    I wish they transmitted the button status as part of the advertising packet, that'd be so much easier than having to connect to them.

    Anyway, in your case above, it does look like that characteristic can only be accessed using notify, because I'm pretty sure I see the phrase "READ NOTIFY" a lot, but in your screenshots it's just showing "NOTIFY" ie no read.

    And just to make sure that you use the notify method, it seems the manufacturer has neutered the read method to not return any data ie a 0 length array, from which you are trying to extract data anyway, hence the array out of bounds.

    Perhaps the manufacturer is trying to make their iTags different to other manufacturers' in order to prevent their software being used with other iTags. Or perhaps it's just a programming slipup.

    Right, now I'll actually grab nrF Connect and a few iTags here and confirm what I just wrote ;-)
     
    Last edited: Jul 1, 2019
  3. emexes

    emexes Well-Known Member Licensed User

    I have three iTags, of two varieties (judging by the Bluetooth Ids), and they all show "READ NOTIFY" in nRF Connect.

    So I think an immediate solution for your case might be something like:
    Code:
    Sub Manager_DataAvailable(ServiceID As String, Characteristics As Map)
      
        
    if ServiceID.CompareTo(ButtonService) then
            
    Dim SetNotifyFlag As Boolean = True    'if no button data received, then enable notifications

            
    Dim ButtonData as Object = Characteristics.Get(ButtonCharacteristic)
            
    If ButtonData <> Null then
                
    Dim TempByteArray() As Byte = ButtonData
                
    If TempByteArray.Length > 0 Then
                    ButtonState = TempByteArray(
    0)
                    SetNotifyFlag = 
    False    'button data received, no need to (re)enable notifications
                End If
            
    End If

            
    If SetNotifyFlag Then
                manager.SetNotify(ButtonService, ButtonCharacteristic, 
    True)
            
    End If
        
    End If
          
    End Sub
     
    Last edited: Jul 1, 2019
    Daniel-White, f0raster0 and Erel like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice