How to use HTML code as a string

Hi All

I have an HTML code that I want to send it to a string and send it via client.println() function but I cant

the code I want to put it into a string is :

div.tab button { background-color: inherit; float: left; border: none; outline: none; cursor: pointer; padding: 14px 16px; transition: 0.3s; font-size: 17px; }

I dont know how to do it??

char* someString = "div.tab button {"
    "background-color: inherit;"
    "float: left;"
    "border: none;"
    "outline: none;"
    "cursor: pointer;"
    "padding: 14px 16px;"
    "transition: 0.3s;"
    "font-size: 17px;"
"}";
String html = "div.tab button {\
    background-color: inherit;\
    float: left;\
    border: none;\
    outline: none;\
    cursor: pointer;\
    padding: 14px 16px;\
    transition: 0.3s;\
    font-size: 17px;\
}";

The String class is not reliable in a small memory footprint system like a microcontroller.

Thanks a lot

and can I send it via client.printl() function??

It's css what you have there, not html. Put styles in a separate static file. From sketch code serve only data as json or some simple html with 'classed' elements.

And use the F() macro for constant strings in sketch.

Thanks

You do not have to send everything in one go. A couple of client.println() can also do.

aarg: The String class is not reliable in a small memory footprint system like a microcontroller.

OP was asking for a string... It looks like I'm getting too used to the 1MB flash of the ESP8266. Good I haven't started playing with my ESP32 yet :) The ATtiny13 that I'm eagerly awaiting is going to give me a nice learning curve in slimming down sketches.

wvmarle: OP was asking for a string...

So, you need to brush-up on your comprehension.

I have another question too

I have this code:
40 Min

and it gives me error to the double cotation of the “button”

what should I replace with the double cotation??

it’s html. you can use ’ instead of ". or escape the " with \

"<button class=\"button\">40 Min</button>"

Thanks a lot

Hi

I want to run a web server via SPIFFS of arduino and my code is here but the web page is not loading.

#include <ESP8266WiFi.h>
#include “FS.h”

const char* ssid =“Amir”;
const char* password =“911183012”;

WiFiServer server(80);

void setup() {

Serial.begin(115200);
delay(10);

Serial.println();
Serial.println();
Serial.print(“Connecting to”);
Serial.println(ssid);

WiFi.begin(ssid,password);

while(WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");

}
Serial.println("");
Serial.println(“WiFi connected”);

server.begin();
Serial.println(“Server Started”);
Serial.println(WiFi.localIP());//give us a IP that we can use it into web browser
SPIFFS.begin();
SPIFFS.format();
}

void loop() {
WiFiClient client = server.available();
if(!client){
return;
}
Serial.println(“new client”);
while(!client.available()){
delay(1);
}
String req = client.readStringUntil(’\r’);
Serial.println(req);
client.flush();
File WebServer = SPIFFS.open("/C:\Users\Amir\Desktop\sketch_aug04a\data\WebServer.html", “w”);
if (!WebServer) {
Serial.println(“file open failed”);
}

delay(1);
Serial.println(“Client disconnected”);

}

@wvmarle turns out, that OP is programing a sketch for the ESP :-)

char CSS[] = R"=====(
div.tab button {
    background-color: inherit;
    float: left;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 14px 16px;
    transition: 0.3s;
    font-size: 17px;
}
)=====";

...
Serial.println(CSS);

I want to run a web server via SPIFFS of arduino and my code is here but the web page is not loading.

ESP8266 includes an example named FSBrower which stores HTML, CSS, etc. in the SPIFFS file system.

https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer/examples/FSBrowser