본문 바로가기

메이커 이야기/메이커 이야기

스마트 미러 만들기 프로젝트_#5.날씨 정보, 기상 예측

반응형

안녕하세요.

 

지난번에 이어 이번에는 날씨 정보와 기상 정보를 가져오는 실습을 해보도록 하겠습니다.

 

날씨 정보를 가져오는 방법들은 다양하겠지만,

 

저희가 사용하는 MagicMirror 코드에서는 openweather.org 사이트를 통해서 날씨 정보를 가져오도록 하고 있습니다.

 

openweather.org사이트의 날씨 정보가 400,000개의 지역에 날씨 정보를 제공해주는 아주 방대한 서비스 입니다.

 

세상에 이런 정보가 있다니 ... 놀랄 뿐이죠

 

우선 날씨 정보를 보여주기 위해서는 어떤 정보들이 필요한지 알아봐야겠습니다.

 

config.js파일 내에서 weatherforecast를 보시면,

location, locationID, appid(API KEY) 정보가 필요한데요

여기서 location은 꼭 필요한 정보는 아닙니다.

Location ID값과 appid값을 알면 되겠네요~!

 

modules: [
	{
		module: "weatherforecast",
		position: "top_right",	// This can be any of the regions.
									// Best results in left or right regions.
		config: {
			// See 'Configuration options' for more information.
			location: "Amsterdam,Netherlands",
			locationID: "", //Location ID from http://bulk.openweathermap.org/sample/city.list.json.gz
			appid: "abcde12345abcde12345abcde12345ab" //openweathermap.org API key.
		}
	}
]

 

■ Location ID 값 찾기

 

openweathermap.org에서는 전세계 날씨 정보를 알려주기 때문에, 수많은 지역 정보값들이 있습니다. 이는 json 방식으로 데이터를 제공해주고 있는데요

json데이터는 한눈에 보기 편하게 만들어놓은 데이터 통신 포멧이라고 보시면 이해가 빠릅니다.

 

JSON 날씨 다운받기 (http://bulk.openweathermap.org/sample/city.list.json.gz)

 

위 링크를 통해서 받으시면 되며, 저는 성남에 거주하고 있기 때문에,

성남 지역 정보를 활용해보도록 할 것입니다. 성남시를 찾아보니 

아래와 같이 되어 있네요 ?!

{
    "id": 1897000,
    "name": "Seongnam-si",
    "state": "",
    "country": "KR",
    "coord": {
      "lon": 127.137779,
      "lat": 37.43861
    }
  },

 

 

■ 날씨 API값 가져오기

 

날씨 정보를 가져오기 위해서는 우선 홈페이지에서 API키를 발급 받아야 합니다.

 

1. API키 발급 받기

 

https://openweathermap.org/

 

Сurrent weather and forecast - OpenWeatherMap

Dashboard and Agro API We provide satellite imagery, weather data and other agricultural services that are based on geodata. By using Agro API , you can easily power your solution based on this information. Dashboard is a visual service where you can easy

openweathermap.org

우선 위 사이트에 접속하셔서 회원가입을 완료하여 주세요

 

 

회원가입이 완료되면 

API키를 발급 받을 건데요

우선 API키를 발급바는 건 CUrrent Weather Data 현재 날씨를 알려주는 API를 활용해보도록 하겠습니다.

 

 

위에 절차대로 API Key를 복사하셔서 앞서 config.js에 넣어주시면 됩니다.

 

 

modules: [
	{
		module: "weatherforecast",
		position: "top_right",	// This can be any of the regions.
									// Best results in left or right regions.
		config: {
			// See 'Configuration options' for more information.
			location: "Seongnam-si",
			locationID: "1897000", //Location ID from http://bulk.openweathermap.org/sample/city.list.json.gz
			appid: "124asdgt24255151a" //openweathermap.org API key.
		}
	}
]

 

이렇게 날씨정보까지 가져오는걸 완료했습니다.

위에 current weather까지 함께 넣으시면,

오늘의 날씨와 / 5일간의 날씨 정보도 함께 나타납니다!

 

다음번에는 Calender 부분을 수정해보도록 하겠습니다.

 

 

그 외에도 다양한 3rd Party Module 이 존재하니,

이를 활용하시면 더욱더 멋진 매직 미러를 만들 수 있습니다.

 

https://github.com/MichMich/MagicMirror/wiki/3rd-Party-Modules

 

반응형