2017년 4월 10일 월요일

BluetoothServer1.IsConnected or BluetoothClient1.IsConnected


actually a very easy issue but either I am too dumb to see the problem or I have an issue here
I want to work with an event when the mobile phone disconnects from the hands-free in the car.
I assume that when a hands-free is connected either bluetooth server or client of the phone is set to true and I can use the logic when true turns to false again.
But I have tried with three hands frees now and the isconnected stays always at false (the clock1 fires every three seconds and I have a beep included to assure that the when function really works).
Why does this not work or does anybody have another idea how I can detect when a bluetooth device is disconnected?
Thank you for your help :)9
--
the property IsConnected will unfortunately not be updated, after a device will be disconnected, which means you will get Error 516: Unable to write: Connection reset by peer", see also chapter "known issues" here https://puravidaapps.com/btchat.php, however you can catch that error in the Screen.ErrorOccurred event

--
thank you for your quick response.

But I checked your known issues and it says there
As far as I can see, after client or server disconnected, there is no possibility for the chat partner to see, that the connection is gone. Therefore currently an "Error 516: Unable to write: Connection reset by peer" will be diplayed after trying to send a text without connection
But I am not talking about the partner since in that case the parter would be the hands-free, wouldn't it?
The IsConnected is running on my own phone and when the hands-free is disconnected then the status has to change because if not it would stay forever at true. Or do I have to set it at false myself?

--
when the hands-free is disconnected then the status has to change because if not it would stay forever at true.
that's correct, as far as I remember correctly, it stays forever at true 

-- 
In my case it stays forever false ... grrrr

I try the idea  to catch an error

--
I am despairing.

I am using the command bluetoothclient1.Sendtext Text:a
to verify if there is a bluetooth device connected or not and although I have tried with three differed free-hands the error message shown on the device is:
Error 515: Not connected to a Bluetooth device
although the free-hands work and bluetooth shows in the mobile device the correct connection

--
are you sure, you have a successful connection?

This is the correct method to connect to a Bluetooth device:


boolean Connect(text address)
Connect to the Bluetooth device with the specified address and the Serial Port Profile (SPP). Returns true if the connection was successful.

--
thank you for this tip.

Until now I never connected myself the Bluetooth connection manually with the programming language (like you propose) but I assumed that this happens already with Android automatically.

Does your proposal mean that I cannot rely that the phone itself (the operating system) establishes the connection and then the value of IsConnected is automatically True?

--
there is nothing automatic, you have to do the connection

-- 
sorry if I engage you so much into this discussion and I am very grateful.

But why can the application not assume that Android runs a bluetooth connection already when in reality it is an established connection to a hands-free?

When I request the physical position I also get it without activating GPS or other location methods. The location is stored in the locationsensor already.

You understand what I mean? My idea would be actually to check if under the normal Android operating system a bluetooth connection is already running and inform the app if it is disconnected. The app does not need a bluetooth connection. It is only required to know when a connection is lost.

--
 I don't have one of these gadgets.....then possibly user a timer to poll whether the connection exists continually and if the connection is no longer there  ....connection was NOT successful  becomes connections is LOST  ?           Does that work?

--
I implemented your proposal explicity in a separate project.

But the problem remains the same. Neiter via the web connect nor as an app installed on the phone it establishes a bluetooth connection with the hands-free when selected.

Failure message is: Error 507: Unable to connect. Is the device turned on?

BUT when I connect the phone WITHOUT the app directly to the hands-free via Bluetooth in Settings of the Samsung S3, it connects with no problems (just not via the app) and the hands-free works.

There must be something in the app which does not allow the bluetooth connection to be established ...

--
thank you and yes, that is possibly not possible with App Inventor.

Since I am not a programmer, App Inventor was the obvious choice for me.

My idea was to create an App which saves automatically the position of my car when the phone gets disconnected from the hands-free of the car.

Like this it is not necessary to press a save button opening the app beforehand etc. :)

--

댓글 없음:

댓글 쓰기