일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 코스피
- Home Assistant
- 해외주식
- 월패드
- 오블완
- MQTT
- Espressif
- 매터
- 애플
- 배당
- Python
- 현대통신
- 힐스테이트 광교산
- 미국주식
- 파이썬
- ConnectedHomeIP
- 홈네트워크
- SK텔레콤
- 티스토리챌린지
- matter
- Apple
- 국내주식
- RS-485
- cluster
- 공모주
- 나스닥
- homebridge
- Bestin
- raspberry pi
- esp32
- Today
- Total
YOGYUI
Raspberry Pi - Zigbee2mqtt 설치 및 실행 본문
zigbee2mqtt 공식 가이드 참고
(라즈베리파이에 node.js는 미리 설치해둔 경우)
www.zigbee2mqtt.io/getting_started/running_zigbee2mqtt.html
1. Git Clone
sudo git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
pi@raspberrypi:~ $ sudo git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
Cloning into '/opt/zigbee2mqtt'...
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 14958 (delta 25), reused 23 (delta 14), pack-reused 14911
Receiving objects: 100% (14958/14958), 26.26 MiB | 8.25 MiB/s, done.
Resolving deltas: 100% (11149/11149), done.
디렉터리 확인
pi@raspberrypi:~ $ ls /opt/zigbee2mqtt
cli.js data docker images index.js lib LICENSE npm-shrinkwrap.json package.json README.md scripts test update.sh
설치 후 디렉터리 권한 변경
pi@raspberrypi:~ $ sudo chown -R pi:pi /opt/zigbee2mqtt
2. Install Dependencies
pi@raspberrypi:~ $ cd /opt/zigbee2mqtt
pi@raspberrypi:/opt/zigbee2mqtt $ npm ci --production
warning은 무시한다
3. Configuration
nano, vim, gedit 등 아무런 에디터를 통해서 /opt/zigbee2mqtt/data/configuration.yaml 파일을 수정한다
# Home Assistant integration (MQTT discovery)
homeassistant: false
# allow new devices to join
permit_join: true
# MQTT settings
mqtt:
# MQTT base topic for zigbee2mqtt MQTT messages
base_topic: zigbee2mqtt
# MQTT server URL
server: 'mqtt://localhost'
# MQTT server authentication, uncomment if required:
# user: my_user
# password: my_password
# Serial settings
serial:
# Location of CC2531 USB sniffer
port: /dev/ttyACM0
인증을 위해 user와 password를 추가해준다 (옵션)
중요: CC2531 USB Dongle의 포트를 serial: port에 적어줘야한다
CC2531 USB Dongle 사용법과 관련해서는 yogyui.tistory.com/entry/CC2531-USB-Dongle-Arduino%EB%A1%9C-flashing%ED%95%98%EA%B8%B0-CCLoader 를 참고한다
Serial device list up by ID
pi@raspberrypi:~ $ ls -l /dev/serial/by-id
total 0
lrwxrwxrwx 1 root root 13 Jan 10 20:48 usb-FTDI_FT232R_USB_UART_AG0KADO0-if00-port0 -> ../../ttyUSB2
lrwxrwxrwx 1 root root 13 Jan 10 20:48 usb-FTDI_FT232R_USB_UART_AG0KAE4R-if00-port0 -> ../../ttyUSB0
lrwxrwxrwx 1 root root 13 Jan 10 20:48 usb-FTDI_FT232R_USB_UART_AG0KAJ76-if00-port0 -> ../../ttyUSB1
lrwxrwxrwx 1 root root 13 Jan 13 01:00 usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B001CCE25AF-if00 -> ../../ttyACM0
ttyACM0이 CC2531 USB dongle Port name이다
configuration.yaml의 default값이 /dev/ttyACM0 이므로 수정할 필요가 없다
4. Start Server
pi@raspberrypi:~ $ cd /opt/zigbee2mqtt
pi@raspberrypi:/opt/zigbee2mqtt $ npm start
실행 결과
pi@raspberrypi:~ $ cd /opt/zigbee2mqtt
pi@raspberrypi:/opt/zigbee2mqtt $ npm start
> zigbee2mqtt@1.17.0 start /opt/zigbee2mqtt
> node index.js
Zigbee2MQTT:info 2021-01-13 01:20:06: Logging to console and directory: '/opt/zigbee2mqtt/data/log/2021-01-13.01-20-05' filename: log.txt
Zigbee2MQTT:info 2021-01-13 01:20:06: Starting Zigbee2MQTT version 1.17.0 (commit #07cdc9d)
Zigbee2MQTT:info 2021-01-13 01:20:06: Starting zigbee-herdsman (0.13.46)
Zigbee2MQTT:info 2021-01-13 01:20:13: zigbee-herdsman started
Zigbee2MQTT:info 2021-01-13 01:20:13: Coordinator firmware version: '{"meta":{"maintrel":3,"majorrel":2,"minorrel":6,"product":0,"revision":20190608,"transportrev":2},"type":"zStack12"}'
Zigbee2MQTT:info 2021-01-13 01:20:13: Currently 0 devices are joined:
Zigbee2MQTT:warn 2021-01-13 01:20:13: `permit_join` set to `true` in configuration.yaml.
Zigbee2MQTT:warn 2021-01-13 01:20:13: Allowing new devices to join.
Zigbee2MQTT:warn 2021-01-13 01:20:13: Set `permit_join` to `false` once you joined all devices.
Zigbee2MQTT:info 2021-01-13 01:20:13: Zigbee: allowing new devices to join.
Zigbee2MQTT:info 2021-01-13 01:20:13: Connecting to MQTT server at mqtt://localhost
Zigbee2MQTT:error 2021-01-13 01:20:23: Not connected to MQTT server!
Zigbee2MQTT:error 2021-01-13 01:20:33: Not connected to MQTT server!
(Ctrl + C 로 종료)
MQTT 서버(브로커)를 실행중이지 않다면 Not connected to MQTT server 에러를 볼 수 있다
이왕 하는김에 브로커까지 파이에 설치해버리자
5. MQTT Broker (mosquitto) 설치
참고: www.hackster.io/dhairya-parikh/running-a-mqtt-broker-on-raspberry-pi-63c34
커맨드 라인에서 mosquitto와 mosquitto-clients를 같이 설치 (서버로만 쓸거면 clients는 필요없음)
sudo apt install mosquitto mosquitto-clients
실행 결과
pi@raspberrypi:~ $ sudo apt install mosquitto mosquitto-clients
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libev4 libmosquitto1 libwebsockets8
The following NEW packages will be installed:
libev4 libmosquitto1 libwebsockets8 mosquitto mosquitto-clients
0 upgraded, 5 newly installed, 0 to remove and 6 not upgraded.
Need to get 388 kB of archives.
After this operation, 843 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ftp.harukasan.org/raspbian/raspbian buster/main armhf libev4 armhf 1:4.25-1 [34.5 kB]
Get:2 http://ftp.harukasan.org/raspbian/raspbian buster/main armhf libmosquitto1 armhf 1.5.7-1+deb10u1 [57.6 kB]
Get:3 http://ftp.harukasan.org/raspbian/raspbian buster/main armhf libwebsockets8 armhf 2.0.3-3 [85.6 kB]
Get:4 http://ftp.harukasan.org/raspbian/raspbian buster/main armhf mosquitto armhf 1.5.7-1+deb10u1 [143 kB]
Get:5 http://ftp.harukasan.org/raspbian/raspbian buster/main armhf mosquitto-clients armhf 1.5.7-1+deb10u1 [66.8 kB]
Fetched 388 kB in 4s (109 kB/s)
Selecting previously unselected package libev4:armhf.
(Reading database ... 169605 files and directories currently installed.)
Preparing to unpack .../libev4_1%3a4.25-1_armhf.deb ...
Unpacking libev4:armhf (1:4.25-1) ...
Selecting previously unselected package libmosquitto1:armhf.
Preparing to unpack .../libmosquitto1_1.5.7-1+deb10u1_armhf.deb ...
Unpacking libmosquitto1:armhf (1.5.7-1+deb10u1) ...
Selecting previously unselected package libwebsockets8:armhf.
Preparing to unpack .../libwebsockets8_2.0.3-3_armhf.deb ...
Unpacking libwebsockets8:armhf (2.0.3-3) ...
Selecting previously unselected package mosquitto.
Preparing to unpack .../mosquitto_1.5.7-1+deb10u1_armhf.deb ...
Unpacking mosquitto (1.5.7-1+deb10u1) ...
Selecting previously unselected package mosquitto-clients.
Preparing to unpack .../mosquitto-clients_1.5.7-1+deb10u1_armhf.deb ...
Unpacking mosquitto-clients (1.5.7-1+deb10u1) ...
Setting up libmosquitto1:armhf (1.5.7-1+deb10u1) ...
Setting up libev4:armhf (1:4.25-1) ...
Setting up mosquitto-clients (1.5.7-1+deb10u1) ...
Setting up libwebsockets8:armhf (2.0.3-3) ...
Setting up mosquitto (1.5.7-1+deb10u1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/mosquitto.service → /lib/systemd/system/mosquitto.service.
Processing triggers for systemd (241-7~deb10u5+rpi1) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for libc-bin (2.28-10+rpi1) ...
재부팅 후에도 자동시작되도록 설정
sudo systemctl enable mosquitto
실행 결과
pi@raspberrypi:~ $ sudo systemctl enable mosquitto
Synchronizing state of mosquitto.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mosquitto
설정과 동시에 서버가 시작되었다 (옵션 지정하지 않으면 서버의 기본포트는 1883이다)
상태를 알고 싶으면 systemctl status mosquitto 실행
pi@raspberrypi:~ $ sudo systemctl status mosquitto
● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-01-13 01:32:49 KST; 6min ago
Docs: man:mosquitto.conf(5)
man:mosquitto(8)
Main PID: 24692 (mosquitto)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/mosquitto.service
└─24692 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Jan 13 01:32:49 raspberrypi systemd[1]: Starting Mosquitto MQTT v3.1/v3.1.1 Broker...
Jan 13 01:32:49 raspberrypi systemd[1]: Started Mosquitto MQTT v3.1/v3.1.1 Broker.
다시 zigbee2mqtt를 실행하면 다음과 같은 실행결과를 얻을 수 있다
pi@raspberrypi:/opt/zigbee2mqtt $ npm start
> zigbee2mqtt@1.17.0 start /opt/zigbee2mqtt
> node index.js
Zigbee2MQTT:info 2021-01-13 01:42:23: Logging to console and directory: '/opt/zigbee2mqtt/data/log/2021-01-13.01-42-23' filename: log.txt
Zigbee2MQTT:info 2021-01-13 01:42:23: Starting Zigbee2MQTT version 1.17.0 (commit #07cdc9d)
Zigbee2MQTT:info 2021-01-13 01:42:23: Starting zigbee-herdsman (0.13.46)
Zigbee2MQTT:info 2021-01-13 01:42:26: zigbee-herdsman started
Zigbee2MQTT:info 2021-01-13 01:42:26: Coordinator firmware version: '{"meta":{"maintrel":3,"majorrel":2,"minorrel":6,"product":0,"revision":20190608,"transportrev":2},"type":"zStack12"}'
Zigbee2MQTT:info 2021-01-13 01:42:26: Currently 0 devices are joined:
Zigbee2MQTT:warn 2021-01-13 01:42:26: `permit_join` set to `true` in configuration.yaml.
Zigbee2MQTT:warn 2021-01-13 01:42:26: Allowing new devices to join.
Zigbee2MQTT:warn 2021-01-13 01:42:26: Set `permit_join` to `false` once you joined all devices.
Zigbee2MQTT:info 2021-01-13 01:42:26: Zigbee: allowing new devices to join.
Zigbee2MQTT:info 2021-01-13 01:42:26: Connecting to MQTT server at mqtt://localhost
Zigbee2MQTT:info 2021-01-13 01:42:26: Connected to MQTT server
Zigbee2MQTT:info 2021-01-13 01:42:26: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'
MQTT 서버에 제대로 연결이 되었다
이제 zigbee 기반의 IoT 디바이스들을 라즈베리파이와 연동할 준비가 완료되었다
(샤오미나 이케아 등 제품들을 각 제조사마다 제공하는 허브 없이 라즈베리파이로 모두 제어할 가능성이 열린다, 물론 최대 접속 가능 개수는 cc25xx 디바이스의 하드웨어나 펌웨어 스펙에 의한 한계가 분명히 있지만..)
지원하는 디바이스 목록은 다음 링크에서 확인 가능 (굉장히 많다)
www.zigbee2mqtt.io/information/supported_devices.html
구글 홈어시스턴트도 zigbee2mqtt를 공식적으로 지원한다 (앱등이라 관심은 없다)
'Hardware > Raspberry Pi' 카테고리의 다른 글
Raspberry Pi - Failed to execute child process "xterm" (No such file or directory) 해결하기 (0) | 2021.08.02 |
---|---|
Raspberry Pi - Real VNC "Cannot currently show the desktop" 문제해결 (0) | 2021.07.30 |
Raspberry Pi - ffmpeg + ffserver 동작환경 설정하기 (0) | 2021.07.30 |
Raspberry Pi - 부팅 시 터미널(LXTerminal)로 파이썬 스크립트 자동실행 (0) | 2021.07.10 |
Mosquitto authentication (사용자 인증) 설정 (0) | 2021.01.13 |