• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Ethernet Shield z SD problem.
#1
Witam Serdecznie. 

Mam "mały" problem z moim Shield'em... otóż po podłączeniu do Uno 1602 i wgraniu np. z przykładów WebServer wszystko śmiga... po zmianie adresu pod lan 192.168.x.1xx.

Chciałem pokombinować z przekaźnikami podłączyć i pracować z nimi przez przeglądarkę. Znalazłem sketh'a w Internetach no i tutaj zaczyna się problem, bo nie wiem czy Moje Uno z 1602 jest niedostosowane czy problem leży po stronie kodu czy samego shield'a. 

Link bezpośredni do sketha i źródła : Klik
Kod : 

Kod:
/*
 Web Server 2 Relays
 based on "Web Server" Examples by "David A. Mellis" and "Tom Igoe"
*/

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

#define HTTP_VERB             "GET"
#define LINE_BUFFER_SIZE      255
#define REQUEST_BUFFER_SIZE   96

#define TIMER_PORTE_AUTO      500

// 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(10,42,254,250); <- zmiana na : 192.168.3.10x

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

EthernetServer server(80);

int switchOneState = LOW;
int switchTwoState = LOW;

const int switchOne =  7;
const int switchTwo =  8;

void setup()
{
 // Initialize the relays
 pinMode(switchOne, OUTPUT);
 pinMode(switchTwo, OUTPUT);

 // start the Ethernet connection and the server:
 Ethernet.begin(mac, ip);
 server.begin();
}

void open_door()
{
 digitalWrite(switchOne, HIGH);
 delay(TIMER_PORTE_AUTO);
 digitalWrite(switchOne, LOW);
 // open door
}

// Extract /XYZ from a request line :
// GET /XYZ HTTP/1.1

void get_page(char *line, char *request, char *verb)
{
 int i = 0;
 int verb_and_space_len = strlen(verb) + 1; // add the space between the verb and the request
 for (; line[i + verb_and_space_len] && ( line[i + verb_and_space_len] != ' ' ) && (i < REQUEST_BUFFER_SIZE); i++)
   request[i] = line[i + verb_and_space_len];
 request[i] = 0;
}

void loop()
{
 char lineBuffer[LINE_BUFFER_SIZE];
 int  lineBufferIndex = 0;
 char requestBuffer[REQUEST_BUFFER_SIZE];

 // listen for incoming clients
 EthernetClient client = server.available();
 if (client) {
   // an http request ends with a blank line
   boolean currentLineIsBlank = true;
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       // 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();
         client.println("<!DOCTYPE HTML>");
         client.println("<html>");
         client.println("<body>");

         client.println("<h1>HELLO</h1>");
         get_page(lineBuffer, requestBuffer, HTTP_VERB);

         if (strcmp(requestBuffer, "/openthedoor") == 0) {
           open_door();
         } else {
           client.println("<a href='/openthedoor'>open</a> <br />");
         }
         client.println("</body></html>");

         // reinit
         lineBufferIndex = 0;

         break;
       }
       if (c == '\n') {
         // you're starting a new line
         currentLineIsBlank = true;
         lineBuffer[lineBufferIndex++] = 0;
       }
       else if (c != '\r') {
         // you've gotten a character on the current line
         currentLineIsBlank = false;
         if (lineBufferIndex <= LINE_BUFFER_SIZE - 1)
           lineBuffer[lineBufferIndex++] = c;
       }
     }
   }
   // give the web browser time to receive the data
   delay(1);
   // close the connection:
   client.stop();
 }
}

Jak widać najbardziej łopatologiczny przykład... dwa realy'e i wszystko. Po Wrzuceniu jak i na Uno tak samo jak i na Mega i odczekaniu 3-5 min nie oddzywa się pod HTTP. Strona Niedostępna i ch*$#. (szlag mnie trafia).

Pod Routerem wszystkie zabezpieczenia są OFF, zrobiłem wyjścia pod porty od 21 do 80 pod TCP i  UDP - Ale kiedy wszystko niby działa pod przykładem WebServer nawet wtedy na zakładce w routerze "Client List" nie pokazuje się Shield są tylko dwa PC'ty i to wszystko. Nie wiem może źle myślę ale jeśli Shield jest zbindowany pod adres IP i posiada MAC to powinien się tam znaleźć. Pół dnia dzisiaj próbuję dość o co chodzi że "to" działa a "to" nie ....


Macie jakieś pomysły ? 

Moj Router to TL-WR340G mam jeszcze ( TL-W8951ND ) - z tym kompletnie nie potrafię sobie poradzić z ustawieniami ... posiada zewn. IP więc ktoś mógł by pomóc.
 
Odpowiedź
#2
Spróbuj bez ip zainicjować , router ma zapewne włączony routing DHCP i nie będzie chciał się łączyć z urządzeniem które mu narzuca swoje ip.
Ważne aby robić co się lubi albo lubić co się robi .
Arduino UNO, TINY, PRO MINI
Pomoc nagradzamy punktami reputacji Wink
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości