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