TCPClient as simple logger [SOLVED]

I’ve came up with following code that looks pretty reasonable for me and manages to send requests at decent rate.

 uint32_t before = micros();

if(client.connect(server, 9606)) {
    client.println("GET /v.php?"+requestSrting+" HTTP/1.0");
    client.println("Content-Length: 0");
    client.println();
    uint32_t startWait = micros();
    while(!client.available() && micros() < startWait + 5000) {delayMicroseconds(5);} /** We wait to server starts actually responding. Timeout is 5 miliseconds */
    client.flush();
    client.stop();  
}
uint32_t after = micros();

averageCount++;
averageTime = (after - before)/averageCount; //Count average request time in micros

Average time is reported as ~166. I think this is a good result
@Dave is this looking fine?

1 Like

I consider issue resolved for me for now
Now to deal with i2c :smiley:

http://screenshots.ryotsuke.ru/scr_76db495c5d5a.png

Drops to zero are actually i2c read errors

Nice! Should that be milliseconds delay instead of micros?

Is micros returning microseconds? If yes, that should be microseconds delay as after-before = 150 here, that is under one millisecond

Ah, I’m used to requests / servers generally taking on the order of 3-50 milliseconds to respond, but if you’re totally local then that works too. :smile:

I tested out and basically if the delay is not there, the core actually does not execute the request to the server…and eventually starts flashing green.

Wondering what might be the issue without the delay since flush and stop is executed before the next connection is made…

Yes, apparently
The code which waits for server reply works very well for me https://community.spark.io/t/tcpclient-as-simple-logger/3014/22?u=ryotsuke

Though for remote webservers it is reasonable to increase timeout dramatically

@Dave & @mohit,

possible for us to assign maximum 7 out of the 8 sockets for TCP? Leaving 1 for the heartbeat.

The 1st time i tried TCPclient code early, i made some mistakes and could push firmware through the cloud anymore :slight_smile: 8 iterations was all it took for all the sockets to be used up.

Maybe i’ll take a look in the morning! time for some sleep @ 1.45am :spark:

Hello. Sorry for coming into this topic so late. But the above solution link doesn’t seem to work. Can you refresh it? Thank you so much for your time.

1 Like