본문 바로가기

RaspberryPi/RP2040_W6100

[RP2040_W6100] 웹서버 테스트 - Base64 인코딩 방식 이미지 출력하기

 

 

 

 

[RP2040_W5500] 보드를 이용하여 웹페이지 출력 테스트 예제를 참고로 W6100에서 웹서버 예제를 테스트 해 보자

 

[RP2040_W5500] Webserver 테스트

지난 포스트에서 Ethernet_Generic 라이브러리를 이용해서 이더넷 전송 속도 개선을 했고 이제 웹서버를 구현 해 보자 웹서버의 가장 기본이 되는 뼈대 코드를 작성해보자. 새로운 라이브러리로 ESP32

nexp.tistory.com

 

이번에는 이미지를 출력해 보면 좋을것 같다.

 

웹페이지에 이미지를 출력하는 방법은 여러 가지가 있지만 가장 간단하게 할 수 있는 Base64 인코딩 방식으로 이미지를 출력 해보자

 

#define USE_W5100                           false
#define USE_THIS_SS_PIN                     17

#define SerialDebug   Serial
#define DEBUG_ETHERNET_GENERIC_PORT         SerialDebug
#define DEBUG_ETHERNET_WEBSERVER_PORT       SerialDebug
#define USE_UIP_ETHERNET   false

#define USE_ETHERNET_GENERIC  true
#define USE_ETHERNET_ESP8266  false
#define USE_ETHERNET_ENC      false
#define USE_CUSTOM_ETHERNET   false

#define ETHERNET_USE_RPIPICO      true

#define USING_W6100                         true

byte mac[] =	{ 0x00, 0x08, 0xDC, 0x00, 0x00, 0x00 };


#include <SPI.h>
#include "Ethernet_Generic.h"
#include <EthernetWebServer.h>

EthernetWebServer server(80);

const int Led1Pin = 25;

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
<body>
    <h1><center>LED - Control</h1><br>
    <p style="text-align: center;">
    <a href="On">
  <center>
    <div>
<img alt="led_on1.jpg" 
src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQE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H/al8Vfsu6B8INR1Px18SNd8O2nxJvoNf8Jw6RNau2p2nwnvbbxndL4auHXWoLeyttRswEmvNQtlgsxKn8ro1Dw8WKn/gt54rVgNxD+Ff27k4yV43265IIIIGSO4GRQBznm/Fz/pDH8OP/DD/ALdn/wA+ivrD9hf/AIWnJ+1/+zybz/gkn4G+G1inxN8PPefES3+DP7W3hq78A2bXTQXPjG2174mfErxB4O0268N28kmrwzalpN40klqttAiPMJU+cjqPh0MFP/Bb7xSCSAM+Fv27MEkgAbvI298nnhQWOFUkftN/wRy+DHxA8RfE3xD8eNG/4KNeOv2p/hR4W0rWvAOueDrzR/j5pWg3fivWbPT7yyN3F8bLiHTriTw/bEail14d0241CK6njtr6+toZ3t7kA/pKt/8AVLgKAdzYQ5HzMWOSQMsSSW+VfmJ+UdBNUcS7FI2hfmYnHcsSzNjJwWYsx5JJJYncTUlABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFAFC/srTUbe5sr63gvLO7gktrq1uYo7i2ubaeN4p7e4t5leGeCeKSSKaKVHSSN2R1IOK/Gv9oD/ght/wAE/virf3Xi3TvA3i34QapcNPJeW3wf8UxeH9AubiRndrmPwv4h0jxZ4c0lzhVMWg6XpNoQgLWzOWdiigDyT4R/8EAv2CdN1iHWvEcnxt+IUFjNHKdA8WfETTdP0W9CsGMV9/wgPhHwTq8sMmAsscerw+YvysSK/bb4WfCf4bfBbwfo/wAPfhR4L8P+APBOgQSRaT4a8M6dBpumWnnSlp5vKiXfPd3Ui+deX1zJNeXkzNNdTzSHdRRQB6RRRRQAUUUUAFFFFABRRRQB/9k=">
    </div>
    </center>
    </a>        
</center>
</script>
</div>
</body>
</html>
)rawliteral";

void handle_root()
{
  server.send(200, "text/html", index_html);
}

void handleNotFound()
{
  String message = F("File Not Found\n\n");

  message += F("URI: ");
  message += server.uri();
  message += F("\nMethod: ");
  message += (server.method() == HTTP_GET) ? F("GET") : F("POST");
  message += F("\nArguments: ");
  message += server.args();
  message += F("\n");

  for (uint8_t i = 0; i < server.args(); i++)
  {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }

  server.send(404, F("text/plain"), message);

  digitalWrite(Led1Pin, 0);
}

void initWebServer() 
{
  //페이지 요청 처리 함수 등록
  server.on("/", handle_root);
  server.onNotFound(handleNotFound);

  server.begin();
}

void setup()
{
  pinMode(Led1Pin, OUTPUT);
  digitalWrite(Led1Pin, 1);

  // Open serial communications and wait for port to open:
  SerialDebug.begin(115200);

  while (!SerialDebug && millis() < 5000);

  SerialDebug.print("\nStarting HelloServer2 on ");
  SerialDebug.print(BOARD_NAME);
  SerialDebug.print(F(" with "));
  SerialDebug.println(ETHERNET_WEBSERVER_VERSION);

  Ethernet.init (USE_THIS_SS_PIN);

  // start the ethernet connection and the server:
  // Use Static IP
  Ethernet.begin(mac);

  SerialDebug.print(F("Connected! IP address: "));
  SerialDebug.println(Ethernet.localIP());

  initWebServer();

  SerialDebug.print(F("HTTP HelloServer2 started @ IP : "));
  SerialDebug.println(Ethernet.localIP());
}

void loop()
{
  server.handleClient();
}

 

 

컴파일후 다운로드 해 보면 이미지가 출력 되는것을 확인 할 수 있다.

 

 


이제 이미지 클릭시 보드의 LED를 제어 할수 있도록 해보자

 

우선 클릭에 따라 이미지를 쉽게 바꿀 수 있도록 웹페이지를 수정하자. 변경되어야 할 부분을 $ 으로 표기 해서 쉽게 바꿀 수 있도록 했다.

#define STR_LED_ON_IMG F("/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQ...")
#define STR_LED_OFF_IMG F("/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBA...")

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
<body>
    <h1><center>$LED_STATUS$</h1><br>
    <p style="text-align: center;">
    <a href="$LED_URL$">
  <center>
    <div>
<img alt="led_on1.jpg" 
src="data:image/jpeg;base64,$IMAGE_LED1$">
    </div>
    </center>
    </a>        
</center>
</script>
</div>
</body>
</html>
)rawliteral";

 

 

홈페이지 접속시 호출되는 함수에서 상태에 따라서 replace 함수로 페이지 내용을 바꿀수 있도록 하자 

void handle_root()
{
  String str_new_page = index_html;

  str_new_page.replace("$LED_STATUS$", "LED - ON");
  str_new_page.replace("$LED_URL$", "On");
  
  str_new_page.replace("$IMAGE_LED1$", STR_LED_ON_IMG);

  server.send(200, "text/html", str_new_page);
}

 

 

 

이미지 클릭시 처리 하는 함수도 수정한다.

//On 버튼 페이지 처리함수
void SetLedStatusOn()
{
  Serial.println("On");
  digitalWrite(Led1Pin, 1);

  String str_new_page = index_html;

  str_new_page.replace("$LED_STATUS$", "LED - OFF");
  str_new_page.replace("$LED_URL$", "Off");
  
  str_new_page.replace("$IMAGE_LED1$", STR_LED_OFF_IMG);


  server.send(200, "text/html", str_new_page);
}

//Off 버튼 페이지 처리함수
void SetLedStatusOff()
{
    Serial.println("Off");
    digitalWrite(Led1Pin, 0);

  String str_new_page = index_html;

  str_new_page.replace("$LED_STATUS$", "LED - ON");
  str_new_page.replace("$LED_URL$", "On");
  
  str_new_page.replace("$IMAGE_LED1$", STR_LED_ON_IMG);

    server.send(200, "text/html", str_new_page);
}


void initWebServer() 
{
  //페이지 요청 처리 함수 등록
  server.on("/", handle_root);
  server.on("/On", HTTP_GET, SetLedStatusOn);
  server.on("/Off", HTTP_GET, SetLedStatusOff);

  server.onNotFound(handleNotFound);

  server.begin();
}

 

 

 

수정 프로그램을 실행하면 이미지를 출력하면서 LED On/Off를 웹페이지에서 제어 할수 있다.

 

 

 

반응형