Sketch compilation : need Help

I'm trying to combine 2 sketches as one wherein the first code is OTA through which I can push/update the code using the wifi and secondly is for home automation which controls my home lights/switch (ON/OFF) using Amazon Alexa.

Both codes work fine independently but give different errors when i copy past the second one below the first code.

Both codes need to upload over NodeMCU esp8266

but give different errors when i copy past the second one below the first code.

You should post an example of what you tried and the errors that you got, but I assume that you have at least combined the setup() and loop() functions from each program into single functions in the combined code.

 [
OTA Code is as follow:-

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>


const char* ssid = "";             //!!!!!!!!!!!!!!!!!!!!! name of your router
const char* password = "";                //!!!!!!!!!!!!!!!!!!!!!your wifi password.

WiFiServer server(80);

void setup() {

Serial.begin(115200);
Serial.println("Booting");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(500);
ESP.restart();
}

// Port defaults to 8266
// ArduinoOTA.setPort(8266);

// Hostname defaults to esp8266-[ChipID]
ArduinoOTA.setHostname("Bedroom");

// No authentication by default
ArduinoOTA.setPassword((const char *)"123");

ArduinoOTA.onStart([]() {
Serial.println("Start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

server.begin();
}

void loop() {
ArduinoOTA.handle();
delay(10);              }      // delay to gife the arduino time to move to the next operation. 


*********************************************************************

And the second Home automation code is 

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiUdp.h>
#include <functional>
#include "switch.h"
#include "UpnpBroadcastResponder.h"
#include "CallbackFunction.h"
#include "CallbackFunction.h"


// prototypes
boolean connectWifi();

//on/off callbacks
void Fan3On();
void Fan3Off();
void Outlight1On();
void Outlight1Off();
void Tubelight3On();
void Tubelight3Off();
void Socket3On();
void Socket3Off();

// Change this before you flash
const char* ssid = "";
const char* password = "";

boolean wifiConnected = false;

UpnpBroadcastResponder upnpBroadcastResponder;

Switch *Fan3 = NULL;
Switch *Outlight1 = NULL;
Switch *Tubelight3 = NULL;
Switch *Socket3 = NULL;

void setup()
{
pinMode (D1, OUTPUT);
pinMode (D2, OUTPUT);
pinMode (D3, OUTPUT);
pinMode (D4, OUTPUT);
digitalWrite (D1, HIGH);
digitalWrite (D2, HIGH);
digitalWrite (D3, HIGH);
digitalWrite (D4, HIGH);
Serial.begin(9600);

// Initialise wifi connection
wifiConnected = connectWifi();

if (wifiConnected) {
upnpBroadcastResponder.beginUdpMulticast();

// Define your switches here. Max 14
// Format: Alexa invocation name, local port no, on callback, off callback
Fan3 = new Switch("Fan 3", 80, Fan3On, Fan3Off);
Outlight1 = new Switch("Outlight 1", 81, Outlight1On, Outlight1Off);
Tubelight3 = new Switch("Tubelight3", 82, Tubelight3On, Tubelight3Off);
Socket3 = new Switch("Socke 3", 83, Socket3On, Socket3Off);

Serial.println("Adding switches upnp broadcast responder");
upnpBroadcastResponder.addDevice(*Fan3);
upnpBroadcastResponder.addDevice(*Outlight1);
upnpBroadcastResponder.addDevice(*Tubelight3);
upnpBroadcastResponder.addDevice(*Socket3);
}
}

void loop()
{
if (wifiConnected) {
upnpBroadcastResponder.serverLoop();

Fan3->serverLoop();
Outlight1->serverLoop();
Tubelight3->serverLoop();
Socket3->serverLoop();
}
}

void Fan3On() {
Serial.print("Switch Fan 3 turn on ...");
digitalWrite (D1, LOW);
}

void Fan3Off() {
Serial.print("Switch Fan 3 turn off ...");
digitalWrite (D1, HIGH);
}

void Outlight1On() {
Serial.print("Switch Outlight 1 turn on ...");
digitalWrite (D2, LOW);
}

void Outlight1Off() {
Serial.print("Switch Outlight 1 turn off ...");
digitalWrite(D2, HIGH);
}
void Tubelight3On() {
Serial.print("Switch Tubelight3 turn on ...");
digitalWrite (D3, LOW);
}

void Tubelight3Off() {
Serial.print("Switch Tubelight3 turn off ...");
digitalWrite (D3, HIGH);
}

void Socket3On() {
Serial.print("Switch Relay 4 turn on ...");
digitalWrite (D4, LOW);
}

void Socket3Off() {
Serial.print("Switch Socket 3 turn off ...");
digitalWrite(D4, HIGH);
}

// connect to wifi – returns true if successful or false if not
boolean connectWifi() {
boolean state = true;
int i = 0;

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");

// Wait for connection
Serial.print("Connecting ...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 20) {
  state = false;
  break;
}
i++;
}

if (state) {
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
else {
Serial.println("");
Serial.println("Connection failed.");
}

return state;
}]

See:
http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

Rakesh_84:
OTA Code is as follow:-

You can't simply paste two sketches together without editing them to make them work as one.

You'll need to integrate your 'void setup' and 'void loop' portions so you only have one of each.

Oh .. and forum rules say to surround your code with code tags before posting.

JB