Streaming data from an Android device to a PC via USB - android

I need to stream a set of numbers, 6 floats, from an android device to a PC, to which it is connected by a USB cable. All the solutions I have found proposes using a WiFi connection. However, I have found that the latency caused by this is not acceptable. As such I have decided that I am going to hire someone to integrate the components, thus enabling direct communication. Until then, however, I want to try a variety of devices to see what works and the quickest way to "Integrate" two devices is by allowing them to share a (US)Buss. However, this is the one field I have zero experience with.
Do you make a socket and treat the connection as a network connection or is there another fancier way to achieve what I want? I have seen some talk about making a device driver for this purpose and I do not feel like crashing my OS 500 times again. I find it hard to believe that the android devices do not have some kind of driver already made that I can exploit.
The android code is written in Java, but it could be changed depending on what people suggest. The main chunk of mys system lies on the PC and is written in C++.
I need the latency of the stream to be as low as possible since the entire system needs to be as real time as possible. The limit is 15 ms between data acquisition on the device and the rendering of the simulation on the PC.
TL/DR: I need to stream data from a program on an android device to a PC with as little latency as possible; i.e. one way communication. As long as I can stream bytes I can design protocols and translate the bytes on the receiving end. My global cap is 15 ms and I need to stream continually updated 6 floats. What is the best way to achieve this?
Thank you in advance for your help.

Raw USB is probably not the way to go. USB is a device-oriented specification and cannot be used in a general send-arbitrary-bytes-across-a-wire way.
If Wi-Fi really is too slow, you could try purchasing an Android-compatible USB-Ethernet adaptor and connecting the device to the computer via a wired network connection, which might reduce the latency. Android recognises many types of these adaptors and you communicate over the network connection in the same way as other networks.

We ended up using the ADB brigde and it seems to be stable and fast enough for our purposes. All we had to do was to open a socket and connect with TCP. For some reason it fails when we try to connect with UDP, but I assume this might be due to ignorence on our part.

Related

Sending a lot of data from PC to Android via Wi-Fi

I've developed applications which handle a connection between a PC and an Android phone via Wi-Fi. I try to send a lot of data really often. The TCP/IP protocol, which I used, allow me to achieve just low speed - around 1 Mbit/s. I found that with 802.11n standard we can achieve speed up to 150 Mbit/s. I've set my router to use only 802.11n standard, but I didn't notice any improvement.
What level of speed should be expected? I understand that part of data is lost, but is there any better solution? Any ideas? Where can I find some information to better understand this topic?
You should expect much better performance running 11n with TCP/IP, perhaps 20 Mbit/s in a good environment. But since it is radio, the medium is shared between all users of the air so it is not easy to give a good answer that is valid everywhere.
A tool to test your network throughput is Iperf available on Google Market for your Android device and on Sourceforge. You could use this to see if it is your application or external factors that might affect performance.
If you want to debug it further, you could use Wireshark together with a Wi-Fi sniffer card to see individual packets/transmission rates and retransmission.

Android stream audio to other devices

Hello I'm in the early stages of an app and part of it i need to stream audio from one device to multiple devices. I have been googling around looking for the best solution on doing this so far i found these two projects each with problems.
Spydroid http://code.google.com/p/spydroid-ipcamera/
Problem The problem with this one is it creates an rtsp stream which is limited to one connected device. If i browse to the link on both of my computers i see both clients connect in the app but then the second one to connect instantly disconnects and the app says my phone doesn't support this feature. I dove into the source and found in the Session.java file there were if statements with comments above them saying prevents two connections from being made i commented out the if statements and the catch clause caught me after running it. This project would be perfect if i could get it to work with multiple connections as it works over 3g.
PttDroid http://code.google.com/p/pttdroid/
Problem The problem with this one is it allows me the multiple connections i need but i only can get it working over wifi. It says on the home page there that it works over 3g but only the unicast i need multi cast over 3g and wifi and i was unable to get the unicast to work as well over 3g.
So my question comes down to this what path should i go down and look more into for streaming audio from my android device to multiple computers and other android devices.
Thank you very much for any help!
Cellular networks do not usually support multicast packets. The cellular routers simply don't route them, so that is a dead end.
You thus need to do unicast to multiple destinations which may be challenging for the limited cellular bandwidth of the phone. You are very likely to run into contention on the cellular bandwidth with just one or two streams, even if you can get them running out of the same device. (Multiple Spydroid streams of the same file for instance.)
If I were building a system to do this, I would consider setting up a server to do reflection. So I would look to use something like Spydroid to run an RTSP stream up to a server and then reflect that off the server to a number of subscribers. This is not a small project but would allow you to stream to multiple users using the servers higher bandwidth.
There is apparently a project going after this reflector strategy here:
https://code.google.com/p/js4ms/wiki/RTSPMulticastReflector
I have not tested it at all to know if it works, but that should at least get you started on the right path.

how to control pc mouse from android device without client server

I need to create an application that control PC mouse(pointer) through android device without downloading a server on pc, it should be able to communicate directly with my pc I already checked out the remote droid application but the user would need to download a client server to communicate with the phone
so is there way to remote control pc mouse through phone without downloading a client server on pc?
note: I am working on android 2.3.3 thus i cant use wifi direct and usb accessor
Why not just simulate regular bluetooth mouse, a standard bluetooth mouse which has its drivers as part of most os's.
no one can control your pc remotely without bluetooth pairing.
in theory i think it should be possible, but it requires knowledge in hardware and low level software (so its not a task suitable for most developers).
It doesn't matter what the client is, the fundamental question is "Can you move the mouse cursor on your PC from anywhere without installing software"
The short answer is no - which is a good thing! Otherwise, anyone on your network could just take control of your PC...
That said, you could, in theory, create an RDP (Remote Desktop) connection and use that to control the PC as a whole - but that is very complex, has been done already and would still require the user to allow remote desktop connections to the computer (Control Panel->System->Advanced->Remote)
Edit - Bare minimum app:
There are a number of ways to approach this but the absolute simplest app I can envision involves having an application on the PC listen for connections on a TCP/IP port. You'd then send messages to this port from Android using the Sockets classes.
The app would receive these messages, parse them and perform the appropriate mouse actions.
Make sure that you include an authentication/authorisation mechanism - you don't want random strangers to be able to control your PC just because they broke your wifi.
You may find it easier to build the desktop app to accept messages using the HTTP protocol (RFC) - This is a standard, widely used and very flexible mechanism for client-server communication. Why reinvent the wheel? This would also make your Android-side code far simpler as you could use HttpURLConnection and other similar classes which abstract the complexity of managing sockets.
You may also want to consider if the app should provide any feedback to the client - eg the new mouse position or a success/failure.
NB: Running the app as a windows service or website might seem preferable to a desktop app (doesn't need to be started by the user, nothing in taskbar/system tray) but there are considerable drawbacks to both - Windows services can't interract with the desktop easily (what happens if nobody is logged in?) and websites run as a different user so in addition to not having the same desktop, they have limited permissions.
It might be a case that i misunderstood the point. I think however that you can play with the BT protocols. If you find a way to recognize the phone form the pc like a BT mouse you can control the pointer. I think some of the low end SonyEriksson phones had that option build in.(SE880i).
Though I am not sure how the driver problem will be solved.
Regards
TT
If it is possible to plug into PC's USB Then
Arduino mouse using a cheap Arduino board
https://www.arduino.cc/reference/en/language/functions/usb/mouse/
Arduino wifi or bluetooth using same or another board (or connect by Serial, UART, SPI, I2C cable).
software on cell phone (Android) to connect to wifi/bluetooth
Some hacking at the C level.
Notes
- no driver on the PC
- Could do the same with PIC32 (even with
PIC8/16 but might take longer).
This is a typical real world IoT type project.
As a project it is between 40 and 160 hours to demo prototype for an experienced consultant. Parts cost estimate under $400 besides cell phone cost.
120 to 500 hours for 20 production prototypes + layout and assembly cost about $4000.
Production target unit cost under $25.
In other words a neat Kickstarter project.
Experienced soft/hardware & lucky hacker could do it 24 to 36 hours.
In Micromax q2+ Iam able to access the bluetooth - remote control and after pairing be able to move the mouse to my pc. One thing is am unable to do any action events.

Live data transfer over USB

I'm trying to figure out how to transfer frames rendered on a computer to an android phone. Wifi and Bluetooth aren't fast enough for a smooth framerate, but the data transfer speed across the USB connector is more than enough (up to 480 megabytes/ second). Thing is, I can't figure out how to do it- there's nothing in the Android docs and I haven't found anything online. How can I access the USB connection?
You can't access the USB connection in any documented and supported fashion.
It's not possible at all? Are there any hacks that allow it?
It's not an app for publication, and I don't mind messing with my own phone.
Try turning debug mode on and using adb to connect to the device. You can manually push files to the phone (e.g. to the sdcard) which you can in turn periodically check in your app. You can also write files the other way around (from your app) and have your PC app check that file, again over ADB. That way you can establish simple protocols for communication.
I also need this right now, but a bit more difficult since I try to access the phone from an programmable integrated device with USB host chip inside. Which probably means reverse engineering ADB...
Either way, it's a pretty hacky solution but it should work over all phones as long as debug mode is turned on, which makes it feasible.

How to utilize network for p2p file sharing on Android Platform?

I'm working on some apps for the android platform and I have two problems that I'm not quite sure how to approach, and both are closely related.
How can I send a relatively small data file from one android device to another (preferably over the internet or directly through wireless network)?
Is it possible to create a temporary p2p live data stream from one android device to another? An example application would be to stream low-res video from phone A's camera to phone B, or audio.
I would much appreciate being pointed in the right direction on either issue (File transfer or real time data transfer).
You could try to get Google's library libjingle to work on Android. It provides quite advanced NAT Traversal capabilities, which should be able to get through the carriers' firewalls.
One approach would be to use the socket classes in java.net.
To use WiFi to send data among devices, you can try to establish an ad-hoc network among the devices that will communicate. I think you can use Android's WiFi API to do that. Once you have the ad-hoc network setup, you can establish a simple TCP connection between the devices and transfer the files.
Sockets do not work between phones. I've tried with two actual phones using socket communications and there seems to be a firewall in the carriers that prevents communications on ports different than port 80. Then if you try to use port 80 you get a 'Permission Denied' exception.
One possibility is to investigate the JXTA framework. The Practical JXTA II book is available online for reading at Scribd.

Categories

Resources