つ⋅⌄⋅)づ⌁⌁도움⌁⌁⋆
2020.07.29_라즈베리파이 본문
process - 실행 중인 프로그램
prcessor -
ps -ef | grep process.py : 파이프라인 명령어인데 파일에서 특정한 파일을 찾는 명령어
netstat -nlpt : 사용 중인 port확인 가능하다
sudo kill PID숫자 : 해당 PID 가진 포트를 죽인다 (실행 끝내기)
--> flask로 작업을 하다 보면 이전에 실행한 프로세스가 종료되지 않아서 포트가 충돌 나는 경우가 있을 때 사용
< cron과 deamon 개념잡기 >
: cron은 주기적인 실행이 필요할 때 사용 (스케쥴러)
일정 등록한 게 하나도 없을 때
<cron 코드>
import RPi.GPIO as GPIO
import time
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT, initial=GPIO.LOW)
try:
num = 0
while(True):
time.sleep(1)
GPIO.output(21, 0)
time.sleep(1)
GPIO.output(21, 1)
num = num + 1
if(num == 5):
GPIO.cleanup()
break
except KeyboardInterrupt:
GPIO.cleanup()
-> 5번 실행하고 자동으로 꺼진다
: deamon - 계속 실행되는 것
<daemon 코드>
#! /usr/bin/env python3.4
import RPi.GPIO as GPIO
import time
GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT, initial=GPIO.LOW)
try:
num = 0
while(True):
time.sleep(1)
GPIO.output(21, 0)
time.sleep(1)
GPIO.output(21, 1)
num = num + 1
if(num == 5):
GPIO.cleanup()
break
except KeyboardInterrupt:
GPIO.cleanup()
< 공공데이터 활용하기 >
https://www.data.go.kr/iim/api/selectAPIAcountView.do
공공데이터 포털
국가에서 보유하고 있는 다양한 데이터를『공공데이터의 제공 및 이용 활성화에 관한 법률(제11956호)』에 따라 개방하여 국민들이 보다 쉽고 용이하게 공유•활용할 수 있도록 공공데이터(Datase
www.data.go.kr
from urllib.parse import urlencode
import requests
import json
url = "http://apis.data.go.kr/1360000/VilageFcstInfoService/getUltraSrtNcst"
queryString = "?" + urlencode(
{
"base_date" : "20200729",
"base_time" : "1500",
"nx" : 96,
"ny" : 79,
"numOfRows" : "10",
"pageNo" : 1,
"dataType" : "JSON"
}
)
queryURL = url + queryString + "&ServiceKey=CHAwZoDzVQvr1Vsoq%2B10sl2d1hqAsF61YWv0c9mUrGN8Uejkwbe9suDje8HdAZEAlnz1FdsC6k11sd%2BgdXFBuw%3D%3D"
response = requests.get(queryURL)
print("=== response json data start ===")
print(response.text)
print("=== response json data end ===")
print()
r_dict = json.loads(response.text)
r_response = r_dict.get("response")
r_body = r_response.get("body")
r_items = r_body.get("items")
r_item = r_items.get("item")
result = {}
for item in r_item:
if(item.get("category") == "T1H"):
result = item
break
print("=== response dictionary(python object) data start ===")
print(result.get("baseTime")[:-2] +"시 온도는 " +
result.get("obsrValue") + "도 입니다")
print("=== response dictionary(python object) data end ===")
print()