creating HTTP persistent connection, to create 'smooth' data over GSM sending Project goals


Send data over GSM to firebase
Fast sampling - need to send 16 bytes every half second to firebase
Send data using GET or POST to server with PHP script, that redirect data to firebase


Problems -- 
Extremely low data rate! 


Using standard GET or POST request from client(arduino) side, is impossible to achieve second (2) project goal.
To send data correctly I need to close connection with server, so next data package unfortunately waits(2-6 seconds) for establishing a new connection.

Is this quite nonsense? I'm using ArduinoHttpClient library.


My actual Nonsense Connection and fully useless, but works


while(1){

http.post("/test.php","application/x-www-form-urlencoded","data=0");
http.stop(); //closing connection with server

//next instruction take over 5 second to establish new connection :(

http.post("/test.php","application/x-www-form-urlencoded","data=0");
http.stop(); //closing connection with server, whyyy?
}


Data are send once per 2 - 6 seconds, this is not even funny. NEED to send data every 0.5 seconds!

So I decided to create super solution, which not works :C

while(1){ 
    http.post("/test.php","application/x-www-form-urlencoded","data=0");
    delay(xxx);
//no connection closing, no wasting time for establishing new one :)
}


Just tell my why this connection is not "Keep-Alive", also used with 


  http.sendHeader("Connection: Keep-Alive"); or
  http.connectionKeepAlive();


//First run
http.post(blabla);// returns value: 0 &amp; data are logged into firebase
//Second run
http.post(blabla);// returns value: -2 &amp; data are not logged in firebase


my test.php file

&lt;?php
require_once 'firebaseLib.php';
$url = 'https://czujniki-aa5ca.firebaseio.com/';
// --- Use your token from Firebase here
$token = ':-CCCCCCCCCCCCCCCCCCCCCCC';

$arduino_data_post = $_POST['data'];
$firebasePath = '/';

$fb = new fireBase($url, $token);
$response = $fb-&gt;push($firebasePath, $arduino_data_post);
sleep(2);
The ArduinoHttpCliemt library's HttpClient.stop() method does two things. It resets the state of the HttpClient object and stops the underlying Client connection (TCP connection). If HttpClient.stop() is not called, the internal state is not good to call get() or post() again.

The method resetState() is called in HttpClient.stop() to reset the internal state of the HttpClient object. But resetState() is protected. To call it we must modify the library header file.

In HttpClient.h make resetState() public (by moving 'protected:') and then in sketch call resetState() before post(). It will put the HttpClient object into initial state without disconnecting the underlying TCP connection.