---
title: "아두이노이더넷 쉴드로 기상청 날씨데이타 가져오기"
url: "https://maker.wiznet.io/gemma/projects/%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8%EC%9D%B4%EB%8D%94%EB%84%B7-%EC%89%B4%EB%93%9C%EB%A1%9C-%EA%B8%B0%EC%83%81%EC%B2%AD-%EB%82%A0%EC%94%A8%EB%8D%B0%EC%9D%B4%ED%83%80-%EA%B0%80%EC%A0%B8%EC%98%A4%EA%B8%B0/"
markdown_url: "https://maker.wiznet.io/gemma/projects/%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8%EC%9D%B4%EB%8D%94%EB%84%B7-%EC%89%B4%EB%93%9C%EB%A1%9C-%EA%B8%B0%EC%83%81%EC%B2%AD-%EB%82%A0%EC%94%A8%EB%8D%B0%EC%9D%B4%ED%83%80-%EA%B0%80%EC%A0%B8%EC%98%A4%EA%B8%B0/md"
type: "UCC: User Created Content"
author: "아두이노로 놀기"
author_url: "https://blog.naver.com/PostView.nhn?blogId=mkhee77&logNo=221458277679"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "아두이노로 놀기"
original_url: "https://blog.naver.com/PostView.nhn?blogId=mkhee77&logNo=221458277679"
published: "2022-12-29"
language: "ko"
hardware: ["Arduino UNO", "WIZnet W5100 ethernet shield"]
likes: 2
views: 527
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# 아두이노이더넷 쉴드로 기상청 날씨데이타 가져오기

> 기상청의 공개된 정보를 가져와서 날씨를 표시한다.

Original author: 아두이노로 놀기 (source: https://blog.naver.com/PostView.nhn?blogId=mkhee77&logNo=221458277679)

## Components

- **Arduino UNO** x 1 ([docs](https://www.farnell.com/datasheets/1682209.pdf))
- **WIZnet W5100 ethernet shield** x 1 ([docs](https://www.wiznet.hk/en/open-source-hardware/102-w5100s-ethernetshield.html?search_query=W5100+ethernet+shield&results=84))

## Article

기상청 날씨누리에서 원하는 지역을 선택한 후 RSS데이타를 가져오면 된다.

지금 아두이노 이더넷 쉴드 W5100을 가지고 있으니, 아두이노 우노와 이더넷 쉴드 W5100을 사용하여 날씨정보를 가져와야 겠다.

먼저 아두이노 IDE의 예제중 Ethernet>WebClientRepeating을 사용한다.

​

/*

Repeating Web client

​

This sketch connects to a a web server and makes a request

using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or

the Adafruit Ethernet shield, either one will work, as long as it's got

a Wiznet Ethernet module on board.

​

This example uses DNS, by assigning the Ethernet client with a MAC address,

IP address, and DNS address.

​

Circuit:

* Ethernet shield attached to pins 10, 11, 12, 13

​

created 19 Apr 2012

by Tom Igoe

modified 21 Jan 2014

by Federico Vanzati

​

<http://www.arduino.cc/en/Tutorial/WebClientRepeating>

This code is in the public domain.

​

*/

​

[#include](https://blog.naver.com/PostListByTagName.naver?blogId=mkhee77&encodedTagName=include) &lt;SPI.h>

[#include](https://blog.naver.com/PostListByTagName.naver?blogId=mkhee77&encodedTagName=include) &lt;Ethernet.h>

​

// assign a MAC address for the ethernet controller.

// fill in your address here:

byte mac[] = {

0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED

};

// Set the static IP address to use if the DHCP fails to assign

//IPAddress ip(192, 168, 0, 177);

//IPAddress myDns(192, 168, 0, 1);

​

// initialize the library instance:

EthernetClient client;

​

char server[] = "[www.arduino.cc";](http://www.arduino.cc%22%3B/) // also change the Host line in httpRequest()

//IPAddress server(64,131,82,241);

​

unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds

const unsigned long postingInterval = 10*1000; // delay between updates, in milliseconds

​

void setup() {

// You can use Ethernet.init(pin) to configure the CS pin

//Ethernet.init(10); // Most Arduino shields

//Ethernet.init(5); // MKR ETH shield

//Ethernet.init(0); // Teensy 2.0

//Ethernet.init(20); // Teensy++ 2.0

//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet

//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet

​

// start serial port:

Serial.begin(9600);

while (!Serial) {

; // wait for serial port to connect. Needed for native USB port only

}

​

// start the Ethernet connection:

Serial.println("Initialize Ethernet with DHCP:");

if (Ethernet.begin(mac) == 0) {

Serial.println("Failed to configure Ethernet using DHCP");

// Check for Ethernet hardware present

if (Ethernet.hardwareStatus() == EthernetNoHardware) {

Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");

while (true) {

delay(1); // do nothing, no point running without Ethernet hardware

}

}

if (Ethernet.linkStatus() == LinkOFF) {

Serial.println("Ethernet cable is not connected.");

}

// try to congifure using IP address instead of DHCP:

Ethernet.begin(mac, ip, myDns);

Serial.print("My IP address: ");

Serial.println(Ethernet.localIP());

} else {

Serial.print(" DHCP assigned IP ");

Serial.println(Ethernet.localIP());

}

// give the Ethernet shield a second to initialize:

delay(1000);

}

​

void loop() {

// if there's incoming data from the net connection.

// send it out the serial port. This is for debugging

// purposes only:

if (client.available()) {

char c = client.read();

Serial.write(c);

}

​

// if ten seconds have passed since your last connection,

// then connect again and send data:

if (millis() - lastConnectionTime > postingInterval) {

httpRequest();

}

​

}

​

// this method makes a HTTP connection to the server:

void httpRequest() {

// close any connection before send a new request.

// This will free the socket on the WiFi shield

client.stop();

​

// if there's a successful connection:

if (client.connect(server, 80)) {

Serial.println("connecting...");

// send the HTTP GET request:

client.println("GET /latest.txt HTTP/1.1");

client.println("Host: [www.arduino.cc");](http://www.arduino.cc%22%29%3B/)

client.println("User-Agent: arduino-ethernet");

client.println("Connection: close");

client.println();

​

// note the time that the connection was made:

lastConnectionTime = millis();

} else {

// if you couldn't make a connection:

Serial.println("connection failed");

}

}

---

Source: https://maker.wiznet.io/gemma/projects/%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8%EC%9D%B4%EB%8D%94%EB%84%B7-%EC%89%B4%EB%93%9C%EB%A1%9C-%EA%B8%B0%EC%83%81%EC%B2%AD-%EB%82%A0%EC%94%A8%EB%8D%B0%EC%9D%B4%ED%83%80-%EA%B0%80%EC%A0%B8%EC%98%A4%EA%B8%B0/
