# TCPClient as simple logger \[SOLVED\]

**URL:** <https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014>\
**Category:** Firmware\
**Created:** [February 21, 2014, 7:49am UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014 "2014-02-21T07:49:39Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [February 21, 2014, 4:50pm UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014/22 "2014-02-21T16:50:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [February 21, 2014, 4:58pm UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014/23 "2014-02-21T16:58:10Z")

</div>

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

[http://screenshots.ryotsuke.ru/scr\_76db495c5d5a.png](http://screenshots.ryotsuke.ru/scr_76db495c5d5a.png)

Drops to zero are actually i2c read errors

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [February 21, 2014, 5:04pm UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014/24 "2014-02-21T17:04:46Z")

</div>

Nice! Should that be milliseconds delay instead of micros?

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [February 21, 2014, 5:08pm UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014/25 "2014-02-21T17:08:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/dave/32/181_2.png) [@Dave](https://community.particle.io/u/Dave)\
**Post date:** [February 21, 2014, 5:12pm UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014/26 "2014-02-21T17:12:08Z")

</div>

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. 😄

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [February 21, 2014, 5:18pm UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014/27 "2014-02-21T17:18:29Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![ryotsuke](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ryotsuke/32/1902_2.png) [@ryotsuke](https://community.particle.io/u/ryotsuke)\
**Post date:** [February 21, 2014, 5:27pm UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014/28 "2014-02-21T17:27:50Z")

</div>

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](https://community.spark.io/t/tcpclient-as-simple-logger/3014/22?u=ryotsuke)

Though for remote webservers it is reasonable to increase timeout dramatically

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [February 21, 2014, 5:45pm UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014/29 "2014-02-21T17:45:41Z")

</div>

@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 🙂 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:

---

<div class="post-metadata">

**Author:** ![dmw234](https://avatars.discourse-cdn.com/v4/letter/d/ce73a5/32.png) [@dmw234](https://community.particle.io/u/dmw234)\
**Post date:** [September 13, 2015, 8:41am UTC](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014/30 "2015-09-13T08:41:20Z")

</div>

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.

[Previous page](https://community.particle.io/t/tcpclient-as-simple-logger-solved/3014.md?page=1)
