문제

I want to send sensor data from an Android device to a Apache web server. The sensor is connected to the Android device using the IOIO board and is sampled at an regular interval.

The raw sensor data is approximately 1 byte/second and I'm trying to find an efficient way to send this to the web server which is based on Apache and has support for PHP and ASP (ChiliASP I think).

In order to have a low monthly cost, I would like to use pre-paid mobile subscription and these usually have a fixed maximum data limit (something like 500 MB/month).

Since the sensor should send data 24/7, I would like to keep the required data traffic at a minimum. Even if the amount of data is not very large, I think that the overhead in terms of protocol headers could be an issue. If each sample (1 byte) is sent separately, the overhead/payload ratio will be very poor. On solution is of course to aggregate some data and send it in bigger chunks.

I have successfully tested Java HttpURLConnection to send data using an HTTP POST and have some questions about this:

  1. How large is the overhead due to HTTP headers? Is there some easy way to measure it?
  2. Is there some other protocol supported by Android and Apache which I could consider?
도움이 되었습니까?

해결책

You can use a simple HTTP GET/POST request and send json encoded data as parameters to a web service implemented in php or any other language of your choice. I don't think it get's simpler/smaller than http get/post and json (unless someone can correct me). JSON is an excellent, easy and flexible format for data interchange and is much simpler and more concise than xml. JSON parsing is available natively in most languages including Java, JavaScript and PHP. It also very widely used.

An HTTP get request, for example, doesn't have much overhead except the length of parameters you wish to send. Here's a typical GET request:

GET /pub/WWW/TheProject.php?arg1=foo&arg2=bar HTTP/1.1 

arg1 & arg2 are the arguments I'm passing to TheProject.php.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top