14. Supplementary Explanation about 13 Week Class And Explanation the AWS - EnglishNo/ESP32 GitHub Wiki

13μ£Όμ°¨ μ›Ή μ„œλ²„ μ½”λ“œμ— λŒ€ν•œ 보좩 μ„€λͺ…

#include <Wire.h>
#include <WiFi.h>
#include "DHT.h"

#define DHTTYPE DHT11
int Pin = 13;
DHT dht(Pin, DHTTYPE);

const char* ssid = "SK_WiFiGIGA1AA7";
const char* password = "2006085191";

WiFiServer server(80);

float temp;
float humid;

void setup() {
    Serial.begin(115200);
    dht.begin();

    Serial.print("Connecting to Wifi Network");
    Serial.println(ssid);
    WiFi.begin(ssid, password); // μ™€μ΄νŒŒμ΄ μ€€λΉ„.

    while (WiFi.status() != WL_CONNECTED) { // μ™€μ΄νŒŒμ΄κ°€ 연결될 λ•ŒκΉŒμ§€ 진행.
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("Successfully connected to WiFi.");
    Serial.print("IP address of ESP32 is : ");
    Serial.println(WiFi.localIP()); // μ‚¬μš©μ€‘μΈ μ™€μ΄νŒŒμ΄κ°€ μ§€κΈ‰ν•˜λŠ” IP 좜λ ₯.
    server.begin();
    Serial.println("Server started \n");
    Serial.print("http://"); Serial.println(WiFi.localIP());
}

void loop() {
    temp = dht.readTemperature();
    humid  = dht.readHumidity();
    WiFiClient client = server.available();

    if(client) {
        Serial.println("Web Client connected ");
        String request = client.readStringUntil('\r');

        // μ„œλ²„κ°€ λ³΄λ‚΄μ€˜μ•Ό ν•˜λŠ” ν—€ 정보 3가지
       client.println("HTTP/1.1 200 OK"); // μ„œλ²„κ°€ μ •μƒμ μœΌλ‘œ μ‘λ‹΅ν–ˆμŒμ„ λ³΄μ—¬μ€Œ.
       client.println("Content-type:text/html"); // μ„œλ²„μ— λ³΄λ‚΄λŠ” 데이터가 text ν˜•μ‹μ˜ html λ¬Έμ„œλΌλŠ” 것을 μ•Œλ €μ€Œ. 
       client.println("Connection : close"); // 응닡이 되면 접속을 λŠλŠ”λ‹€λŠ” 것을 의미.
       client.println(""); // μ—”ν„°

       // HTML μ½”λ“œ 정보(body)
       client.println("<html>");

       client.println("<head>");
       client.println("<title> DHT11 </title>");
       client.println("<style type=\"text/css\">");
       client.println(".title {text-align: center; font-size: 60px;}"); // HTML의 CSSμ—μ„œ 클래슀 μž‘μ„± λͺ¨μŠ΅μž„.
       client.println("th, td {font-size: xx-large;}"); // HTML의 νƒœκ·Έλ₯Ό μž‘μ„± μ‹œ, λͺ¨λ“  ν•΄λ‹Ή νƒœκ·Έμ— CSS 적용.
       client.println("sup {font-size: 18px;}");
       client.println("</style>");
       client.println("</head>");

       client.println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;CHARSET=UTF-8\" name=\"SmartDevice\" >"); // μ„œλ²„μ— λ‚˜μ˜€λŠ” ν•œκΈ€μ΄ κΉ¨μ Έ λ‚˜μ™€μ„œ μ‚¬μš©ν•¨.
       client.println("<META HTTP-EQUIV=\"refresh\" CONTENT=\"10\">");

       client.println("<body>");
       client.println("<H1 class=\"title\"> ESP32 DHT11 Web Server </H1>");

       client.println("<table width=\"400\" height=\"200\" align=\"center\">");
       client.println("<tr> <th> MEASUREMENT </th> <th> VALUE </th> </tr>");

       client.println("<tr align=\"center\"> <td>");
       client.println("<sub><svg xmlns=\"http://www.w3.org/2000/svg\" height=\"1.5em\" viewBox=\"0 0 320 512\"><style>svg{fill:#ff2e2e}</style><path d=\"M160 64c-26.5 0-48 21.5-48 48V276.5c0 17.3-7.1 31.9-15.3 42.5C86.2 332.6 80 349.5 80 368c0 44.2 35.8 80 80 80s80-35.8 80-80c0-18.5-6.2-35.4-16.7-48.9c-8.2-10.6-15.3-25.2-15.3-42.5V112c0-26.5-21.5-48-48-48zM48 112C48 50.2 98.1 0 160 0s112 50.1 112 112V276.5c0 .1 .1 .3 .2 .6c.2 .6 .8 1.6 1.7 2.8c18.9 24.4 30.1 55 30.1 88.1c0 79.5-64.5 144-144 144S16 447.5 16 368c0-33.2 11.2-63.8 30.1-88.1c.9-1.2 1.5-2.2 1.7-2.8c.1-.3 .2-.5 .2-.6V112zM208 368c0 26.5-21.5 48-48 48s-48-21.5-48-48c0-20.9 13.4-38.7 32-45.3V144c0-8.8 7.2-16 16-16s16 7.2 16 16V322.7c18.6 6.6 32 24.4 32 45.3z\"/></svg></sub>");
       client.println("Temperature </td> ");
       client.println("<td>");
       client.print(temp);
       client.println("<sup>*C</sup> </td> </tr>");

       client.println("<tr align=\"center\"> <td>");
       client.println("<sub><svg xmlns=\"http://www.w3.org/2000/svg\" height=\"1.5em\" viewBox=\"0 0 384 512\"><style>svg{fill:#3881ff}</style><path d=\"M192 512C86 512 0 426 0 320C0 228.8 130.2 57.7 166.6 11.7C172.6 4.2 181.5 0 191.1 0h1.8c9.6 0 18.5 4.2 24.5 11.7C253.8 57.7 384 228.8 384 320c0 106-86 192-192 192zM96 336c0-8.8-7.2-16-16-16s-16 7.2-16 16c0 61.9 50.1 112 112 112c8.8 0 16-7.2 16-16s-7.2-16-16-16c-44.2 0-80-35.8-80-80z\"/></svg></sub>");
       client.println("Humidity </td>");
       client.println("<td>");
       client.print(humid);
       client.println("<sup>%</sup> </td> </tr>");

       client.println("</table>");
       client.println("</body>");
       client.println("</html>");
       client.stop(); // html λ‚΄μš©μ΄ μ’…λ£Œλ¨μ„ μ•Œλ €μ€Œ.
       client.println(); // ν΄λΌμ΄μ–ΈνŠΈν•œν…Œ 헀더와 λ°”λ”” 정보λ₯Ό μ™„λ²½ν•˜κ²Œ μ „μ†‘λ¨μœΌλ‘œμ„œ μ’…λ£Œ.

       Serial.println("Client disconnected."); // 컴퓨터(μ‹œλ¦¬μ–Ό λͺ¨λ‹ˆν„°)ν•œν…Œ 좜λ ₯ν•˜λŠ” λ‚΄μš©
       Serial.println("");
    }
}

1. μ„œλ²„μ— λ³΄λ‚΄λŠ” HTML 헀더 정보

client.println("HTTP/1.1 200 OK"); // -> μ„œλ²„κ°€ μ™„λ²½νžˆ λ™μž‘ν–ˆμŒμ„ μ•Œλ €μ€Œ.
client.println("Content-type:text/html"); // -> μ„œλ²„λ‘œ λ³΄λ‚΄λŠ” 데이터가 "html" ν˜•μ‹μ˜ "text" μž„μ„ μ•Œλ €μ€Œ. 
client.println("Connection : close"); // -> 응닡이 되면 접속을 λŠλŠ”λ‹€λŠ” 것을 μ˜λ―Έν•¨.

2. μ—”ν„° 및 html μ½”λ“œ μ’…λ£Œ μ„ μ–Έ

client.println(); // -> μ—”ν„°λ₯Ό μˆ˜ν–‰ν•¨.
client.stop(); // -> 데이터 전솑 μ’…λ£Œ, 즉 html λ‚΄μš©μ΄ μ’…λ£Œλ¨μ„ μ•Œλ €μ€Œ.

AWS(μ•„λ§ˆμ‘΄μ›Ήμ„œλΉ„μŠ€)

image

AWS에 λŒ€ν•œ μ„€λͺ…

  • μ•„λ§ˆμ‘΄μ˜ μžνšŒμ‚¬λ‘œ, 2006년에 섀립. μ£Όλ ₯ μ œν’ˆμ€ ν΄λΌμš°λ“œ μ„œλ²„μŠ€.
  • 개발자 μ—”μ§€λ‹ˆμ–΄ λ“±μ˜ IT κ΄€κ³„μžλ“€μ΄ μ£Όμš” 고객이며(특히 μ˜ˆμ‚°μ΄ 적은 μŠ€νƒ€νŠΈμ—…, ν•΄μ™Έ μ§„μΆœμ„ λ…Έλ¦¬λŠ” 업체), AWSκ°€ μ œκ³΅ν•˜λŠ” μ„œλΉ„μŠ€λŠ” "인프라".
  • AWS μ„œλΉ„μŠ€λ₯Ό "μΈν”„λΌλ‘œμ„œμ˜ μ„œλΉ„μŠ€"라고 λΆ€λ₯΄λŠ” 데, λŒ€λŸ‰μ˜ μ„œλ²„, μŠ€ν† λ¦¬μ§€, λ„€νŠΈμ›Œν¬ μž₯λΉ„λ₯Ό ꡬ맀해놓고 μ‚¬μš©μžμ—κ²Œ 인프라λ₯Ό λŒ€μ—¬ν•΄ μ£Όκ³ , μ‚¬μš©μžλŠ” 각 μž₯λΉ„λ₯Ό μ‚¬μš©ν•œ 만큼만 λΉ„μš©μ„ μ§€λΆˆν•˜λ©΄ 되기 λ•Œλ¬Έ.

ν΄λΌμš°λ“œλž€ 무엇인가

image

  • κΈ°μ—… 내에 μ„œλ²„μ™€ μ €μž₯μž₯치λ₯Ό 두지 μ•Šκ³  외뢀에 μ•„μ›ƒμ†Œμ‹±ν•΄ μ“°λŠ” μ„œλΉ„μŠ€. 빅데이터λ₯Ό ν΄λΌμš°λ“œλ‘œ κ΄€λ¦¬ν•˜λ©΄ 뢄석과 ν™œμš©μ— 용이. μ˜ˆμƒμΉ˜ λͺ»ν•œ νŠΈλž˜ν”½ 폭주λ₯Ό μ—Όλ €ν•΄ κ³Όλ„ν•œ μ„€λΉ„νˆ¬μžλ₯Ό ν•  ν•„μš”λ„ μ—†μŒ.
  • 퍼블릭(κ°œλ°©ν˜•) ν΄λΌμš°λ“œ, 프라이빗(νμ‡„ν˜•) ν΄λΌμš°λ“œλ‘œ λ‚˜λ‰¨. ν΄λΌμš°λ“œ μ—…μ²΄μ˜ 데이터 μ„Όμ„œμ— λ³΄κ΄€ν•˜κ³ μž ν•˜λ©΄ "퍼블릭 ν΄λΌμš°λ“œ", κΈ°μ—… μ•ˆμ΄λ‚˜ 데이터 μ„Όμ„œμ˜ λ…λ¦½λœ μ„œλ²„μ— λ³΄κ΄€ν•˜κ³ μž ν•  μ‹œ "프라이빗 ν΄λΌμš°λ“œ".
  • ν΄λΌμš°λ“œ μ„œλΉ„μŠ€λ₯Ό μ œκ³΅ν•˜λŠ” μ—…μ²΄λŠ” λ§Žμ€ μ΄μš©μžλ“€μ˜ 데이터λ₯Ό λ³΄κ΄€ν•˜λ―€λ‘œ, μ„œλ²„μ˜ λ³΄μ•ˆ 관리에 μ² μ €ν•΄μ•Ό ν•˜κ³ , λŒ€λŸ‰μ˜ 데이터 보관 및 처리λ₯Ό 효율적으둜 ν•˜λŠ” 기술 λ©΄μ—μ„œλ„ 지속적인 λ°œμ „μ΄ 되고 있음.

μ°Έκ³  μ‚¬μ΄νŠΈ

AWS - https://terms.naver.com/entry.naver?docId=3580218&cid=59088&categoryId=59096

ν΄λΌμš°λ“œ - https://terms.naver.com/entry.naver?docId=2066705&cid=50305&categoryId=50305 / https://terms.naver.com/entry.naver?docId=4383209&cid=59941&categoryId=59941


λͺ°λžλ˜ 단어 정리

  • μŠ€ν† λ¦¬μ§€ - μ»΄ν“¨ν„°μ—μ„œ 데이터λ₯Ό μ €μž₯ν•˜λŠ” 곡간. λ˜λŠ” 그런 곡간이 마련된 μž₯치.
  • μ•„μ›ƒμ†Œμ‹± - κΈ°μ—… μ—…λ¬΄μ˜ 일뢀 λΆ€λ¬Έμ΄λ‚˜ 과정을 경영 효과 및 효율의 κ·ΉλŒ€ν™”λ₯Ό μœ„ν•œ λ°©μ•ˆμœΌλ‘œ μ œμ‚Όμžμ—κ²Œ μœ„νƒν•΄ μ²˜λ¦¬ν•˜λŠ” 것. (κ΄€λ ¨ μš©μ–΄ - μ•„μ›ƒμ†Œμ‹± μ„œλΉ„μŠ€)
  • νŠΈλž˜ν”½ - μ „ν™” λ˜λŠ” 컴퓨터 ν†΅μ‹ μ˜ νŠΉμ • μ „μ†‘λ‘œμ—μ„œ 일정 μ‹œκ°„ 내에 흐λ₯΄λŠ” μ •λ³΄μ˜ μ΄λ™λŸ‰.

AWS IoT λ””λ°”μ΄μŠ€ μƒμ„±ν•˜λŠ” 법 (=? AWS μ‚¬μš©λ²•?)

AWS이 ESP32ν•˜κ³  ν†΅μ‹ ν•˜λ €λ©΄, λ””λ°”μ΄μŠ€ 자격 증λͺ…을 μ‚¬μš©ν•΄ "AWS IoT Core"ν•˜κ³  μ—°κ²°λ˜μ–΄μ•Ό 함. 그리고 "publish", "subscribe" κΆŒν•œμ΄ μžˆλŠ” μ£Όμ œλ„ 지정해야 함.

  1. "Get Started for Free(무료둜 μ‹œμž‘ν•˜κΈ°)" λ²„νŠΌμ„ 눌렀 AWS 계정 생성.
  2. AWS IoT console μ—μ„œ "Register a new thing", "Create a single thing" 을 선택.
  3. μƒˆ ν•­λͺ©μ˜ 이름을 "MyNewESP32"둜 지정. λ‚˜λ¨Έμ§€ ν•„λ“œλŠ” κΈ°λ³Έκ°’μœΌλ‘œ μ„€μ •λœ μƒνƒœλ‘œ 두고, "Next(λ‹€)" λ²„νŠΌ 클릭.
  4. "Create certificate"λ₯Ό ν΄λ¦­ν•˜κ³ , ESP32에 μ—°κ²°ν•˜κΈ° μœ„ν•΄ "thing cert(사물 μΈμ¦μ„œ)", "private key(개인 ν‚€)", "Amazon Root CA 1"만 λ‹€μš΄λ‘œλ“œ.
  5. "Activate", "Attach a policy"λ₯Ό 선택.
  6. "policy"λ₯Ό μΆ”κ°€ν•˜λŠ” 것을 κ±΄λ„ˆλ›°κ³ , "Register Thing" 선택.
  7. AWS IoT console μ‚¬μ΄λ“œ λ©”λ‰΄μ—μ„œ "Secure", "Policies", "Create a policy" 선택.
  8. Policy 이름을 "ESP32Policy"둜 ν•˜κ³ , "Advanced" νƒ­ 선택.
  9. λ‹€μŒ policy ν…œν”Œλ¦Ώμ„ λΆ™μ—¬ λ„£κΈ°.
    {
        "Version": "2012-10-17",
        "Statement": [
        {
            "Effect": "Allow",
            "Action": "iot:Connect",
            "Resource": "arn:aws:iot:REGION:ACCOUNT_ID:client/MyNewESP32"
        },
        {
            "Effect": "Allow",
            "Action": "iot:Subscribe",
            "Resource": "arn:aws:iot:REGION:ACCOUNT_ID:topicfilter/esp32/sub"
        },
    {
            "Effect": "Allow",
            "Action": "iot:Receive",
            "Resource": "arn:aws:iot:REGION:ACCOUNT_ID:topic/esp32/sub"
        },
        {
            "Effect": "Allow",
            "Action": "iot:Publish",
            "Resource": "arn:aws:iot:REGION:ACCOUNT_ID:topic/esp32/pub"
        }
        ]
    }
    

  10. "REGION"λ₯Ό ν˜„μž¬ 운영 쀑인 AWS Region λ§žμΆ”κΈ°. (REGIONλŠ” AWS console window의 상단 였λ₯Έμͺ½ ꡬ석에 λ°œκ²¬λœλ‹€κ³  함.)
  11. "ACCOUNT_ID"을 μžμ‹ μ˜ μ•„μ΄λ””λ‘œ λ°”κΎΈκΈ°. (이것은 μ΄κ³³μ—μ„œ 찾을 수 μžˆλ‹€κ³  함.)
  12. "Create" 클릭.
  13. AWS IoT consoleμ—μ„œ "Secure", "Certification" 선택. λ””λ°”μ΄μŠ€λ₯Ό μœ„ν•΄ μƒμ„±λœ ν•­λͺ© μ„ νƒν•˜κ³ , "Actions", "Attach policy" 선택.
  14. "Esp32Policy", "Attach" 선택.

-주의-

μœ„μ˜ μ„€λͺ…은 μ‚¬μ΄νŠΈ λ²ˆμ—­ κΈ°λŠ₯ λ˜λŠ” 자의둜 해석해 μž‘μ„±ν•œ 것이고, AWSλ₯Ό 직접 μ‚¬μš© μ•ˆν•˜κ³  μ‚¬μ΄νŠΈ λ‚΄μ˜ μ„€λͺ…μœΌλ‘œλ§Œ μž‘μ„±ν•œ 것이라 틀릴 수 있음.

μ°Έκ³  μ‚¬μ΄νŠΈ

AWS μ‚¬μ΄νŠΈ - https://aws.amazon.com/ko/blogs/compute/building-an-aws-iot-core-device-using-aws-serverless-and-an-esp32/?fbclid=IwAR10PAaXduCq2nlWX6gKLWuaVJPGIp9ybXRUD8cC4nVASYD-OtjM2LY_rSI


이번 μˆ˜μ—…μ—μ„œ μ•Œκ²Œ 된 점

  • μ €λ²ˆ μ‹€μŠ΅μ‹œκ°„μ˜ μš©λ„λ₯Ό λͺ¨λ₯΄κ±°λ‚˜ μ™œ κ·Έλ ‡κ²Œ μ ν˜€ μžˆλŠ”μ§€ κΆκΈˆν–ˆλ˜ μ½”λ“œλ“€μ˜ μš©λ„κ°€ νŠΉμ§•μ„ μ•Œκ²Œ λ˜μ—ˆλ‹€.
  • AWSν•˜κ³  ν΄λΌμš°λ“œ, κ·Έ μ™Έμ˜ μš©μ–΄λ“€μ— λŒ€ν•΄ μ•Œκ²Œ λ˜μ—ˆλ‹€.
⚠️ **GitHub.com Fallback** ⚠️