PureBasic & Bluetooth LE?

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

PureBasic & Bluetooth LE?

Post by Lebostein »

Is this possible? For example to communicate with the new LEGO electric devices...
https://lego.github.io/lego-ble-wireless-protocol-docs/
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PureBasic & Bluetooth LE?

Post by infratec »

I don't know if GATT is possible with the 'normal' bluetooth lib.

But you can write a wrapper for the standard bluetooth stuff:

Code: Select all

; https://docs.microsoft.com/en-us/windows/desktop/api/bluetoothapis/
; http://mielke.cc/brltty/archive/Windows/Bluetooth/BluetoothAPIs.h
; https://www.purebasic.fr/german/viewtopic.php?f=8&t=23878


#BLUETOOTH_MAX_NAME_SIZE = 248
#BLUETOOTH_MAX_PASSKEY_SIZE = 16
#BLUETOOTH_MAX_PASSKEY_BUFFER_SIZE = #BLUETOOTH_MAX_PASSKEY_SIZE + 1

Structure BLUETOOTH_ADDRESS
    StructureUnion
        ullLong.q       ; easier to compare again BLUETOOTH_NULL_ADDRESS
        rgBytes.a[6]    ; easier To format when broken out
    EndStructureUnion
EndStructure

Structure BLUETOOTH_DEVICE_INFO
  dwSize.l
  Address.BLUETOOTH_ADDRESS
  ulClassofDevice.l
  fConnected.l
  fRemembered.l
  fAuthenticated.l
  stLastSeen.SYSTEMTIME
  stLastUsed.SYSTEMTIME
  szName.s[#BLUETOOTH_MAX_NAME_SIZE]
EndStructure

PrototypeC.l Proto_BluetoothAuthenticateDevice(hwndParent.l , hRadio.l, *pbtbi.BLUETOOTH_DEVICE_INFO, *pszPasskey.p-Unicode, ulPasskeyLength.l)

Global BluetoothAuthenticateDevice.Proto_BluetoothAuthenticateDevice

BluetoothLibrary = OpenLibrary(#PB_Any, "Bthprops.cpl")
If BluetoothLibrary
  
  BluetoothAuthenticateDevice = GetFunction(BluetoothLibrary, "BluetoothAuthenticateDevice")
  
  Debug BluetoothAuthenticateDevice
  
  CloseLibrary(BluetoothLibrary)
EndIf
Last edited by infratec on Sun Apr 28, 2019 10:19 pm, edited 2 times in total.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PureBasic & Bluetooth LE?

Post by infratec »

Btw. HeXOR has already written something:
https://www.purebasic.fr/german/viewtop ... =8&t=23878
Post Reply