Socket latency question

Questions specifically related to the TCP/IP stack that interfaces with the driver.

Socket latency question

Postby borismus » Tue Dec 01, 2009 9:53 pm

Hi All,

I finally received my WiShield in the mail, and started experimenting with it a few days ago. I'm trying to make a socket connection to another device for a music-related application that requires low latency. Here's my code so far. I get about 200ms lag which is about 180ms too much.

Code: Select all
byte server_ip[] = {192,168,1,1};

Client client(server_ip, 12345);


void connect_and_login()
{
  // trying to connect to issho server and login
  Serial.println("> connect_and_login"); 
  if(client.connect()) {
    Serial.println("Client connected.");
  }
  else {
    Serial.println("Client could NOT connect.");
  }
}


void setup()
{
  pinMode(BUTTON_PIN, INPUT);
  Serial.begin(9600);
  Serial.println("> setup"); 
  WiFi.begin(local_ip, gateway_ip, subnet_mask);

  connect_and_login();
}


void loop()
{
  if(!client.connected()) {
    connect_and_login();
    return;
  }
  int buttonValue = digitalRead(BUTTON_PIN);
  if (buttonValue == HIGH) {
    Serial.println("beat!");
    client.println("1");
  }
  delay(20);
}


Oh and I should mention that this is after I tweaked WiShield's stack.c to use a 50ms timer. Even at this value, WiShield behaves pretty erratically. Decreasing the poll time causes even weirder behavior.

Code: Select all
     // original periodic timer value for polling - 500 milliseconds
     // timer_set(&periodic_timer, CLOCK_SECOND / 2);
     // new periodic timer value for polling - 50 milliseconds
     timer_set(&periodic_timer, CLOCK_SECOND / 20);


Does anyone have any good ideas about decreasing latency? I'm sending across very small amounts of data so throughput doesn't matter to me.

Thanks!
Boris
borismus
 
Posts: 2
Joined: Tue Dec 01, 2009 9:40 pm

Re: Socket latency question

Postby GregEigsti » Tue Dec 01, 2009 11:46 pm

Quick question, where and when did you get your WiShield "driver" code and samples? The sample sketch bit that you posted does not look familiar to me - its quite possible that I am using out of date WiShield software :lol:

I was able to achieve a much higher latency though had to be careful not to push it too hard or the Arduino/WiShield would "hang"; but you should easily be able to get better than a 200ms latency for sends.

Any particular reason that you have the "delay(20)" in your loop()? And have you tried without the Serial.print's in your code; doubt that makes much of a difference but who knows.

I am just wondering where your WiShield and sample code came from; does not look like the socket code that I achieved lower latencies with.

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: Socket latency question

Postby borismus » Tue Dec 01, 2009 11:52 pm

Initially I was using the zip version but then I saw an attractive alternative from I think one of the WiShield employees. Here's a link to the forum: viewtopic.php?f=15&t=18&start=20

The delay(20) was just an experiment. I tried delay-free to no avail. I'll try without Serial.* but I don't think that's the issue.

What sort of latency were you getting, with what version of the WiShield library? Did you decrease the polling timer? Anyway could you please share your Arduino sketch/C modules?

Thanks,
Boris
borismus
 
Posts: 2
Joined: Tue Dec 01, 2009 9:40 pm

Re: Socket latency question

Postby GregEigsti » Thu Dec 03, 2009 12:53 am

The WiShield code that you referred to was provided by a user breemen and looks like it might provide a nice wrapper around the uIP stack (the stack in use by the WiShield). I have not used his code and cannot comment on it - but with the stock WiShield code (with a tweak or two) I was able to achieve less theoretical latency than you are seeing. Interestingly the thread that you referred me to is one that I was going to refer you to ;) If you search on posts from fdarvas you can follow the saga of trying to squeeze more out of the WiShield. I say theoretical because I was buffering data and sending it out in chunks - which may or may not work for you. However I'm pretty sure what I was doing would easily beat the latencies that you are seeing. You will just have to take a look and see ;)

I was able to get 2-4 bytes out a millisecond (if I remember correctly) but that was setup was asking too much and was pretty unstable. Though I think what you want to do should easily be achievable. I found my setup to be pretty stable sending every 2-4 milliseconds - again faster than you need.

I'd suggest getting the stock WiShield software via the links in the wiki and giving that a try - if anything you'll get more support on the supported version of the WiShield code than you will on user submitted code.

PM me with your email address and I'll send you the zip of my code. Yes, it did decrease the app poll timeout like you are doing as well as utilized the userland sketch UIP_APPCALL function to achieve that lower latency. If I remember correctly that is ;)
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website


Return to TCP/IP Stack

Who is online

Users browsing this forum: No registered users and 1 guest