Pages: 1 [2]   Go Down
Author Topic: Bug in Ethernet Library in new Arduino 0013  (Read 2937 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How much time between connections?  Can you post your code?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
I need more space !!! Everyone is closing in on me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <Ethernet.h>


byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xEF, 0xED };
byte ip[] = {192, 168, 0, 10 };

int CurrentTime = 0;
const int TimeOutMax = 6000;

boolean DebugMode = true;

Server server = Server(23);


void setup()
{
  pinMode(StatusLED, OUTPUT);      // sets the digital pin as output
  digitalWrite(StatusLED, HIGH);
  pinMode(Learner, INPUT);
  pinMode(IR1, OUTPUT);
  pinMode(IR2, OUTPUT);
  pinMode(IR3, OUTPUT);
  pinMode(IR4, OUTPUT);
  digitalWrite(StatusLED, LOW);
  delay(200);
  Ethernet.begin(mac, ip);
  server.begin();
  digitalWrite(StatusLED, HIGH);
  Serial.begin(9600);
  
}

void loop()
{
 Client client = server.available();
 if (client)
 {
   if (DebugMode)
   {
     Serial.println("Connected");
   }
   byte ReadyChar;
  
   ReadyChar = client.read();
  
   if (ReadyChar == 0)
   {

   }
   if (ReadyChar == 255)
   {
       client.write(255);
       GetCommandData(client);  
       client.stop();
   }
 }
 else
 {
   if (DebugMode)
   {
     Serial.println("Not Connected");
   }
 }
}


There is more too it if you want to see it all, but there is normally 10 seconds between connections (sometimes a little less or more). I timed the code to get from the Serial.println("Not Connected"); back to that statement after it connects transfers data and does it thing then back to saying "Not Connected" normally takes about 400 ms.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are you using to connect to the Arduino?  What exactly are you wanting it to do?

I'd try getting rid of that client.stop();

Seeing the rest of your code and knowing more about what you want to accomplish may help.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
I need more space !!! Everyone is closing in on me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will post the rest of it this evening, but I added the client.stop(); because it wasn't working (it didn't help)

I'm trying to send IR codes to the ardunio then have it flash an emitter to turn my TV on and off, I have an IPAQ running a .net app that takes a standard IR hex code converts it to number of burst pairs, clock speed, and an array or on times and off times. I want to send those to the arduino and once it has the complete information I want to it flash the emitter and send it (which all of that works) the problem comes when I want to send multiple IR codes in a row (example I want to scan though the guide or something ... pushing the guide button then the up or down arrow a couple times) thats when the .net application gets an error saying the arduino actively refused the connection
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
I need more space !!! Everyone is closing in on me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <Ethernet.h>


byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xEF, 0xED };
byte ip[] = {192, 168, 0, 10 };
int StatusLED = 2;                // Pin For Power Light
int Learner = 3;    
int IR1 = 4;                      // Pin For Top Left IR
int IR2 = 5;                      // Pin For Bottom Left IR
int IR3 = 6;                      // Pin For Top Right IR
int IR4 = 7;                      // Pin For Bottom Right IR

int incomingInt = 0;
int ClockSpeed = 0;
int OnesData = 0;
int TensData = 0;
int HunsData = 0;
int ThosData = 0;
int TThoData = 0;
int SendPort = 0;

int CurrentTime = 0;
const int TimeOutMax = 6000;

boolean DebugMode = true;

Server server = Server(23);


void setup()
{
  pinMode(StatusLED, OUTPUT);      // sets the digital pin as output
  pinMode(Learner, INPUT);
  pinMode(IR1, OUTPUT);
  pinMode(IR2, OUTPUT);
  pinMode(IR3, OUTPUT);
  pinMode(IR4, OUTPUT);
  Ethernet.begin(mac, ip);
  server.begin();
  digitalWrite(StatusLED, HIGH);
  Serial.begin(9600);
  digitalWrite(StatusLED, HIGH);
}

void loop()
{
 Client client = server.available();
 if (client)
 {
   if (DebugMode)
   {
     Serial.println("Connected");
   }
   byte ReadyChar;
  
   ReadyChar = client.read();
  
   if (ReadyChar == 0)
   {

   }
   if (ReadyChar == 255)
   {
       client.write(255);
       GetCommandData(client);  
       client.stop();
   }
 }
 else
 {
   if (DebugMode)
   {
     Serial.println("Not Connected");
   }
 }
}

int TimeOut(Client client)
{
   CurrentTime = 0;
    do
    {
      if (CurrentTime > TimeOutMax)
      {
        if (DebugMode)
        {
          Serial.println("Comm Error");
        }
        return -1;
      }
      CurrentTime = CurrentTime + 1;
    } while (client.available() == 0);
    return 0;
}

int GetNumber(Client client)
{
  TThoData = 0;
  ThosData = 0;
  HunsData = 0;
  TensData = 0;
  OnesData = 0;
  
  if (TimeOut(client) != 0)
  {
    return -1;
  }
  TThoData = client.read();
  TThoData = TThoData * 10000;
 
  if (TimeOut(client) != 0)
  {
    return -1;
  }
  ThosData = client.read();
  ThosData = ThosData * 1000;
 
  if (TimeOut(client) != 0)
  {
   return -1;
  }
  HunsData = client.read();
  HunsData = HunsData * 100;

  if (TimeOut(client) != 0)
  {
    return -1;
  }
  TensData = client.read();
  TensData = TensData * 10;
 
  if (TimeOut(client) != 0)
  {
    return -1;
  }
  OnesData = client.read();
  
  return OnesData + TensData + HunsData + ThosData + TThoData;
}


void GetCommandData(Client client)
{
 
  byte ReadyChar;

    if (TimeOut(client) != 0)
    {
      return;
    }
    ReadyChar = client.read();

    if (ReadyChar == 1)                  // Goto IR Data
    {
      client.write(255);
      GetIRData(client);
    }
}

void GetIRData(Client client)
{
  byte ReadyChar;
  if (TimeOut(client) != 0)
  {
    return;
  }  
  int TempPort = 0;
  TempPort = client.read();

  switch (TempPort)
  {
   case 1:
    SendPort = 4;
    break;
   case 2:
    SendPort = 5;
    break;
   case 3:
    SendPort = 6;
    break;
   case 4:
    SendPort = 7;
  }
  
  incomingInt = GetNumber(client);
  if (incomingInt == -1)
  {
    return;
  }
  
  ClockSpeed = GetNumber(client);
  if (ClockSpeed == -1)
  {
    return;
  }
  
  int OnTimes[incomingInt+1];
  int OffTimes[incomingInt+1];

  for (int count=0; count <= incomingInt; count++)
  {
 
    OnTimes[count] = GetNumber(client);
    if (OnTimes[count] == -1)
    {
      return;
    }
  
   OffTimes[count] = GetNumber(client);
    if (OffTimes[count] == -1)
    {
      return;
    }
  
  }
  
   for (int count1=0; count1 <= incomingInt; count1++)
   {
      TurnOn(OnTimes[count1]*2, SendPort);

      digitalWrite(SendPort, LOW);
      if (OffTimes[count1] < 16383)
      {
        delayMicroseconds(OffTimes[count1]);
      }
      else
      {
        delay(OffTimes[count1]/1000);
      }
    }
}

void TurnOn(int time, int IRPort)
{

  boolean PinOn = false;

  for (int C=0; C <= time; C=C+ClockSpeed)
  {
    if (PinOn == false)
    {
      digitalWrite(IRPort, HIGH);
      delayMicroseconds(8);//ClockSpeed);
    }
    else
    {
      digitalWrite(IRPort, LOW);
      delayMicroseconds(9);//ClockSpeed);
    }
    PinOn = !PinOn;
  }
}
Logged

Pages: 1 [2]   Go Up
Jump to: