4

For my university senior project, I've been tasked with creating an Android app that will function as a HUD for the driver of a Formula Hybrid vehicle. The Raspberry Pi will gather all sorts of data from vehicle sensors (RPM, engine temp, battery temp, fuel level, ect.). The Pi then sends this data through some interface over to the phone (USB, presumably).

I could also go the route of using PiUI and could perform all design and implementation on the Pi itself, using the Android phone as a display only. However, this method uses WiFi in order for the phone to connect to the Pi-hosted server. I'm concerned that this method might not be in real-time.

In your guys' opinion, is there a preferred method? I think the most elegant solution is a dedicated Android app that interprets data sent over USB, and updates the UI accordingly. However, I have yet to find a way to interface an Android app to Pi software over USB.

1

However, this method uses WiFi in order for the phone to connect to the Pi-hosted server. I'm concerned that this method might not be in real-time.

If you are on the same WLAN and you do this properly then I'm sure it will be fast enough. You could stream video from the pi to the phone over the air this way no problem, and the amount of data you are talking about is obviously substantially less than that.

If there's some kind of real time latency, it will be in the processing on the pi itself, not in the network (unless it's very congested, which a LAN should not be if it uses appropriate equipment). Point to point communication on local wifi networks is generally instantaneous.

I think the most elegant solution is a dedicated Android app that interprets data sent over USB...However, I have yet to find a way to interface an Android app to Pi software over USB.

IMO it sounds more awkward than elegant; since the pi's wifi is on USB and it's the USB bus that's the bottleneck there, this won't be any faster. It is possible; Android has an API for USB, obviously, as does linux, but here's the catch: the linux API is not a userspace one. I.e., you might need to be writing a kernel driver for communicating with the phone. There is also libusb.

You could look into the source code for adb, not sure if that is C or java. It does not involve a special kernel driver, implying there is some option via a generic userspace interface.

At a glance, having flirted with the kernel USB interface before, I'd say you are looking at way, way more work this way, to accomplish something that is going to be no faster, and much more awkward, than a wifi one.

Using network sockets, OTOH, is relatively simple. If you haven't learned network programming yet, you might as well now. It's certainly going to be a lot more generally useful than knowing how to write a USB driver. Not quite as cool of course.

1

If I was doing this I would use nginx and PHP CGI, Its fast and low on resources. Instead of USB I would use WiFi or LAN conenction. USB Host on the Pi is more complex.

Create some static HTML pages. You need to read on the internet how to set headers for Android/Iphone to make it work like an "APP" if thats what you want.

I would then create bash scripts that does a specific task of gathering data for a certain thing and execute them from the PHP. This is not the preferred way to do it on production but its easy for secured networking. ie, not internet. Output your data as JSON serialiased objects.

Create a PHP "API" that executes the script, binds the data to an onbject and return that onject as JSON. This way, it is extensible, meaning you can create your "APP" or allow other thigns, like computers, of Text Overlay to request data from the PHP paths.

On your static pages you would use jQuery, they can consume JSON easily, and build your HUD using any other jQuery plugins. The PHP part would be purely for data, and the website would be simple HTML pages.

If all this is way over your head, then the PiUI is a pretty good example of what I described above. Not sure if it has an API though, where you could get data and use it how you like though.

The concern of realtime is hwo you implement the scripts. jQuery AJAX can be run to do allot of requests locally, but ideally, like goldilocks suggest, you might want to use sockets instead, which is more involved. But you can look into NodeJS

You can also do this in Perl or Mono C#. It all depends on what programming language you are most comfortable.

You could also just pump data out the UART port but you need to create and conform to some kind of data model so you can reliably parse the text on the other side.

  • 1
    Check for 'volley' Android lib ... – Michael D. Nov 19 '14 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.