현관문 프로젝트) LED Strip + Door sensor + esp8266 & pi 4편 (AWS IoT)

최재혁·2023년 3월 6일
0

1. Architecture

2. Result

Door sensor close

{
  "battery": 100,
  "contact": true,
  "linkquality": 136,
  "power_outage_count": 191,
  "voltage": 3015
}

Door sensor open

{
  "battery": 100,
  "contact": false,
  "linkquality": 149,
  "power_outage_count": 191,
  "voltage": 3015
}

3. Setting in rasberry pi

3-1. create docker-compose.yml

// zigbee2mqtt/docker-compose.yml
version: '3.8'
services:
  mqtt:
    image: eclipse-mosquitto:2.0
    restart: unless-stopped
    volumes:
      - "./mosquitto:/mosquitto"
    ports:
      - "1883:1883"
      - "8883:8883"
    command: "mosquitto -c ./mosquitto/conf.d/bridge.conf -v"

  zigbee2mqtt:
    container_name: zigbee2mqtt
    restart: unless-stopped
    image: koenkk/zigbee2mqtt
    volumes:
      - ./zigbee2mqtt-data:/app/data
      - /run/udev:/run/udev:ro
    ports:
      - 8080:8080
    environment:
      - TZ=Asia/Seoul
    devices:
      - /dev/ttyACM0
    depends_on:
      - mqtt

3-2. create zigbee2mqtt configuration.yaml

// zigbee2mqtt/zigbee2mqtt-data/configuration.yaml

# Let new devices join our zigbee network
permit_join: true
# Docker-Compose makes the MQTT-Server available using "mqtt" hostname
mqtt:
  base_topic: zigbeemqtt
  server: mqtt://mqtt
# Zigbee Adapter path
serial:
  port: /dev/ttyACM0
# Enable the Zigbee2MQTT frontend
frontend:
  port: 8080
# Let Zigbee2MQTT generate a new network key on first start
advanced:
  network_key: GENERATE
output: 'json'

참조 : https://www.zigbee2mqtt.io/guide/getting-started/#installation

3-3. create bridge.conf

listener 1883
allow_anonymous true

# ============================================================
# Bridge to AWS IOT
# ============================================================

connection awsiot

#<Paste your AWS IoT Core ATS endpoint retrieved from the AWS CLI in the form of xxxxxxxxxxxxxxx-ats.iot.<region>.amazonaws.com:8883

address xxxxxxxxxxxxxxx-ats.iot.<region>.amazonaws.com:8883

# Specifying which topics are bridged and in what fashion
topic awsiot_to_localgateway in 1
topic localgateway_to_awsiot out 1
topic both_directions both 1

# Setting protocol version explicitly
bridge_protocol_version mqttv311
bridge_insecure false

# Bridge connection name and MQTT client Id, enabling the connection automatically when the broker starts.
cleansession true
clientid bridgeawsiot
start_type automatic
notifications false
log_type all

# ============================================================
# Certificate based SSL/TLS support
# ============================================================

#Path to the rootCA
bridge_cafile /etc/mosquitto/certs/rootCA.pem

# Path to the PEM encoded client certificate
bridge_certfile /etc/mosquitto/certs/cert.crt

# Path to the PEM encoded client private key
bridge_keyfile /etc/mosquitto/certs/private.key

#END of bridge.conf

참조 : https://aws.amazon.com/ko/blogs/iot/how-to-bridge-mosquitto-mqtt-broker-to-aws-iot/

profile
한다면 하는 남자! 줄여서 한남!

0개의 댓글