This question follows on from Unity3D -- Send message to other mobile phones in the same vicinity
However, I made mistake of restricting to Unity3D.
So I would like to re-ask the question without that constraint.
Let us say we have 20 mobile phone users in a cave (so no Wi-Fi networks / isGPS)
One user hits a button, and every other user's screen flashes, (within a few milliseconds)
How to accomplish this?
What if everyone is using an iPhone?
What if there is a mix of iPhone and android users?
Finally, is there any solution that would cover a wider range of phones?
You should have some network so that mobiles can share some data. Bluetooth can have maximum of 10 m distance coverage (depends upon devices though). Since, all mobile are running same app they should be linked to a network and communicate. Please Check:
http://developer.android.com/samples/BluetoothLeGatt/index.html
You can create one device as server and communicate among other devices.
https://github.com/polyclef/BluetoothChatMulti
If you have installed the app on all of the devices then in all probability yes, if the device supports push (pretty much any smartphone) then you can use the push service to synchronize the devices based on geofencing (ie, 10m from my location), there are some other discovery routes you could try to (without using the B word) pinging other devices
the app would need to be able to provide some sort of server service if it was to create its own private network based on the IP addresses of the devices it found nearby, as those devices would have to connect to that phone acting as a server. the network interface shouldn't be important, but connecting the satellite devices to the server should be. You could try doing it based on which device can provide data services, aka hotspot. You can easily connect devices to networks programmatically.
at that point your faced with the classic client server problem. There is going to be a huge amount of work to get devices configured, network creation, client server infrastructure if it has to be done without data, packet optimization. Very expensive and very high risk depending on how many restrictions there are.
Search for How to make a html5 group chat and then build on that example.
Possibly send commands to the chat delimited by a / character where a javascript could then execute the command.
Good Luck with your design.
Danny117
Related
To try out the nearbyAPI, I decided to build an app that would allow a teacher to track attendance of student in a class.
Similar to what Caren Chang is doing.
I have gone through the google sample codes on rockpaperscissors and walkietalkie
But only a single device seems to connect at any one time when i test the samples using 4 phones.
I want to build a teacher and student app which the teacher advertises and discovers students, sends payloads to each and every connected device simultaneously as more devices become connected in a classroom set up.
How can i use nearby api to connect and send data to new and multiple devices simultaneously?
That's a great use case, and one we've talked about in the past.
If it's specifically for attendance, then you don't need to form a connection. You can have each device advertise while one device constantly scans. You'll build up a list of devices quickly that way.
If you want to do more than attendance, though, such as pushing an assignment to everyone's device, you'll need to build a mesh. To start with, you'll want to use Strategy.P2P_CLUSTER. We have 3 strategies available inside Nearby Connections (CLUSTER, STAR, POINT_TO_POINT) and cluster is the most general one. With cluster, you can connect to as many devices as you want, and you can receive incoming connections from as many devices as you want. Or, almost... The Bluetooth radio inside phones is weak and can only hold 3~4 connections at a time.
To be able to connect all ~30 devices, I'd recommend forming a 'snake-like' connection. The head and tail of the device will scan and advertise at the same time (and devices that aren't connected to anyone are considered snakes of length 1). The heads and tails will keep connecting to each other (being sure not to connect to itself*), and you'll pretty quickly have a long chain of connections connecting everyone together. From there, you can forward messages down the chain to make sure everyone gets it.
To avoid connecting to yourself, you can either assign every device a random number (eg. 1, 4, 8, 10) and each device tries to connect to the next highest number, or you can broadcast a message when connecting and disconnect if you get an echo back (because the broadcast went in a circle).
I am planning on creating an application that will allow multiple devices running the application to send messages (urls/ids/strings) to a another device running the application.
So if I had 4 devices. Device A, B, C & D. Device A decides to become the host device, devices B, C & D will then like to see Device A through the app, and then send some requests to Device A.
My challenge is picking the correct/most efficient and cost effective method of doing this.
I have considered the following options
Peer-to Peer connection
Starting and running a server on host device on the fly
Push notifications
I have deliberately avoided the user of a middle-man server as I want to avoid additional costs as I do not have any foresight on how this app will do commercially. I secondly must mention that at any one time, I would not expect more than 10 devices would want to send messages to this 'Host Device' and no more than 50-100 messages to be sent over the course of 5 hours. So not to taxing.
All the devices would be on their individual mobile networks but potentially on the same wifi. I do not want to restrict this to being on the same network.
Any thoughts on what would be the best option in my case would be greatly appreciated. I am personally leaning towards peer-to-peer as it would seem easiest to implement and would do fine with the number of requests the host device would be able to handle.
Thanks in advance,
James
Considering they may be on different mobile networks and you don't need real time communication, I would consider push notifications.
And you can have problems with peer-to-peer connection across different mobile networks, it is probably blocked. And you would waste resources to connect/disconnect for every message, because you can't keep the connection running or you will drain the device's battery.
I'm developing a piece of software which consists on mobile clients and a machine acting like a server. This is for a highly trusted environment (not public), so I don't care much about security.
I want the clients to be allowed to perform a certain action only if they are, say, 2 meters from the server.
As the client is actually an HTML5 app, it would be better if the server perform the check, not the clients (maybe the clients can send its position to the server and then he performs the check), but if it cannot be done, it doesn't matter.
I have run out of ideas about how this can be done. I have thought about bluetooth and geolocation, but can that detect if the client is at least 5 meters nearby?
Is this even remotely possible?
You can use sound waves to do this. These links might help you get started:
How to estimate distance between two android devices? (bluetooth preferred)
http://www.ehow.com/how_6075947_measure-two-locations-using-sound.html
http://iqtainment.wordpress.com/acoustic-ruler/
I have to make an application to pair an iOS and Android device (iPhone 5, iPad 3, Galaxy S3, Nexus 7 they all use Bluetooth 4.0) and then send data to each other.
Is this amount of data limited ? Can we send something like a photo or a PDF?
I've already done the pairing and sending data between 2 iOS devices using CoreBluetooth and the sample code from Apple BTLE_Transfer
Of what i understood, a Peripheral (Server) can Advertise to a Central (Client).
This central is scanning around itself, and then try to find the Server by looking for the UUID of the service advertised.
When i make a Server on Android, it is waiting for a connection (listening), i know the UUID and the mac address of my Server.
But when i scan with my iPhone (scanning for the same UUID of course), i can't find the server.
So is there a possibility for the android server to advertise like the Peripheral on iOS?
Or maybe a possibility for my iPhone client to connect using the mac address of the server?
Q: Is this amount of data limited ? Can we send something like a photo or a PDF?
Bluetooth Low Energy was not optimised for sending large amounts of data, nor is it optimised for streaming. It is more suitable for sending small chunks of data periodically (e.g. temperature readings, time, etc). Please have a look at this answer to understand how BLE transfer is different from classic Bluetooth. That being said, you can still send large amounts of data over BLE, and the amount of data is unlimited. However, this might end up being unreliable and relatively slow.
Q: So is there a possibility for the android server to advertise like the Peripheral on iOS?
Being a server/client is a completely different thing from being a peripheral/central:-
Peripheral/central dictates how the connection is made. A central device should initiate the connection. A peripheral device should advertise and wait for a connection request.
Client/Server dictates how the data is distributed. The Gatt Server holds the data. The Gatt Client can read, write or be notified (getting a continuous stream of readings) of this data. In most cases, the server is also the peripheral, but this is not mandatory.
So to answer your question, yes, the server can advertise like the peripheral on iOS. However, for Android, this feature is not yet available and will be part of the next version (Android L) release. Please see this answer for more information.
Q: Or maybe a possibility for my iPhone client to connect using the mac address of the server?
As far as I know, in coreBluetooth you would need the UUID, not the MAC Address, of a peripheral device to connect to it. You do not need to know the services being advertised from the peripheral device. Your best bet would be to scan for peripheral devices, and then connect to the one with the UUID and/or the advertising data that u know belong to your peripheral.
I hope this helps.
I'm not sure. Bluetooth LE isn't good idea to transfer large files. In one request phone you have only 18 bytes.
Nexus 7 bluetooth chip has some defect - not work correctly.
Try free application for IPhone - Light Blue.
so...
First question: yes.
Second: Yes but it's not good idea. MAc address in Iphone is alternating every 10 minutes and all turn on/off bluetooth.
In general, sending large files is best done using an internet connection (over the cloud), there are many frameworks that can cut down the overhead for you.
However, the main question is still how to discover to which device you would want to send the data.
There could be multiple ways of doing that on your own such as using BLE or even sound.
To be honest, its a lot of work so if your app is end-user driven, i would suggest using a framework that can do cross platform discovery for you such as: http://p2pkit.io or google nearby.
Disclaimer: i work for Uepaa developing p2pkit for iOS and Android
Actually i am developing tracking app and want to send Location updates between two Android phones so that both can track one another over the Map. My application must get real time updates from other android device for better tracking.
I Have searched couple of techniques but don't know which one is best
Using Sockets: making one device as Server while other as Client
Possible Limitation:
What if IP address of Server is changed (because WIFI don't have a
static IP)
Cannot access if the IP address of server is private
Only client can connect to Server and Server cannot connect to Client
Using Intermediate Server: create an intermediate server and make a communication via that server.
Possible Limitation:
Slow because each Android device first send these updates to server
and then server push these updates to other android device
Please provide me your suggestion about which one is the best way to do this.
Since you didn't state the Device API level you want to support I'll provide you with an option for Android v4 (API level 14) devices. It's called Wi-Fi Direct and allows p2p connections between phones. It's essentially your socket approach, but allows easy neighbour discovery and allows transfers in both directions.
Well wifi is out.. Not for your stated purpose at least. Unless your map is quite small. Wifi is for say 100 meters (on a really good day)
Not knowing as much about android as I do of other mobiles, I'd say you're in for some pain.
I'd suspect connecting to your phone with a peer to peer might be a real slog.. some providers won't let it happen.
I have an approach more than an answer..
From an android phone, see if you can get your ip address.
From a desk, ping that ip address.
If it works, you're well on your way..
Id even say given the size of your info, you could use pinging as your main data carrier.
Pings can contain more than just random bytes. You could include an ID, and GPS in the contents you send in your ping. --- perhaps include a check sum ---
Do most of the work desk to phone, because development would be faster.. Then when your phone is capable of catching the pings.. Well then sending the ping should be easy as.