lousoperscopimaligni
Member
I managed to implement the functions necessary for detecting bluetooth devices. now that my connection is successful, I'd like to understand how I can get the information I need to be sent. In my case, I should convert this JS function:
while this is my B4A code for bluetooth connection:
REQUEST AUDIT:
function RequestAudit() {
Help("Caratteristica audit request " + uid_request);
_service.getCharacteristic(uid_request).then(function (characteristic) {
var cmd = "request";
var cmdbyte = encEncoder.encode(cmd);
return characteristic.writeValueWithResponse(cmdbyte);
}).then(function () {
$("#out").html("File requested");
}).catch(function (err) {
$("#out").html(err);
});
}
while this is my B4A code for bluetooth connection:
BLE2 IMPLEMENTATION:
Sub FAS_Scan
Dim Permissions As List
Dim phone As Phone
If phone.SdkVersion >= 31 Then
Permissions = Array("android.permission.BLUETOOTH_SCAN", "android.permission.BLUETOOTH_CONNECT", rp.PERMISSION_ACCESS_FINE_LOCATION)
Else
Permissions = Array(rp.PERMISSION_ACCESS_FINE_LOCATION)
End If
For Each per As String In Permissions
Log(per)
rp.CheckAndRequest(per)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("No permission: " & Permission, True)
Return
End If
Next
Log("Ricerco...")
foundDevices.Clear
bluetoothListView.Clear
StartScan
End Sub
Sub Manager_StateChanged (State As Int)
Select State
Case blmanager.STATE_POWERED_OFF
Log("POWERED OFF")
Case blmanager.STATE_POWERED_ON
Log("POWERED ON")
Case blmanager.STATE_UNSUPPORTED
Log("UNSUPPORTED")
End Select
StateChanged
End Sub
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
If(Name <> "") Then
Log("Trovato dispositivo: " & Name & ", " & Id & ", RSSI = " & RSSI & ", AdvertisingData " & AdvertisingData)
Log("Nome dispositivo trovato: " & Name)
Log("Id dispositivo trovato :" & Id)
Log("UUID dispositivo trovato :" & UUID(Id))
ConnectedName = Name
foundDevices.Add(Id)
bluetoothListView.Add(CreateItem("BLUETOOTH", "bluetooth.png",Name & " " & Id),"")
End If
End Sub
Public Sub StartScan
If blmanager.State <> blmanager.STATE_POWERED_ON Then
Log("Not powered on.")
Else
Log("power on")
blmanager.Scan2(Null, False)
End If
End Sub
Public Sub StateChanged
If connected Then
Log("Connected: " & ConnectedName)
Else
Log("Not connected")
End If
End Sub
'Funzione che restituisce l'UUID completo del distributore FAS
Private Sub UUID(id As String) As String
Return "0000" & id.ToLowerCase & "-0000-1000-8000-00805f9b34fb"
End Sub
Private Sub bluetoothListView_ItemClick (Index As Int, Value As Object)
blmanager.StopScan
Log(Index & " " & Value)
Log(foundDevices.Get(Index))
blmanager.Connect(foundDevices.Get(Index))
End Sub