Hi...Is it possible show MAC address connected pc? I use ethernet sield wiznet w5100. If yes so how? thx
If you mean the mac address of a pc connected to a socket on the w5100, you can't using the standard ethernet library. You can using the w5100.h file, but it isn't easy. You must get the socket number of the socket you are using.
#include <utility/w5100.h>
byte destMac[6];
W5100.readSnDHAR(sock,destMac);
edit: You do not include the size with that call. My bad. I removed the "6" in the function call.
SurferTim:
If you mean the mac address of a pc connected to a socket on the w5100, you can't using the standard ethernet library. You can using the w5100.h file, but it isn't easy. You must get the socket number of the socket you are using.#include <utility/w5100.h>
byte destMac[6];
W5100.readSnDHAR(sock,destMac);
edit: You do not include the size with that call. My bad. I removed the "6" in the function call.
i have something but i don´t know how continue and this number of socket i don´t idea how ... i am beginner in this area
#include <SPI.h>
#include <Ethernet.h>
#include <utility/w5100.h>
SOCKET s; // our socket that will be opened in RAW mode
byte destMac[6]; //destination hw address
int rbuflen; // length of data to receive
int sbuflen; // length of data to send
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
void loop() {
// initialize the w5100 chip and open a RAW socket
W5100.init();
W5100.writeSnMR(s, SnMR::MACRAW);
W5100.execCmdSn(s, Sock_OPEN);
if (Sock_OPEN)
Serial.println("Open socket");
else
Serial.println("Something bad");
// check if we have received something
rbuflen = W5100.getRXReceivedSize(s);
if (rbuflen>0) {
// receive packet
W5100.recv_data_processing(s, rbuf, rbuflen);
W5100.execCmdSn(s, Sock_RECV);
if (Sock_RECV)
Serial.println("Received socket");
else
Serial.println("Something bad 1"); }
}
thank you for help me
It appears the variable 's' is your socket number, so:
W5100.readSnDHAR(s,destMac);
SurferTim:
It appears the variable 's' is your socket number, so:W5100.readSnDHAR(s,destMac);
my out from program is :
Open socket
MAC:
FF:FF:FF:FF:FF:FF
Is a computer connected to the socket?
SurferTim:
Is a computer connected to the socket?
yes...
This worked for me. It checks all sockets status. The w5100 remembers the mac address even after the device disconnects.
byte socketStat[MAX_SOCK_NUM];
byte destMac[6];
void ShowSockStatus()
{
 for (int i = 0; i < MAX_SOCK_NUM; i++) {
  Serial.print(F("Socket#"));
  Serial.print(i);
  uint8_t s = W5100.readSnSR(i);
  socketStat[i] = s;
  Serial.print(F(":0x"));
  Serial.print(s,16);
  Serial.print(F(" "));
  Serial.print(W5100.readSnPORT(i));
  Serial.print(F(" D:"));
  uint8_t dip[4];
  W5100.readSnDIPR(i, dip);
  for (int j=0; j<4; j++) {
   Serial.print(dip[j],10);
   if (j<3) Serial.print(".");
  }
  Serial.print(F("("));
  Serial.print(W5100.readSnDPORT(i));
  Serial.print(F(") "));
  W5100.readSnDHAR(i,destMac);
  for (int j=0; j<6; j++) {
   if(destMac[j] < 16) Serial.print(F("0"));
   Serial.print(destMac[j],HEX);
   if (j<5) Serial.print(":");
  }
 Â
  Serial.println();
 }
}
SurferTim:
This worked for me. It checks all sockets status. The w5100 remembers the mac address even after the device disconnects.byte socketStat[MAX_SOCK_NUM];
byte destMac[6];
void ShowSockStatus()
{
for (int i = 0; i < MAX_SOCK_NUM; i++) {
Serial.print(F("Socket#"));
Serial.print(i);
uint8_t s = W5100.readSnSR(i);
socketStat[i] = s;
Serial.print(F(":0x"));
Serial.print(s,16);
Serial.print(F(" "));
Serial.print(W5100.readSnPORT(i));
Serial.print(F(" D:"));
uint8_t dip[4];
W5100.readSnDIPR(i, dip);
for (int j=0; j<4; j++) {
Serial.print(dip[j],10);
if (j<3) Serial.print(".");
}
Serial.print(F("("));
Serial.print(W5100.readSnDPORT(i));
Serial.print(F(") "));
W5100.readSnDHAR(i,destMac);
for (int j=0; j<6; j++) {
if(destMac[j] < 16) Serial.print(F("0"));
Serial.print(destMac[j],HEX);
if (j<5) Serial.print(":");
}
Serial.println();
}
}
thanks for program, but on output i have nothing...i have problem with dhcp address printer sketch so maybe it associated with this...can you give here your output?
I loaded up my web server code from the playground.
http://playground.arduino.cc/Code/WebServerST
I have a few files on a SD card, and downloaded the webpage. Then I enter 'r' on the serial monitor.
Socket#0:0x0 80 D:192.168.1.254(3205) 00:0C:42:2D:98:6E
Socket#1:0x0 80 D:192.168.1.254(3206) 00:0C:42:2D:98:6E
Socket#2:0x0 80 D:192.168.1.254(3207) 00:0C:42:2D:98:6E
Socket#3:0x14 80 D:0.0.0.0(0) FF:FF:FF:FF:FF:FF
This mac address is my router because my computer is on a different localnet on the router.
edit: I don't see a call to Ethernet.begin() in your sketch. Try to get a example sketch working first.
SurferTim:
I loaded up my web server code from the playground.
Arduino Playground - HomePageI have a few files on a SD card, and downloaded the webpage. Then I enter 'r' on the serial monitor.
Socket#0:0x0 80 D:192.168.1.254(3205) 00:0C:42:2D:98:6E
Socket#1:0x0 80 D:192.168.1.254(3206) 00:0C:42:2D:98:6E
Socket#2:0x0 80 D:192.168.1.254(3207) 00:0C:42:2D:98:6E
Socket#3:0x14 80 D:0.0.0.0(0) FF:FF:FF:FF:FF:FFThis mac address is my router because my computer is on a different localnet on the router.
edit: I don't see a call to Ethernet.begin() in your sketch. Try to get a example sketch working first.
i don´t know what your full code is doing but i run your code and my output is :
Starting SD..failed
Ready
Socket#0:0x14 80 D:0.0.0.0(0)
Socket#1:0x0 0 D:0.0.0.0(0)
Socket#2:0x0 0 D:0.0.0.0(0)
Socket#3:0x0 0 D:0.0.0.0(0)
and here is example sketch...i have always "Failed to configure Ethernet using DHCP"
#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[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// 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 setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
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:
for(;;)
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
void loop() {
}
Let's start at the beginning. Here is a sketch that tests the SPI connection from the Arduino to the ethernet shield (w5100). If it shows "Starting ethernet...192.168.2.2", then the SPI part is working ok. If it shows anything else, like 0.0.0.0, then the SPI bus communication is failing. Check to insure the shield is fully inserted into the Arduino.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {Â 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,2);
void setup() {
 Serial.begin(9600);
 // disable SD SPI
 pinMode(4,OUTPUT);
 digitalWrite(4,HIGH);
 // Start ethernet
 Serial.print(F("Starting ethernet..."));
 Ethernet.begin(mac, ip);
 Serial.println(Ethernet.localIP());
}
void loop() {
}
SurferTim:
Let's start at the beginning. Here is a sketch that tests the SPI connection from the Arduino to the ethernet shield (w5100). If it shows "Starting ethernet...192.168.2.2", then the SPI part is working ok. If it shows anything else, like 0.0.0.0, then the SPI bus communication is failing. Check to insure the shield is fully inserted into the Arduino.#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,2);
void setup() {
Serial.begin(9600);
// disable SD SPI
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
// Start ethernet
Serial.print(F("Starting ethernet..."));
Ethernet.begin(mac, ip);
Serial.println(Ethernet.localIP());
}
void loop() {
}
it´s working ok...
Then the SPI bus is working ok. Now try this sketch. Does it display "failed" or your network settings?
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {Â 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
void setup() {
 Serial.begin(9600);
 // disable SD SPI
 pinMode(4,OUTPUT);
 digitalWrite(4,HIGH);
 Serial.print(F("Starting ethernet..."));
 if(!Ethernet.begin(mac)) Serial.println(F("failed"));
 else {
   Serial.print(F("IP: "));
   Serial.println(Ethernet.localIP());
   Serial.print(F("Subnet: "));
   Serial.println(Ethernet.subnetMask());
   Serial.print(F("Gateway: "));
   Serial.println(Ethernet.gatewayIP());
   Serial.print(F("DNS server: "));
   Serial.println(Ethernet.dnsServerIP());
}
void loop() {
}
SurferTim:
Then the SPI bus is working ok. Now try this sketch. Does it display "failed" or your network settings?#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
void setup() {
Serial.begin(9600);
// disable SD SPI
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Serial.print(F("Starting ethernet..."));
if(!Ethernet.begin(mac)) Serial.println(F("failed"));
else {
Serial.print(F("IP: "));
Serial.println(Ethernet.localIP());
Serial.print(F("Subnet: "));
Serial.println(Ethernet.subnetMask());
Serial.print(F("Gateway: "));
Serial.println(Ethernet.gatewayIP());
Serial.print(F("DNS server: "));
Serial.println(Ethernet.dnsServerIP());
}
void loop() {
}
now i have failed
Is the ethernet shield connected to a router? Are the LEDs on the front of the RJ45 socket lit?
SurferTim:
Is the ethernet shield connected to a router? Are the LEDs on the front of the RJ45 socket lit?
LEDs are ok but i have shield connected to a pc not router.
Then the DHCP Ethernet.begin(mac) will not work. Normally the pc ethernet interface does not have a dhcp server.
SurferTim:
Then the DHCP Ethernet.begin(mac) will not work. Normally the pc ethernet interface does not have a dhcp server.
and can I show mac address connected pc to ethernet shield without router?only ethernet shield and pc
The w5100 will only show a mac address for a device that has been connected, either as a client to the w5100 server, or as a server to the w5100 client. If you are not familiar with setting up a server on the pc and opening that port on its firewall, it may be best to set up the Arduino as the server.
This will require a bit of knowledge about networks. The Arduino and the pc must be assigned ips within the same localnet range. Do you know how to get the network settings for the pc ethernet interface?