온도계¶
날씨 API를 사용하여 간단한 IoT 아날로그 온도계를 만들 수 있습니다. 아래 그림은 섭씨 13도 정도를 나타냅니다.
눈금자를 아래 링크에서 다운로드 받으세요.
https://github.com/TheMatrixGroup/DynamiKontrol/raw/master/examples/thermometer.pdf
소스코드¶
from dynamikontrol import Module
import requests, time
from datetime import datetime
module = Module()
# weather of Seoul, Korea
lat = 37.566536 # latitude
lon = 126.977966 # longitude
url = f'https://fcc-weather-api.glitch.me/api/current?lat={lat}&lon={lon}'
while True:
res = requests.get(url).json()
temp = res['main']['temp']
print(f'{datetime.now()} temperature {temp} degree')
angle = int(temp * 10 / 3)
module.motor.angle(angle)
time.sleep(60)
module.disconnect()