I have a Question and hope anybody can help me.
Is it possible to get a background image to this web server ?
maybe with a attached sd card shield to the esp8266 nodemcu ?
I only want to use Arduino Ide and the nodemcu board maybe with sd card shield.
Here is my code i use it all around my home projects
// Test_0.6
byte unterProgramm = 0; // Merker für Unterprogram.
#include <ESP8266WiFi.h>
const char* ssid = "SSIDHERE";
const char* password = "PASSHERE";
unsigned long ulReqcount;
unsigned long ulReconncount;
int hb_state = LOW; // led_hb status
unsigned long previousMillis = 0;
const long interval_hb = 500; // interval für led_hb
const int ledc = 16; // Led ( grün ) zeigt eine bestehende Verbindung zum Router an.
const int led_r = 5; // Led ( blau ) zeigt eine aktive Datenverbindung zwischen Client und ESP8266 an.
const int led_hb = 4; // Led ( rot )
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
WiFiServer server(99);
//########################################################################################---SETUP---##############################################################################################################
void setup() {
ulReqcount=0;
ulReconncount=0;
WiFi.mode(WIFI_STA);
WiFiStart();
Serial.begin(115200); // BAUD RATE ( Standart: 115200 )
mySwitch.enableTransmit(2); // 2 = Pin D4
pinMode(ledc,OUTPUT);
pinMode(led_r,OUTPUT);
pinMode(led_hb,OUTPUT);
}
void WiFiStart()
{
ulReconncount++;
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
digitalWrite(ledc,LOW);
}
Serial.println("");
Serial.println("WiFi connected");
digitalWrite(ledc,HIGH);
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
//###########################################################################################----LOOP-----######################################################################################################
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval_hb) {
previousMillis = currentMillis;
if (hb_state == LOW) {
hb_state = HIGH;
} else {
hb_state = LOW;
}
digitalWrite(led_hb, hb_state);
}
// check if WLAN is connected
if (WiFi.status() != WL_CONNECTED)
{
WiFiStart();
}
// Check if a client has connected
WiFiClient client = server.available();
if (!client)
{
digitalWrite(led_r,LOW);
return;
}
// Wait until the client sends some data
Serial.println("new client");
digitalWrite(led_r,HIGH);
unsigned long ultimeout = millis()+250;
while(!client.available() && (millis()<ultimeout) )
{
delay(1);
}
if(millis()>ultimeout)
{
Serial.println("client connection time-out!");
return;
}
// Read the first line of the request
String sRequest = client.readStringUntil('\r');
//Serial.println(sRequest);
client.flush();
// stop client, if request is empty
if(sRequest=="")
{
Serial.println("empty request! - stopping client");
client.stop();
return;
}
// get path; end of path is either space or ?
// Syntax is e.g. GET /?pin=MOTOR1STOP HTTP/1.1
String sPath="",sParam="", sCmd="";
String sGetstart="GET ";
int iStart,iEndSpace,iEndQuest;
iStart = sRequest.indexOf(sGetstart);
if (iStart>=0)
{
iStart+=+sGetstart.length();
iEndSpace = sRequest.indexOf(" ",iStart);
iEndQuest = sRequest.indexOf("?",iStart);
// are there parameters?
if(iEndSpace>0)
{
if(iEndQuest>0)
{
// there are parameters
sPath = sRequest.substring(iStart,iEndQuest);
sParam = sRequest.substring(iEndQuest,iEndSpace);
}
else
{
// NO parameters
sPath = sRequest.substring(iStart,iEndSpace);
}
}
}
///////////////////////////////////////////////////////////////////////////////
// output parameters to serial, you may connect e.g. an Arduino and react on it
///////////////////////////////////////////////////////////////////////////////
if(sParam.length()>0)
{
int iEqu=sParam.indexOf("=");
if(iEqu>=0)
{
sCmd = sParam.substring(iEqu+1,sParam.length());
Serial.println(sCmd);
}
}
///////////////////////////
// format the html response
///////////////////////////
String sResponse,sHeader;
////////////////////////////
// 404 for non-matching path
////////////////////////////
if(sPath!="/")
{
sResponse="<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>";
sHeader = "HTTP/1.1 404 Not found\r\n";
sHeader += "Content-Length: ";
sHeader += sResponse.length();
sHeader += "\r\n";
sHeader += "Content-Type: text/html\r\n";
sHeader += "Connection: close\r\n";
sHeader += "\r\n";
}
///////////////////////
// format the html page
///////////////////////
else
{
ulReqcount++;
sResponse = "<html><head><title>Homecontrolserver</title></head><body>";
sResponse += "<font color=\"#000000\"><body bgcolor=\"#FFFFFF\">";
sResponse += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=yes\">";
sResponse += "<h1>Homecontrolserver</h1>";
sResponse += "<h1></h1>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<FONT SIZE=+2>";
sResponse += "<p>Schalter 1 <a href=\"?pin=a_ein\"><button>Ein</button></a> <a href=\"?pin=a_aus\"><button>Aus</button></a></p>";
sResponse += "<p>Schalter 2 <a href=\"?pin=b_ein\"><button>Ein</button></a> <a href=\"?pin=b_aus\"><button>Aus</button></a></p>";
sResponse += "<p>Schalter 3 <a href=\"?pin=c_ein\"><button>Ein</button></a> <a href=\"?pin=c_aus\"><button>Aus</button></a></p>";
sResponse += "<p>Schalter 4 <a href=\"?pin=d_ein\"><button>Ein</button></a> <a href=\"?pin=d_aus\"><button>Aus</button></a></p>";
sResponse += "<p>Schalter 5 <a href=\"?pin=e_ein\"><button>Ein</button></a> <a href=\"?pin=e_aus\"><button>Aus</button></a></p>";
sResponse += "<p>Schalter 6 <a href=\"?pin=f_ein\"><button>Ein</button></a> <a href=\"?pin=f_aus\"><button>Aus</button></a></p>";
sResponse += "<p>Alle An <a href=\"?pin=g_ein\"><button>Ein</button></a> <a href=\"?pin=g_aus\"><button>Aus</button></a></p>";
//////////////////////
// react on parameters
//////////////////////
if (sCmd.length()>0)
{
// write received command to html page
sResponse += "INFO: " + sCmd + "<BR>";
// switch GPIO
if(sCmd.indexOf("a_ein")>=0)
{
Serial.println("a_ein");
mySwitch.setRepeatTransmit(15);
mySwitch.send(1000, 24);
}
else if(sCmd.indexOf("a_aus")>=0)
{
Serial.println("a_aus");
mySwitch.setRepeatTransmit(15);
mySwitch.send(1, 24);
}
if(sCmd.indexOf("b_ein")>=0)
{
Serial.println("b_ein");
mySwitch.setRepeatTransmit(15);
mySwitch.send(2000, 24);
}
else if(sCmd.indexOf("b_aus")>=0)
{
Serial.println("b_aus");
mySwitch.setRepeatTransmit(15);
mySwitch.send(1, 24);
} else if(sCmd.indexOf("c_ein")>=0)
{
Serial.println("c_ein");
mySwitch.setRepeatTransmit(15);
mySwitch.send(3000, 24);
} else if(sCmd.indexOf("c_aus")>=0)
{
Serial.println("c_aus");
mySwitch.setRepeatTransmit(15);
mySwitch.send(1, 24);
} else if(sCmd.indexOf("d_ein")>=0)
{
Serial.println("d_ein");
mySwitch.setRepeatTransmit(15);
mySwitch.send(4000, 24);
} else if(sCmd.indexOf("d_aus")>=0)
{
Serial.println("d_aus");
mySwitch.setRepeatTransmit(15);
mySwitch.send(1, 24);
} else if(sCmd.indexOf("e_ein")>=0)
{
Serial.println("e_ein");
mySwitch.setRepeatTransmit(15);
mySwitch.send(5000, 24);
} else if(sCmd.indexOf("e_aus")>=0)
{
Serial.println("e_aus");
mySwitch.setRepeatTransmit(15);
mySwitch.send(1, 24);
} else if(sCmd.indexOf("f_ein")>=0)
{
Serial.println("f_ein");
mySwitch.setRepeatTransmit(15);
mySwitch.send(6000, 24);
} else if(sCmd.indexOf("f_aus")>=0)
{
Serial.println("f_aus");
mySwitch.setRepeatTransmit(15);
mySwitch.send(1, 24);
} else if(sCmd.indexOf("g_ein")>=0)
{
Serial.println("g_ein");
mySwitch.setRepeatTransmit(15);
mySwitch.send(1000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(2000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(3000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(4000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(5000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(6000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(7000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(8000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(9000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(10000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(11000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(12000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(13000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(14000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(15000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(16000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(17000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(18000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(19000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(20000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(21000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(22000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(23000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(24000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(25000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(26000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(27000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(28000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(29000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(30000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(31000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(32000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(33000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(34000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(35000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(36000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(37000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(38000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(39000, 24);
delay(100);
mySwitch.setRepeatTransmit(15);
mySwitch.send(40000, 24);
delay(100);
} else if(sCmd.indexOf("g_aus")>=0)
{
Serial.println("g_aus");
mySwitch.setRepeatTransmit(15);
mySwitch.send(1, 24);
}
}
sResponse += "<FONT SIZE=-2>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "<BR>Aufrufzähler = ";
sResponse += ulReqcount;
sResponse += " - Verbindungszähler = ";
sResponse += ulReconncount;
sResponse += "<BR>";
sResponse += "<BR>";
sResponse += "</body></html>";
sHeader = "HTTP/1.1 200 OK\r\n";
sHeader += "Content-Length: ";
sHeader += sResponse.length();
sHeader += "\r\n";
sHeader += "Content-Type: text/html\r\n";
sHeader += "Connection: close\r\n";
sHeader += "\r\n";
}
// Send the response to the client
client.print(sHeader);
client.print(sResponse);
// and stop the client
client.stop();
Serial.println("Client disonnected");
}
code works thats not the Problem, i only want to add simple as possible a picture for the webpage background thats all.
Hope someone can help
regards from Germany