can anyone recommend a method for low latency bi-directional com link between my pc app and android slave app. the app i have works now via wifi but the latency is too slow (about 300mS), i'm looking to get it down to 10mS or so.
the android is acting like a glorified remote control to the game on the pc. the apk displays a low res image and sends button presses back to the game and the round trip need to be quick
i'm thinking the only option beside the network, is to connect a usb cable but i don't see a lot of support for that path and not even sure it would be lower latency than wifi
any ideas please?
USB would have much lower latency, and there's plenty of USB support in Android. Check out http://developer.android.com/guide/topics/connectivity/usb/accessory.html Bluetooth may also be an option, but I'm not sure if it will get you to the latency you want- USB can.
Related
I have a photo-taking Android app (written in React Native, but I can add native modules if need be) that pairs with a gallery-type app on the user's computer (written in Electron with React). The number of photos can be large (we've had upwards of a thousand photos at a time), and they need to be transferred, uncompressed and uncropped, to the computer app. I need a reliable way to do this without routing the data through the Internet first.
Things I've tried
Node USB: Looks like a good library, but is unusable without installing a driver on the user's computer. The driver then appears to replace the default Windows USB driver, and the phone becomes inaccessible through normal means (opening a file explorer in Windows). Perhaps there's some way to switch drivers "on the fly", using the driver only while transferring photos, and then switching it back out for the system driver once we're done?
ADB: This is the original solution I tried, and it does exactly what I need it to, with two dealbreaking problems: for one, the phone needs to have Dev Mode enabled, and for two, ADB doesn't seem to recognize all devices (we've had a lot of trouble getting it to work with an LG V20, for example). The ideal answer to this question would be something like ADB without those two issues.
WiFi routing: we connect the phone to the same WiFi network as the host computer, use WebSockets to handshake IPs through the Internet, and then initiate a direct connection over the WiFi network. If I cannot find any other solutions, this will likely be the one I'll go for. The biggest problem with this option is the relatively large amount of manual setup required. Our users don't tend to be very technically savvy, and I don't know how reasonable it is to assume they will have WiFi in their home. At any rate, this cannot be the only option for transfer. Further, transferring gigabyte(s) of photos over the wireless network will cause a slowdown for everyone on the same network.
Tether routing: we tether the phone to the computer, and initiate a direct connection much in the same way as in the above step. The downsides to this method are that only phones with SIM cards can activate tethering (not all of our phones have SIM cards, as connectivity isn't their primary purpose for our needs), plus all of the other traffic on the computer will now be routed through the phone, which would be bad for customers' data caps who do have SIM cards. Additionally, there is no way to programmatically turn tethering on, there is only the ability to bring up the tethering menu; it's not too big a dealbreaker, but the other two very much are.
Bluetooth: Generally meets my requirements, but the data transfer rate is far too low, being an order of magnitude below WiFi.
WiFi Direct: I did not actually try this, because I could not find a working way to have the PC accept the WiFi Direct connection. It promises exceptional speeds, but there are no modules or libraries that I've found that would help me enable it.
SD Card: The lowest of the low tech methods, just save everything to the SD card and have the client take the card out and plug it into their computer. Would hands-down go with this, except for the need for a SD card port (guaranteed neither for the client's computer or their phone).
The obvious: manual drag and dropping required files from the phone to the PC. This is how we do things now, and it's fraught with problems. Text files have the last 15-20 characters cut off from them, for some reason, during transfer; many of the photos on the device do not initially show up due to the known issue with MTP not forcing a media rescan on the phone; and users sometimes drop files in the wrong places, leading to unnecessary support calls. This method surely needs to be replaced.
I've been searching for a solution for this problem for two months now, and it's hard to believe that nobody has had a use case for Android like this. It's been made clear that USB communication between Android and PC is non-trivial, I'm sure there are programs that do that, Windows to start off with. Yet try as I might, there are no solutions that work out of the box. Has anyone dealt with an issue like this before? What were your solutions? How would you approach this problem?
When downloading large files on Android it is recommended to use Download Manager, it supports a lot of native features like the progress bar, and notification, also the download task will be handled by OS, and more efficient.
React Native Fetch Blob library support this feature
You dont really need to route the data through the internet.
You can just exchange meta data through the internet:
Extend your desktop app with folder-import functionality (Plug your phone normally via USB, brose to the folder, import).
When you execute this process, let it notify a webservice of some sort (push notifications? Im no phone-app dev.) with which files the desktop-app has imported from which device (ids, filenames, ...) and the phone gets this meta data and can continue its process of whatever it is doing!
Obviously the best solution is a communication channel over USB. Until you figure that one out, you could implement it temporarily this way!
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.
I'm starting a project where I'm going to try to write a program for Android that will control and/or send/receive input to/from an Arduino gadget. Like, make an LED light blink, as the simplest example. I can either get a Bluetooth shield for the Arduino board and go the Bluetooth route, as per the example Androino! Control an Arduino from your Android device using a cheap Bluetooth module.
Or I can buy a USB host shield for the Arduino board and have the phone talk to the Arduino device via a USB connection, as per the example Adventures in Android ADK Development: Hardware.
Which implementation option is easier and more foolproof both from hardware setup (soldering? compatibility issues?) and programming perspectives (additional Python scripting required? 'listening' on Android for a Bluetooth device vs. a USB device and sending data back and forth?) I've been doing Android development for a couple of months, but I have NO experience with Arduino.
I don't mean this to be a lazy question - I'm able to do the research, but I'm inexperienced and am trying to choose my implementation right away so I can order the right hardware stuff in time for a deadline. I have to make sure I choose an implementation I can actually DO.
EDIT: Might it be easier still to use an ethernet shield on the Arduino board and have the Arduino gadget talk to the Android phone via TCP/IP? I don't know why this didn't occur to me from the beginning. But there seems to be far less in term of tutorials on this kind of implementation, for reasons I'm unsure of.
I am currently working on a project that interfaces an Arduino and an Android phone via bluetooth. And from my experience so far all I can say is STAY AWAY!
All the articles online about cheap bluetooth modules working perfectly are highly misleading to say the least. It might be easy and perfect if you buy an $80 shield, but not if you're on a budget. I bought a $30 shield and it only seems to work on one of the seven Android devices I have tried to use. Furthermore, it seems completely unresponsive to the standard bluetooth connection methodology and requires a host of workaround/hackish method calls that are all highly unsafe and unstable.
On the other hand a USB connection is far more reliable, better supported and of course has the inherent advantage of speed and since it is well supported does not suffer from all the pitfalls bluetooth connectivity does. It is just as easy to setup from a hardware perspective (no work required if you get a decent shield), reasonably priced compared to bluetooth shields and in my experience generally easier to code.
If you are on a budget and can do with a hardwired connection I highly recommend USB over bluetooth.
I don't know the details of either. But I would say if the phone is going to stay with the board then use USB. For lower latency and in general, I find a hardwired connection to be better for all applications.
I have no experience in Arduino and some decent experience in Android and I decided to get the usb connection to work from the phone to arduino to light up the led.
I used a Nexus One and an Arduino Mega ADK and I got the usb connection working in around 5 hours of tinkering and I was absolutely excited to get the led to light up when I clicked a button. But then I decided to go to the next level because bluetooth sounded way too cool to pass up.
Anyways around 30 hours later I FINALLY got it working and I can say it was COMPLETELY worth it. There was a TON I needed to learn, but once I got it working I can say it was not all in vain.
I bought the Bluetooth Itead V2.2 shield ($25 for me) then connected it to my arduino and used my Nexus One with Amarino to send a signal to my chip and turn off and on the led.
http://iteadstudio.com/store/index.php?main_page=product_info&products_id=468
From my experience it was definitely difficult, but the learning curve is what makes these projects so fun. So I would say GO FOR IT!
Good luck in your future works!
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.
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.