Bonjour,
J'ai acheté un Shield Ethernet ENC28J60 (datasheet : https://www.mouser.c...9662b-62019.pdf ) .
Je souhaiterai créer une interface web me permettant de contrôler différents éléments de mon Arduino Uno (comme des LEDs, changer la valeurs de variable, jouer des sons...)
Pour cela, j'utilise la bibliothèque EtherCard.h.
Pour l'instant, j'ai une simple interface permettant de change la couleur du led RGB de chez Adafruit, avec 3 boutons.
Mon problème vient ensuite.
Lorsque je veux rajouter d'autres boutons (par exemple pour gérer la difficulté d'un jeu ou jouer des sons), ma page web ne fonctionne plus...
Voici mon code fonctionnel :
#include <EtherCard.h> #include <PololuLedStrip.h> #define LED_COUNT 1 //Number of led connected #define LED1 4 // define LED pin PololuLedStrip<4> ledStrip; rgb_color colors[LED_COUNT]; static byte myip[] = { 192, 168, 2, 177 }; // ethernet interface ip address static byte gwip[] = { 192, 168, 1, 254 }; // gateway ip address static byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 }; // ethernet mac address - must be unique on your network bool boolLedR = false; bool boolLedG = false; bool boolLedB = false; byte Red = 0, Green = 0, Blue = 0; byte Ethernet::buffer[500]; // tcp/ip send and receive buffer BufferFiller bfill; void setup() { Serial.begin(9600); pinMode(LED1, OUTPUT); if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) Serial.println( "Failed to access Ethernet controller"); ether.staticSetup(myip, gwip); ether.printIp("IP: ", ether.myip); ether.printIp("GW: ", ether.gwip); ether.printIp("DNS: ", ether.dnsip); } //En tête HTML const char http_OK[] PROGMEM = "HTTP/1.0 200 OK\r\n" "Content-Type: text/html\r\n" "Pragma: no-cache\r\n\r\n"; const char http_Found[] PROGMEM = "HTTP/1.0 302 Found\r\n" "Location: /\r\n\r\n"; const char http_Unauthorized[] PROGMEM = "HTTP/1.0 401 Unauthorized\r\n" "Content-Type: text/html\r\n\r\n" "<h1>401 Unauthorized</h1>"; //Principal page of my interface void homePage() { bfill.emit_p(PSTR("$F" "<html>" "<head>" "<title>Escape Dimension</title>" "<meta http-equiv='refresh' content='5'/>" "</head>" "<body>" "<h1 style='text-align:center'> Game master </h1>" "<div style='border-style: solid'>" "Color led :" "<button><a href=\"?ledr=$F\">$F</a></button>" //L'ajout de ces trois boutons (ou même d'un seul) arrête de faire fonctionne mon programme... // "<button>Difficulte 1</button>" // "<button>Difficulte 2</button>" // "<button>Difficulte 3</button>" "</div>" "</body>" "</html>" ), http_OK, boolLedR ? PSTR("off") : PSTR("on"), boolLedR ? PSTR("RED allume") : PSTR("RED eteint"), boolLedG ? PSTR("off") : PSTR("on"), boolLedG ? PSTR("GREEN allume") : PSTR("GREEN eteint"), boolLedB ? PSTR("off") : PSTR("on"), boolLedB ? PSTR("BLUE allume") : PSTR("BLUE eteint") ); } void loop() { colors[0] = rgb_color(Green, Red, Blue); ledStrip.write(colors, LED_COUNT); // wait for an incoming TCP packet, but ignore its contents word len = ether.packetReceive(); word pos = ether.packetLoop(len); if (pos) { delay(1); // necessary for my system bfill = ether.tcpOffset(); char *data = (char *) Ethernet::buffer + pos; if (strncmp("GET /", data, 5) != 0) { // Unsupported HTTP request // 304 or 501 response would be more appropriate bfill.emit_p(http_Unauthorized); } else { data += 5; if (data[0] == ' ') { // Return home page homePage(); } else if (strncmp("?ledr=on", data, 8) == 0) { // Set boolLedR true and redirect to home page boolLedR = true; Red = 255; bfill.emit_p(http_Found); } else if (strncmp("?ledr=off", data, 9) == 0) { // Set boolLedR false and redirect to home page boolLedR = false; Red = 0; bfill.emit_p(http_Found); } else if (strncmp("?ledg=on", data, 8) == 0) { // Set boolLedR true and redirect to home page boolLedG = true; Green = 255; bfill.emit_p(http_Found); } else if (strncmp("?ledg=off", data, 9) == 0) { // Set boolLedR false and redirect to home page boolLedG = false; Green = 0; bfill.emit_p(http_Found); } else if (strncmp("?ledb=on", data, 8) == 0) { // Set boolLedR true and redirect to home page boolLedB = true; Blue = 255; bfill.emit_p(http_Found); } else if (strncmp("?ledb=off", data, 9) == 0) { // Set boolLedR false and redirect to home page boolLedB = false; Blue = 0; bfill.emit_p(http_Found); } else { // Page not found bfill.emit_p(http_Unauthorized); } } ether.httpServerReply(bfill.position()); // send http response } }
Je vous ai mis en commentaire de ma fonction homePage les boutons qui ne veulent pas fonctionner...
J'en viens donc à vous pour savoir si quelqu'un sait d'où pourrait venir le problème