

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 자습서: AWS IoT 및 Raspberry Pi를 사용하여 토양 수분 모니터링
<a name="iot-moisture-tutorial"></a>

이 자습서에서는 [Raspberry Pi](https://www.raspberrypi.org/), 습도 센서를 사용하고 주택 식물 또는 정원의 토양 습도 수준을 AWS IoT 모니터링하는 방법을 보여줍니다. Raspberry Pi는 센서에서 습도 수준과 온도를 읽은 다음 데이터를 보내는 코드를 실행합니다 AWS IoT. 습도 수준이 임계값 아래로 떨어질 때 Amazon SNS 주제를 구독하는 주소로 이메일을 AWS IoT 보내는 규칙을에서 생성합니다.

**참고**  
이 튜토리얼은 최신이 아닐 수 있습니다. 이 주제가 처음 게시된 이후로 일부 참조가 대체되었을 수 있습니다.

**Contents**
+ [사전 조건](#iot-moisture-prereqs)
+ [설 AWS IoT정](iot-moisture-setup.md)
  + [1단계: AWS IoT 정책 생성](iot-moisture-policy.md)
  + [2단계: AWS IoT 사물, 인증서 및 프라이빗 키 생성](iot-moisture-create-thing.md)
  + [3단계: Amazon SNS 주제 생성 및 구독](iot-moisture-create-sns-topic.md)
  + [4단계: 이메일 전송 AWS IoT 규칙 생성](iot-moisture-create-rule.md)
+ [Raspberry Pi와 습도 센서 설정](iot-moisture-raspi-setup.md)

## 사전 조건
<a name="iot-moisture-prereqs"></a>

이 자습서를 완료하려면 다음이 필요합니다.
+  AWS 계정.
+ 관리자 권한이 있는 IAM 사용자.
+ Windows, macOS, Linux 또는 Unix를 실행하며 [AWS IoT 콘솔](https://console.aws.amazon.com/iot/home)에 액세스할 수 있는 개발 컴퓨터.
+ 최신 [Raspberry Pi OS](https://www.raspberrypi.com/software/operating-systems/)를 실행하는 [Raspberry Pi 3B 또는 4B](https://www.raspberrypi.com/products/). 설치 방법은 Rasberry Pi 웹사이트의 [운영 체제 설치](https://www.raspberrypi.com/documentation/computers/getting-started.html#installing-the-operating-system) 섹션을 참조하세요.
+ Raspberry Pi용 모니터, 키보드, 마우스 및 Wi-Fi 네트워크 또는 이더넷 연결.
+ Raspberry Pi 호환 습도 센서.. 이 자습서에서 사용되는 센서는 [JST 4핀 및 암 소켓 케이블 헤더](https://www.adafruit.com/product/3950)가 있는 [Adafruit STEMMA I2C 정전식 습도 센서](https://www.adafruit.com/product/4026)입니다.

# 설 AWS IoT정
<a name="iot-moisture-setup"></a>

이 자습서를 완료하려면 다음 리소스를 생성해야 합니다. 디바이스를 연결하려면 IoT 사물 AWS IoT, 디바이스 인증서 및 AWS IoT 정책을 생성합니다.
+  AWS IoT 사물입니다.

  사물이란 물리적 디바이스(이 경우는 Rasberry Pi)를 의미하며, 그 안에는 디바이스에 관한 정적 메타데이터가 들어 있습니다.
+ 디바이스 인증서입니다.

  모든 디바이스에는 AWS IoT와 연결하여 인증하는 디바이스 인증서가 있어야 합니다.
+  AWS IoT 정책.

  각 디바이스 인증서에는 하나 이상의 AWS IoT 정책이 연결되어 있습니다. 이러한 정책은 디바이스가 액세스할 수 있는 AWS IoT 리소스를 결정합니다.
+  AWS IoT 루트 CA 인증서입니다.

  디바이스 및 기타 클라이언트는 AWS IoT 루트 CA 인증서를 사용하여 통신 중인 AWS IoT 서버를 인증합니다. 자세한 내용은 [서버 인증](server-authentication.md) 단원을 참조하십시오.
+  AWS IoT 규칙입니다.

  규칙에는 쿼리와 하나 이상의 규칙 작업이 있습니다. 쿼리는 디바이스 메시지에서 데이터를 추출하여 메시지 데이터를 처리해야 할지 여부를 결정합니다. 규칙 작업은 데이터가 쿼리와 일치할 경우에 해야 할 일을 지정합니다.
+ Amazon SNS 주제 및 주제 구독

  규칙은 Raspberry Pi의 습도 데이터를 모니터링합니다. 값이 임계값 미만일 경우에는 Amazon SNS 주제로 메시지를 전송합니다. Amazon SNS에서 주제를 구독하는 모든 이메일 주소로 메시지를 전송합니다.

 



# 1단계: AWS IoT 정책 생성
<a name="iot-moisture-policy"></a>

Raspberry Pi가 연결하고 메시지를 보낼 수 있도록 허용하는 AWS IoT 정책을 생성합니다 AWS IoT.

1. [AWS IoT 콘솔](https://console.aws.amazon.com/iot)에서 **시작하기** 버튼이 표시되면 선택합니다. 또는 탐색 창에서 **Security**(보안)를 확장한 후 **Policies**(정책)를 선택합니다.

1. **You don’t have any policies yet(아직 정책이 없습니다)** 대화 상자가 나타나면 **Create a policy(정책 생성)**를 선택합니다. 그렇지 않은 경우, **생성**을 선택합니다.

1.  AWS IoT 정책의 이름을 입력합니다(예: **MoistureSensorPolicy**).

1. **설명문 추가** 부분에서 기존 정책을 다음 JSON으로 바꿉니다. *리전* 및 *계정을* AWS 리전 및 AWS 계정 번호로 바꿉니다.  
****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Allow",
               "Action": "iot:Connect",
               "Resource": "arn:aws:iot:us-east-1:123456789012:client/RaspberryPi"
           },
           {
               "Effect": "Allow",
               "Action": "iot:Publish",
               "Resource": [
                   "arn:aws:iot:us-east-1:123456789012:topic/$aws/things/RaspberryPi/shadow/update",
                   "arn:aws:iot:us-east-1:123456789012:topic/$aws/things/RaspberryPi/shadow/delete",
                   "arn:aws:iot:us-east-1:123456789012:topic/$aws/things/RaspberryPi/shadow/get"
               ]
           },
           {
               "Effect": "Allow",
               "Action": "iot:Receive",
               "Resource": [
                   "arn:aws:iot:us-east-1:123456789012:topic/$aws/things/RaspberryPi/shadow/update/accepted",
                   "arn:aws:iot:us-east-1:123456789012:topic/$aws/things/RaspberryPi/shadow/delete/accepted",
                   "arn:aws:iot:us-east-1:123456789012:topic/$aws/things/RaspberryPi/shadow/get/accepted",
                   "arn:aws:iot:us-east-1:123456789012:topic/$aws/things/RaspberryPi/shadow/update/rejected",
                   "arn:aws:iot:us-east-1:123456789012:topic/$aws/things/RaspberryPi/shadow/delete/rejected"
               ]
           },
           {
               "Effect": "Allow",
               "Action": "iot:Subscribe",
               "Resource": [
                   "arn:aws:iot:us-east-1:123456789012:topicfilter/$aws/things/RaspberryPi/shadow/update/accepted",
                   "arn:aws:iot:us-east-1:123456789012:topicfilter/$aws/things/RaspberryPi/shadow/delete/accepted",
                   "arn:aws:iot:us-east-1:123456789012:topicfilter/$aws/things/RaspberryPi/shadow/get/accepted",
                   "arn:aws:iot:us-east-1:123456789012:topicfilter/$aws/things/RaspberryPi/shadow/update/rejected",
                   "arn:aws:iot:us-east-1:123456789012:topicfilter/$aws/things/RaspberryPi/shadow/delete/rejected"
               ]
           },
           {
               "Effect": "Allow",
               "Action": [
                   "iot:GetThingShadow",
                   "iot:UpdateThingShadow",
                   "iot:DeleteThingShadow"
               ],
               "Resource": "arn:aws:iot:us-east-1:123456789012:thing/RaspberryPi"
           }
       ]
   }
   ```

1. **생성(Create)**을 선택합니다.

# 2단계: AWS IoT 사물, 인증서 및 프라이빗 키 생성
<a name="iot-moisture-create-thing"></a>

 AWS IoT 레지스트리에 Raspberry Pi를 나타내는 사물을 생성합니다.

1. [AWS IoT 콘솔](https://console.aws.amazon.com/iot/home) 탐색 창에서 **관리**를 선택한 후 **사물**을 선택합니다.

1. **You don't have any things yet(아직 사물이 없습니다)** 대화 상자가 표시되면 **Register a thing(사물 등록)**을 선택합니다. 그렇지 않은 경우, **생성**을 선택합니다.

1. ** AWS IoT 사물 생성** 페이지에서 **단일 사물 생성을** 선택합니다.

1. **디바이스를 디바이스 레지스트리에 추가** 페이지에서 IoT 사물 이름(예: **RaspberryPi**)을 입력하고 **다음**을 선택합니다. 사물을 생성한 후에는 사물 이름을 변경할 수 없습니다. 사물 이름을 변경하려면 새 사물을 생성하고 새 이름을 지정한 다음 이전 사물을 삭제해야 합니다.

1. **사물에 인증서 추가** 페이지에서 **Create certificate(인증서 생성)**를 선택하세요.

1. **다운로드** 링크를 선택하여 인증서, 프라이빗 키 및 루트 CA 인증서를 다운로드합니다.
**중요**  
이 때에만 인증서와 프라이빗 키를 다운로드할 수 있습니다.

1. 인증서를 활성화하려면 **활성화**를 선택합니다. 디바이스를 AWS IoT에 연결하려면 인증서가 활성 상태여야 합니다.

1. **정책 연결**을 선택합니다.

1. **Add a policy for your thing(사물에 정책 추가)**은 **MoistureSensorPolicy**를 선택하고 **사물 등록**을 선택합니다.

# 3단계: Amazon SNS 주제 생성 및 구독
<a name="iot-moisture-create-sns-topic"></a>

Amazon SNS 주제 생성 및 구독

1. [AWS SNS 콘솔](https://console.aws.amazon.com/sns/home)의 탐색 창에서 **주제**를 선택한 다음 **주제 생성**을 선택합니다.

1. 유형을 **표준**으로 선택하고 주제의 이름(예: **MoistureSensorTopic**)을 입력합니다.

1. 주제의 표시 이름을 입력합니다(예: **Moisture Sensor Topic**). 이것이 Amazon SNS 콘솔에서 표시되는 주제의 이름입니다.

1. **주제 생성**을 선택합니다.

1. Amazon SNS 주제 세부 정보 페이지에서 **구독 생성**을 선택합니다.

1. **프로토콜**에서 **이메일**을 선택합니다.

1. **엔드포인트**에 이메일 주소를 입력합니다.

1. **구독 생성**을 선택합니다.

1. 이메일 클라이언트를 열고 제목이 **MoistureSensorTopic**인 메시지를 찾습니다. 이메일을 열고 **구독 확인** 링크를 클릭합니다.
**중요**  
구독을 확인할 때까지 이 Amazon SNS 주제에서 이메일 알림을 수신할 수 없습니다.

입력한 텍스트가 포함된 이메일 메시지를 수신해야 합니다.

# 4단계: 이메일 전송 AWS IoT 규칙 생성
<a name="iot-moisture-create-rule"></a>

 AWS IoT 규칙은 디바이스에서 메시지를 수신할 때 수행할 쿼리와 하나 이상의 작업을 정의합니다. AWS IoT 규칙 엔진은 디바이스에서 보낸 메시지를 수신하고 메시지의 데이터를 사용하여 일부 조치를 취해야 하는지 여부를 결정합니다. 자세한 내용은 [에 대한 규칙 AWS IoT](iot-rules.md) 단원을 참조하십시오.

이 자습서에서는 Raspberry Pi가 `aws/things/RaspberryPi/shadow/update`에 메시지를 게시합니다. 이것은 디바이스와 Thing Shadow 서비스에서 사용하는 내부 MQTT 주제입니다. Raspberry Pi는 다음 형식의 메시지를 게시합니다.

```
{
    "reported": {
        "moisture" : moisture-reading,
        "temp" : temperature-reading
    }
}
```

수신되는 메시지에서 습도와 온도 데이터를 추출하는 쿼리를 생성합니다. 그리고 데이터를 가져와 습도 값이 임계값 미만일 경우 Amazon SNS 주제 구독자에게 전송하는 Amazon SNS 작업도 만듭니다.

**Amazon SNS 규칙 생성**

1. [AWS IoT 콘솔](https://console.aws.amazon.com/iot/home)에서 **메시지 라우팅**을 선택한 다음 **규칙**을 선택합니다. **아직 규칙이 없습니다** 대화 상자가 나타나면 **규칙 생성**을 선택합니다. 또는 **규칙 생성**을 선택합니다.

1. **규칙 속성** 페이지에서 **규칙 이름**(예: **MoistureSensorRule**)을 입력하고 간단한 **규칙 설명**(예: **Sends an alert when soil moisture level readings are too low**)을 제공합니다.

1. **다음**을 선택하고 SQL 문을 구성합니다. **SQL 버전을** **2016-03-23**로 선택하고 다음 AWS IoT SQL 쿼리 문을 입력합니다.

   ```
   SELECT * FROM '$aws/things/RaspberryPi/shadow/update/accepted' WHERE state.reported.moisture < 400
   ```

   이 설명문은 `moisture` 값이 `400` 미만일 때 규칙 작업을 트리거합니다.
**참고**  
다른 값을 사용해야 할 수 있습니다. Raspberry Pi에서 코드를 실행한 후에 센서를 터치하거나, 물 속에 넣거나, 화분에 두면 센서에서 가져온 값을 볼 수 있습니다.

1. **다음**을 선택하고 규칙 작업을 첨부합니다. **작업 1**에서 **단순 알림 서비스**를 선택합니다. 이 규칙 작업에 대한 설명은 **메시지를 SNS 푸시 알림으로 보내기**입니다.

1. **SNS 주제**에서 [3단계: Amazon SNS 주제 생성 및 구독](iot-moisture-create-sns-topic.md), **MoistureSensorTopic**에서 생성한 주제를 선택하고 **메시지 형식**을 **RAW**로 둡니다. **IAM 역할**에서 **새 역할 생성**을 선택합니다. 역할 이름(예: **LowMoistureTopicRole**)을 입력한 후 **역할 생성**을 선택합니다.

1. **다음**을 선택하고 검토한 후 **생성**을 선택하여 규칙을 생성합니다.

# Raspberry Pi와 습도 센서 설정
<a name="iot-moisture-raspi-setup"></a>



Raspberry Pi에 microSD 카드를 삽입하고, 모니터, 키보드, 마우스, 이더넷 케이블(Wi-Fi를 사용하지 않는 경우)을 연결합니다. 전원 케이블은 아직 연결하지 마세요.

JST 점퍼 케이블을 습도 센서에 연결합니다. 점퍼의 반대쪽에 다음 4개 와이어가 있습니다.
+ 녹색: I2C SCL
+ 흰색: I2C SDA
+ 적색: 전원(3.5V)
+ 검은색: 접지

Raspberry Pi를 이더넷 잭으로 오른쪽에 고정합니다. 이 방향에서 상단에 GPIO 핀 열이 2개 있습니다. 습도 센서의 와이어를 핀 하단 열에 다음 순서로 연결합니다. 제일 왼쪽 핀부터 시작하여 적색(전원), 흰색(SDA), 녹색(SCL)을 연결합니다. 핀 하나는 건너뛰고 검은색(접지) 와이어를 연결합니다. 자세한 내용은 [Python 컴퓨터 배선](https://learn.adafruit.com/adafruit-stemma-soil-sensor-i2c-capacitive-moisture-sensor/python-circuitpython-test) 단원을 참조하세요.

전원 케이블을 Raspberry Pi에 연결하고 반대쪽 끝을 벽면 콘센트에 꽂아 전원을 켭니다.

**Raspberry Pi 구성**

1. **Welcome to Raspberry Pi(Raspberry Pi를 소개합니다)**에서 **다음**을 선택합니다.

1. 국가, 언어, 시간대 및 키보드 배열을 선택합니다. **다음**을 선택합니다.

1. Raspberry Pi 암호를 입력하고 **다음**을 선택합니다.

1. Wi-Fi 네트워크를 선택하고 **다음**을 선택합니다. Wi-Fi 네트워크를 사용하지 않을 때는 **건너뛰기**를 선택합니다.

1. **다음**을 선택하고 소프트웨어 업데이트를 확인합니다. 업데이트가 완료되면 **다시 시작**을 클릭하여 Raspberry Pi를 다시 시작합니다.

Raspberry Pi가 시작되면 I2C 인터페이스를 활성화합니다.

1. Raspbian 데스크톱 좌측 상단 모서리에서 Raspberry 아이콘을 클릭하고, **기본 설정**을 선택한 다음 **Raspberry Pi Configuration(Raspberry Pi 구성)**을 선택합니다.

1. **인터페이스** 탭에서 **I2C**의**활성화**를 선택합니다.

1. **확인**을 선택합니다.

CircuitPython의 Adafruit STEMMA 습도 센서용 라이브러리가 작성됩니다. Raspberry Pi에서 이를 실행하려면 Python 3 최신 버전을 설치해야 합니다.

1. 명령 프롬프트에서 다음 명령을 실행하여 Raspberry Pi 소프트웨어를 업데이트합니다.

   `sudo apt-get update`

   `sudo apt-get upgrade`

1. 다음 명령을 실행하여 Phthon 3 설치를 업데이트합니다.

   `sudo pip3 install --upgrade setuptools`

1. 다음 명령을 실행하여 Raspberry Pi GPIO 라이브러리를 설치합니다.

   `pip3 install RPI.GPIO`

1. 다음 명령을 실행하여 Adafruit Blinka 라이브러리를 설치합니다.

   `pip3 install adafruit-blinka`

   자세한 내용은 [Raspberry Pi에서 CircuitPython 라이브러리 설치](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi)를 참조하세요.

1. 다음 명령을 실행하여 Adafruit Seesaw 라이브러리를 설치합니다.

   `sudo pip3 install adafruit-circuitpython-seesaw`

1. 다음 명령을 실행하여 AWS IoT Device SDK for Python을 설치합니다.

   `pip3 install AWSIoTPythonSDK`

이제 Raspberry Pi에 필요한 라이브러리가 모두 설치되었습니다. **moistureSensor.py**라는 파일을 만들고 다음 Python 코드를 파일에 복사합니다.

```
from adafruit_seesaw.seesaw import Seesaw
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTShadowClient
from board import SCL, SDA

import logging
import time
import json
import argparse
import busio

# Shadow JSON schema:
#
# {
#   "state": {
#       "desired":{
#           "moisture":<INT VALUE>,
#           "temp":<INT VALUE>            
#       }
#   }
# }

# Function called when a shadow is updated
def customShadowCallback_Update(payload, responseStatus, token):

    # Display status and data from update request
    if responseStatus == "timeout":
        print("Update request " + token + " time out!")

    if responseStatus == "accepted":
        payloadDict = json.loads(payload)
        print("~~~~~~~~~~~~~~~~~~~~~~~")
        print("Update request with token: " + token + " accepted!")
        print("moisture: " + str(payloadDict["state"]["reported"]["moisture"]))
        print("temperature: " + str(payloadDict["state"]["reported"]["temp"]))
        print("~~~~~~~~~~~~~~~~~~~~~~~\n\n")

    if responseStatus == "rejected":
        print("Update request " + token + " rejected!")

# Function called when a shadow is deleted
def customShadowCallback_Delete(payload, responseStatus, token):

     # Display status and data from delete request
    if responseStatus == "timeout":
        print("Delete request " + token + " time out!")

    if responseStatus == "accepted":
        print("~~~~~~~~~~~~~~~~~~~~~~~")
        print("Delete request with token: " + token + " accepted!")
        print("~~~~~~~~~~~~~~~~~~~~~~~\n\n")

    if responseStatus == "rejected":
        print("Delete request " + token + " rejected!")


# Read in command-line parameters
def parseArgs():

    parser = argparse.ArgumentParser()
    parser.add_argument("-e", "--endpoint", action="store", required=True, dest="host", help="Your device data endpoint")
    parser.add_argument("-r", "--rootCA", action="store", required=True, dest="rootCAPath", help="Root CA file path")
    parser.add_argument("-c", "--cert", action="store", dest="certificatePath", help="Certificate file path")
    parser.add_argument("-k", "--key", action="store", dest="privateKeyPath", help="Private key file path")
    parser.add_argument("-p", "--port", action="store", dest="port", type=int, help="Port number override")
    parser.add_argument("-n", "--thingName", action="store", dest="thingName", default="Bot", help="Targeted thing name")
    parser.add_argument("-id", "--clientId", action="store", dest="clientId", default="basicShadowUpdater", help="Targeted client id")

    args = parser.parse_args()
    return args


# Configure logging
# AWSIoTMQTTShadowClient writes data to the log
def configureLogging():

    logger = logging.getLogger("AWSIoTPythonSDK.core")
    logger.setLevel(logging.DEBUG)
    streamHandler = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    streamHandler.setFormatter(formatter)
    logger.addHandler(streamHandler)


# Parse command line arguments
args = parseArgs()

if not args.certificatePath or not args.privateKeyPath:
    parser.error("Missing credentials for authentication.")
    exit(2)

# If no --port argument is passed, default to 8883
if not args.port: 
    args.port = 8883


# Init AWSIoTMQTTShadowClient
myAWSIoTMQTTShadowClient = None
myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient(args.clientId)
myAWSIoTMQTTShadowClient.configureEndpoint(args.host, args.port)
myAWSIoTMQTTShadowClient.configureCredentials(args.rootCAPath, args.privateKeyPath, args.certificatePath)

# AWSIoTMQTTShadowClient connection configuration
myAWSIoTMQTTShadowClient.configureAutoReconnectBackoffTime(1, 32, 20)
myAWSIoTMQTTShadowClient.configureConnectDisconnectTimeout(10) # 10 sec
myAWSIoTMQTTShadowClient.configureMQTTOperationTimeout(5) # 5 sec

# Initialize Raspberry Pi's I2C interface
i2c_bus = busio.I2C(SCL, SDA)

# Intialize SeeSaw, Adafruit's Circuit Python library
ss = Seesaw(i2c_bus, addr=0x36)

# Connect to AWS IoT
myAWSIoTMQTTShadowClient.connect()

# Create a device shadow handler, use this to update and delete shadow document
deviceShadowHandler = myAWSIoTMQTTShadowClient.createShadowHandlerWithName(args.thingName, True)

# Delete current shadow JSON doc
deviceShadowHandler.shadowDelete(customShadowCallback_Delete, 5)

# Read data from moisture sensor and update shadow
while True:

    # read moisture level through capacitive touch pad
    moistureLevel = ss.moisture_read()

    # read temperature from the temperature sensor
    temp = ss.get_temp()

    # Display moisture and temp readings
    print("Moisture Level: {}".format(moistureLevel))
    print("Temperature: {}".format(temp))
    
    # Create message payload
    payload = {"state":{"reported":{"moisture":str(moistureLevel),"temp":str(temp)}}}

    # Update shadow
    deviceShadowHandler.shadowUpdate(json.dumps(payload), customShadowCallback_Update, 5)
    time.sleep(1)
```

파일을 찾을 수 있는 위치에 파일을 저장합니다. 다음 파라미터로 `moistureSensor.py` 명령줄을 실행할 수 있습니다.

엔드포인트  
사용자 지정 AWS IoT 엔드포인트입니다. 자세한 내용은 [디바이스 섀도우 REST API](device-shadow-rest-api.md) 단원을 참조하십시오.

rootCA  
 AWS IoT 루트 CA 인증서의 전체 경로입니다.

cert  
 AWS IoT 디바이스 인증서의 전체 경로입니다.

키  
 AWS IoT 디바이스 인증서 프라이빗 키의 전체 경로입니다.

thingName  
사물 이름(이 경우는 `RaspberryPi`)입니다.

clientId  
MQTT 클라이언트 ID입니다. `RaspberryPi`를 사용합니다.

명령줄의 모양은 다음과 같아야 합니다.

`python3 moistureSensor.py --endpoint your-endpoint --rootCA ~/certs/AmazonRootCA1.pem --cert ~/certs/raspberrypi-certificate.pem.crt --key ~/certs/raspberrypi-private.pem.key --thingName RaspberryPi --clientId RaspberryPi`

센서를 만지거나, 화분에 넣거나, 물 컵에 넣어 센서가 다양한 습도에 반응하는지 확인해봅니다. 필요할 경우 `MoistureSensorRule`에서 임계값을 변경할 수 있습니다. 습도 센서 판독값이 규칙의 SQL 쿼리 문에 지정된 값 아래로 떨어지면는 Amazon SNS 주제에 메시지를 AWS IoT 게시합니다. 습도와 온도 데이터가 있는 이메일 메시지가 수신되어야 합니다.

Amazon SNS에서 이메일 메시지 수신을 확인한 후에 **CTRL\$1C**를 눌러 Python 프로그램을 저장합니다. Python 프로그램으로 전송되는 메시지로 요금이 발생할 가능성은 적지만 사용 후에는 프로그램을 중지시키는 것이 좋습니다.