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


http.stop(); //closing connection with server

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

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

//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 & data are logged into firebase
//Second run
http.post(blabla);// returns value: -2 & data are not logged in firebase

my test.php file

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

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

$fb = new fireBase($url, $token);
$response = $fb->push($firebasePath, $arduino_data_post);
  • does the 'modem' disconnect from network with no active connection? search for a setting to keep the GPRS connection connected
    – Juraj
    May 22 '19 at 5:05
  • @Juraj i think modem doesn't turn off networking itself, I will check the code and post back. If it will not work, i will test it on pure AT commands. May 22 '19 at 9:30
  • try in the library in HttpClient.h make resetState() public (by moving 'protected:') and then in sketch call resetState() before post()
    – Juraj
    May 22 '19 at 9:48
  • @Juraj [link] (ibb.co/7rc2Yt8) look at the screenshot. resetState() is working fine, and now we dont need to use stop(), but essentially it works like .stop(); Look at the timestamp, delay between data uploading is still awful. 0 means 0 error code, so data are send successfully May 22 '19 at 10:18

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.

  • Yes that's work, but time between POST's is still huge. [link] (ibb.co/7rc2Yt8) screenshot May 22 '19 at 13:35
  • add #define LOGGING at the beginning of HttpClient.cpp, to see if it uses the connection or reconnects
    – Juraj
    May 22 '19 at 13:49
  • [link] (ibb.co/k88TXXm) logging returns: connection already open, connected. Look at time, delay increases while new posts are sended. Is it opening new connections, instead of using first one? May 22 '19 at 14:05
  • no it always prints Connected. so it is reusing the connection. that was your question. the request takes time, not the connection.
    – Juraj
    May 22 '19 at 14:08
  • try to read the response with int statusCode = client.responseStatusCode();
    – Juraj
    May 22 '19 at 14:15

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.