Multiple blueTooth serial connections

rayellam

Member
Licensed User
Longtime User
Hi All,

A newbie question.

I have a requirement where there will be multiple slave devices (up to 48 slave devices per master) sending data back to a master device on a regular basis. The transmission medium is Bluetooth over virtual serial ports. Each slave device will send around 30 bytes of data per transmission. i was originally hoping to get around all 48 slaves in around 1 minute (ideally).

The set up I have at the moment consists of 6 slave devices and all are set to listen for the master which is requesting data from each slave. The master has 6 serial objects and 6 AStream objects set up so each slave has its own “channel” of communication. Each slave’s code is in a service that will wake up at a period of time, wait for a request from the master, send the data and go to sleep for a while to conserve battery. All serial and AStream objects on the master are re-dimmed when needed.

All is working reasonably well and has a repeatability of successful connections of around 90%. The problem I’m finding is that the master has to connect to each device in a sequential fashion, therefore slowing the refresh rate to get around all slaves. On average it takes around 8 to 10 seconds to successfully address each slave. If I try to request the data too quickly then I get serial errors from the master side.

Would it be better if the master was the listener? I have read a few posts here using network sockets where it looks like the master is the listener and things can be done in a more “parallel” fashion?


Any thoughts on this would be appreciated.

Thanks

Ray
 

rayellam

Member
Licensed User
Longtime User
i chose bluetooth because i need to detect when any of the slaves goes out of range of the Master. Maybe i could use sockets over a local WiFi connection?
 
Upvote 0

KitCarlson

Active Member
Licensed User
Longtime User
Just a thought, based without multi-channel experience. Have you tried multi-channel connections at once, and see how that works. Not sure if there is a significant power savings in sequential connections.
 
Upvote 0

rayellam

Member
Licensed User
Longtime User
Just a thought, based without multi-channel experience. Have you tried multi-channel connections at once, and see how that works. Not sure if there is a significant power savings in sequential connections.

Hi Kit,
Thanks for the answer. Yes that was the first thing i tried but there are to many comms errors on the master side when i fire all the comms requests from the master to the slaves simultaneously. I have error traps on the async and serial connections side as well as time out errors (master side). I was on the understanding when i started out on this that i would be able to fire the code from the master end simultaneously and was hoping the threading in B4A would allow for this. One more note, i was not intending to fire all 48 channels at once but rather do it all in blocks of maybe 4 to 6. I read some stuff on bluetooth before i started that suggested that only 7 connections are allowed on a Bluetooth piconet at once, im not sure if this relates to using serial connections in B4A but to be on the safe side i have structured the code mechanism to take this into account?

The code i am using is based on the serial chat example using AStreams. I'm not really certain why this methodology dont work, im a real newbie with Android but learning fast :)

Power is not an issue on the master device as this has an external battery pack and such is powered up all the time. The slaves are the ones that need to conserve the power and that is why i put them into a pseudo "sleep" mode with BT + WiFi + Screen Off + partial lock on for a period of time.

Thanks for your input

Ray
 
Upvote 0

rayellam

Member
Licensed User
Longtime User
Do all of these devices share the same wifi network? If yes then you should check HttpServer. It will be much simpler and more reliable.
Hi Erel,
They don't at the moment as im not using WiFi but im guessing they could do ;-) i will have a read on HttpServer, maybe this is the fix............many thanks for the suggestion

Cheers
Ray
 
Upvote 0

KitCarlson

Active Member
Licensed User
Longtime User
I can see the need to sequence the requests in multiple BT connections. I am wondering if you find just one connection very reliable? If not, there may be a problem in the data handling in newdata subs.

The WiFi sounds great for your application.
 
Upvote 0

rayellam

Member
Licensed User
Longtime User
The WiFi sounds great for your application.

An update........httpServer is DEFINITELY the road to go for this kind of communication. It is fast, the learning curve is much easier than blue tooth and the reliability is much higher when connecting. I intend to use the bluetooth communication as a form of redundancy if there is no communication via the server. The upshot being i did not waste a lot of time on the bluetooth learning curve :)

One question i have, maybe Erel can answer this?

I want to keep the wifi network private and NOT connected to the internet, so therefore i have used one of the devices as a "local" hotspot for all the devices. Is there anyway i can have the Master application resident on the hotsopt device (see the first post for a description of the way the system works) or do i need an extra device for the Master app to reside on?

Thanks for the input guy's...........i will DEFINITELY recommend B4A to anyone that will listen ;-)

Cheers
Ray
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I want to keep the wifi network private and NOT connected to the internet, so therefore i have used one of the devices as a "local" hotspot for all the devices. Is there anyway i can have the Master application resident on the hotsopt device (see the first post for a description of the way the system works) or do i need an extra device for the Master app to reside on?
Do you want to run the server app on the device that creates the hotspot? It will work fine. It doesn't really matter.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Would it be better if the master was the listener?

With Bluetooth and all RF communications a master can't be the listener.. Unless you could synch all devices with a master clock, which is not practical.. Instead you must (Ask) each device in sequence and move to the next after registering that device's response. Otherwise you will need to follow Erel suggestion to use web service or configure the master as server and forget BT.

Oops!
I was searching the forum for something and found this thread.. Didn't notice it's that old. Sure I clicked on the reminder but I did this many times because get that message even for a 2 month old thread.
 
Upvote 0
Top