Leonardo connect W5100 not work

Hi Everyone,
I’m try connect W5100 ethernet board, but it’s not send message.

Ethernet program as blew:
#define W5100
#include “SocketIOClient.h”
#include “Ethernet.h”
#include “SPI.h”

SocketIOClient client;

byte mac = { 0xAA, 0x00, 0xBE, 0xEF, 0xFE, 0xEE };
char hostname = “192.168.0.164”;
int port = 5438;

extern String RID;
extern String Rname;
extern String Rcontent;

unsigned long previousMillis = 0;
long interval = 10000;
void setup() {
pinMode(10, OUTPUT); //for some ethernet shield on the mega : disables the SD and enables the W5100
digitalWrite(10, HIGH);
Serial.begin(9600);
Ethernet.begin(mac);

if (!client.connect(hostname, port))
Serial.println(F(“Not connected.”));
if (client.connected())
{
client.send(“connection”, “message”, “Connected !!!”);
}
else
{
Serial.println(“Connection Error”);
while(1);
}
delay(1000);
}

void loop()
{
pinMode(10, OUTPUT); //for some ethernet shield on the mega : disables the SD and enables the W5100
digitalWrite(10, HIGH);
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
//client.heartbeat(0);
client.send(“atime”, “message”, “Time please?”);
}
if (client.monitor())
{
Serial.println(RID);
if (RID == “atime” && Rname == “time”)
{
Serial.print("Time is ");
Serial.println(Rcontent);
}
}
}

Do this:

Add this line:

while(!Serial);

to your sketch after this line:

Serial.begin(9600);

Upload the sketch to your Arduino board.

Open the Serial Monitor.

Post the output you see.


When using the Leonardo, the board is not reset when you open Serial Monitor. This means that any output printed to Serial between the time you upload the sketch or power the board and when you open Serial Monitor is lost. That could include the very helpful Serial output in your setup() function.

The line:

while(!Serial);

causes the board to wait in that while loop until a serial connection is opened, which means you will see all the serial output from your program.

One thing to note is that if you had a sketch that you wanted to use without Serial Monitor open, you would not want to add that line, because the program would never run. When you're troubleshooting a problem this is useful, but later you might want to remove it.

Hi pert,

I’m add this line, and it is successfully output screen as test.jpg.

while(!Serial);

But i have a question.

I want connect internet by W5100 ethernet board, but this line feel not work. I don’t receive any reply message by W5100 ethernet board as test1.jpg.

 client.send("connection", "message", "Connected !!!!");

thanks.

test1.JPG

billop's test.JPG:

If you look at the examples that come with the Ethernet library (File > Examples > Ethernet), there is some code that provides useful troubleshooting information.

Replace this line of your sketch:

Ethernet.begin(mac);

with this:

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
      while (true) {
        delay(1); // do nothing, no point running without Ethernet hardware
      }
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip, myDns);
  } else {
    Serial.print("  DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  }

Upload it to your Arduino board, then post what you see in Serial Monitor.