Go Down

Topic: control an Alen&Heath QU-16 digital mixer by MIDI over TCP (Read 4724 times) previous topic - next topic

owai

Hello,

Here's the mixer: http://www.allen-heath.com/ahproducts/qu-16/
Here's the midi spec: http://www.allen-heath.com/media/Qu-MIDI-Protocol-V1.3.pdf
And here's some pictures and videos of my project: https://www.dropbox.com/sh/sg2imqzq8rb8yij/ZRZtgNIDFj

Here's my code (Compiled for a UNO + ethernet shield W5100, but I also tried a DUE + W5100, same problem!):
Code: [Select]
/*
  tcp client

Arduino Ethernet shield w5100.

* Ethernet shield attached to pins 10, 11, 12, 13
* carte micro sd = pin 4

*/

#include <SPI.h>
#include <Ethernet.h>



// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0x25, 0x11, 0x80 };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(192, 168, 1, 5); // numeric IP for Google (no DNS)
//char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;


void(* resetFunc) (void) = 0; //declare reset function @ address 0

class Strip
{
  public:
    int pin;
    byte CH;
    byte VX;
    byte dernierEnvoye;
    byte val;

    void init(int p, byte c, byte v)
    {
      pin = p;
      CH = c;
      VX = v;
    }

    void tester()
    {
      val = map(analogRead(pin), 0, 1023, 0x00, 0x7F);
      if (val != dernierEnvoye)
      {
        byte buf[] = { 0xB0, 0x63, CH, 0xB0, 0x62, 0x20 , 0xB0, 0x06, val, 0xB0, 0x26, VX};
        client.write(buf, 12);
        //client.write(0xFE);
        dernierEnvoye = val;
      }
    }
};

const int nbStrip = 6;
Strip strip[nbStrip];

int nbFE = 0;
const int ledVerte = 32;
const int ledRouge = 33;

void setup() {
  pinMode(ledVerte, OUTPUT);
  pinMode(ledRouge, OUTPUT);

  digitalWrite(ledVerte, HIGH);   // vert
  digitalWrite(ledRouge, HIGH);   // rouge


  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH); // disable SD SPI


  strip[0].init(A0, 0X2C, 0x03);
  strip[1].init(A1, 0X29, 0x03);
  //strip[2].init(A1, 0X2A, 0x03);
  strip[2].init(A1, 0X2B, 0x03);
  //strip[4].init(A1, 0X2C, 0x03);
  strip[3].init(A2, 0X24, 0x03);
  strip[4].init(A2, 0X25, 0x03);
  strip[5].init(A3, 0X23, 0x03);
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  Serial.println("start!");
  //  while (!Serial) {
  //   ; // wait for serial port to connect. Needed for Leonardo only
  // }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);

  digitalWrite(ledVerte, LOW);   // vert
  digitalWrite(ledRouge, LOW);   // rouge
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  bool connexionOK = false;
  for (int j = 0; j < 256; j++)
  {
    if (j % 2 == 0)
      digitalWrite(ledRouge, HIGH);   // rouge
    else
      digitalWrite(ledRouge, LOW);   // rouge

    IPAddress server(192, 168, 1, j); // QU-16 ip
    Serial.println(j);
    if (client.connect(server, 51325))
    {
      connexionOK = true;
      break;
    }
  }

  if (connexionOK) {
    connexionOK = true;
    Serial.println("connected");
    Serial.println(Ethernet.localIP());
    digitalWrite(ledVerte, HIGH);   // vert
  }
  else {
    digitalWrite(ledRouge, HIGH);   // rouge
    Serial.println("connection failed");
    delay(1000);               // wait for a second
    Serial.println("resetting");
    resetFunc();  //call reset
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:

  bool recu = false;
  if (client.available())
  {
    recu = true;
    client.flush();
   
    byte c = client.read();
    Serial.print(c, HEX);
    Serial.print(" ");

    if (c == 0xFE)
    {
      nbFE++;
      if (nbFE >= 2)
      {
        digitalWrite(ledVerte, HIGH);  //vert
        nbFE = 0;

      }
      else
        digitalWrite(ledVerte, LOW);   // vert
      Serial.println();
    }
  }

  if (recu)
  {
    for (int s = 0; s < nbStrip; s++)
      strip[s].tester();
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    digitalWrite(ledRouge, HIGH);   // rouge
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    delay(1000);               // wait for a second
    Serial.println("resetting");
    resetFunc();  //call reset

    // do nothing forevermore:
    while (true)
    {
      ;
    };
  }
 
 
digitalWrite(ledVerte, LOW);   // vert
}


The Arduino searches for the mixer's ip adress and connects to it. This is ok.
The mixers begins to send "FE" every 300ms to keep the link active. This is ok.
The arduino reads some potentiometers values and send them to the mixer, by midi/tcp. This works fine. (you can see the videos!)
When I use the mixer directly (without touching the arduino), the mixer sends midi messages to the arduino to tell "this fader moved from... to ..." and this can be around 50 bytes (sometimes more) at once. When this happens, the arduino receive these midi informations and writes them to Serial. Then the "FE" byte starts again at 300ms interval. OK
But if there's too much messages coming at once from the mixer to the arduino, something goes wrong, the arduino stops responding...  :(

I tried to ignore every message coming from the mixer (don't use the 'client.read()', or replaced it by a 'client.flush()), -> not better  :~
I tried to remove everything related to "Serial" (maybe it is too slow compared to the ethernet) -> not better  :~
I tried to disable the micro SD card reader (not used) -> not better

Does anybody have an idea?

Thank you for reading!

Johan

pylon

Quote
But if there's too much messages coming at once from the mixer to the arduino, something goes wrong, the arduino stops responding...


What are too much messages? What's the serial output in this case?

A "software reset":
Code: [Select]
    resetFunc();  //call reset


does not reset the W5100, so you should better implement a correct error handling but to simply start over. I'm unsure if this even does what you expect on the Due.

owai

Thank you for your help!


Quote
But if there's too much messages coming at once from the mixer to the arduino, something goes wrong, the arduino stops responding...


What are too much messages? What's the serial output in this case?


It's some hexa codes, almost the same as the Arduino sends when it asks to move a fader. When I move a fader on the mixer (with my hand), the mixers sends midi messages like "B0 63 20 B0 62 17..." (for every "step" so this makes quickly 50-100 bytes for one fader move). I will copy/paste the output soon.


A "software reset":
Code: [Select]
    resetFunc();  //call reset


does not reset the W5100, so you should better implement a correct error handling but to simply start over. I'm unsure if this even does what you expect on the Due.


I agree with you, this code is not "beautiful", more like a "hack". Better error handling is the good way to go  ;) But... the Arduino seems freezed and I don't know where/how I could detect it  :(

I had one more idea yesterdy: if I use my "DUE", I can create a second loop "multi-thread" that could verify if the main loop is dead... and "reboot/reset" if necessary...

SurferTim

If the connection fails or the server stalls, it will lock up your code. The client.connected() call will return true until the server closes the connection and the client gets the close message. If the connection is broken or the server stalls, that close message is never received by the client. The client will then wait for packets that will never arrive, locking up your sketch.

The best way to avoid that is to incorporate a timeout feature to close and reopen the connection. I don't have a persistent connection example, but here is my client sketch in the playground.
http://playground.arduino.cc/Code/WebClient
Look through the GET example for the variable loopCount. If no packet is received from the server in 10 seconds, it closes the connection on the client end. You should do the same. If you do not receive a packet for 10 seconds, close the connection on your end and immediately reopen it.

owai


SurferTim

The way I test this is to disconnect the ethernet cable from the ethernet shield once the connection is established. You should test your code the same way. Let your Arduino connect to the mixer, then pull out the CAT5 cable from the Arduino, then plug it back in after a few seconds. If it doesn't reconnect, then your code needs some more work.

owai

hello, here's the output before I make any change:

Code: [Select]

FE
FE
FE
FE
FE
FE
FE
FE
FE
FE
B0 63 28 B0 62 20 B0 6 58 B0 26 3 B0 63 2A B0 62 20 B0 6 58 B0 26 3 B0 63 28 B0 62 20 B0 6 59 B0 26 3 B0 63 2A B0 62 20 B0 6 59 B0 26 3 FE
FE
FE
FE
FE
FE
FE
FE
FE
FE
FE
FE
B0 63 28 B0 62 20 B0 6 55 B0 26 3 B0 63 2A B0 62 20 B0 6 55 B0 26 3 B0 63 28 B0 62 20 B0 6 54 B0 26 3 B0 63 2A B0 62 20 B0 6 54 B0 26 3 B0 63 28 B0 62 20 B0 6 53 B0 26 3 B0 63 2A B0 62 20 B0 6 53 B0 26 3 B0 63 28 B0 62 20 B0 6 52 B0 26 3 B0 63 2A B0 62 20 B0 6 52 B0 26 3 B0 63 28 B0 62 20 B0 6 51 B0 26 3 B0 63 2A B0 62 20 B0 6 51 B0 26 3 B0 63 2A B0 62 20 B0 6 50 B0 26 3 B0 63 2A B0 62 20 B0 6 51 B0 26 3 B0 63 28 B0 62 20 B0 6 50 B0 26 3 B0 63 2A B0 62 20 B0 6 50 B0 26 3 B0 63 2A B0 62 20 B0 6 4F B0 26 3 B0 63 28 B0 62 20 B0 6 4F B0 26 3 B0 63 28 B0 62 20 B0 6 4E B0 26 3 B0 63 2A B0 62 20 B0 6 4E B0 26 3 B0 63 28 B0 62 20 B0 6 4D B0 26 3 B0 63 2A B0 62 20 B0 6 4D B0 26 3 B0 63 2A B0 62 20 B0 6 4C B0 26 3 B0 63 28 B0 62 20 B0 6 4C B0 26 3 B0 63 28 B0 62 20 B0 6 4B B0 26 3 B0 63 2A B0 62 20 B0 6 4B B0 26 3 B0 63 28 B0 62 20 B0 6 4A B0 26 3 B0 63 2A B0 62 20 B0 6 4A B0 26 3 B0 63 2A B0 62 20 B0 6 49 B0 26 3 B0 63 28 B0 62 20 B0 6 49 B0 26 3 B0 63 28 B0 62 20 B0 6 48 B0 26 3 B0 63 2A B0 62 20 B0 6 48 B0 26 3 B0 63 28 B0 62 20 B0 6 47 B0 26 3 B0 63 2A B0 62 20 B0 6 47 B0 26 3 B0 63 2A B0 62 20 B0 6 46 B0 26 3 B0 63 28 B0 62 20 B0 6 46 B0 26 3 B0 63 28 B0 62 20 B0 6 45 B0 26 3 B0 63 2A B0 62 20 B0 6 45 B0 26 3 B0 63 28 B0 62 20 B0 6 44 B0 26 3 B0 63 2A B0 62 20 B0 6 44 B0 26 3 B0 63 28 B0 62 20 B0 6 43 B0 26 3 B0 63 2A B0 62 20 B0 6 43 B0 26 3 B0 63 2A B0 62 20 B0 6 42 B0 26 3 B0 63 28 B0 62 20 B0 6 42 B0 26 3 B0 63 28 B0 62 20 B0 6 41 B0 26 3 B0 63 2A B0 62 20 B0 6 41 B0 26 3 B0 63 2A B0 62 20 B0 6 40 B0 26 3 B0 63 28 B0 62 20 B0 6 40 B0 26 3 B0 63 28 B0 62 20 B0 6 41 B0 26 3 B0 63 28 B0 62 20 B0 6 40 B0 26 3 B0 63 28 B0 62 20 B0 6 3F B0 26 3 B0 63 2A B0 62 20 B0 6 3F B0 26 3 B0 63 2A B0 62 20 B0 6 3E B0 26 3 B0 63 28 B0 62 20 B0 6 3E B0 26 3 B0 63 2A B0 62 20 B0 6 3F B0 26 3 B0 63 28 B0 62 20 B0 6 3F B0 26 3 B0 63 28 B0 62 20 B0 6 40 B0 26 3 B0 63 2A B0 62 20 B0 6 40 B0 26 3 B0 63 28 B0 62 20 B0 6 41 B0 26 3 B0 63 28 B0 62 20 B0 6 40 B0 26 3 B0 63 28 B0 62 20 B0 6 41 B0 26 3 B0 63 2A B0 62 20 B0 6 41 B0 26 3 B0 63 28 B0 62 20 B0 6 42 B0 26 3 B0 63 2A B0 62 20 B0 6 42 B0 26 3 B0 63 2A B0 62 20 B0 6 43 B0 26 3 B0 63 28 B0 62 20 B0 6 43 B0 26 3 B0 63 28 B0 62 20 B0 6 44 B0 26 3 B0 63 2A B0 62 20 B0 6 44 B0 26 3 B0 63 28 B0 62 20 B0 6 45 B0 26 3 B0 63 2A B0 62 20 B0 6 45 B0 26 3 B0 63 28 B0 62 20 B0 6 46 B0 26 3 B0 63 2A B0 62 20 B0 6 46 B0 26 3 B0 63 2A B0 62 20 B0 6 47 B0 26 3 B0 63 28 B0 62 20 B0 6 47 B0 26 3 B0 63 28 B0 62 20 B0 6 48 B0 26 3 B0 63 2A B0 62 20 B0 6 48 B0 26 3 B0 63 2A B0 62 20 B0 6 49 B0 26 3 B0 63 2A B0 62 20 B0 6 48 B0 26 3 B0 63 28 B0 62 20 B0 6 49 B0 26 3 B0 63 2A B0 62 20 B0 6 49 B0 26 3 B0 63 28 B0 62 20 B0 6 4A B0 26 3 B0 63 2A B0 62 20 B0 6 4A B0 26 3 B0 63 28 B0 62 20 B0 6 4B B0 26 3 B0 63 2A B0 62 20 B0 6 4B B0 26 3 B0 63 28 B0 62 20 B0 6 4A B0 26 3 B0 63 28 B0 62 20 B0 6 4B B0 26 3 B0 63 28 B0 62 20 B0 6 4C B0 26 3 B0 63 2A B0 62 20 B0 6 4C B0 26 3 B0 63 28 B0 62 20 B0 6 4D B0 26 3 B0 63 2A B0 62 20 B0 6 4D B0 26 3 B0 63 28 B0 62 20 B0 6 4E B0 26 3 B0 63 2A B0 62 20 B0 6 4E B0 26 3 B0 63 28 B0 62 20 B0 6 4F B0 26 3 B0 63 2A B0 62 20 B0 6 4F B0 26 3 B0 63 28 B0 62 20 B0 6 50 B0 26 3 B0 63 2A B0 62 20 B0 6 50 B0 26 3 B0 63 28 B0 62 20 B0 6 51 B0 26 3 B0 63 2A B0 62 20 B0 6 51 B0 26 3 B0 63 28 B0 62 20 B0 6 52 B0 26 3 B0 63 2A B0 62 20 B0 6 52 B0 26 3 B0 63 28 B0 62 20 B0 6 53 B0 26 3 B0 63 2A B0 62 20 B0 6 53 B0 26 3 B0 63 28 B0 62 20 B0 6 54 B0 26 3 B0 63 2A B0 62 20 B0 6 54 B0 26 3 B0 63 2A B0 62 20 B0 6 53 B0 26 3 B0 63 2A B0 62 20 B0 6 54 B0 26 3 B0 63 28 B0 62 20 B0 6 53 B0 26 3 B0 63 2A B0 62 20 B0 6 53 B0 26 3 B0 63 28 B0 62 20 B0 6 52 B0 26 3 B0 63 2A B0 62 20 B0 6 52 B0 26 3 B0 63 28 B0 62 20 B0 6 51 B0 26 3 B0 63 2A B0 62 20 B0 6 51 B0 26 3 B0 63 28 B0 62 20 B0 6 50 B0 26 3 B0 63 28 B0 62 20 B0 6 51 B0 26 3 B0 63 2A B0 62 20 B0 6 50 B0 26 3 B0 63 2A B0 62 20 B0 6 51 B0 26 3 B0 63 28 B0 62 20 B0 6 50 B0 26 3 B0 63 2A B0 62 20 B0 6 50 B0 26 3 FE
B0 63 28 B0 62 20 B0 6 4F B0 26 3 B0 63 2A B0 62 20 B0 6 4F B0 26 3 B0 63 2A B0 62 20 B0 6 50 B0 26 3 B0 63 2A B0 62 20 B0 6 4F B0 26 3 B0 63 2A B0 62 20 B0 6 4E B0 26 3 B0 63 28 B0 62 20 B0 6 4E B0 26 3 B0 63 28 B0 62 20 B0 6 4D B0 26 3 B0 63 2A B0 62 20 B0 6 4D B0 26 3 B0 63 28 B0 62 20 B0 6 4C B0 26 3 B0 63 2A B0 62 20 B0 6 4C B0 26 3 B0 63 28 B0 62 20 B0 6 4B B0 26 3 B0 63 2A B0 62 20 B0 6 4B B0 26 3 B0 63 28 B0 62 20 B0 6 4A B0 26 3 B0 63 2A B0 62 20 B0 6 4A B0 26 3 B0 63 2A B0 62 20 B0 6 49 B0 26 3 B0 63 28 B0 62 20 B0 6 49 B0 26 3 B0 63 28 B0 62 20 B0 6 48 B0 26 3 B0 63 2A B0 62 20 B0 6 48 B0 26 3 B0 63 28 B0 62 20 B0 6 47 B0 26 3 B0 63 2A B0 62 20 B0 6 47 B0 26 3 B0 63 28 B0 62 20 B0 6 46 B0 26 3 B0 63 2A B0 62 20 B0 6 46 B0 26 3 B0 63 28 B0 62 20 B0 6 45 B0 26 3 B0 63 2A B0 62 20 B0 6 45 B0 26 3 B0 63 28 B0 62 20 B0 6 44 B0 26 3 B0 63 2A B0 62 20 B0 6 44 B0 26 3 B0 63 28 B0 62 20 B0 6 43 B0 26 3 B0 63 2A B0 62 20 B0 6 43 B0 26 3 B0 63 28 B0 62 20 B0 6 42 B0 26 3 B0 63 2A B0 62 20 B0 6 42 B0 26 3 B0 63 28 B0 62 20 B0 6 41 B0 26 3 B0 63 2A B0 62 20 B0 6 41 B0 26 3 B0 63 28 B0 62 20 B0 6 40 B0 26 3 B0 63 2A B0 62 20 B0 6 40 B0 26 3 B0 63 28 B0 62 20 B0 6 3F B0 26 3 B0 63 2A B0 62 20 B0 6 3F B0 26 3 B0 63 28 B0 62 20 B0 6 3E B0 26 3 B0 63 2A B0 62 20 B0 6 3E B0 26 3 B0 63 2A B0 62 20 B0 6 3D B0 26 3 B0 63 28 B0 62 20 B0 6 3D B0 26 3 B0 63 28 B0 62 20 B0 6 3C B0 26 3 B0 63 2A B0 62 20 B0 6 3C B0 26 3 B0 63 28 B0 62 20 B0 6 3B B0 26 3 B0 63 2A B0 62 20 B0 6 3B B0 26 3 B0 63 28 B0 62 20 B0 6 3A B0 26 3 B0 63 2A B0 62 20 B0 6 3A B0 26 3 B0 63 28 B0 62 20 B0 6 39 B0 26 3 B0 63 2A B0 62 20 B0 6 39 B0 26 3 B0 63 28 B0 62 20 B0 6 38 B0 26 3 B0 63 2A B0 62 20 B0 6 38 B0 26 3 B0 63 28 B0 62 20 B0 6 39 B0 26 3 B0 63 28 B0 62 20 B0 6 38 B0 26 3 FE
FE
FE
FE
FE
FE
FE
FE
FE
FE
FE


(here my arduino didn't crash, s you can see the "FE" continuing after the fader moved)

now, i'll try your timeout ideas!

Johan

owai

Hello,

It is now ok!! When the network stalls for more than 1000 ms, I reset the board.
This is perfect for me!

Thank you so much! We have a concert saturday  8)

Code: [Select]
/*
  tcp client

Arduino Ethernet shield w5100.

* Ethernet shield attached to pins 10, 11, 12, 13
* carte micro sd = pin 4

*/

#include <SPI.h>
#include <Ethernet.h>



// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0x25, 0x11, 0x80 };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(192, 168, 1, 5); // numeric IP for Google (no DNS)
//char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

int connectLoop;

void(* resetFunc) (void) = 0; //declare reset function @ address 0

class Strip
{
  public:
    int pin;
    byte CH;
    byte VX;
    byte dernierEnvoye;
    byte val;

    void init(int p, byte c, byte v)
    {
      pin = p;
      CH = c;
      VX = v;
    }

    void tester()
    {
      val = map(analogRead(pin), 0, 1023, 0x00, 0x7F);
      if (val != dernierEnvoye)
      {
        byte buf[] = { 0xB0, 0x63, CH, 0xB0, 0x62, 0x20 , 0xB0, 0x06, val, 0xB0, 0x26, VX};
        client.write(buf, 12);
        dernierEnvoye = val;
      }
    }
};

const int nbStrip = 6;
Strip strip[nbStrip];

int nbFE = 0;
const int ledVerte = 32;
const int ledRouge = 33;

void setup() {
  pinMode(ledVerte, OUTPUT);
  pinMode(ledRouge, OUTPUT);

  digitalWrite(ledVerte, HIGH);   // vert
  digitalWrite(ledRouge, HIGH);   // rouge


  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH); // disable SD SPI


  strip[0].init(A0, 0X2C, 0x03);
  strip[1].init(A1, 0X29, 0x03);
  //strip[2].init(A1, 0X2A, 0x03);
  strip[2].init(A1, 0X2B, 0x03);
  //strip[4].init(A1, 0X2C, 0x03);
  strip[3].init(A2, 0X24, 0x03);
  strip[4].init(A2, 0X25, 0x03);
  strip[5].init(A3, 0X23, 0x03);
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  Serial.println("start!");
  //  while (!Serial) {
  //   ; // wait for serial port to connect. Needed for Leonardo only
  // }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);

  Serial.print("my ip is ");
  Serial.println(Ethernet.localIP());

  digitalWrite(ledVerte, LOW);   // vert
  digitalWrite(ledRouge, LOW);   // rouge
  Serial.println("searching for Alen&Heath QU mixer...");


  bool connexionOK = false;
  digitalWrite(ledRouge, HIGH);   // rouge

  IPAddress server(192, 168, 10, 3); // QU-16 ip
  Serial.println("192.168.10.3"); // DEFAULT IP ADRESS
  if (client.connect(server, 51325))
    connexionOK = true;

  if (!connexionOK)
  {// START AUTODETECT
    for (int j = 2; j < 256; j++)
    {
      //192.168.1.x
      digitalWrite(ledRouge, LOW);   // rouge

      IPAddress server(192, 168, 1, j); // QU-16 ip
      Serial.print("192.168.1.");
      Serial.println(j);
      if (client.connect(server, 51325))
      {
        connexionOK = true;
        break;
      }

      //192.168.10.x
      digitalWrite(ledRouge, HIGH);   // rouge

      IPAddress server2(192, 168, 10, j); // QU-16 ip
      Serial.print("192.168.10.");
      Serial.println(j);
      if (client.connect(server2, 51325))
      {
        connexionOK = true;
        break;
      }
    }
  }

  if (connexionOK) {
    connexionOK = true;
    Serial.println("connected");
    digitalWrite(ledVerte, HIGH);   // vert
  }
  else {
    digitalWrite(ledRouge, HIGH);   // rouge
    Serial.println("connection failed");
    delay(1000);               // wait for a second
    Serial.println("resetting");
    resetFunc();  //call reset
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:

  bool recu = false;
  if (client.available())
  {
    connectLoop = 0;
    for (int s = 0; s < nbStrip; s++)
      strip[s].tester();
    //client.flush();

    byte c = client.read();
    Serial.print(c, HEX);
    Serial.print(" ");

    if (c == 0xFE)
    {
      nbFE++;
      if (nbFE >= 2)
      {
        digitalWrite(ledVerte, HIGH);  //vert
        nbFE = 0;

      }
      else
        digitalWrite(ledVerte, LOW);   // vert
      Serial.println();
    }
  }

  delay(1);
  connectLoop++;
  if (connectLoop > 1000)
  {
    Serial.println();
    Serial.println(F("Timeout"));
    client.stop();
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    digitalWrite(ledRouge, HIGH);   // rouge
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    //delay(1000);               // wait for a second
    Serial.println("resetting");
    resetFunc();  //call reset
/*
    // do nothing forevermore:
    while (true)
    {
      ;
    };
    */
  }


// digitalWrite(ledVerte, LOW);   // vert
}

netnut

I have the same issue of the W5100 + Arduino hanging after a few hours to a few days. I have tried:

Uno+Ethernet shield, this hangs after a few hours
Arduino Ethernet board, this hangs after 1-3 days

The use of the timeout after no packet has been received for 10 seconds is clever. However, I cannot use a delay() as I am processing interrupts and don't want to lose one. If I knew where the code was hanging, perhaps I can use a counter and a timer. So that when the timer popped (say every 5 minutes), I can check the counter and if the counter showed there was a hang then I can perform the reset. Would this work ? Are any of these calls blocking:
client.available(), client.connect() or client.connected() ?

My code is very similar to the WebClientRepeating code, except that I am POSTing instead of GETing.
http://arduino.cc/en/Tutorial/WebClientRepeating

Many Thanks,

Netnut


owai

Hello,

I'm not an ethernet expert... I don't think i can help you a lot...


Are any of these calls blocking:
client.available(), client.connect() or client.connected() ?


I think no: during my tests, I removed all the "reading calls" on the arduino, ignoring any packet coming from the other device; this didn' change anything  :~
Someone told me that it's some code inside the w5100 that is defective and blocks the ethernet card. The arduino is still "alive", because it can test the link and reset if necessary...

good luck!

and if you find a clue, please tell us  :)

pylon

Quote
My code is very similar to the WebClientRepeating code, except that I am POSTing instead of GETing.


Post your code.

SurferTim

Quote
Someone told me that it's some code inside the w5100 that is defective and blocks the ethernet card. The arduino is still "alive", because it can test the link and reset if necessary...

That is not correct. It is normally your code that causes the lockup. Take a look at the link I posted above. It has both GET and POST examples.

Go Up