2017년 8월 6일 일요일

Bluetooth Cognitive dissonance. (confused)


Why does it seem like I am missing a needed event handler with the Bluetooth server.  I am trying build I simple proof of concept app that sends a string of text between phones.  All to the point of understanding the Bluetooth blocks better. 

I can connect the devices just fine. My apps see each other etc. However, I am missing how to put the server into a "wait for incoming bytes" state and if that is default then I am missing the event "incoming bytes do this". Grah... The .ReceiveText [number of bytes] seems logical but if the incoming bytes are unkown and I plug in the .BytesAvailableToRecieve my app crashes.... 

I get the feeling I am stuck in an "event driven" programming mindset that I need to breakout of to make this work. But I cant get a hand hold on it. 

I think I need a stronger drink....

And a deeper understanding of the bones and sinews of Bluetooth.

Shival and Liz I know have worked with this component. Anyone else?

--
I just put it in a loop on a timer to check if bytes available > 1

But you are right a event for data available would be great for both the client and the server.

--
Maybe a feature request its in order!
Tony Barnes
TheAIrepository.info
Http://groups.google.com/group/theairepository

--
So polling will work?

--
A timer to poll is the best option i could find.
Timer check if bytes available >0 run function

in function
Clear temp storage variable
while not bytes available = 0
->append text to variable
return temp variable after loop breaks.

This way you capture all data being sent and combine it into 1 string.

Alternatively for messaging use the function that gets all data till end of string and just make sure the messages you send either way end in a NULL (\0)

--
Shival's polling should work fine.

Please file an issue for a new event. Sorry about that!

--
Wolf, can you take a look at this? It might be the Vicodin but I am stuck. 


--
Ok i think you need to actually define the service name to something.

Look at my bluetooth connect example.
You do not need to split on connection.

I can't see anything natively wrong though there's a bluetooth error method isn't there.
Might want to see if that spits anything out.

I tried to make something similar ages ago but i didn't have 2 android devices to test.

--
Any idea what I've got wrong here Liz?

--
I gather that you want to have the same program running on two separate devices and send/receive messages. To accomplish that, you don't really need both devices to be both client and server - that would be two connections. You only need one device to be the server and the other device to be the client - just one connection. Even with just one connection, each side can send and each side can receive, so that's all you really need.

As Shival pointed out, you don't need to split the address when you pass it to the Connect block. The Connect block will trim off anything after the first space, so it will handle any item that came from the AddressesAndNames property.

Take a look at the changes I made. Once a connection is made, one side knows it is the client and the other know it is the server.


--
I knew I only needed one server/client connection but when you are building one app they both need to be there... so I was trying to figure out how to get that done as well. Rather than have two apps, a server app and a client app. 

--
Ladies and gentlemen the lesson here is READ THE SOURCE before you post. 

Liz, has anyone ever told you that you are a genius? 

Allow me to join the undoubted hundreds that have... 

--
I can't thank you enough for getting me past that brain seizure.  If it permissible I'll give you specific credit in my bluetooth tutorial chapter. After 3 hours fiddling with the thing I was hosed. 

Seems simple on this side of it but it always does when someone explains it. 

Again, Thank you for taking the time. 

I am grateful. 

--
Thanks! I am glad to help.
I'll be away without internet access for a few days.

--
Good stuff everyone.  I'm building a bluetooth controller for my coffee roaster to monitor and control the temperature and flow of natural gas. Next step is to write an Android app to communicate to my bluetooth controller.  The app will run on my Galaxy Tab to provide a nice 7" touchscreen UI to my roaster.

This bluetooth source provides excellent fundamental examples.  Thank you.

--
hello, i have been searching the forum on how to use the Bluetooth component, client and server. i have had no luck. i don't understand how to find and pair with another Bluetooth enabled device. i figure if i learn this, then i could start to experiment. but since i cant get pass this, i cant even start to learn it, or exp. it. Plz help me......ANYBODY, both blocks editor and text plzz

--
I have several examples of using the components that may help with an understanding

http://ai.kittywolf.net/index.php/BlueTooth_Client_Connect - client connect example.

http://ai.kittywolf.net/index.php/BTChat - chat between 2 phones 1 as client 1 as server just sending text.

http://ai.kittywolf.net/index.php/BTDraw - drawing between 2 phones with a shared canvas.

--
ive been looking at your ex. i just don't understand it, is that pre built to pair with a selected device, or can i use it to pair to my own devices. Thank you for your speedy response

--
Pairing happens at the android OS level.
Session establishment occurs in the app in server mode it starts the bluetooth server listening with an ID
In client mode you click the list of devices button to connect to that list is populated by the list of already pre paired bluetooth devices
you then connect with the connect button.

if you download the source the comments are there to review and see what does what.

--
I like the fact that we have access to the list of paired devices. Has anyone found a good way to dectect which paired device is in range?
Lets say I have a bluetooth chat program and I have paired with everyone in a college class room. Later at the bar I run the program and it searches out
and finds anyone in the bar with whom I have paired and prompts me to open a chat channel with them.
If I have 100 paired devices, using the current AddressesAndNames property, I have to select who I want to chat with from a liist of 100 devices.
If I don't know who is in range, like a crowded bar where you can't see someone 5 feet away, you wont even know who to open a chat channel with.
One method I thought of would be to iterate through all 100 devices trying to open a connection to each in turn. Time consuming.
Any better ideas?
Chris Rennie
Been away from AI for a while. Trying to teach myself java and the android SDK.
Makes me appreciate AI that much more.

--
naa theres no way to detect range ithats low level in the bluetooth API.

additionally bluetooth can only link to a max of 7 devices from 1 master host.
AI and bluetooth however i think is a 1 to 1 with its server component i do not think it could do something like a room.

--
is there a way you can email me the source, becuase i can not change the program they r open with to veiw em. Plz and thank you. (and i can not right click them and change the file they r opened with that way)

--
the ai source for both projects are on the wiki
you download the zip and then upload it as a project to AI.

--
ohhhhhh thank you for all your help. THANK YOU

--

댓글 4개:

  1. If you want your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (no matter why you broke up) you have to watch this video
    right away...

    (VIDEO) Win your ex back with TEXT messages?

    답글삭제
  2. Have you ever tried maximizing your free bitcoin collections with a BITCOIN FAUCET ROTATOR?

    답글삭제
  3. BlueHost is definitely one of the best hosting company with plans for all of your hosting needs.

    답글삭제
  4. If you are looking to buy bitcoins online, Paxful is the #1 source for bitcoins as it allows buying bitcoins by 100's of different payment methods, such as Western Union, MoneyGram, PayPal, Visa, MasterCard, American Express and they even allow converting your gift cards for bitcoins.

    답글삭제