본문 바로가기
아두이노

아두이노 이더넷 웹서버 만들기 -#7

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

개인적으로 지난번 소스코드도 딱히 어려운 부분이 없어 보이는데, 
설명을 약간 추가해야 할 부분이라면 loop과 wepPage정도 일듯 합니다.
loop은 클라이언트가 요청하는 정보를 표시하는 부분 혹은 모으는 부분과 클라이언트에게 정보를 보내는 부분으로 나누어 있다고 보시면 될듯 합니다.
그리고 void read_temp(char*& p) 함수의 정의 부분도 유심히 보면 좋을듯 합니다.
콜바이 밸류, 콜바이 레프런스 부분인데, 주소값을 참고하기위해서는 콜바이 레프런스가 필요합니다.
쉽게 말해서 어디까지 문장을 작성했는지 모르기 때문에 그 주소값이 필요한거죠.
주소라도 복사기 되기 때문에 그렇겠죠.

 

void loop() 
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) 
  {
    Serial.println("new client");
    // an http request ends with a blank line
    bool currentLineIsBlank = true;
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) 
        {
          webPage1(client);
          break;
        }
        if (c == '\n'
        {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r'
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    Serial.println("client disconnected");
  }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

 

 

void read_temp(char*& p)
{
    for(int i = 0; i < 5; i++)
    {
        double t;
        t  = analogRead (A0+i); // A0의 값을 불러옵니다.
        t *= 5.0 / 10.24//온도값을 계산하는 공식입니다.
        p += sprintf(p, "T(A%1d)=%s C<br/>\n", i, String(t,1).c_str());             
    }
    return  ;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

댓글