Reputation: 1000
I'm working on a simple project in which i need to control a Arduino Robot (2-servo motors) through an Android
Phone's Gyroscope Sensor
, via Internet.
As you can visualize, 3-axis Gyroscopic Coordinates change quite sensitively even with little change in Phone's orientation in 3D space, so i want to minimize the Lag to milliseconds.
Now aside from hardware, my first milestone is to send Gyroscope coordinates from Android to a computer through internet as Fast and Continuously as possible (like a RealTime stream of Numeric data). I know traditional HTTP based Client-Server
mechanism will be quite slow therefore i've looked into following:
- Google's Chanel API
- WebRTC
- WebSockets
According to my research, Channel API shows latency that from 10ms to even in Seconds. Also GAE limits requests to 30 seconds. Here is a Channels API stress test: http://channelapistresstest.appspot.com/ Try clicking "send 5"-button a lot, and you will see latency numbers going up to several seconds.
Now WebRTC sounds most promising and faster than WebSockets. I'll be really grateful if someone can guide me about practical implementation of WebRTC in Native JAVA and Native Android (Any good libraries? i want to send coords. from Android and Receive via a JAVA-SE client on Desktop). I'm not interested in Hybrid App solutions (like Crosswalk
). I would also like to know about How should i setup a Signalling Server. Summing it up i have following questions:
- Which method should i use? (Channel API, WebSockets, WebRTC or something else) with native Java and android support?
- Incase of WebRTC, how should i setup a Signalling server? (just brief description) or a WebSocket Server for WebSockets?
- Can i make use of Google's Cloud platform or something similar to reduce complexity at my end?
- Any overall suggestion?
Thanks in advance.
Upvotes: 1
Views: 1987
Reputation: 5949
You do not want to use WebRTC. WebRTC requires you to setup a separate signaling channel like WebSockets anyway, so it is needlessly complex and very heavyweight for what you are trying to do.
If your requirement is simply to communicate a series of gyroscope values from an device to another, I recommend:
A simple server to print socket input to standard output is just a few lines of Python, for example. This does require you to learn to use sockets because your clients need to be interpreting the byte stream in the same way. You can also use WebSockets, but this may increase the complexity of your server significantly; Java EE is significantly more complex than Java SE, for example.
If you want data integrity (I imagine you do), you should use TCP.
If you are really worried about latency, you should also skip going to the Internet. Run everything on a LAN. I imagine you have to see the device under control anyway, so there's no point on going out to the Internet.
Upvotes: 3
Reputation: 1665
I would ignore WebRTC for this project. It is more complicated to setup and requires a special server.
WebSocket should be just fine for this project. It is as fast as TCP.
If you would like to avoid even this delay at all cost, but packet loss is not a problem, then I would go for simple UDP. For all these, you don't need any library, just a few lines of code.
Upvotes: 2