I spent a week looking for a convenient answer to my question. I am trying to connect Android to Arduino through Cloud, Where it has 2 operations:
Arduino can trigger a push notification to the android device anywhere.
Android operates Arduino through Cloud.
now the first point is easy to be done, by having a 3rd party server where Arduino POST user credentials (can be configured when the device is bought) with the message to PHP server then the server will get GCM's Registeration ID from MySQL and POST it through cURL to GCM to push notification to the related Android device.
or by using Arduino YUN, we can directly send cURL from Arduino itself.
However for the second point where I am stuck, I can't figure out a way to maintain the IP address of the Arduino without actually making the user to enter the IP address of his Internet in the Android application interface.
The solutions I came up so far:
Connect another Android device to Arduino at all the time using ADK then it will become a communication between Android device with another Android device through GCM and the GCM will handle getting the IP addresses of both.
Using MAC address to get to the Arduino but this is insufficient approach because the MAC addresses are hard coded in Arduino, and then spoofing may occurs.
I am not convinced with the proposed solutions so is there a possible way to use GCM or any similar system like Parse in Arduino and make it have a unique registration ID just like android then I can map the user's Android registeration ID with the related Arduino registration ID. or can anybody give me another solution or method I can follow. Thanks in advance.
P.S: I dont want to use static IP address or Port forwarding, the idea of this project is to create a device that is user friendly and doesn't require a lot of configuration from the customer.
Knowing that your Arduino already communicates with a third-party server, you can take advantage of it and additionally get the IP address of the Arduino device making the GCM id registration (in PHP you'd do this by using $_SERVER['REMOTE_ADDR']).
This way you can keep a 1-to-1 identification of a GCM id and a public IP address to know to which Arduino device to send the signal.
This would need that you implement some timeout process (for instance, implement a keepalive system and if a device doesn't send a POST request each X time, just remove it from whithin the connected devices). Also, if the same device connects from two different IP addresses, just keep the last one so you're not mixing up.
Related
I have seen examples of Arduino acting as a server using the Ethernet. But I am working on a project that requires my Arduino to act a server that will listen for client requests using no Ethernet, but only GSM/GPRS shield. I have a SIMCOM SIM808 GSM/GPRS/GPS module.
I will have my Android send requests to that Arduino & the Arduino will perform the operations accordingly. I have searched a lot, but haven't found any such example. That got me wondering if it was even possible? If yes, how?
Do feel free to direct me to links / posts that have such tutorial.
Thank you for your time.
of course it is possible.
GSM/GPRS shield will convert data to serial.
You will need to configure it with AT commands.
The main problem I see here is that GPRS will not have a fixed IP address, so you would not be able to reach it if you don't know the address.
Somehow the Arduino should send you every now and then its public IP address, which I am sure you can retrieve with an AT command.
Except also your mobile will not have a fixed IP address.
So you'll probably need a server in between to record IP addresses.
I am actually working on this type of problem, but use different hardware and libraries, so I am not able to help you more at the moment.
I will soon have a project on Kickstarter for this type of solution.
I am trying to make an Android app that is supposed to send messages between two clients via their IP address.
I currently have a set up that enables a server that runs in the background that listens for incoming messages and its address is the device's IP address. However, I am not able to reach this server unless both devices are connected to the same network.
I want to know if there was a way to send the message to the router, which will then send the message to the specified device via its port number or another specifier, instead of sending the message directly to the device's IP address.
I have been searching and found that some instant messaging programs have a similar kind of set up and I read that Net Send used to do a similar job in previous versions of Windows. I have not been able to find anything that relates to doing this on Android though. At this point, I just want to know if this is possible and if someone could guide me in the right direction. I am just not sure if this idea is possible.
I want to try my best not to have a single dedicated server that all messages are sent to, then from there the server distributes the messages appropriately. I would rather have each device run its independent server in the background so it can be reached from any other device globally.
One way to accomplish this is to set up port forwarding on the router for the server hosting this application.
There may be complications, depending on how the application works. If it does use broadcasts, you are not going to be able to get it to work as you have described. If the application uses an IP address and port, then port forwarding on the server's router will probably work, but you may need to adjust settings in any firewall protecting the server.
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.
I'm trying to learn android and for my app i have few questions.
If i type a computer name on the EditText in my android phone, I
should be able to ping the device (So basically i need to first
resolve the ARP to get the mac address of the device which I want to
ping and then send the ping as an ICMP request).
I believe there is some command to retrieve the computer name and
send this ping command, but i would like to do it the hard way so
that i can learn stuffs better - It would be nice if you can show me
some pointers to some tutorial apps and open source code which does
similar tasks.
Once I have identified and connected to the device. I should be able
to start a chat with the device.
Assume the second device is also an android device, how can I
establish basic message sending from one android device to another.
Basically my app will be a client and server (I guess 2 services - service listening to sockets for incoming messages and client can send out messages).
Does anyone know any sample app / tutorials [basically code examples] which does this in android.
To Nr.1
I'm not quite sure why you first need to ping the device, as you could simply try to connect to the given device (using a timeout) and see if it can be connected.
I found some informations on this, here.
To Nr.2
So, if you want your Devices to communicate to each other, you'll want to use Sockets.
But, if your App is only for chatting and you don't need to know if the last send package was successfully send, you could also use UDP instead of TCP (So you don't need your application to run both the Server and the Client-Socket).
Although, all your questions could have been answered by doing a little googleing...
I am developing a multi threaded client-server Android app in which both clients and the server are android phones( the server is not centrally located) and are located in the same network, under the control of one single router.
The server will start the application first. When the clients starts the app, they should get the IP address of the server phone automatically, so that when they click the address, they can be connected to the server.
Right now, I have made a provision that the server phone displays its IP address on the screen when the app starts running. When a client starts the app, it is provided with a text field in which the user can manually type the server's IP address and get connected to it.
Can anyone give me any pointers on how I can get the server's IP address to be displayed on the client phone automatically? Do I need a central database or something like that? I am new to android programming and don't really have any idea about this.
See if this is useful: Android IP address with java
You might want to think about implementing a UPnP solution. See this Universal Plug and Play as a starter then check the links at the end for relevant docs/references.
UPnP doesn't require devices to explicitly know the network details of other devices and instead they locate each other using a discovery protocol (SSDP).
One solution is to ping local IP range in a loop. Put a small timeout duration. It would be better if you run it in separate threads. If you get ping response, this would mean the server is available.