Bonjour,
Je débute dans l'utilisation du shield Ethernet pour arduino et pour le moment je cherche simplement à communiquer avec le shield.
Il n’y a pas d’adresse Mac sur mon Ethernet shield mais j’ai lu à plusieurs reprises que je pouvais laisser celle de l’exemple.
En revanche pour l’adresse IP il faut la changer mais je ne suis pas sur de savoir comment faire ou du moins laquelle utiliser.
J’ai un Macbook Pro et pour connaître son adresse IP je vais dans :
-Préférences système
-Réseau
-Je sélectionne Wifi
-Avancé
-TCP/IP --> Adresse IPv4 : 192.168.1.11
Sous-réseau : 255.255.255.0
Routeur : 192.168.1.1
Pour l’adresse IP de mon shield je pensais donc mettre 192.168.1.15 mais ça ne fonctionne pas. Quand je tape cette adresse IP dans mon navigateur je n'ai rien. (J'ai essayé d'autres nombres que le 15 et même problème)
Mon shield est branché directement sur mon ordinateur mais je ne sais pas si le câble que j'utilise est un droit ou un croisé (est-ce que cela à une importance ?).
Je m'y prend peu-être mal donc je viens vers vous pour savoir quoi faire.
Merci
Voici mon code
#include <SPI.h>
#include <Ethernet.h>
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// IP address, may need to change depending on network
IPAddress ip(192, 168, 1, 15);
// create a server at port 80
EthernetServer server(80);
void setup()
{
Ethernet.begin(mac, ip); // initialize Ethernet device
server.begin(); // start to listen for clients
}
void loop()
{
EthernetClient client = server.available(); // try to get client
if (client)
{ // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available())
{ // client data available to read
char c = client.read(); // read 1 byte (character) from client
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println ("Content-Type: text/html");
client.println ("Connection: close");
client.println();
// send web page
client.println("");
client.println("");
client.println("");
client.println("Arduino Web Page");
client.println("");
client.println("");
client.println("
Hello from Arduino!
");client.println("
A web page from the Arduino server
");client.println("");
client.println("");
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n')
{
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r')
{
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}