Juntar códigos

Boas, eu estou a tentar juntar dois códigos, no entanto não estou a ter sucesso, alguém me pode dar uma ajuda por favor??

Código 1


Código 2


Código feito

#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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip( 172, 16, 0, 10);
byte gateway[] = { 172, 16, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet masc
String readString;

int pin = 9; 
boolean ligado = true;

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
char userPass[200];
//char header[500];
String header;
//int bufferSize = 0;

void setup() {
  // Open serial communications and wait for port to open:

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.print("server is at ");
  pinMode(pin, OUTPUT); //pin selected to control
  //enable serial data print
  Serial.println("RoboCore Remote Automation V1.1"); // so I can keep track of what is loaded

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();
        header += c;
        if (c == '\n' && currentLineIsBlank) {

          //parse headers
          //bWluaDp0ZXN0 = 'minh:test' (user:password) base64 encode
          String auth = "";
          //parse out user pass from client
          if(int startOfAuth = header.indexOf("Authorization: Basic")) {
            int i = startOfAuth+21;
            while(header.charAt(i) != '\n') {
              auth += header.charAt(i);
          //if HTTP request has ended
        if (c == '\n') {

          ///////////////////// control arduino pin
          Serial.println(readString); //print to serial monitor for debuging
          if(readString.indexOf("?ligar") >0)//checks for on
            digitalWrite(pin, HIGH);    // set pin 4 high
            ligado = false;
            if(readString.indexOf("?desligar") >0)//checks for off
              digitalWrite(pin, LOW);    // set pin 4 low
              ligado = true;
          //clearing string for next read
          //get rid of any whitespaces

          // send a standard http response header
          if(auth.compareTo("bWluaDp0ZXN0") != 0) {
            client.println("HTTP/1.0 401 Authorization Required");
            client.println("WWW-Authenticate: Basic realm=\"Secure\"");
            client.println("Content-Type: text/html");
            client.println("<html>Text to send if user hits Cancel button</html>"); // really need this for the popup!
          } else {
            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("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");

          client.println("<title>RoboCore - Remote Automation</title>");
          client.println("<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>");
          client.println("<link rel='stylesheet' type='text/css' href='http://www.robocore.net/upload/projetos/RemoteAutomationV1.0.css' />");
          client.println("<script type='text/javascript' src='http://www.robocore.net/upload/projetos/RemoteAutomationV1.0.js'></script>");
          client.println("<div id='wrapper'>RoboCore Remote Automation V1.1");
          client.print("<div id='rele'></div><div id='estado' style='visibility: hidden;'>");
          client.println("<div id='botao'></div>");

          //stopping client
        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
    // close the connection:
    Serial.println("client disconnected");


IP do arduino:
Mac Adress: 0x90, 0xA2, 0xDA, 0x00, 0x9B, 0x36

Agradeço a ajuda

Nao estas a ter sucesso em que parte?

Na união do sistema de login ao código de controlo remoto.