Ethernet Utiliser l'arduino avec un serveur php et un module ENC28J60

Bonjours à tous, Je vient d'acquérir un module ENC28J60 sur ebay (à 3€, n'ayant pas le budget pour une shield officiel a 30 €)
J'ai télécharger la librairie nécessaire (http://www.geeetech.com/wiki/index.php/Arduino_ENC28J60_Ethernet_Module)
Je test le programme WebServerSimple, en ayant configurer l'ip comme : 192.168.0.3
Je l'envoie et je test, j'ai bien ma page qui s'affiche.
maintenant, j'ai sur mon pc portable à l'adresse 192.168.0.2 un serveur web (apache2 php5 mysql ...)
avec ma page dans le dossier /test/index.php

J'ouvre donc l'exemple WebClient, je configure les ip's, j'envoie, et la j'ai :

connecting...
connection failed

disconnecting.

#include <Ethernet.h>

byte mac[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
byte ip[] = { 192, 168, 0, 3 };

Server server(80);

void setup() {
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop() {
  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (c == '\n' && current_line_is_blank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          
          client.print("Analog input 0 = <b>");
          client.print(analogRead(0));
          client.println("</b>
");
          client.print("millis() = <b>");
          client.println(millis());
          client.println("</b>
");
          break;
        }
        if (c == '\n') {
          current_line_is_blank = true;
        } else if (c != '\r') {
          current_line_is_blank = false;
        }
      }
    }
    delay(1);
    client.stop();
  }
}

J'ai donc lancer wiresharks pour voir ce qui ce passe sur le réseau :
quand l'arduino est serveur Web, tout marche bien :
http://www.hostingpics.net/viewer.php?id=125396wiresharkarduinoServer1.png

quand l'arduino est client marche pas :
http://www.hostingpics.net/viewer.php?id=955310wiresharkarduinoClient.png

Je ne connais pas très bien le fonctionnement des trames réseau, et j'aimerais qu'on me disent pourquoi sa ne marche pas dans un sens alors que dans l'autre sa marche ...

Merci à vous.
Timiti29

PS: j'utilise un arduino mega 2560

Bonjour,

Déjà quand je lit ça je me dit tout de suite que cette librairie est bidon ...

Due to the function name of ENC28J60 library is same as the original Ethernet library, the original Ethernet library in the library folder must be removed.

Donc utilise une vrai librairie, codé proprement est ça devrait le faire :wink:

Merci de ta réponse, J'avais bien supprimer la librairie originale,
Sur ce, j'ai installer EtherCard, relancer l'IDE, charger l'exemple backSoon.
changer les adresses IP mis le #define STATIC à 1 (je suis sur un réseau indépendant avec juste mon arduino et mon pc sur un switch)

Voila le code :

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
 
#include <EtherCard.h>

#define STATIC 1  // set to 1 to disable DHCP (adjust myip/gwip values below)

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,0,3 };
// gateway ip address
static byte gwip[] = { 192,168,0,1 };
#endif

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x00,0x11,0x22,0x33,0x44,0x55 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "Service Temporarily Unavailable"
  "</title></head>"
  "<body>"
    "<h3>This service is currently unavailable</h3>"
    "<p><em>"
      "The main server is currently off-line.
"
      "Please try again later."
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(9600);
  Serial.println("\n[backSoon]");
  
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  
}

void loop(){
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  }
}

Rien qu'a la compilation il me trouve une erreur :
"backSoon.cpp:23:13: error: variable ‘page’ must be const in order to be put into read-only section by means of ‘attribute((progmem))’"

Je me dit : "Bah ya juste a mettre un const et problème résolut !" mais non il me fout une autre erreur :
(après avoir mis const char page[] PROGMEM = ... ) :

/usr/share/arduino/libraries/EtherCard/tcpip.cpp: In static member function ‘static void EtherCard::browseUrl(prog_char*, const char*, prog_char*, void ()(byte, word, word))’:
/usr/share/arduino/libraries/EtherCard/tcpip.cpp:497:81: error: invalid conversion from ‘const char
’ to ‘prog_char* {aka char*}’ [-fpermissive]
In file included from /usr/share/arduino/libraries/EtherCard/tcpip.cpp:14:0:
/usr/share/arduino/libraries/EtherCard/EtherCard.h:168:15: error: initializing argument 4 of ‘static void EtherCard::browseUrl(prog_char*, const char*, prog_char*, prog_char*, void (*)(uint8_t, uint16_t, uint16_t))’ [-fpermissive]

La je sèche.
Comment résoudre l'erreur ?
Merci à vous.
Timiti29

Rajoute le const dans la fonction de la librairie :wink:
Avec l'ancienne version du compilateur le const n'était pas obligatoire, maintenant il l'est (ce qui est logique).

C'est bien dans les paramètres des prototype et dans la création des fonction browseUrl ?
car j'ai mais tout les prog_char* par const prog_char* dans les prototypes du fichier EtherCard.h et dans la créations des fonctions dans le fichier tcpip.cpp
mais j'ai toujours une erreur du meme genre

/usr/share/arduino/libraries/EtherCard/tcpip.cpp: In static member function ‘static void EtherCard::browseUrl(const prog_char*, const char*, const prog_char*, const prog_char*, void ()(byte, word, word))’:
/usr/share/arduino/libraries/EtherCard/tcpip.cpp:501:19: error: invalid conversion from ‘const prog_char
{aka const char*}’ to ‘prog_char* {aka char*}’ [-fpermissive]
/usr/share/arduino/libraries/EtherCard/tcpip.cpp:503:20: error: invalid conversion from ‘const prog_char* {aka const char*}’ to ‘prog_char* {aka char*}’ [-fpermissive]
/usr/share/arduino/libraries/EtherCard/tcpip.cpp:504:33: error: invalid conversion from ‘const prog_char* {aka const char*}’ to ‘prog_char* {aka char*}’ [-fpermissive]

Merci :wink:
Timiti29

Les lignes en questions sont des assignations de variables, change aussi leurs types en "prog_char const *" :wink:

Tient au passage un truc me titille ... tu utilises quelle carte et avec quelle version de l'ide ?
C'est bizarre, le compilateur fourni devrait toujours être la vielle version de 2008 ...

J'ai modifier la ligne concernant la création des variables ...
Sa a bien compiler, envoyer, maintenant je n'est pas de page web, en principe l'exemple est bien pour hebergé une page web non ? car ya plusieurs exemples ...

J'utilise un Arduino Mega 2560 (Funduino), avec un module ENC28J60 de chez LC Studio

Timiti29

Edit : Dans les commentaires du fichier Ethernet.h, il donnent les branchement pour un arduino UNO,
Ayant un mega, je n'est pas trouver les variables modifier correspondant au pin utiliser, J'utilise les pin 50 à 53, et je souhaite pouvoir choisir la pin CS/SS