Marche pas: UNO+ETHERNET SHIELD 2 en Webserver

Hello,

Je viens d'acquérir mes boards Arduino (UNO+ETHERNET SHIELD 2).
En tant que débutant , je commence par faire clignoter la led sur la broche 13. Jusque là pas de souci, ça clignote, je suis content... :wink:

Alors je décide de passer à un autre niveau qui correspond à mon achat, utiliser l'ethernet shield v2 pour piloter des relais. J'ai vu et lu des tutos, mais je ne comprends que dal! J'ai beau charger les programmes des tutos mais je n'arrive pas au résultat.
Je décide donc de commencer par le début avec les programmes de base Webserver du site Arduino.cc.

Je charge donc le programme suivant et lorsque je me connecte avec mon navigateur à l'adresse 192.168.1.177:80 il n'y a rien (http://192.168.1.177/ est inaccessible).

Quelle est mon erreur ?

Le programme:

/* Web Server */

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0xDC, 0xBC};
IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}


// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}


void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
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"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("
");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}

il faut utiliser la lib Ethernet2

Merci à toi RJNC38, mais comment fait-on ?
Lorsque je j'écris :

#include <Ethernet2.h>

La console me renvoie un message d'erreur. Visiblement Ethernet2.h n'est pas reconnu.

bonjour,
il faut peut être aussi installer la lib en question

et mettre ici les erreurs qui sont retournées

Oui mais je ne sais pas comment installer cette lib ???

https://wiki.mchobby.be/index.php?title=Installation_d'un_librairie_Arduino

Bon alors, j'ai récupéré la lib Ethernet2 sur GitHub - adafruit/Ethernet2: WIZ5500 based Ethernet Shield library

J'ai déposé le dossier Ethernet2 dans /usr/share/arduino/libraries/ avec chmod 777. Je suis sous Ubuntu.

J'ai relancé l'Arduino soft et j'ai charger le sketch depuis : examples -> Etherner2 -> Webserver, ce qui me donne:

#include <SPI.h>
#include <Ethernet2.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

...bla bla bla...

Lorsque je lance le transfert, j'ai le message suivant:

/usr/share/arduino/libraries/Ethernet2/utility/w5500.cpp:181:9: error: ‘class SPIClass’ has no member named ‘endTransaction’
SPI.endTransaction();

Alors là, je me dis que la librairie Ethernet 2 n'est pas prise en charge. Donc, je force en ajoutant la librairie avec un IMPORTER UNE BBILIOTEQUE -> ETHERNET2.
Ce qui me donne l'en-tête du sketch:

#include <Dns.h>
#include <util.h>
#include <EthernetUdp2.h>
#include <EthernetServer.h>
#include <EthernetClient.h>
#include <Twitter.h>
#include <Ethernet2.h>
#include <Dhcp.h>

Lorsque je procède au transfert, la console me renvoie le même message d'erreur:

/usr/share/arduino/libraries/Ethernet2/utility/w5500.cpp:181:9: error: ‘class SPIClass’ has no member named ‘endTransaction’
SPI.endTransaction();

Quelqu'un aurait il une idée de la provenance de mon souci. Ou pourriez-vous me donner la bonne librairie pour l'Ethernet Shield v2 ?

Après diverses recherche, j'ai chargé la dernière version du soft (V1.8.0 sur Arduino.org) puis chargé la librairie Ethernet2.
Miracle, pas d'anomalie de compilation et le sketch Webserver s'est bien chargé.
Par contre, impossible d'accéder à 192.168.1.117. (Ce site est inaccessible http://192.168.1.117/ est inaccessible.)

Je ne comprends toujours pas !!!
Une idée ?

ton arduino est connecté sur quoi ?
que donne la console au démarrage ?
qu'elle est l'adresse ip de ton pc, le masque de sous réseau, la passerelle par défaut ?

Mon Shield est connecté à mon PC. J'ai configuré l'adresse IP du shield à 192.168.1.20 (pour être sûr d'une adresse libre)
Adresse IP du PC (selon ma livebox): 192.168.1.17 masque 255.255.255.0.
Pour la passerelle, je n'ai pas l'info.

TEDDOL:
Pour la passerelle, je n'ai pas l'info.

c'est l'adresse interne de ta livebox

ton pc est en wifi ? son ip est donc son @ en wifi, sur sa carte ethernet y a t'il une configuration
pour faire simple raccordes l'arduino sur la livebox

Ok, j'ai connecté le shield à la box et j'ai lancé le sketch suivant:

#include <SPI.h>
#include <Ethernet2.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x10, 0xDC, 0xBC
};
IPAddress ip(192, 168, 1, 20);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        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");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

La livebox ne détecte pas le shield. Le seul appareil connecté en filaire c'est mon décodeur TV.
Voici ce que m'affiche le gestionnaire de connecteur du PC
![](http://forum.arduino.cc/home/ubuntu971/Bureau/Capture du 2016-12-27 18-44-41.png)

la console de l'IDE affiche:
server is at 192.168.1.20

Impossible pour mon navigateur d'accéder 192.168.1.20

tu ed certain que la plage dhcp de la LB commence après 192.168.1.20 ?
mets en ip 250 à la place de 20
teste un ping de ton arduino avec son ip

passes ton schield en dhcp "Ethernet.begin(mac);" et regardes la console pour voir si la box affecte une adresse
est tu sur de ton cordon (leds qui s'allume sur les rj45) ?
sur certaines box il faut forcer le port en 10Mb FD ...

Je commence à douter de la simplicité d'Arduino...

En bon débutant, je recommence tout le process. Je ne veux pas connecter le shield à ma livebox mais à mon PC. C'est le but du projet. Je coupe la livebox pour éviter tout conflit, d'IP. Je reboot mon PC, je transfert le sketch avec pour IP de shield 192.168.1.250.
Toutes les leds du shield sont allumées. La led ACT scintille lors du transfert.
Le moniteur série de l'IDE m'affiche "server is at 192.168.1.250".
Sous Ubuntu je tente "~$ ping -c 5 192.168.1.250"
Réponse "connect: Network is unreachable"
Mon navigateur m'affiche "http://192.168.1.250/ est inaccessible"

Mais qu'est-ce qui cloche ???

déjà, fais un ifconfig sur ton pc pour voir.
il est en ip fixe?

là, ce n'est pas une question de simplissité d'arduino mais de gestion réseau

Et voici:

ubuntu971@ubuntu971-N71Jv:~$ ifconfig
ens5 Link encap:Ethernet HWaddr 48:5b:39:17:93:b5
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Packets reçus:228 erreurs:2 :0 overruns:0 frame:2
TX packets:8891 errors:0 dropped:0 overruns:0 carrier:97
collisions:0 lg file transmission:1000
Octets reçus:24097 (24.0 KB) Octets transmis:1506175 (1.5 MB)

lo Link encap:Boucle locale
inet adr:127.0.0.1 Masque:255.0.0.0
adr inet6: ::1/128 Scope:Hôte
UP LOOPBACK RUNNING MTU:65536 Metric:1
Packets reçus:557414 erreurs:0 :0 overruns:0 frame:0
TX packets:557414 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:1
Octets reçus:30111404 (30.1 MB) Octets transmis:30111404 (30.1 MB)

ubuntu971@ubuntu971-N71Jv:~$

on peut t'aider a obtenir ce que tu souhaites mais il faut commencer par une config simple (technique du petit pas) : arduino sur ta box avec les exemples simples de la lib
ensuite on sera sur du fonctionnement de ta carte et de la lib et on pourra envisager a une config non DHCP entre PC<->Arduino

Bon, alors on recommence.

Je tranfert le sketch Webserver de la lib Ethernet2. Je connecte le shield à ma livebox.
Je reboot la livebox, histoire qu'elle détecte un nouveau matériel connecté.
Selon le sketch, l'IP attribuée au shield est 192.168.1.177.
Je lance mon navigateur, et là, ça marche!!!!
"analog input 0 is 191
analog input 1 is 138
analog input 2 is 157
analog input 3 is 242
analog input 4 is 458
analog input 5 is 683"

Maintenant, je voudrais me passer de la livebox. Comment procéder ?