본문 바로가기
아두이노

아두이노 이더넷 클라이언트의 시작-#5

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

좀 양이 많은것 같아서 다시 작성한다.

3개의 GET 전송방식의 표현은 동일하지만, 재활용과 이해의 측면에서 이게 더 실용적이다.

 

다시 이야기 하지만 공백하나 줄바꿈 하나 잘못 넣으면 오류가 발생한다.

왜 이렇게 넣어요 하는 질문은 이해 불가의 질문이다. 

만든사람이 그렇게 만들어서 어쩔수 없다. 

사실 불편하게 짝이 없다.

그래도 이방식으로 고수해서 모두 사용하고 있다.

 

void GET_Page2(EthernetClient& c)
{
  // if you get a connection, report back via serial:
  #define CITY "1835235"  //대전 도시 ID
  #define HOST "api.openweathermap.org"
  #define SKEY "1107a6df5ce46cce4179b4a6646xxxx" //개인 APPID  
  
  Serial.print("connecting to ");
  Serial.print(HOST);
  Serial.println("..."); 
  if (client.connect(HOST, 80)) 
  { 
      Serial.println("connected to ");   
      String webpage;
      
      webpage  = "GET ";
      webpage += "/data/2.5/weather?id=";
      webpage += CITY;
      webpage += "&APPID=";
      webpage += SKEY; 
      webpage += " HTTP/1.1\r\n";
      webpage += "Host: ";
      webpage += HOST;
      webpage += "\r\n"
      webpage += "Connection: close\r\n";  
      webpage += "\r\n\r\n";  
      //Serial.println(webpage);      
      c.println(webpage);  
  }
  else 
  {
      // if you didn't get a connection to the server:
      Serial.println("connection failed");
  }    
    return ;
}
void GET_Page3(EthernetClient& c)
{
  // if you get a connection, report back via serial:
  #define CITY "1835235"  //대전 도시 ID
  #define HOST "api.openweathermap.org"
  #define SKEY "1107a6df5ce46cce4179b4a6xxxxx" //개인 APPID  
  
  Serial.print("connecting to ");
  Serial.print(HOST);
  Serial.println("..."); 
  if (client.connect(HOST, 80)) 
  { 
      Serial.println("connected to ");   
      String webpage;
      
      webpage  = "GET ";
      webpage += "/data/2.5/weather?id=" + String(CITY)+ String("&APPID=")+ String(SKEY) + String(" HTTP/1.1\r\n");
      webpage += "Host: " + String(HOST) + String("\r\n");
      webpage += "Connection: close\r\n";  
      webpage += "\r\n\r\n";  
      //Serial.println(webpage);      
      c.println(webpage);  
  }
  else 
  {
      // if you didn't get a connection to the server:
      Serial.println("connection failed");
  }    
    return ;
}
 

댓글