This project is my first experience with Arduino. My project is to create a Motorcycle computer that handles a bunch of different data and logs it. I have done a ton of research and have been through countless topics where other people have implemented something similar, but I still have a few questions about my implementation.
The setup is an Arduino Uno with ethernet shield connected to a small WiFi router located under my motorcycle seat. Then an Android phone app that I created using App Inventor sits on my dash displaying all the information that I want.
At this point I have it working pretty well and I am at the stage where I want to refine some things, so that leads me to my questions.
Right now I am communicating between the Android App and Arduino using /GET requests and responses occurring on timed intervals. I have different addresses called by the App which returns different data, but this means sometimes multiple requests go out at the same time and things start to overlap and it gets messy, especially at the high refresh rate that I want (ideally 250-500ms for speed). I want the speed data to refresh as fast as I can get, but the 0-60 data only needs to refresh every 5ish seconds or less. One thing I could do is put all the information into the same GET response, but then I have to send all the data at a high rate even though I don't need all of it that quickly. This would prevent any possibility for conflicts though.
Another feature which I am starting to work on now is utilizing the Position sensors in the Android to get lean angle information. I'm really not sure the best way to get that information from the Android app back into the arduino so it can be logged to the SD card. I would want this to be at a fairly high rate also, similar to the speed data.
As you can see there is starting to be a lot of data that I want to pass back and forth between the Android and Arduino at a fairly quick rate, and I suspect that I am probably not handling it efficiently right now. Any advice you can give me on making sure my data is transferred as quickly as possible without conflicts would be very helpful. Also I apologize for the long post, I wanted to give as much info up front as possible.
Example of compression:
instead of "analogRead 3 value 368" you could send "A3 368" using acronyms for often occurring words and skipping words that do not add value.
Using binary data means that a value like 368 is send as a 16 bit integer which only takes 2 bytes.
The Android receiving APP can expand this abbreviated info to a long text for the user.
I do not know how your protocol looks like in detail but I have seen many from which 50-75% of the data can be squeezed out by using above trick.
Do you have any suggestions on how I should handle the data measured on the Android phone that I want to send down to the Arduino? Should I try to have the Android app do a PUT command to the arduino? I'm also not sure how I should handle these different simultanious threads of send/receive data. It's almost like I need some kind of multiplexor setup.
After reading up on raw sockets a bit I think I am starting to understand how to implement them on the Arduino, but I am not sure how they would work interfacing with the Android app. I realize that is outside the scope of this forum but do you if that is something I can even do on Android without diving too deep into the unix below?
SurferTim:
Can you use UDP on the Android app? UDP can be much faster if used correctly, and it is much friendlier to raw (byte and integer) data types.
Just my opinion...
I might be able to, i've seen a few things that indicate I might be able to do that (specifically this http://ai.kittywolf.net/index.php/TinywebIP). This networking stuff is all new to me. The rest of the Arduino and embedded programming is what I do every day, but networking is something I've never touched.
If you want to see how it works, try the UdpNtpClient and UDPSendReceiveString examples included with the ethernet library. I use the same theory with my UDP stuff. The "client" device sends a packet to the "server" device, and the "server" sends a response packet back to the "client". I put client and server in quotes because technically there is no client and server in UDP, but to the NTP code, there is a NTP server. ??
I get about 10 packets (48 bytes/packet) per second, but I'm sure I could go faster and bigger. That is all I need right now.
Darn, looks like raw sockets and UDP are not possible with App Inventor at this time. I guess I could start digging into lower level android development.... But that is not exactly where I wanted this project to go.