본문 바로가기
아두이노

아두이노에서 문장 만들기 #1

by 오징어땅콩2 2020. 2. 4.
반응형

코드를 작성 할때 다른 사람들이 보기 편하게 작성하면 보는 사람도 편합니다.
그런데 보기 짜증나게 작성하면 정말 보기 싫어 합니다.
그 중에 대표적인게 문장을 만드는경우 입니다.
아두이노에서 문장을 만드는 일이 많습니다.

문장을 출력 하는일은 잘 없지만,
1. HTML언어로 문장을 만들어야 웹브라우저에서 볼수 있습니다.
2. HTML문장으로 데이터를 전송하여 MYSQL DB에 데이터를 삽입 할때도 문장이 필요합니다.
2.2 여기서 HTTP 전송양식이 XX같아서 정확히 작성하지 않으면 정말 지랄 맞는것 처럼 되지 않습니다.
2.3 심지어는 POST 방식은 줄바꿈 개수까지도 정확해야 합니다.

결국 작성한 내용을 출력해서 확인하는 방법이 제일 좋습니다.

 

아래와 같이 했을경우 문제점이 무엇일까요 ?

내용을 확인 할 수도 있지만 시리얼창에 출력하기가 어렵다는거죠.

client.println("<!DOCTYPE html><html>");

client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");

client.println("<link rel=\"icon\" href=\"data:,\">");

client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");

client.println(".button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;");

client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");

client.println(".button2 {background-color: #77878A;}</style></head>");

client.println("<body><h1>ESP8266 Web Server</h1>");

 

Colored by Color Scripter

 

아래와 같이 두가지 방식으로 문자을 만들수가 있습니다.

char buf[1024];

char*p=buf;

 

+= sprintf(p, "<!DOCTYPE html><html>");

+= sprintf(p, "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");

+= sprintf(p, "<link rel=\"icon\" href=\"data:,\">");

+= sprintf(p, "<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");

+= sprintf(p, ".button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;");

+= sprintf(p, "text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");

+= sprintf(p, ".button2 {background-color: #77878A;}</style></head>");

+= sprintf(p, "<body><h1>ESP8266 Web Server</h1>");

 

client.println(buf);

serial.println(buf);

Colored by Color Scripter

 

String str;

str +=  "<!DOCTYPE html><html>";

str +=  "<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">";

str +=  "<link rel=\"icon\" href=\"data:,\">";

str +=  "<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}";

str +=  ".button { background-color: #195B6A; border: none; color: white; padding: 16px 40px;";

str +=  "text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}";

str +=  ".button2 {background-color: #77878A;}</style></head>";

str +=  "<body><h1>ESP8266 Web Server</h1>";

 

client.println(str);

serial.println(str);

            

Colored by Color Scripter

 

'아두이노' 카테고리의 다른 글

아두이노 Serial MP3 모듈 -#2  (0) 2020.02.06
아두이노 Serial MP3 모듈 -#1  (0) 2020.02.06
아두이노 reset -#4  (0) 2020.01.27
아두이노 reset -#3  (0) 2020.01.27
아두이노 reset -#2  (0) 2020.01.27

댓글