EtherCard.h feste ip adresse

hi,

Ich habe ein frage kann mit EtherCard.h Library ein festen ip haben.
z.B. 192.172.105 und er soll immer mit diesem ip erreichbar sein

Ein Lösung(Antwort) wär geil

#include <EtherCard.h>

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
// ethernet interface ip address

static byte myip[] = { 192,168,1,5 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };

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

// Using a Variable for the Pin, but it is not necessary 
const int ledPin2 = 2;
const int ledPin4 = 4;

// Some stuff for responding to the request
char* on = "ON";
char* off = "OFF";
char* statusLabel;
char* buttonLabel;

// Small web page to return so the request is completed
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable"
"Content-Type: text/html"
"Retry-After: 600"
""
"<html>"
  "<head><title>"
    "www.maxphi.com Arduino 192.168.1.5"
  "</title></head>"
  "<body>"    
    "<h3>Home Automation www.maxphi.com</h3>" 
    "<p>FAN</p>"   
    "<a href='http://192.168.1.5/?FAN=ON'>ON</a>
"
    "<a href='http://192.168.1.5/?FAN=OFF'>OFF</a>
"
    "
"
    "<p>BULB</p>"   
    "<a href='http://192.168.1.5/?BULB=ON'>ON</a>
"
    "<a href='http://192.168.1.5/?BULB=OFF'>OFF</a>
"           
  "</body>"
"</html>"
;

void setup(){
// Set Pin2 to be an Output
  pinMode(ledPin2, OUTPUT);
// Set Pin4 to be an Output
  pinMode(ledPin4, OUTPUT);

// Scary complex intializing of the EtherCard - I don't understand this stuff (yet0  
  ether.begin(sizeof Ethernet::buffer, mymac);
// Set IP using Static
  ether.staticSetup(myip, gwip);
}

void loop(){  
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);

// IF LED2=ON turn it ON
  if(strstr((char *)Ethernet::buffer + pos, "GET /?FAN=ON") != 0) {
      Serial.println("Received ON command");
      digitalWrite(ledPin2, HIGH);
    }

// IF LED2=OFF turn it OFF  
    if(strstr((char *)Ethernet::buffer + pos, "GET /?FAN=OFF") != 0) {
      Serial.println("Received OFF command");
      digitalWrite(ledPin2, LOW);
    }

// IF LED4=ON turn it ON
  if(strstr((char *)Ethernet::buffer + pos, "GET /?BULB=ON") != 0) {
      Serial.println("Received ON command");
      digitalWrite(ledPin4, HIGH);
    }

// IF LED4=OFF turn it OFF  
    if(strstr((char *)Ethernet::buffer + pos, "GET /?BULB=OFF") != 0) {
      Serial.println("Received OFF command");
      digitalWrite(ledPin4, LOW);
    }

//Return a page so the request is completed.
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);  
}

beta01.ino (2.5 KB)

tuy007sal:

// ...

static byte myip = { 192,168,1,5 };
// …
void setup(){
  // …
  ether.staticSetup(myip, gwip);
}

Was denkst du denn, was hier passiert? Nächstes mal bitte Code in Code-Tags posten (der </> Button in der linken oberen Ecke).