0

I am designing a temperature and humidity logging system using microcontrollers and embedded C. The system sends the data to the server using GET method (could be POST,too) whenever it gathers a new data from the sensors. Whenever the power and/or the internet is gone, it logs to an SD card.

I want to send these logged data to the server whenever the internet comes back. When sent separately, each of my request is as follows and it takes about 5 seconds to complete even on my local network.

GET /add.php?userID=0000mac=000:000:000:000:000:000&id=0000000000sensor=000&temp=%2B000.000&hum=000.000 HTTP/1.1\r\nHost: 192.168.10.25\r\n\r\n

However, since my available RAM is very limited to only about 400 bytes in this microcontroller, I cannot buffer and send all the logged data in one request.

For an electricity/internet loss of 2 days, about 3000 of data set is logged. How do I send these to the server in a very quick way?

3
  • Using a for loop? It's unclear what you're asking and your title doesn't match your question.
    – CodeCaster
    Jun 17, 2015 at 11:11
  • @CodeCaster I am sorry for the confusion, I have edited the title and added more info to my question. Jun 17, 2015 at 11:26
  • 5 seconds was because of HTTP 1.1 keeping the connection alive. I have changed it to HTTP 1.0 and it is very fast now. Jun 19, 2015 at 12:57

1 Answer 1

0

Well I think a simple for loop will do it. Here is the pseudocode:

foreach(loggedRequest){
    loadTheRequestFromTheLogFile();
    sendTheDataForThisRequest(); // Hang here until the server returns a response
    clearMemoryFromPreviousRequest();
}

By waiting for the server's response, you will be sure that the data got to the server as well as that you will not have the ram full.

You can also go with an inner for loop with a fixed number of requests and then wait for all their responses. This will be faster but you have to do multiple tests to be sure you're not reaching to the ram limit.

3
  • This is currently what I am doing. However, it takes about 12 minutes to complete about 1500 requests.. Jun 19, 2015 at 7:46
  • 1
    @abdullahkahraman Well you should expect such a huge performance hit when going with such a limitation. On such a small hardware, I would go with UDP and not delete the data. When all the requests are sent, the microcontroller can ask the server which datapoints are missing and send those a second time. Jun 19, 2015 at 16:29
  • Thank you for the UDP tip. I will definitely think on it if my solution does not work, for example if it gets blocked by firewall because of multiple(about 500) requests. Currently I have understood that 5 seconds was because of HTTP 1.1 keeping the connection alive. I have changed it to HTTP 1.0 and it is very fast now. Jun 20, 2015 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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