라즈베리파이4 용 SSD 외장디스크 백업 방법에 대한 고찰

 기존에 SD 카드 이미지를 백업해서 사용했습니다. SD 카드의 느린 속도와 내구성 때문에 한번 씩 문제가 생기면 복구하는데 너무 오랜시간이 소요됩니다. 그래서, SSD로 부팅하고 SSD 장치를 백업하는 방법을 찾아 보았습니다.

  Re: How to make a full backup of Rpi with large SSD?

 

 위 링크 마지막 부분에 macrium reflect 소프트웨어를 추천을 해서 제일 먼저 테스트를 해보았습니다.

 

1. Macrium Reflect

 결론: USB-SSD 백업이 가능하지만, 다시 USB-SSD 장치로 쓰기에서 액서스 거부 증상이 발생

 macrium reflect 8.x

 macrium reflect 7.x

  테스트 한 2개의 버전 모두 동일한 증상

복원시 오류발생 화면

   다른 노트북에서 Macrium Refect 복원하면 정상적으로 복원 작업이 이루어 지지만,복제된 SSD 로 부팅중 중단됨.

 

2. EaseUS Todo
 라즈베리파이의 linux ex4 파티션 인식 못함.

 백업 사용불가

 

3. Acronis Ture Image

기존에 사용하던 2018 버전에서 ex4 파이션 인식을 하지만, 사용량이 0Kb 로 나온다. 2018버전의 오류로 검색된다.

 2020 버전 이후 ex4 파티션 인식문제가 개선되었다고 해서, 최근 버전 2021 버전을 사용한 결과 정상적으로 백업과 복원이 됩니다. SD 카드로 이미지 만들고 복원하는데는 1시간 넘게 걸리는데, 5분도 안걸립니다. 

 하지만, SSD 복제 후 복제된 SSD로 부팅이 되지 않습니다.

 

소프트웨어 받고 테스트 하고 꼬박 24시간 걸려서 찾아낸 결과입니다.

 

결론 :

 라즈베리파이 부팅용으로 사용할 SSD의 경우 윈도우용 백업소프트웨어 Macrium Reflect, EaseUS Todo, Acronis Ture Image 등으로는 정상적인 백업과 복원이 불가능.

 이유는 알수 없습니다. HDMI 모니터로 연결해서 로그를 확인해야 하지만, 현재 HDMI 연결할 모니터가 없다. 로그를 확인해서 메시지를 확인하다 해도, 해결방법도 없을 것 같습니다.

MouseHouse 벽스위치 모델이 가장 yaml설정이 가장 까다롭습니다. 그래서 다른 회사 제품은 아래의 yaml 내용에서 LED 라인 정도 삭제하고 포트만 수정하면 전부 동작이 가능할 것입니다.

ESPHome 설치방법은 https://techclass.tistory.com/1 을 참고하세요.

 

 

[더니즈]님의 글은 ESPHome의 기본 개념을 잡는데 정말 훌륭한 글이었습니다. 오랜 시행착오의 과정을 걱은 노하우까지 전수해 주는 주옥같은 글입니다. ESPHome 에 입문하는데 필독서입니다.

 > esphome 강좌 :  https://cafe.naver.com/stsmarthome/10417 [더니즈] ESPHome Tips #1~

 

- 벽스위치 yaml 스크립트 작성에 [레이군][민쇼] 두분의 글에 매우 많은 도움을 받았습니다.  

다시 한번 감사드립니다.

 > 설정에 도움되는 글 :  https://cafe.naver.com/stsmarthome/10897 [민쇼]님 글

                             https://cafe.naver.com/stsmarthome/10852 [레이군]님 님 글

 > ESPHome 레퍼런스 : https://esphome.io/guides/automations.html

 

 

판매자 링크 : https://www.aliexpress.com/item/32857299145.html?spm=a2g0s.9042311.0.0.27424c4dyDlaNd

 

US $14.24 55% OFF|Wifi Smart Wall Touch Switch Glass Panel Mobile APP Remote Control No Hub Required work with Amazon Alexa Goog

Smarter Shopping, Better Living! Aliexpress.com

www.aliexpress.com

우선,

 다른 스위치는 일반적으로 AC릴레이를 동작시키면 LED가 동작하기 때문에 gpio 포트도 찾기 쉽고 간단하게 제어가 됩니다.

 

 이제품은 다른 벽스위치와 다르게, LED와 AC 전원을 제어하는 릴레이 포트가 별도로 되어있습니다. 그래서, 스크립트 작성에 좀 어려웠습니다. 포트를 쉽게 찾게 해준 글이 바로 [민쇼], [레이군] 두분의 글이 었습니다.

 

쓸때 없는 설명을 대신해서, 설정파일을 그냥 올립니다. 

주석을 달아 놓았으니 아래 내용을 잘 분석하시면, 다른 장치 설정에도 도움이 될 것 같습니다.

 

나머지 부족한 부분은 검색을 통해서 채우셨으면 합니다.

 

 

 

1. "ESPHome > 장치 선택 > Edit"

   저는 공유기에서 자동IP를 할당받는 방법을 사용했습니다. 고정IP 설정하고 싶으신분은 [더니즈]님 강좌를 보시고 수정하시면 됩니다.  필요한 부분 수정해서 붙여 넣으시면 됩니다.

 

 1) 1gang 벽스위치

## MoseHouse 1touch switch
## 아빠방

substitutions:
  node_name: mosehouse01_1touch
  device_name: MoseHouse01 1Touch

esphome:
  name: ${node_name}
  platform: ESP8266
  board: esp01_1m
  on_boot:
    priority: -50
    then:      
      - delay: 10s
      - homeassistant.service:
          service: notify.theniz_telegram
          data:
            message: "Esphome ${device_name}이(가) 시작 되었습니다."

wifi:
  ssid: # WiFi SSID 기록
  password: # WiFi 암호 기록

logger:

api:

ota:

time:
  - platform: sntp
    timezone: UTC-9
    servers:
      - time.bora.net
      - 0.pool.ntp.org
      - 1.pool.ntp.org

sensor:
  - platform: wifi_signal
    name: "${device_name} Wifi Signal"
    id: wifi_sig
    internal: true
    update_interval: 60s
  - platform: template
    name: "${device_name} Wifi Quality"
    icon: "mdi:wifi"
    update_interval: 60s
    unit_of_measurement: '%'
    accuracy_decimals: 0
    lambda: !lambda |-
      if (id(wifi_sig).state < -92.0) {
        return 100.0;
      } else if (id(wifi_sig).state > -21.0) {
        return 1.0;
      } else {
        return round(( -0.0154 * id(wifi_sig).state * id(wifi_sig).state )-( 0.3794 * id(wifi_sig).state ) + 98.182 );
      }

# 입력장치 정의
binary_sensor:
  # touch 1st
  #- platform: gpio
  #  internal: true
  #  pin:
  #    number: GPIO12
  #    mode: INPUT
  #    inverted: True
  #  name: "touch1"
  #  on_press:
  #    - switch.toggle: button1
  
  # touch 2st
  - platform: gpio
    internal: true
    pin:
      number: GPIO3
      mode: INPUT
      inverted: True
    name: "touch2"
    on_press:
      - switch.toggle: button2
  
  # touch 3st
  #- platform: gpio
  #  internal: true
  #  pin:
  #    number: GPIO5
  #    mode: INPUT
  #    inverted: True
  #  name: "touch3"
  #  on_press:
  #    - switch.toggle: button3

# 동작버튼 = 출력장치 정의
switch:
  # Button 1 / Relay 1st
  #- platform: gpio
  #  name: ${device_name} Button1"
  #  pin: GPIO13
  #  id: button1
  #  icon: "mdi:lightbulb"
  #  on_turn_on:
  #    - switch.turn_on: led1
  #  on_turn_off:
  #    - switch.turn_off: led1
  
  # Button 2 / Relay 2st
  - platform: gpio
    name: ${device_name} Button1"  # <-- RENAME
    pin: GPIO4
    id: button2
    icon: "mdi:lightbulb"
    on_turn_on:
      - switch.turn_on: led2
    on_turn_off:
      - switch.turn_off: led2
  
  # Button 3 / Relay 3st
  #- platform: gpio
  #  name: ${device_name} Button3"
  #  pin: GPIO15
  #  id: button3
  #  icon: "mdi:lightbulb"
  #  on_turn_on:
  #    - switch.turn_on: led3
  #  on_turn_off:
  #    - switch.turn_off: led3
  
  # LED 정의
  # LED 1st
  #- platform: gpio
  #  internal: true
  #  name: "LED1"
  #  pin: GPIO16
  #  id: led1
  
  # LED 2st
  - platform: gpio
    internal: true
    name: "LED2"
    pin: GPIO14
    id: led2
  
  # LED 3st
  #- platform: gpio
  #  internal: true
  #  name: "LED3"
  #  pin: GPIO2
  #  id: led3

# 상태ED 정의
status_led:
  pin:
    number: GPIO0
    # inverted: yes

 

 

 2) 2gang 벽스위치

## MoseHouse 2touch switch
## 딸아이방

substitutions:
  node_name: mosehouse02_2touch
  device_name: MoseHouse02 2Touch

esphome:
  name: ${node_name}
  platform: ESP8266
  board: esp01_1m
  on_boot:
    priority: -50
    then:      
      - delay: 10s
      - homeassistant.service:
          service: notify.theniz_telegram
          data:
            message: "Esphome ${device_name}이(가) 시작 되었습니다."

wifi:
  ssid: # WiFi SSID 기록
  password: # WiFi 암호 기록

logger:

api:

ota:

time:
  - platform: sntp
    timezone: UTC-9
    servers:
      - time.bora.net
      - 0.pool.ntp.org
      - 1.pool.ntp.org

sensor:
  - platform: wifi_signal
    name: "${device_name} Wifi Signal"
    id: wifi_sig
    internal: true
    update_interval: 60s
  - platform: template
    name: "${device_name} Wifi Quality"
    icon: "mdi:wifi"
    update_interval: 60s
    unit_of_measurement: '%'
    accuracy_decimals: 0
    lambda: !lambda |-
      if (id(wifi_sig).state < -92.0) {
        return 100.0;
      } else if (id(wifi_sig).state > -21.0) {
        return 1.0;
      } else {
        return round(( -0.0154 * id(wifi_sig).state * id(wifi_sig).state )-( 0.3794 * id(wifi_sig).state ) + 98.182 );
      }

# 입력장치 정의
binary_sensor:
  # touch 1st
  - platform: gpio
    internal: true
    pin:
      number: GPIO12
      mode: INPUT
      inverted: True
    name: "touch1"
    on_press:
      - switch.toggle: button1
  
  # touch 2st
  #- platform: gpio
  #  internal: true
  #  pin:
  #    number: GPIO3
  #    mode: INPUT
  #    inverted: True
  #  name: "touch2"
  #  on_press:
  #    - switch.toggle: button2
  
  # touch 3st
  - platform: gpio
    internal: true
    pin:
      number: GPIO5
      mode: INPUT
      inverted: True
    name: "touch3"
    on_press:
      - switch.toggle: button3

# 동작버튼 = 출력장치 정의
switch:
  # Button 1 / Relay 1st
  - platform: gpio
    name: ${device_name} Button1"
    pin: GPIO13
    id: button1
    icon: "mdi:lightbulb"
    on_turn_on:
      - switch.turn_on: led1
    on_turn_off:
      - switch.turn_off: led1
  
  # Button 2 / Relay 2st
  #- platform: gpio
  #  name: ${device_name} Button2"
  #  pin: GPIO4
  #  id: button2
  #  icon: "mdi:lightbulb"
  #  on_turn_on:
  #    - switch.turn_on: led2
  #  on_turn_off:
  #    - switch.turn_off: led2
  
  # Button 2 / Relay 3st
  - platform: gpio
    name: ${device_name} Button2"  # <-- rename
    pin: GPIO15
    id: button3
    icon: "mdi:lightbulb"
    on_turn_on:
      - switch.turn_on: led3
    on_turn_off:
      - switch.turn_off: led3
  
  # LED 정의
  # LED 1st
  - platform: gpio
    internal: true
    name: "LED1"
    pin: GPIO16
    id: led1
  
  # LED 2st
  #- platform: gpio
  #  internal: true
  #  name: "LED2"
  #  pin: GPIO14
  #  id: led2
  
  # LED 3st
  - platform: gpio
    internal: true
    name: "LED3"
    pin: GPIO2
    id: led3

# 상태ED 정의
status_led:
  pin:
    number: GPIO0
    # inverted: yes

 

 

 3) 3gang 벽스위치

## MoseHouse 3touch switch
## 거실

substitutions:
  node_name: mosehouse04_3touch
  device_name: MoseHouse04 3Touch

esphome:
  name: ${node_name}
  # platform: ESP8266
  # board: d1_mini
  platform: ESP8266
  board: esp01_1m
  on_boot:
    priority: -50
    then:      
      - delay: 10s
      - homeassistant.service:
          service: notify.theniz_telegram
          data:
            message: "Esphome ${device_name}이(가) 시작 되었습니다."

wifi:
  ssid: # WiFi SSID 기록
  password: # WiFi 암호 기록

logger:

api:

ota:

time:
  - platform: sntp
    timezone: UTC-9
    servers:
      - time.bora.net
      - 0.pool.ntp.org
      - 1.pool.ntp.org

sensor:
  - platform: wifi_signal
    name: "${device_name} Wifi Signal"
    id: wifi_sig
    internal: true
    update_interval: 60s
  - platform: template
    name: "${device_name} Wifi Quality"
    icon: "mdi:wifi"
    update_interval: 60s
    unit_of_measurement: '%'
    accuracy_decimals: 0
    lambda: !lambda |-
      if (id(wifi_sig).state < -92.0) {
        return 100.0;
      } else if (id(wifi_sig).state > -21.0) {
        return 1.0;
      } else {
        return round(( -0.0154 * id(wifi_sig).state * id(wifi_sig).state )-( 0.3794 * id(wifi_sig).state ) + 98.182 );
      }

# 입력장치 정의
binary_sensor:
  # touch 1st
  - platform: gpio
    internal: true
    pin:
      number: GPIO12
      mode: INPUT
      inverted: True
    name: "touch1"
    on_press:
      - switch.toggle: button1
  # touch 2st
  - platform: gpio
    internal: true
    pin:
      number: GPIO3
      mode: INPUT
      inverted: True
    name: "touch2"
    on_press:
      - switch.toggle: button2
  # touch 3st
  - platform: gpio
    internal: true
    pin:
      number: GPIO5
      mode: INPUT
      inverted: True
    name: "touch3"
    on_press:
      - switch.toggle: button3

# 동작버튼 = 출력장치 정의
switch:
  # Button 1 / Relay 1st
  - platform: gpio
    name: ${device_name} Button1"  # Relay1
    pin: GPIO13
    id: button1
    icon: "mdi:lightbulb"
    on_turn_on:
      - switch.turn_on: led1
    on_turn_off:
      - switch.turn_off: led1
  # Button 2 / Relay 2st
  - platform: gpio
    name: ${device_name} Button2"  # Relay2
    pin: GPIO4
    id: button2
    icon: "mdi:lightbulb"
    on_turn_on:
      - switch.turn_on: led2
    on_turn_off:
      - switch.turn_off: led2
  # Button 3 / Relay 3st
  - platform: gpio
    name: ${device_name} Button3"  # Relay3
    pin: GPIO15
    id: button3
    icon: "mdi:lightbulb"
    on_turn_on:
      - switch.turn_on: led3
    on_turn_off:
      - switch.turn_off: led3
  
  # LED 정의
  # LED 1st
  - platform: gpio
    internal: true
    name: "LED1"
    pin: GPIO16
    id: led1
  # LED 2st
  - platform: gpio
    internal: true
    name: "LED2"
    pin: GPIO14
    id: led2
  # LED 3st
  - platform: gpio
    internal: true
    name: "LED3"
    pin: GPIO2
    id: led3

# 상태ED 정의
status_led:
  pin:
    number: GPIO0
    # inverted: yes

 

 

 4) 2gang 전등/환풍기 벽스위치 (환풍기 8분 타이머) - 화장실용

## MoseHouse 2touch switch
## 화장실2/환풍기

substitutions:
  node_name: mosehouse08_2touch
  device_name: MoseHouse08 2Touch

esphome:
  name: ${node_name}
  platform: ESP8266
  board: esp01_1m
  on_boot:
    priority: -50
    then:      
      - delay: 10s
      - homeassistant.service:
          service: notify.theniz_telegram
          data:
            message: "Esphome ${device_name}이(가) 시작 되었습니다."

wifi:
  ssid: # WiFi SSID 기록
  password: # WiFi 암호 기록

logger:

api:

ota:

time:
  - platform: sntp
    timezone: UTC-9
    servers:
      - time.bora.net
      - 0.pool.ntp.org
      - 1.pool.ntp.org

sensor:
  - platform: wifi_signal
    name: "${device_name} Wifi Signal"
    id: wifi_sig
    internal: true
    update_interval: 60s
  - platform: template
    name: "${device_name} Wifi Quality"
    icon: "mdi:wifi"
    update_interval: 60s
    unit_of_measurement: '%'
    accuracy_decimals: 0
    lambda: !lambda |-
      if (id(wifi_sig).state < -92.0) {
        return 100.0;
      } else if (id(wifi_sig).state > -21.0) {
        return 1.0;
      } else {
        return round(( -0.0154 * id(wifi_sig).state * id(wifi_sig).state )-( 0.3794 * id(wifi_sig).state ) + 98.182 );
      }

# 입력장치 정의
binary_sensor:
  # touch 1st
  - platform: gpio
    internal: true
    pin:
      number: GPIO12
      mode: INPUT
      inverted: True
    name: "touch1"
    on_press:
      - switch.toggle: button1
  
  # touch 2st
  #- platform: gpio
  #  internal: true
  #  pin:
  #    number: GPIO3
  #    mode: INPUT
  #    inverted: True
  #  name: "touch2"
  #  on_press:
  #    - switch.toggle: button2
  
  # touch 3st
  - platform: gpio
    internal: true
    pin:
      number: GPIO5
      mode: INPUT
      inverted: True
    name: "touch3"
    on_press:
      - switch.toggle: button3

# 동작버튼 = 출력장치 정의
switch:
  # Button 1 / Relay 1st
  - platform: gpio
    name: ${device_name} Button1"
    pin: GPIO13
    id: button1
    icon: "mdi:lightbulb"
    on_turn_on:
      - switch.turn_on: led1
    on_turn_off:
      - switch.turn_off: led1
      - if:
          condition:
            switch.is_on: button3
          then:
            - delay: 480s
            - switch.turn_off: button3
  
  # Button 2 / Relay 2st
  #- platform: gpio
  #  name: ${device_name} Button2"
  #  pin: GPIO4
  #  id: button2
  #  icon: "mdi:lightbulb"
  #  on_turn_on:
  #    - switch.turn_on: led2
  #  on_turn_off:
  #    - switch.turn_off: led2
  
  # Button 2 / Relay 3st
  - platform: gpio
    name: ${device_name} Button2"  # <-- rename
    pin: GPIO15
    id: button3
    icon: "mdi:fan"  #<-- FAN icon
    on_turn_on:
      - switch.turn_on: led3
      #환풍기FAN 동작시
      - if:  # button 1 off 인 경우
          condition:
            switch.is_off: button1
          then:
            - delay: 480s                  # 480s=60s*8분
            - switch.turn_off: button3   # 버튼 OFF
    on_turn_off:
      - switch.turn_off: led3
  
  # LED 정의
  # LED 1st
  - platform: gpio
    internal: true
    name: "LED1"
    pin: GPIO16
    id: led1
  
  # LED 2st
  #- platform: gpio
  #  internal: true
  #  name: "LED2"
  #  pin: GPIO14
  #  id: led2
  
  # LED 3st
  - platform: gpio
    internal: true
    name: "LED3"
    pin: GPIO2
    id: led3

# 상태ED 정의
status_led:
  pin:
    number: GPIO0
    # inverted: yes

 

mosehouse01_1touch.yaml
0.00MB
mosehouse02_2touch.yaml
0.00MB
mosehouse04_3touch.yaml
0.00MB
mosehouse08_2touch.yaml
0.00MB

 

 

 

 

2. "Home Assistant 설정 > 통합 구성요소 > (+)버튼 >ESPHome > IP를 등록(공유기에서 확인)"

    IP를 등록하면 아래와 같이 등록됩니다.

  

 

ESP-12 를 프로그래밍(펌웨어 쓰기)을 하기 위해서는 UARD Download Mode 로 시작해야 합니다

 

출처 : https://deneb21.tistory.com/269

         https://robertoostenveld.nl/esp-12-bootloader-modes/

         https://forum.hobbycomponents.com//viewtopic.php?t=1777

 

결론 : 아래와 같이 연결하고 시작하거나 리셋하면 됩니다.

핀이름

연결방법

 

Vcc

3.3V

 

Gnd

GND

 

GPIO 0

GND

 

GPIO 2

3.3V

 

GPIO 15

GND

 

CH_PD

GND

chip power-down

 

출처 : https://robertoostenveld.nl/esp-12-bootloader-modes/

 

 

출처: https://forum.hobbycomponents.com//viewtopic.php?t=1777
출처 : https://robertoostenveld.nl/esp-12-bootloader-modes/

 

라즈베리파이 3 기준으로 작성하였습니다. 

오류가 있을 수 있으므로 언제든 지적 부탁드립니다.

 

벽스위치 ESPhome 교체 장단점

[장점]

 1. MoseHouse 터치 벽스위치 모델의 경우 납땝없이 펌웨어 교체가능

 2. 원복 펌웨어 백업해 두고, 언제든 복구가 가능합니다.

 3. ESPHome 장점: 아두이노 C 프로그래밍 할려면, 몇주는 밤낮없이 작업해야 할 것을 단 몇줄로 끝

 4. HA 에서 리얼타임으로 응답합니다. 

   ( HA에서 tuya 호환 모델설정하면 5초 정도의 느린 응답이라도 있었지만, 8월말 부터는 완전 차단상태로 HA에서 이제는 사용이 않됩니다. )

 5. MoseHouse 모델이 아니더라도, 링크된 yaml 파일을 약간 수정 응용하시면, 모든 벽스위치에 적용이 가능합니다.

  (MouseHouse 벽스위치 모델이 가장 설정이 가장 까다롭습니다. 그래서 다른 회사 제품은 링크한 yaml 에서 LED 라인 정도 삭제하고 포트만 수정하면 전부 동작이 가능할 것입니다.)

 

[단점]

 1. 기준의 SmartLife 앱에서 사용할 수 없습니다. (2.원복 펌웨어 백업후 복원하면 회복가능)

 

판매자 사이트 : https://www.aliexpress.com/item/32857299145.html?spm=a2g0s.9042311.0.0.27424c4dyDlaNd

 

US $14.24 55% OFF|Wifi Smart Wall Touch Switch Glass Panel Mobile APP Remote Control No Hub Required work with Amazon Alexa Goog

Smarter Shopping, Better Living! Aliexpress.com

www.aliexpress.com

 

1. 우선 Docker 가 설치되어 있어야 합니다.

  제가 사용하는 환경이 Docker 입니다. 

 

 

2. ESPHome 설치합니다.

  설치방법 설명 링크1 - 설치 및 업그레이드 방법이 자세히 설명됨(추천)

     > https://cafe.naver.com/stsmarthome/10417

  설치방법 설명 링크2 - ESPHome 공식 홈페이지 설명

     > https://esphome.io/guides/getting_started_command_line.html

 

2.1 저는 /docker/에 esphome 폴더를 만들었습니다. 

    경로  /docker/esphome

 

2.2 최신 이미지 받기 &  컨테이너 실행

sudo docker run --restart=always -d \
-v /docker/esphome:/config \
-v /etc/localtime:/etc/localtime:ro \
--net=host --name esphome esphome/esphome-armv7:latest

 

 

3. ESPHome 접속하여 설치여부를 확인합니다.

 http://ip:6052

 

 

4. 처음 

버튼을 눌려서 새로 yaml를 작성합니다.

저는 이미 구성한 yaml 파일이 보이지만, 처음 설치하신 분들은 아무 것도 없습니다.

 

 

 

 

5. EDIT 로 편집하시고, Compile 하세요.

   [EDIT] 클릭하여 yaml 파일을 편집합니다. 스크립트 링크> https://techclass.tistory.com/6 

  컴파일이 완료되면 [DOWNLOAD BINARY] 클릭하여 *****.bin 파일을 다운받습니다.

 

  

6. 펌웨어 파일을 라즈베리에 복사

   위에서 Compile 후 DOWNLOAD BINARY 받은 *****.bin를  라즈베리 파이에 복사합니다.

 

 

7. 라즈베리파이 UART(시리얼 포트) 활성화

   * '블루투스'가 내장된 '라즈베리파이3 이상'의 경우 Bluetoot가 uart로 통신을 하고 있으므로 bluetooth를 STOP 해야 합니다.

  출처 :  블로그 링크1  및 링크2,  링크3, 링크4

 

  1) raspi-config 에서 serial 활성화

sudo raspi-config

    아래와 같이 serial를 enable을 해준다음 재부팅합니다.

  2) Bluetooth 사용중지(RPi3의 경우) 

  - boot config에 Bluetooth 사용금지

     라즈베리파이 UART 활성화 : config.txt 편집

sudo nano /boot/config.txt

# /boot/config.txt의 마지막 줄에 다음 두줄을 추가합니다.
enable_uart=1
dtoverlay=pi3-disable-bt

 

  - Disable Console 

   콘솔정보를 serial로 나가는 것을 중지

sudo systemctl stop serial-getty@ttyAMA0.service
sudo systemctl disable serial-getty@ttyAMA0.service 

 

   재부팅후 UART 포트 확인합니다.

ls /dev | grep ttyAMA

 

  아래와 같이 ttyAMA0 라는 장치가 보입니다.

 

 

8. esptool 설치 [소프트웨어 준비]

sudo pip install esptool

 

 

9. ESP-12 펌웨어 프로그래밍 모드 [배경지식]  >  ESP-12 bootloader modes

   프로그래밍 모드로 들어갈려면 아래 처럼 복잡하게 연결해야 한다.

   하지만, 이렇게 납땝할 필요는 없습니다.

https://github.com/klausahrenberg/ThermostatBecaWifi

Vcc   : 3.3V 
Gnd   : GND 
GPIO0 : GND 
GPIO2 : 3.3V 
GPIO15: GND 
CH_PD : GND

 

 

 

 

 

 

 

 

 

10. 터치스위치 PCB 기판 분리

   프로그래밍 하기 위해서, 벽스위치의 터치 패널 PCB를 분리합니다.

   터치 패널기판을 분리하면 220V 전압이 흐르는 DC전원과 릴레이 기판이 보입니다. 배선차단기를 반드시 내리고 작업하세요.

 

2gang 사진
내부 사진은 3gang 사진
터치스위치 PDB 뒷면

프로그래밍 모드에 들어가기 위해 "9. ESP-12 펌웨어 프로그래밍 모드 [배경지식]" 에서 처럼 배선할 필요할 없습니다.

 

아래 사진의 핀헤더(G, 0, R, T, V) 부분에 5개의 선만 연결하면 프로그래밍할 수 있습니다.

배선을 확인해 보니, 나머지 핀들(GPIO2, GPIO15, CH_PD 등)은 이미 Vcc, Gnd 등과 이미 연결되어 있습니다. 

  

핀헤더 홀 단자에 USB-serial 또는 라즈베리파이 GPIO 핀과 연결하면 됩니다.

        GND,  GPIO0, RX,  TX,  VCC 

           G       G      Tx   Rx   3.3v

 

주황색 박스로 표시한 4개 핀헤더는 "위 2개: 3.3V", "아래 2개: GND"와 연결되어 있습니다.

 

11. 라즈베리파이 GPIO 와 연결

      

출처: https://elinux.org/RPi_Low-level_peripherals

 

 * 저는 "빨강-3.3v TX-주황, RX-노랑, GND-녹색" 이렇게 연결했습니다.

 

스위치 기판에는 이렇게 연결했습니다

 처음 동작 확인시에만, 위 사진처럼 납땝 작업을 했습니다. (납땝 하실 필요 없습니다)

<사진> 프로그래밍 모드

이렇게 핀헤더에 연결후, 손가락으로 기판 방향으로 밀면서 아래고 당기고 있으면, 라즈베리 전원에 의해서 부팅되면서 프로그래밍 모드로 진입하게 됩니다.

 

이렇게 잡고 있으면, 납땝없이 프로그래밍 작업이 가능합니다. 이렇게 집안에 있는 9개의 스위치를 납땝없이 작업했습니다.

 

 

12. 펌웨어 백업 및 ESPHome 업로드

  위 "<사진> 프로그래밍 모드" 처럼 핀을 누르며 잡고 있으면서 명령을 실행하면 됩니다. 각각의 명령을 한번 실행후 다시 핀헤더를 때었다가 다시 붙이는 방식으로 재부팅 해야지만, 아래의 각각의 단계가 실행이 됩니다.

 

 12.1 펌웨어 백업

     만약을 대비하여 원본 팜웨어를 백업합니다. 잘못되거나, 원래 펌웨어 복원하고 싶으면 "12.3 펌에어 업로드" 명령어로 복원할 수 있습니다.

esptool.py --port /dev/ttyAMA0 read_flash 0x00000 0x100000 image1M.bin

 12.2 펌웨어 삭제

      기존의 펌웨어 삭제합니다.

esptool.py --port /dev/ttyAMA0 erase_flash

 12.3 펌웨어 업로드

     기존에 복사한 "6. 펌웨어 파일을 라즈베리에 복사"한 파일을 업로드 합니다.

     *****.bin 을 펌웨어 파일 이름으로 바꾸어 주면 됩니다.

esptool.py --port  /dev/ttyAMA0 write_flash -fs 1MB -fm dout 0x0 *****.bin

 

 

13. 다시 SW를 조립하고, 재부팅이 되고 난후

  ESPHome 페이지에 접속하면

  아래와 같이 Online 에 초록색 점이 들어 옵니다.

  저의 경우에는 yaml 파일에 고정ip를 사용하지 않고 있습니다.

  이 경우 [SHOW LOGS]를 누르면 자동 할당된 ip 정보를 확인할 수 있습니다.

  공유기에서 ip를 할당하는 방법을 사용하고 있습니다.

 

+ Recent posts