Control relay and get dht phpmyadmin merge sketches

Hi there,

I will like to merge 2 sketches for do the next actions

1.- dht11 get from the pin 9 the temperature and humidity and send to database

here is the code:

#include "DHT.h"
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Setting MAC Address

#define DHTPIN 9

#define DHTTYPE DHT11

DHT dht(DHTPIN,DHTTYPE);


float humidityData;
float temperatureData;


char server[] = "192.168.1.13";
IPAddress ip(192,168,1,200); 
EthernetClient client; 

/* Setup for Ethernet and RFID */

void setup() {
  Serial.begin(9600);
  dht.begin();
  if (Ethernet.begin(mac) == 0) {
  Serial.println("Failed to configure Ethernet using DHCP");
  Ethernet.begin(mac, ip);
  }
  delay(1000);
}
//------------------------------------------------------------------------------


/* Infinite Loop */
void loop(){
  humidityData = dht.readHumidity();
  temperatureData = dht.readTemperature(); 
  Sending_To_phpmyadmindatabase(); 
  delay(30000); // interval
}


  void Sending_To_phpmyadmindatabase()   //CONNECTING WITH MYSQL
 {
   if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    Serial.print("GET /testing/1-10/arduino/dht.php?humidity=");
    client.print("GET /testing/1-10/arduino/dht.php?humidity=");     //YOUR URL
    Serial.println(humidityData);
    client.print(humidityData);
    client.print("&temperature=");
    Serial.println("&temperature=");
    client.print(temperatureData);
    Serial.println(temperatureData);
    client.print(" ");      //SPACE BEFORE HTTP/1.1
    client.print("HTTP/1.1");
    client.println();
    client.println("Host: 192.168.1.13");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
 }

2.-create a web where you should turn the power on or off

here is the code:

/*
   Rui Santos
   Complete Project Details http://randomnerdtutorials.com
*/

#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(192, 168, 1, 227);

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

// Relay state and pin
String relay1State = "Off";
const int relay = 7;

// Client variables
char linebuf[80];
int charcount = 0;

void setup() {
  // Relay module prepared
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);

  // Open serial communication at a baud rate of 9600
  Serial.begin(9600);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

// Display dashboard page with on/off button for relay
// It also print Temperature in C and F
void dashboardPage(EthernetClient &client) {
  client.println("<!DOCTYPE HTML><html><head>");
  client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body>");
  client.println("<h3>Arduino Web Server - <a href=\"/\">Refresh</a></h3>");
  // Generates buttons to control the relay
  client.println("<h4>Relay 1 - State: " + relay1State + "</h4>");
  // If relay is off, it shows the button to turn the output on
  if (relay1State == "Off") {
    client.println("<a href=\"/relay1on\"><button>ON</button></a>");
  }
  // If relay is on, it shows the button to turn the output off
  else if (relay1State == "On") {
    client.println("<a href=\"/relay1off\"><button>OFF</button></a>");
  }
  client.println("</body></html>");
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    memset(linebuf, 0, sizeof(linebuf));
    charcount = 0;
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        //read char by char HTTP request
        linebuf[charcount] = c;
        if (charcount < sizeof(linebuf) - 1) charcount++;
        // 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) {
          dashboardPage(client);
          break;
        }
        if (c == '\n') {
          if (strstr(linebuf, "GET /relay1off") > 0) {
            digitalWrite(relay, HIGH);
            relay1State = "Off";
          }
          else if (strstr(linebuf, "GET /relay1on") > 0) {
            digitalWrite(relay, LOW);
            relay1State = "On";
          }
          // you're starting a new line
          currentLineIsBlank = true;
          memset(linebuf, 0, sizeof(linebuf));
          charcount = 0;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(0);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

It´s run but when I try to merge, shows me errors.

Please help.

But you’re not going to share the errors?

Good luck.

Sure, here is the merge code and errors

/*
  merge by alex
*/
#include "DHT.h"
#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(192, 168, 1, 227);

#define DHTPIN 9

#define DHTTYPE DHT11

DHT dht(DHTPIN,DHTTYPE);


float humidityData;
float temperatureData;


char server[] = "192.168.1.13";

EthernetClient client;

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

// Relay state and pin
String relay1State = "Off";
const int relay = 7;

// Client variables
char linebuf[80];
int charcount = 0;

void setup() {
    Serial.begin(9600);
  dht.begin();
  if (Ethernet.begin(mac) == 0) {
  Serial.println("Failed to configure Ethernet using DHCP");
  Ethernet.begin(mac, ip);
  }
  delay(1000);
  // Relay module prepared
  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);

  // Open serial communication at a baud rate of 9600
  Serial.begin(9600);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}
/* Infinite Loop */
void loop(){
  humidityData = dht.readHumidity();
  temperatureData = dht.readTemperature(); 
  Sending_To_phpmyadmindatabase(); 
  delay(30000); // interval
}

void Sending_To_phpmyadmindatabase()   //CONNECTING WITH MYSQL
 {
   if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    Serial.print("GET /testing/1-10/arduino/dht.php?humidity=");
    client.print("GET /testing/1-10/arduino/dht.php?humidity=");     //YOUR URL
    Serial.println(humidityData);
    client.print(humidityData);
    client.print("&temperature=");
    Serial.println("&temperature=");
    client.print(temperatureData);
    Serial.println(temperatureData);
    client.print(" ");      //SPACE BEFORE HTTP/1.1
    client.print("HTTP/1.1");
    client.println();
    client.println("Host: 192.168.1.13");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
 }

// Display dashboard page with on/off button for relay
// It also print Temperature in C and F
void dashboardPage(EthernetClient &client) {
  client.println("<!DOCTYPE HTML><html><head>");
  client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body>");
  client.println("<h3>Arduino Web Server - <a href=\"/\">Refresh</a></h3>");
  // Generates buttons to control the relay
  client.println("<h4>Relay 1 - State: " + relay1State + "</h4>");
  // If relay is off, it shows the button to turn the output on
  if (relay1State == "Off") {
    client.println("<a href=\"/relay1on\"><button>ON</button></a>");
  }
  // If relay is on, it shows the button to turn the output off
  else if (relay1State == "On") {
    client.println("<a href=\"/relay1off\"><button>OFF</button></a>");
  }
  client.println("</body></html>");
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    memset(linebuf, 0, sizeof(linebuf));
    charcount = 0;
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        //read char by char HTTP request
        linebuf[charcount] = c;
        if (charcount < sizeof(linebuf) - 1) charcount++;
        // 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) {
          dashboardPage(client);
          break;
        }
        if (c == '\n') {
          if (strstr(linebuf, "GET /relay1off") > 0) {
            digitalWrite(relay, HIGH);
            relay1State = "Off";
          }
          else if (strstr(linebuf, "GET /relay1on") > 0) {
            digitalWrite(relay, LOW);
            relay1State = "On";
          }
          // you're starting a new line
          currentLineIsBlank = true;
          memset(linebuf, 0, sizeof(linebuf));
          charcount = 0;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(0);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

error shows :

Arduino:1.8.9 (Windows 10), Tarjeta:“Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)”

ATENCIÓN: Categoría ‘Actuators’ de la biblioteca Seeed-PCA9685 no es válida. Configurando a ‘Uncategorized’
test-dht11-relay:33:22: error: conflicting declaration ‘EthernetServer server’

EthernetServer server(80);

^

D:\desarrollo\sites\htdocs\testing\1-10\arduino\test-dht11-relay\test-dht11-relay.ino:26:6: note: previous declaration as ‘char server [13]’

char server = “192.168.1.13”;

^

D:\desarrollo\sites\htdocs\testing\1-10\arduino\test-dht11-relay\test-dht11-relay.ino: In function ‘void setup()’:

test-dht11-relay:60:10: error: request for member ‘begin’ in ‘server’, which is of non-class type ‘char [13]’

server.begin();

^

D:\desarrollo\sites\htdocs\testing\1-10\arduino\test-dht11-relay\test-dht11-relay.ino: In function ‘void loop()’:

test-dht11-relay:117:6: error: redefinition of ‘void loop()’

void loop() {

^

D:\desarrollo\sites\htdocs\testing\1-10\arduino\test-dht11-relay\test-dht11-relay.ino:65:6: note: ‘void loop()’ previously defined here

void loop(){

^

test-dht11-relay:119:34: error: request for member ‘available’ in ‘server’, which is of non-class type ‘char [13]’

EthernetClient client = server.available();

^

exit status 1
conflicting declaration ‘EthernetServer server’