Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Tethering by Bluetooth - how to connect to remote profile?


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


Permlink Replies: 5 - Last Post: Feb 20, 2017 8:11 AM Last Post By: Antonio Tortosa...
Grzegorz Żochow...

Posts: 5
Registered: 9/30/16
Tethering by Bluetooth - how to connect to remote profile?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 8, 2017 5:20 AM
Hello!

I have a problem with TTetheringMahaner (name: thrngmngr_1) and TTetheringProfile (thrngprfl_1). I try to connect tablet with PC computer by Bluetooth. I did two programs: first one is working on the PC, second on Samsung Galaxy Tab A (Android 5.1.1). I tried to send a string from tablet to PC. Everytime I get message "Profile {ID} is not connected" and I have no idea why. What I do wrong?

I tried to upgrade Android SDK and NDK. I did it, but it didn't solve the problem.

Source code is simple.

// =============================================================================
// AutoConnect to remote computer
procedure TForm1.btn_ConnectClick(Sender: TObject);
begin
	thrngmngr_1.AutoConnect();
end;
 
// =============================================================================
// Show remote manager ID
procedure TForm1.thrngmngr_1PairedToRemote(const Sender: TObject; const AManagerInfo: TTetheringManagerInfo);
begin
	lb_ManagerIdentifier.Text := 'Paired to ' + AManagerInfo.ManagerIdentifier;
end;
 
// =============================================================================
// Connect profile
procedure TForm1.btn_Connect2Click(Sender: TObject);
begin
	thrngprfl_1.Connect(thrngmngr_1.RemoteProfiles[0]);
end;
 
// =============================================================================
// Send string to remote computer
procedure TForm1.btn_SendStringClick(Sender: TObject);
begin
	if thrngmngr_1.RemoteProfiles.Count = 0 then
		Exit;
 
	thrngprfl_1.SendString(thrngmngr_1.RemoteProfiles[0], 'test', edt_1.Text);
     // exception "Profile {ID} is not connected"
end;
 
// =============================================================================
// After Connect Profile
procedure TForm1.thrngprfl_1AfterConnectProfile(const Sender: TObject; const AProfileInfo: TTetheringProfileInfo);
begin
	ShowMessage('Profile connected');
end;


I dropped TTetheringMahaner and TTetheringProfile on the main form, turned on "Enable" property, chose "Bluetooth" as AllowedAdapter and connected both components togeteher.
Profile.Group is the same in both programs.

Delphi 10.1 Berlin Update 2
Windows 7 64-bit

Movies:
https://youtu.be/BTOY8Wydqr4 (source code and main form)
https://youtu.be/PS52nAKjh-s (the programs in action)

I tried other path too -- without using AutoConnect. Result is the same.
Does abybody have experience with Tathering by Bluetooth?

Sorry for my English.
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Tethering by Bluetooth - how to connect to remote profile?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 9, 2017 5:54 AM   in response to: Grzegorz Żochow... in response to: Grzegorz Żochow...
Grzegorz Żochow...

Posts: 5
Registered: 9/30/16
Re: Tethering by Bluetooth - how to connect to remote profile?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 10, 2017 6:06 AM   in response to: Eli M in response to: Eli M

I know this website and a few others (my favorite is here: http://www.webdelphi.ru/2016/09/app-tethering-v-delphi-10-1-berlin/), but they all describe tathering using Network adapter. I didn't try Network, but the programs don't work with Bluetooth adapter. Additionally I can't run the Android program compiled from source codes, which are attached to the website (it shows Delphi splash screen and terminates quickly). I think FireMonkey has many bugs (I found some and I don't trust FM anymore).
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Tethering by Bluetooth - how to connect to remote profile?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 12, 2017 8:58 AM   in response to: Grzegorz Żochow... in response to: Grzegorz Żochow...
Delete the AndroidManifest.template.xml file in the old demo project and it may work.
Grzegorz Żochow...

Posts: 5
Registered: 9/30/16
Re: Tethering by Bluetooth - how to connect to remote profile?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 10, 2017 8:04 AM   in response to: Grzegorz Żochow... in response to: Grzegorz Żochow...
I found random reason of problem.

Unfortunately I did procedures for each TTatheringManager and TTatheringProfile events (for diagnosis and learning). And:

1. Probability of failure is 100% if all procedures are defined and connected to the components (inside procedures was only one line: ListBox.Items.Add('what this procedure do') except procedures which need to accept something like "AcceptResource").
2. Probability of failure is 100% if all procedures are defined and connected to the components. Even if they are empty (all lines are commented).
3. Probability of failure is 50% if there are only 3 procedures connected to TTatheringProfile: AfterConnectProfile, ActionUpdated and ResourceReceived (only last has a few lines, first both have only commented lines)
4. Probability of failure is 0% if there is only one procedure: thrngprfl_1ResourceReceived.

I didn't try with other combinations.
Antonio Tortosa...

Posts: 6
Registered: 1/12/08
Re: Tethering by Bluetooth - how to connect to remote profile?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2017 8:11 AM   in response to: Grzegorz Żochow... in response to: Grzegorz Żochow...
Hi Grzegorz.

Grzegorz Żochowski wrote:
Hello!

I have a problem with TTetheringMahaner (name: thrngmngr_1) and TTetheringProfile (thrngprfl_1). I try to connect tablet with PC computer by Bluetooth. I did two programs: first one is working on the PC, second on Samsung Galaxy Tab A (Android 5.1.1). I tried to send a string from tablet to PC. Everytime I get message "Profile {ID} is not connected" and I have no idea why. What I do wrong?

You need to pair both devices before using tethering. Bluetooth needs that both devices are paired in order to establish connection.

I tried to upgrade Android SDK and NDK. I did it, but it didn't solve the problem.

Source code is simple.

// =============================================================================
// AutoConnect to remote computer
procedure TForm1.btn_ConnectClick(Sender: TObject);
begin
	thrngmngr_1.AutoConnect();
end;

Please be careful using code that uses the UI inside thethering. There can be problems because tethering does communications outside the UI thread, some events are sinchronized, but others not, and a safer approach is to surround the code you are going to execute with...
 TThread.Synchronize( procedure
begin
   // your code goes here
end)

Please, review the code, I've written it from my memory.

// =============================================================================
// Show remote manager ID
procedure TForm1.thrngmngr_1PairedToRemote(const Sender: TObject; const AManagerInfo: TTetheringManagerInfo);
begin
	lb_ManagerIdentifier.Text := 'Paired to ' + AManagerInfo.ManagerIdentifier;
end;
 
// =============================================================================
// Connect profile
procedure TForm1.btn_Connect2Click(Sender: TObject);
begin
	thrngprfl_1.Connect(thrngmngr_1.RemoteProfiles[0]);
end;
 
// =============================================================================
// Send string to remote computer
procedure TForm1.btn_SendStringClick(Sender: TObject);
begin
	if thrngmngr_1.RemoteProfiles.Count = 0 then
		Exit;
 
	thrngprfl_1.SendString(thrngmngr_1.RemoteProfiles[0], 'test', edt_1.Text);
     // exception "Profile {ID} is not connected"
end;
 
// =============================================================================
// After Connect Profile
procedure TForm1.thrngprfl_1AfterConnectProfile(const Sender: TObject; const AProfileInfo: TTetheringProfileInfo);
begin
	ShowMessage('Profile connected');
end;


I dropped TTetheringMahaner and TTetheringProfile on the main form, turned on "Enable" property, chose "Bluetooth" as AllowedAdapter and connected both components togeteher.
Profile.Group is the same in both programs.

Try to choose first the adapter, and then "Enable" the manager.

Try those things and see what happens.

Also see that Tethering has a built-in feature for debugging that you can enable, I think that there were some samples using it.
If you cannot find one say it and I'll try to find out the code and post here.

Delphi 10.1 Berlin Update 2
Windows 7 64-bit

Movies:
https://youtu.be/BTOY8Wydqr4 (source code and main form)
https://youtu.be/PS52nAKjh-s (the programs in action)

I tried other path too -- without using AutoConnect. Result is the same.
Does abybody have experience with Tathering by Bluetooth?

Yes I have...


Sorry for my English.

No problem with that, my English is also a bit confusing sometimes.

Un saludo, Antonio Tortosa.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02