Android Question Data from Nordic UART

warwound

Expert
Licensed User
Longtime User
I have a BBC micro:bit with a PIR sensor attached.
It sends (text) data via it's bluetooth UART service, the data counts the periods between PIR motion detections.
I want to receive this data on my S7 and convert it to speech.
(My project is a talking lap timer for my indoor buggy racing).

I have this working using USB for serial comms but am struggling to get it working with bluetooth.

When i couldn't get the BLE2 library to work i tried the BleManager library.
This is my current activity code using BleManager:
B4X:
Sub Process_Globals
   Private UART_SERVICE_UUID As String="6e400001-b5a3-f393-e0a9-e50e24dcca9e"
   Private UART_SERVICE_RX_CHARACTERISTIC As String="6e400002-b5a3-f393-e0a9-e50e24dcca9e"
   Private UART_SERVICE_TX_CHARACTERISTIC As String="6e400003-b5a3-f393-e0a9-e50e24dcca9e"
   
   Private ByteConverter1 As ByteConverter
   Private TTS1 As TTS
End Sub

Sub Globals
   Private BleManager1 As BleManager
   Private TtsIsReady As Boolean
   Private ToggleButtonEnable As ToggleButton
   Private UartRxBleCharacteristic As BleCharacteristic
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Main")
   BleManager1.Initialize("BleManager1")
   Dim ScanStatus As Boolean=BleManager1.Scan(6000, Null)
   Log("ScanStatus: "&ScanStatus)
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   TTS1.Release
End Sub

Sub Activity_Resume
   If Not(TTS1.IsInitialized) Then
     TTS1.Initialize("TTS1")
     TtsIsReady=False
   End If
End Sub

Sub BleManager1_CharacteristicChanged (Characteristic As BleCharacteristic)
   Log("BleManager1_CharacteristicChanged")
End Sub

Sub BleManager1_CharacteristicRead (Success As Boolean, Characteristic As BleCharacteristic)
   Log("BleManager1_CharacteristicRead")
End Sub

Sub BleManager1_CharacteristicWrite (Success As Boolean, Characteristic As BleCharacteristic)
   Log("BleManager1_CharacteristicWrite")
End Sub

Sub BleManager1_Connected (ServiceIds As Map)
   Log("BleManager1_Connected")
   
   For Each ServiceId As String In ServiceIds.Keys
     If ServiceId=UART_SERVICE_UUID Then
       Dim BleService1 As BleService=ServiceIds.Get(ServiceId)
       UartRxBleCharacteristic=BleService1.GetCharacteristics.Get(UART_SERVICE_RX_CHARACTERISTIC)
       If UartRxBleCharacteristic.IsInitialized Then
         Log("UART_SERVICE_RX_CHARACTERISTIC found")
         '   Log("Read characteristic: "&BleManager1.ReadCharacteristic(UartRxBleCharacteristic))   '   no notification with this either
         BleManager1.SetCharacteristicNotification(UartRxBleCharacteristic, True)
       Else
         Log("UART_SERVICE_RX_CHARACTERISTIC not found")
       End If
       Exit
     End If
   Next

End Sub

Sub BleManager1_DeviceFound (Name As String, MacAddress As String)
   Log("BleManager1_DeviceFound: "&Name)
   If Name="BBC micro:bit" Then
     BleManager1.Connect(MacAddress, True)
   End If
End Sub

Sub BleManager1_Disconnected
   Log("BleManager1_Disconnected")
End Sub

Sub BleManager1_DiscoveryFinished
   Log("BleManager1_DiscoveryFinished")
End Sub

Sub LogIt(Message As String)
   Log(Message)
   '   ToastMessageShow(Message, False)
End Sub

Sub TTS1_Ready (Success As Boolean)
   If Success Then
     TtsIsReady=True
     TTS1.Speak("Speech enabled", True)
   Else
     LogIt("Error initializing TTS engine")
   End If
End Sub
The log output typically looks like this:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
ScanStatus: true
** Activity (main) Resume **
BleManager1_DeviceFound: BBC micro:bit
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
Discovering services.
BleManager1_Connected
UART_SERVICE_RX_CHARACTERISTIC found

My micro:bit is found and connected to, the Nordic UART Service characteristic is found and i enabled notifications but no notifications occur.

If i connect to my micro:bit with the 'nRF Connect' android app i see various services:

device-2017-04-23-164758.jpg



I click the 'Nordic UART Service' notification enabler button (outlined red in my screenshot), then the RX Characteristic button (the down arrow button under the outlined button) and see the data coming through from my micro:bit on the nRF Connect log:

device-2017-04-23-170021.jpg


So i'm asking if anyone can see what i am missing in my activity code to enable these RX notifications?

Thanks.
 
Top