I'm developing an application that communicates with Arduino (Arduino Uno), I used two ways to communicate so far, via :
1. USB (I used the usb-serial-for-android and Physicaloid libraries) and
2. Bluetooth, sending and receiving data.
Via Bluetooth was a little slow and sometimes the information was simply not sent or received, the USB communication sending data was pretty fast, but still, sometimes the connection does not open, and it's very random, run the application and USB connection does not open, close the application, run again and the connection open, have not tried connecting via Wifi.
My question is this, what is the ideal and safest way to perform connection with Arduino?
Bluetooth connection is best, because HC05 adapters are dirt cheap and those use UART for communication (the same as com- port )
Related
How can I do these steps in android (Eclipse)? In a simple example. I am beginner.
For transfer data over wi-fi.
Server device opens a socket and listens on it.
Server device broadcasts the local IP and Port it's listening on.
Client devices receive broadcast and initiate a connection.
Transfer data between server and each client or clients and server.
This is very broad and would require a lot of code to show, and therefore I recommend viewing
http://developer.android.com/guide/topics/connectivity/wifip2p.html
WifiP2P is very cool, but can be tricky to setup. If you want to start playing around with wireless communication you may want to look at the BluetoothChat Example.
Bluetooth and specifically Bluetooth Low Energy are emerging as the standard communication protocol for Internet of Things. If you want to start digging into what you can do the example should work right off the bat with the latest version of Android Studio.
I am writing an Android app that manages two connections: one to a paired and connected bluetooth device, and one to a TCP socket connected to a particular host/port.
It acts as a tether for the second bluetooth device. Anything it reads from the bluetooth socket it writes to the TCP socket, and anything read from the TCP socket is written to the bluetooth socket.
My question is whether there is a canonical way to do something like this. What was meant to be a simple forwarder app is quickly turning into a more complicated threaded application.
The second bluetooth device has no data connectivity, and shouldn't even realize that it's communicating through a third party. It doesn't even know the host/port needed to connect to the TCP socket
I want to create a connection between my Android and a PC (or another device) just like in the Bluetooth menu from settings.
I have manage to get the list of all bt devices in my range and get their MAC addresses.
So, I have the BluetoothDevice, how can i connect to it or pair with it? I saw a lot of stuff about creating a server on PC, but I don't want that, i just wanna connect with the device.
My attempt were to get the UUID of the device and use createRfcommSocketToServiceRecord...but when i try socket.connect() it cannot connect (because I don't have a server). So practically I need to make the same structure that the OS is doing (connect with the device, if the connected device is trying to send i can receive the info and so on).
If I managed to connect with the device, I want to listen all that it is emitting, no matter the data...I haven't researched this topic, but any advice will be nice.
The connection must be made with any device that supports bluetooth, and I don't have access to it (of course the device is giving me the permission to connect).
Grab the Android sample projects by doing this http://developer.android.com/tools/samples/index.html
They have an app called BluetoothChat that pretty much does just what you want.
The thing about the 'server' is just in the connection, one side needs to open a listening port and that side is arbitrarily the 'server'. Once they are connected they are merely peers and you can write/read data till the cows come home.
I'm interested in the viability of implementing an Android application that interacts with a UDP service. I'm sure Android supports UDP:
http://www.helloandroid.com/tutorials/simple-udp-communication-example
What I'm less clear about is whether or not such an application would actually work on an Android phone on a typical tariff - for bidirectional communication. I want the Android client to contact a remotely hosted service by UDP (announcing itself) and for the server to subsequently notify the Android device about real-time events.
I'm concerned that a mobile device on a commercial network might be forced to change IP address - for example - when moving in/out of a Wi-Fi zone... and I'm unclear if NAT would be a problem on a typical 3G network.
Is it really viable to use UDP for bi-directional (best-effort) communications both to and from an Android phone?
There are a few issues for you to look at here. First, UDP is perfectly useable by Android. It can send and receive UDP packets just fine. The larger issue is really that the phone cannot receive incoming UDP connections that it did not open the initial connection for, unless it is on WiFi and rhe connection is coming from the same LAN.
On 3G/4G the phone is not addressable from the outside because the Wireless carrier has in place a firewall with a proxy server. So, incoming connections are not passed over that firewall. If, instead the phone opens the connection from behind the firewall, then bidirectional traffic can flow over that link.
Now, the problem you will have will be
1) Keeping the link alive when the phone goes from network (3G) to network (Wifi)
2) Battery life from the constantly open connection
Most likely, you really want C2DM for what you are looking at.
I have an application that needs to keep the bluetooth discovery process in a loop to always discover new bluetooth devices (when the BroadcastReceiver gets a BluetoothAdapter.ACTION_DISCOVERY_FINISHED, I just call the startDiscovery() again). I've recently added some socket communication to the app, that basically opens a Socket to a server, sends data and then closes the socket.
When I'm using 3G, everything works fine and a sniffer shows no TCP Retransmissions, the socket is cleanly opened and closed. Using Wifi, however, shows lots of TCP Retransmissions and sometimes even failures to connect the socket (with java.net.SocketException timeout).
I'm using a Samsung Galaxy S with Android 2.2.1. Is there something I'm overlooking?
Can you try to configure and move WiFi to a different channel ? If you are using WiFi also in the 2.4 GHz band interference is expected specially during initial discovery / connection, after connection it should become better as Bluetooth should frequency hop to avoid interference (unless WiFi is clogging the complete spectrum)