Android Question Looking for a way to communicate 1 to N devices [SOLVED]

Serge Bertet

Active Member
Licensed User
Hi,
I need to enable a communication from 1 master device to N slave devices.
spent 3 days testing different solutions:
- I tried BLE but some devices have Android 4 ... so no way,
- Tried also direct Wifi but as I can see it is a 1 to 1 protocol,
- Tried with Erel's chat example using Bluetooth but I don't know if I need to open 1 stream for each serial and if has a chance to work,
- I saw that I can use a unique IP with a router ... but if there is no router that will not work.

I am thinking using Ajax/HTTP protocol, I do not really need realtime answer but there can be some latency.
Is there another way to do that?

Thx
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
Hi Serge,

Some questions:
1. Are all devices on the same network ?
2. Are all devices in close proximity to each other ?
3. Do you want to speak/broadcast to devices which might be far away from each ? (i.o.w. not in reach of BT or Direct WiFi)
4. Do your devices have Internet Access all the time ?
5. What do you need to send to the devices ?

Depending on these answer, I might have a perfect solution for you.
 
Upvote 0

Serge Bertet

Active Member
Licensed User
Hi Bill, thanks for your interrest in the question.
It seems that using direct wifi it is possible to create a local network on 127.0.0.1 I also can ask every body to change they IP (if possible) but I don't know if they'll agree.
All devices will be be very close 10 meters maximum maybe 15, no more
I'm not sure if every device have an Internet access.
It looks like only bluetooth is able to work in this case
I just want to send small frames of small string (10 to 20 chars) no more.

I'm so excited to know your idea ... please ask me if you need more information.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
It seems that using direct wifi it is possible to create a local network on 127.0.0.1.

I'm not sure if every device have an Internet access.

As long as each device is connected to a router then you can use an internal MQTT system, no internet needed. I've done that in my office whilst testing ideas and the MQTT libraries are available on the forum.

EDIT: Erel you got the before me, I hate editing and answering questions on my phone ;)
 
Upvote 0

Serge Bertet

Active Member
Licensed User
OK, many thanks ...
I'll learn what MQTT is and see if I can do something with that.
I'll come back mark [SOLVED] this thread.
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
And you all beat me to it - EISH !!

So here is a Graphic that explains it.

Note you can use the B4J/B4i/B4A MQTT Brokers as a solution or use the Open Source Mosquito Broker (which is actually just a nice word for "Server") - but this is a great solution and will do exactly what you want it to do. The very nice thing is - you are not limited to sending just text messages, but can send images, sound (size does matter - so watch that), JSON etc AND with some clever programming - you can even send it to an individual device as well.

So please enjoy your voyage of discovery - ask questions - we are here to help.

upload_2018-10-2_10-40-15.png


and as Peter always says: "Enjoy"
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
I like that Image @BillMeyer, I like it so much that I've just saved it to my personal Image folder, cheers it will come in handy some day ;)

Hmm, you forgot the three dots "..." after "Enjoy" :)

You are more than welcome Sir and indeed I did so here goes:

Enjoy...
 
Upvote 0

Serge Bertet

Active Member
Licensed User
Hello all, I'm back after a long time since my last post here (I was working on another functionnality in may app).
I started installing MQTT based on the Erel's "simple chat UDP" example ... I don't know if this is the good point to start.
I added jMQTT v1.00, jMqttBroker v1.04, ByteConverter v1.10 but when compiling the IDE complains about too old libraries compiled a wrong way (with an old tool), I don't know wich one.
Even with a 120 seconds timeout it is not enough (the error appeared one time only).
Locked at:
B4A Version : 8.50
Analyse du code. (0.12s)
Building folders structure. (0.48s)
Compilation du code. (1.07s)
Compilation du code des layouts. (0.09s)
Organiser les bibliothèques. (6.22s)
Génération du fichier R. (0.95s)
Compilation du code du débogueur. (3.82s)
Compilation du code Java. (5.15s)
Conversion bytes code - dex optimisé. <== locked here or error message sometime

I know there is another library with donation somewhere, maybe better to do the job? Even if I had to pay this is not a problem.
I'll continue to see if I can find some others libs.

I'm almots sure some admin will complain that this post is at the wrong place ... sorry in advance ... I'll move it if so.

Edit: based on Erel's advice I increased the IDE's memory in ini file: MaxRamForDex=4096 but same problem: timeout and this message:
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.log4j.chainsaw.ControlPanel$3) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

Erel's app compiled with success. Here are my used libs:

libs.jpg


Edit2: After removing my no more used old BluetoothManager class it is working.

Sorry for any disturbance guys ...
 
Last edited:
Upvote 0

Serge Bertet

Active Member
Licensed User
Hi,
I think everything is working ... til now ...
In some places where no router are available I plan to use a Wifi repeater (IP of mine is 10.0.10.0) so every body can connect I so get the same IP segment.
I know that it is possible to turn a phone into a router ... maybe that can work ... I'll see.
Next thing to implement is a file transfert.
Thank you very much for your help, Bill and others
Serge
 
Upvote 0
Top