Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: BlueTooth client-server with Seattle


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: May 17, 2017 8:59 PM Last Post By: Startek Startek
Startek Startek

Posts: 16
Registered: 2/4/17
BlueTooth client-server with Seattle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 15, 2017 6:47 PM
I'm trying to develop a simple client-server type system utilising Bluetooth but am having problems. The server will be at a fixed location running Windows. Clients will be dedicated Android devices on vehicles. When a vehicle is in position the driver presses a button to issue an instruction to the server to perform a task.

I am using Bluetooth Classic as Seattle doesn't support LE on Windows (counter to the Help, Windows 10 supports LE; do Berlin or Tokyo?) - the structure might be more suited to LE but I don't have an issue with Classic.

Currently in my code I can detect and list devices and list paired devices and the android "client" can connect to the Windows server but when I try to send some text using TBluetoothSocket.SendData it fails with java.lang.NullPointerException somewhere deep down.

I am using Delphi 10 Seattle Version 23.0.20618.2753

I have looked at the BlueChat & EchoClassic demos. For BlueChat the Windows program can send text to the android phone but I can't get anything back to Windows. EchoClassic just raises lots of exceptions on both sides (and the code is written quite poorly anyway).

Here is some relevant code - I could make my test project available but I don't know how to attach files here using the web interface.

[code]
procedure TFRM_MobileScales.BTN_ConnectClick(Sender: TObject);
var
index : integer;
device : TBlueToothDevice;
const
SERVER_NAME = 'MESA2HHVS'; { name of bluetooth server device (computer name) }
begin
try
Bluetooth1.Enabled := True;
index := Bluetooth1.PairedDevices.Count - 1;
while (index >=0) and (Bluetooth1.PairedDevices[index].DeviceName <> SERVER_NAME) do
dec(index);
Memo1.Lines.Add('Connected Device Index=' + IntToStr(index));
if index >= 0 then
begin
device := Bluetooth1.PairedDevices[index];
//Bluetooth1.Pair(device);
FClientSocket := Bluetooth1.CreateClientSocket(device, BLUETOOTH_GUID, False);
//FClientSicket.SendData('A');
end;
except
on E : Exception do
Memo1.Lines.Add(E.Message);
end;
end;

procedure TFRM_MobileScales.BTN_SendClick(Sender: TObject);
var
txt : TBytes;
len : integer;
begin
try
if Assigned(FClientSocket) then
begin
txt := TEncoding.UTF8.GetBytes(EDT_Data.Text);
len := Length(txt);
if len > 0 then
FClientSocket.SendData(txt); // this dies
end;
except
on E : Exception do
Memo1.Lines.Add(E.Message);
end;
end;
[/code]
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: BlueTooth client-server with Seattle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 16, 2017 9:49 AM   in response to: Startek Startek in response to: Startek Startek
Am 16.05.2017 um 03:47 schrieb Startek Startek:

Here is some relevant code - I could make my test project available but I don't know how to attach files here using the web interface.

Hello,

afaik attachments are o0nly possible in the special "attachments" group
on this server. You can post a link to the post in the attachments group
here.

Greetings

Markus
Startek Startek

Posts: 16
Registered: 2/4/17
Re: BlueTooth client-server with Seattle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 16, 2017 7:43 PM   in response to: Markus Humm in response to: Markus Humm
Thanks Markus, I have posted the project in attachments.

PS. Sorry for emailing you with my reply before - I meant to post it here.

On 17/05/2017 2:49 AM, Markus Humm wrote:

Am 16.05.2017 um 03:47 schrieb Startek Startek:

Here is some relevant code - I could make my test project available but I don't know how to attach files here using the web interface.

Hello,

afaik attachments are o0nly possible in the special "attachments" group
on this server. You can post a link to the post in the attachments group
here.

Greetings

Markus
Startek Startek

Posts: 16
Registered: 2/4/17
Re: BlueTooth client-server with Seattle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2017 6:31 PM   in response to: Startek Startek in response to: Startek Startek
Trying to test BlueTooth, I can compile the "..\Bluetooth\BlueChat"
demo. My Windows tablet can receive messages but no Android devices can
receive typed messages (Android-to-Android or Windows-to-Android). Can
anyone get that demo working (receive on Android)?

Reiner
Startek Startek

Posts: 16
Registered: 2/4/17
Re: BlueTooth client-server with Seattle  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2017 8:59 PM   in response to: Startek Startek in response to: Startek Startek
Ok - found my problem - I forgot to call TBluetoothSocket.Connect

Still, connection seems very flaky and I have to connect twice from the
android before I can send anything otherwise it complains about a broken
pipe.

On 18/05/2017 11:31 AM, Startek Startek wrote:
Trying to test BlueTooth, I can compile the "..\Bluetooth\BlueChat"
demo. My Windows tablet can receive messages but no Android devices can
receive typed messages (Android-to-Android or Windows-to-Android). Can
anyone get that demo working (receive on Android)?

Reiner
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02