1. flask 설치 : 라즈베리파이에 기본으로 설치되어 있음
    1. 파이썬 2.x
      1. sudo apt-get install python-pip
      2. sudo pip install flask
    2. 파이썬 3.x
      1. sudo apt-get install python3-pip
      2. sudo pip3 install flask
  2. 간단한 웹서버 구축 : web_server.py

    1. route() 메서드가 Flask에 정의되어 있어 그것을 사용
    2. debug=True : 디버깅 결과를 출력
    3. port=1234 : 1234 Port를 사용(기본은 5000번 포트 사용)
    4. host=0.0.0.0 : public하게 하여 모두 접속 가능
  3. 실행 : python3 web_server.py
  4. 웹브라우저에서 접속
    1. http://192.168.0.14:1234/
      1. 출력 : This is main page.
    2. http://192.168.0.14:1234/sub
      1. 출력 : This is sub page.
    3. http://192.168.0.14:1234/led/on
      1. 출력 : Led is now on
    4. http://192.168.0.14:1234/led/off
      1. 출력 : Led is now off
  5. flask를 이용하여 LED를 켜고 끄기 구현
    1. 서버 실행 : python3 web_led.py
    2. 클라이언트 접속 결과
    3. flask 웹서버 구성 : web_led.py
    4. 홈페이지 구성:/templates/index.html
    5. 홈페이지 스타일 지정 : /static/style.css

       
error: Content is protected !!