Toby's Study Blog
article thumbnail

๐Ÿค– ์‹ค์Šต ๋ชฉํ‘œ

์ด์ „ ์ฑ„ํŒ… ์„œ๋ฒ„, ์ฑ„ํŒ… ํด๋ผ์ด์–ธํŠธ ํ”„๋กœ๊ทธ๋žจ์— ์ด์–ด IoT ์„œ๋ฒ„, ํด๋ผ์ด์–ธํŠธ ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
์ฑ„ํŒ… ์„œ๋ฒ„, ์ฑ„ํŒ… ํด๋ผ์ด์–ธํŠธ ๋‚ด์šฉ -> https://toby12.tistory.com/53

  1. iot_server, iot_client ํ”„๋กœ๊ทธ๋žจ ์ž‘์„ฑ 
  2. ํ”„๋กœ๊ทธ๋žจ ๋นŒ๋“œ  
  3. ์„ผ์„œ, ๋””๋ฐ”์ด์Šค ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ๊ตฌ์ถ•
  4. ํด๋ผ์ด์–ธํŠธ -> ์„œ๋ฒ„ ์„ผ์„œ ๋ฐ์ดํ„ฐ ์กฐํšŒ ์š”์ฒญ ๋ฐ ํ™•์ธ
  5. ํด๋ผ์ด์–ธํŠธ -> ์„œ๋ฒ„ ๋””๋ฐ”์ด์Šค ์„ค์ • ์—…๋ฐ์ดํŠธ ์š”์ฒญ ๋ฐ ํ™•์ธ

๐Ÿค– ์ƒ์„ธ ๊ธฐ๋Šฅ

์„œ๋ฒ„ 

  1. ์†Œ์ผ“ ๋ฐ ์Šค๋ ˆ๋“œ ์ดˆ๊ธฐํ™”:
    • ์„œ๋ฒ„ ์†Œ์ผ“ ์ƒ์„ฑ ๋ฐ ์ดˆ๊ธฐํ™”
    • ํด๋ผ์ด์–ธํŠธ์˜ ์—ฐ๊ฒฐ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์Šค๋ ˆ๋“œ๋ฅผ ์ƒ์„ฑ
  2. ํด๋ผ์ด์–ธํŠธ ๊ด€๋ฆฌ:
    • ์ตœ๋Œ€ 32๊ฐœ์˜ ํด๋ผ์ด์–ธํŠธ๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฐ์—ด๊ณผ ํ•ด๋‹น ํด๋ผ์ด์–ธํŠธ ์ˆ˜๋ฅผ ์ถ”์ ํ•˜๋Š” ๋ณ€์ˆ˜ ์„ค์ •
    • ํด๋ผ์ด์–ธํŠธ์˜ ID ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ฏธ๋ฆฌ ๋“ฑ๋ก๋œ ์ •๋ณด์™€ ๋น„๊ตํ•˜์—ฌ ์ธ์ฆ
  3. ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ:
    • ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์— ์ ‘์†ํ•˜๋ฉด ์Šค๋ ˆ๋“œ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ํด๋ผ์ด์–ธํŠธ์™€ ํ†ต์‹ ์„ ๋‹ด๋‹น
  4. MySQL ์—ฐ๋™:
    • MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐํ•˜๊ณ  ํด๋ผ์ด์–ธํŠธ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์กฐํšŒ ๋ฐ ์—…๋ฐ์ดํŠธ
    • "sensor" ๋ฐ "device" ํ…Œ์ด๋ธ”์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์™€ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „์†ก
  5. ํด๋ผ์ด์–ธํŠธ ๊ฐ„ ๋ฉ”์‹œ์ง€ ์ „์†ก:
    • ํด๋ผ์ด์–ธํŠธ ๊ฐ„ ๋ฉ”์‹œ์ง€๋ฅผ ์ฃผ๊ณ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ ๊ตฌํ˜„
    • ํŠน์ • ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ฉ”์‹œ์ง€๋ฅผ ์ „์†กํ•  ์ˆ˜ ์žˆ์Œ
    • ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์š”์ฒญํ•˜๋ฉด ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฅผ ์กฐํšŒํ•˜์—ฌ ์ „์†ก
  6. ๋ฐ์ดํ„ฐ ์—…๋ฐ์ดํŠธ:
    • ํด๋ผ์ด์–ธํŠธ๊ฐ€ "SET DEVICE" ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋ฉด MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ํ•ด๋‹น ๋””๋ฐ”์ด์Šค ๊ฐ’์„ ์—…๋ฐ์ดํŠธ
  7. ๋ฎคํ…์Šค ์‚ฌ์šฉ:
    • ๋ฎคํ…์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋™์‹œ์— ์—ฌ๋Ÿฌ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์— ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ์„ ์ œ์–ด.

ํด๋ผ์ด์–ธํŠธ

  1. ์†Œ์ผ“ ๋ฐ ์Šค๋ ˆ๋“œ ์ดˆ๊ธฐํ™”:
    • ์„œ๋ฒ„์— ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•ด ์†Œ์ผ“์„ ์ƒ์„ฑํ•˜๊ณ  ์ดˆ๊ธฐํ™”.
  2. ์—ฐ๊ฒฐ ๋ฐ ๋กœ๊ทธ์ธ:
    • ์„œ๋ฒ„์— ์ ‘์†ํ•œ ํ›„, ๋ฏธ๋ฆฌ ์ง€์ •๋œ ID์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ๊ทธ์ธ.
  3. ๋ฉ”์‹œ์ง€ ์†ก์ˆ˜์‹ :
    • ์‚ฌ์šฉ์ž๊ฐ€ ํ‘œ์ค€ ์ž…๋ ฅ์„ ํ†ตํ•ด ๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์„œ๋ฒ„๋กœ ์ „์†ก.
    • ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ์ˆ˜์‹ ํ•œ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅ.
  4. ์Šค๋ ˆ๋“œ ์ƒ์„ฑ:
    • ๋ฉ”์‹œ์ง€ ์ „์†ก ๋ฐ ์ˆ˜์‹ ์„ ๋ณ‘๋ ฌ๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ๊ฐ์˜ ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋‘ ๊ฐœ์˜ ์Šค๋ ˆ๋“œ ์ƒ์„ฑ.
  5. 'quit' ๋ช…๋ น์–ด ์ฒ˜๋ฆฌ:
    • ์‚ฌ์šฉ์ž๊ฐ€ 'quit'์„ ์ž…๋ ฅํ•˜๋ฉด ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ข…๋ฃŒ๋˜๋„๋ก ์„ค์ •.
  6. ๋ฉ”์‹œ์ง€ ํฌ๋งท ์ฒ˜๋ฆฌ:
    • ์ž…๋ ฅ๋œ ๋ฉ”์‹œ์ง€๋ฅผ ์„œ๋ฒ„์— ์ „์†กํ•˜๊ธฐ ์ „์— ํฌ๋งท์— ๋งž๊ฒŒ ๊ฐ€๊ณต.
  7. ๋น„๋ฐ€๋ฒˆํ˜ธ ์ „์†ก:
    • ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์— ์—ฐ๊ฒฐ๋˜๋ฉด ๋จผ์ € ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ „์†ก.

๐Ÿค– ์‹ค์Šต ๊ฒฐ๊ณผ

iot client ํ”„๋กœ๊ทธ๋žจ ์ž‘์„ฑ

  1. iot_server.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <string.h>
    #include <arpa/inet.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <pthread.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <dirent.h>
    #include <sys/time.h>
    #include <time.h>
    #include <errno.h>
    #include <mysql/mysql.h>
    #include <ctype.h>
    
    #define BUF_SIZE 200
    #define MAX_CLNT 32
    #define ID_SIZE 10
    #define ARR_CNT 5
    #define DEBUG
    
    // ๋ฉ”์‹œ์ง€ ์ •๋ณด ๊ตฌ์กฐ์ฒด
    typedef struct {
      int fd;         // ํŒŒ์ผ ์‹๋ณ„์ž
      char *from;     // ๋ณด๋‚ธ ์‚ฌ๋žŒ ID
      char *to;       // ๋ฐ›๋Š” ์‚ฌ๋žŒ ID
      char *msg;      // ๋ฉ”์‹œ์ง€ ๋‚ด์šฉ
      int len;        // ๋ฉ”์‹œ์ง€ ๊ธธ์ด
      int is_sent;    // ์ „์†ก ์—ฌ๋ถ€ ํ”Œ๋ž˜๊ทธ
    } MSG_INFO;
    
    // ํด๋ผ์ด์–ธํŠธ ์ •๋ณด ๊ตฌ์กฐ์ฒด
    typedef struct {
      int index;      // ํด๋ผ์ด์–ธํŠธ ์ธ๋ฑ์Šค
      int fd;         // ํŒŒ์ผ ์‹๋ณ„์ž
      char ip[20];    // ํด๋ผ์ด์–ธํŠธ IP ์ฃผ์†Œ
      char id[ID_SIZE];  // ํด๋ผ์ด์–ธํŠธ ID
      char pw[ID_SIZE];  // ํด๋ผ์ด์–ธํŠธ ๋น„๋ฐ€๋ฒˆํ˜ธ
    } CLIENT_INFO;
    
    void *clnt_connection(void *arg); // ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
    void send_msg(MSG_INFO *msg_info, CLIENT_INFO *first_client_info); // ๋ฉ”์‹œ์ง€ ์ „์†ก ํ•จ์ˆ˜
    void error_handling(char *msg); // ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
    void log_file(char *msgstr); // ๋กœ๊ทธ ํŒŒ์ผ ์ž‘์„ฑ ํ•จ์ˆ˜
    void init_mysql(); // MySQL ์ดˆ๊ธฐํ™” ํ•จ์ˆ˜
    void send_data_to_client(int client_fd, char *name, char *request_type); // ํด๋ผ์ด์–ธํŠธ์— ๋ฐ์ดํ„ฐ ์ „์†ก ํ•จ์ˆ˜
    void find_data(int client_fd, char *name, char *request_type); // ๋ฐ์ดํ„ฐ ์ฐพ๊ธฐ ํ•จ์ˆ˜
    
    char *trim(char *str); // ๋ฌธ์ž์—ด ์–‘ ๋์˜ ๊ณต๋ฐฑ ์ œ๊ฑฐ ํ•จ์ˆ˜
    int clnt_cnt = 0;  // ํ˜„์žฌ ์—ฐ๊ฒฐ๋œ ํด๋ผ์ด์–ธํŠธ ์ˆ˜
    pthread_mutex_t mutx;  // ๋ฎคํ…์Šค ์„ ์–ธ
    MYSQL *conn;  // MySQL ์—ฐ๊ฒฐ ๊ฐ์ฒด
    
    int main(int argc, char *argv[]) {
      int serv_sock, clnt_sock;
      struct sockaddr_in serv_adr, clnt_adr;
      int clnt_adr_sz;
      int sock_option = 1;
      pthread_t t_id[MAX_CLNT] = {0};
      int str_len = 0;
      int i;
      char idpasswd[(ID_SIZE * 2) + 3];
      char *pToken;
      char *pArray[ARR_CNT] = {0};
      char msg[BUF_SIZE];
    
      // ์ดˆ๊ธฐ ํด๋ผ์ด์–ธํŠธ ์ •๋ณด ๋ฐฐ์—ด
      CLIENT_INFO client_info[MAX_CLNT] = {
          {0, -1, "", "KHJ_LIN", "PASSWD"},
          {0, -1, "", "KHJ_SQL", "PASSWD"},
          {0, -1, "", "3", "PASSWD"},
          {0, -1, "", "32", "PASSWD"}};
    
      // ํฌํŠธ ๋ฒˆํ˜ธ๋ฅผ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์ง€ ์•Š์•˜์„ ์‹œ ์ข…๋ฃŒ 
      if (argc != 2) {
        printf("Usage : %s <port>\n", argv[0]);
        exit(1);
      }
      fputs("IoT Server Start!!\n", stdout);
      init_mysql(); // MySQL ์ดˆ๊ธฐํ™”
    
      // ๋ฎคํ…์Šค ์ดˆ๊ธฐํ™”
      if (pthread_mutex_init(&mutx, NULL))
        error_handling("mutex init error");
    
      // ์†Œ์ผ“ ์ƒ์„ฑ
      serv_sock = socket(PF_INET, SOCK_STREAM, 0);
    
      // ์„œ๋ฒ„ ์ฃผ์†Œ ๊ตฌ์กฐ์ฒด ์ดˆ๊ธฐํ™”
      memset(&serv_adr, 0, sizeof(serv_adr));
      serv_adr.sin_family = AF_INET;
      serv_adr.sin_addr.s_addr = htonl(INADDR_ANY);
      serv_adr.sin_port = htons(atoi(argv[1]));
    
      // ์†Œ์ผ“ ์˜ต์…˜ ์„ค์ •
      setsockopt(serv_sock, SOL_SOCKET, SO_REUSEADDR, (void *)&sock_option,
                 sizeof(sock_option));
    
      // ๋ฐ”์ธ๋”ฉ ์ฒ˜๋ฆฌ
      if (bind(serv_sock, (struct sockaddr *)&serv_adr, sizeof(serv_adr)) == -1)
        error_handling("bind() error");
    
      // ๋ฆฌ์Šค๋‹ ์ฒ˜๋ฆฌ
      if (listen(serv_sock, 5) == -1)
        error_handling("listen() error");
    
      // ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ ๋Œ€๊ธฐ ๋ฐ ์ฒ˜๋ฆฌ
      while (1) {
        clnt_adr_sz = sizeof(clnt_adr);
        clnt_sock = accept(serv_sock, (struct sockaddr *)&clnt_adr, &clnt_adr_sz);
    
        // ํด๋ผ์ด์–ธํŠธ ์ˆ˜๊ฐ€ ์ตœ๋Œ€ ํด๋ผ์ด์–ธํŠธ ์ˆ˜๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด ์—ฐ๊ฒฐ ๊ฑฐ๋ถ€
        if (clnt_cnt >= MAX_CLNT) {
          printf("socket full\n");
          shutdown(clnt_sock, SHUT_WR);
          continue;
        } else if (clnt_sock < 0) {
          perror("accept()");
          continue;
        }
    
        // ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ID ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ˆ˜์‹ 
        str_len = read(clnt_sock, idpasswd, sizeof(idpasswd));
        idpasswd[str_len] = '\0';
    
        // ID ๋ฐ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ฒ˜๋ฆฌ
        if (str_len > 0) {
          i = 0;
          pToken = strtok(idpasswd, "[:]");
          while (pToken != NULL) {
            pArray[i] = pToken;
            if (i++ >= ARR_CNT)
              break;
            pToken = strtok(NULL, "[:]");
          }
          // ๋“ฑ๋ก๋œ ํด๋ผ์ด์–ธํŠธ ์ •๋ณด์—์„œ ID์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ผ์น˜ ์—ฌ๋ถ€ ํ™•์ธ
          for (i = 0; i < MAX_CLNT; i++) {
            if (!strcmp(client_info[i].id, pArray[0])) {
              if (client_info[i].fd != -1) {
                // ์ด๋ฏธ ๋กœ๊ทธ์ธํ•œ ๊ฒฝ์šฐ
                sprintf(msg, "[%s] Already logged!\n", pArray[0]);
                write(clnt_sock, msg, strlen(msg));
                log_file(msg);
                shutdown(clnt_sock, SHUT_WR);
                // MCU ํด๋ผ์ด์–ธํŠธ์˜ ๊ฒฝ์šฐ ๊ธฐ์กด ์—ฐ๊ฒฐ ๋Š๊ธฐ
                shutdown(client_info[i].fd, SHUT_WR);
                client_info[i].fd = -1;
                break;
              }
              // ID์™€ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ผ์น˜ ์‹œ ํด๋ผ์ด์–ธํŠธ ์ •๋ณด ์—…๋ฐ์ดํŠธ
              if (!strcmp(client_info[i].pw, pArray[1])) {
                strcpy(client_info[i].ip, inet_ntoa(clnt_adr.sin_addr));
                pthread_mutex_lock(&mutx);
                client_info[i].index = i;
                client_info[i].fd = clnt_sock;
                clnt_cnt++;
                pthread_mutex_unlock(&mutx);
                sprintf(msg, "[%s] New connected! (ip:%s,fd:%d,sockcnt:%d)\n",
                        pArray[0], inet_ntoa(clnt_adr.sin_addr), clnt_sock, clnt_cnt);
                log_file(msg);
                write(clnt_sock, msg, strlen(msg));
                // ํด๋ผ์ด์–ธํŠธ ์—ฐ๊ฒฐ์— ๋Œ€ํ•œ ์Šค๋ ˆ๋“œ ์ƒ์„ฑ ๋ฐ ๋ถ„๋ฆฌ
                pthread_create(t_id + i, NULL, clnt_connection,
                               (void *)(client_info + i));
                pthread_detach(t_id[i]);
                break;
              }}}
          // ๋“ฑ๋ก๋œ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ์—ฐ๊ฒฐ ๊ฑฐ๋ถ€
          if (i == MAX_CLNT) {
            sprintf(msg, "[%s] Authentication Error!\n", pArray[0]);
            write(clnt_sock, msg, strlen(msg));
            log_file(msg);
            shutdown(clnt_sock, SHUT_WR);
          }
        } else
          shutdown(clnt_sock, SHUT_WR);
      }
      return 0;
    }
    // MySQL ์ดˆ๊ธฐํ™” ํ•จ์ˆ˜
    void init_mysql() {
      conn = mysql_init(NULL);
      if (conn == NULL) {
        fprintf(stderr, "mysql_init() failed\n");
        exit(1);
      } else if (mysql_real_connect(conn, "127.0.0.1", "iot", "pwiot", "iotdb", 0,
                                   NULL, 0) == NULL) {
        fprintf(stderr, "mysql_real_connect() failed\n");
        mysql_close(conn);
        exit(1);
      } else {
        fputs("MYSQL Start!!\n", stdout);
      }}
    // ํด๋ผ์ด์–ธํŠธ์˜ ๋ฐ์ดํ„ฐ ์กฐํšŒ
    void find_data(int client_fd, char *name, char *request_type) {
      MYSQL_RES *result;
      MYSQL_ROW row;
      char query[BUF_SIZE];
      char data_info[BUF_SIZE];
    
      // MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ
      if (strcmp(request_type, "[ALLMSG]GET SENSOR") == 0) {
        sprintf(query,
                "SELECT illu, temp, humi, date, time FROM sensor WHERE name='%s' "
                "ORDER BY id DESC LIMIT 1",
                name);
        if (mysql_query(conn, query)) {
          fprintf(stderr, "SELECT query failed: %s\n", mysql_error(conn));
          return;
        }
        result = mysql_store_result(conn);
        if (result == NULL) {
          fprintf(stderr, "mysql_store_result() failed\n");
          return;
        }
        row = mysql_fetch_row(result);
        if (row != NULL) {
          int illu = atoi(row[0]);
          int temp = atoi(row[1]);
          int humi = atoi(row[2]);
          char date[BUF_SIZE];
          char time[BUF_SIZE];
          strncpy(date, row[3], BUF_SIZE);
          strncpy(time, row[4], BUF_SIZE);
          size_t remaining_space = BUF_SIZE - 1;
          remaining_space -= snprintf(
              data_info, remaining_space,
              "[SENSOR_DATA] %s: Illuminance=%d, Temperature=%d, Humidity=%d, "
              "Date=%s, Time=%s\n",
              name, illu, temp, humi, date, time);
        }
        mysql_free_result(result);
      } else if (strcmp(request_type, "[ALLMSG]GET DEVICE") == 0) {
        sprintf(query,
                "SELECT value, date, time FROM device WHERE name='%s' ORDER BY id "
                "DESC LIMIT 1",
                name);
        if (mysql_query(conn, query)) {
          fprintf(stderr, "SELECT query failed: %s\n", mysql_error(conn));
          return;   
           }
           // MySQL์กฐํšŒ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ ํฌ์ธํ„ฐ ๋ณ€์ˆ˜
           result = mysql_store_result(conn);
    	// ๊ฒฐ๊ณผ๊ฐ€ ์—†๊ฑฐ๋‚˜ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ ์ข…๋ฃŒ
            if (result == NULL) {
                fprintf(stderr, "mysql_store_result() failed\n");
                return;
            }
    	// ๊ฒฐ๊ณผ๋ฅผ ํ–‰์œผ๋กœ ์ €์žฅ
            row = mysql_fetch_row(result);
    
    	// ๊ฐ€์ ธ์˜จ ํ–‰์ด ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ 
            if (row != NULL) {
            // ํ–‰์—์„œ ์ฒซ ๋ฒˆ์งธ ์—ด ๊ฐ’์„ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜
                int value = atoi(row[0]);
            // ํ–‰์—์„œ ๋‘ ๋ฒˆ์งธ, ์„ธ ๋ฒˆ์งธ ์—ด ๊ฐ’์„ ๋ฌธ์ž์—ด๋กœ ๋ณต์‚ฌ
                char date[BUF_SIZE];
                char time[BUF_SIZE];
                strncpy(date, row[1], BUF_SIZE);
                strncpy(time, row[2], BUF_SIZE);
    	// ๋ฐ์ดํ„ฐ ์ •๋ณด ๋ฌธ์ž์—ด์„ ์ €์žฅํ•  ๋ฒ„ํผ ๋ฐ ๋‚จ์€ ๊ณต๊ฐ„ ๊ณ„์‚ฐ
                size_t remaining_space = BUF_SIZE - 1;
            // ๋ฐ์ดํ„ฐ ์ •๋ณด๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฒ„ํผ์— ์ €์žฅ
                remaining_space -= snprintf(data_info, remaining_space, "[DEVICE_INFO] %s: Value=%d, Date=%s, Time=%s\n", name, value, date, time);
            }
            mysql_free_result(result);
        } else {
            fprintf(stderr, "Invalid request type: %s\n", request_type);
            return;
        }
        // ๋ฐ์ดํ„ฐ ์ •๋ณด๋ฅผ ํด๋ผ์ด์–ธํŠธ์— ์ „์†ก
        write(client_fd, data_info, strlen(data_info));
    }
    
    // ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ฐ์ดํ„ฐ ์ „์†ก
    void send_data_to_client(int client_fd, char *name, char *request_type) {
        if (strcmp(request_type, "[ALLMSG]GET SENSOR") == 0) {
     	find_data(client_fd, name,request_type);
        } else if (strcmp(request_type, "[ALLMSG]GET DEVICE") == 0) {
    	find_data(client_fd, name,request_type);
        } else {
            fprintf(stderr, "Invalid request type: %s\n", request_type);
        }}
    // ํด๋ผ์ด์–ธํŠธ ์“ฐ๋ ˆ๋“œ ํ•จ์ˆ˜
    void *clnt_connection(void *arg) {
        // ์ „๋‹ฌ๋ฐ›์€ ์ธ์ž๋ฅผ ํด๋ผ์ด์–ธํŠธ ์ •๋ณด ๊ตฌ์กฐ์ฒด๋กœ ํ˜•๋ณ€ํ™˜
        CLIENT_INFO *client_info = (CLIENT_INFO *)arg;
    
        // ๋ณ€์ˆ˜ ๋ฐ ๋ฐฐ์—ด ์ดˆ๊ธฐํ™”
        int str_len = 0;
        int index = client_info->index;
        char msg[BUF_SIZE];
        char to_msg[MAX_CLNT * ID_SIZE + 1];
        int i = 0;
        char *pToken;
        char *pArray[ARR_CNT] = {0};
        char strBuff[130] = {0};
        char sql_cmd[BUF_SIZE]; // ์ฟผ๋ฆฌ ๋ช…๋ น๋ฌธ ์ €์žฅ์šฉ ๋ฐฐ์—ด
        int res;                // ์ฟผ๋ฆฌ ์‹คํ–‰ ๊ฒฐ๊ณผ ์ €์žฅ์šฉ ๋ณ€์ˆ˜
        int *sock;              // ์†Œ์ผ“ ์ •๋ณด ์ €์žฅ์šฉ ๋ณ€์ˆ˜
    
        // ๋ฉ”์‹œ์ง€ ์ •๋ณด ๋ฐ ์ฒซ ๋ฒˆ์งธ ํด๋ผ์ด์–ธํŠธ ์ •๋ณด ๊ตฌ์กฐ์ฒด ์ดˆ๊ธฐํ™”
        MSG_INFO msg_info;
        CLIENT_INFO *first_client_info;
        first_client_info = (CLIENT_INFO *)((void *)client_info - (void *)(sizeof(CLIENT_INFO) * index));
    
        // ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ๋ฉ”์‹œ์ง€๋ฅผ ๊ณ„์† ์ฝ์–ด์˜ค๋Š” ๋ฃจํ”„
        while (1) {
            // ๋ฒ„ํผ ์ดˆ๊ธฐํ™” ๋ฐ ํด๋ผ์ด์–ธํŠธ๋กœ๋ถ€ํ„ฐ ๋ฉ”์‹œ์ง€ ์ฝ๊ธฐ
            memset(msg, 0x0, sizeof(msg));
            str_len = read(client_info->fd, msg, sizeof(msg) - 1);
    
            // ๋ฉ”์‹œ์ง€ ๊ธธ์ด๊ฐ€ 0 ์ดํ•˜์ธ ๊ฒฝ์šฐ ์—ฐ๊ฒฐ ์ข…๋ฃŒ
            if (str_len <= 0)
                break;
    
            // ๋ฌธ์ž์—ด ๋์— null ์ถ”๊ฐ€
            msg[str_len] = '\0';
    
            // ๋ฐ›์€ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ
            printf("%s: %s", client_info->id, msg);
    
            // [ALLMSG]GET SENSOR ๋ฉ”์‹œ์ง€์ธ ๊ฒฝ์šฐ SENSOR ๋ฐ์ดํ„ฐ ์ „์†ก
            if (strcmp(trim(msg), "[ALLMSG]GET SENSOR") == 0) {
                send_data_to_client(client_info->fd, client_info->id, "[ALLMSG]GET SENSOR");
            }
            // [ALLMSG]GET DEVICE ๋ฉ”์‹œ์ง€์ธ ๊ฒฝ์šฐ DEVICE ๋ฐ์ดํ„ฐ ์ „์†ก
            else if (strcmp(trim(msg), "[ALLMSG]GET DEVICE") == 0) {
                send_data_to_client(client_info->fd, client_info->id, "[ALLMSG]GET DEVICE");
            }
            // [ALLMSG]SET DEVICE ๋ฉ”์‹œ์ง€์ธ ๊ฒฝ์šฐ ๊ฐ’ ์—…๋ฐ์ดํŠธ
            else if (strstr(msg, "[ALLMSG]SET DEVICE")) {
                // SET DEVICE ๋ฉ”์‹œ์ง€ ํŒŒ์‹ฑ
                int value;
                char device[20];
    
                // ๋ณ€์ˆ˜ ๋ฐ ๋ฐฐ์—ด ์ดˆ๊ธฐํ™”
                memset(sql_cmd, 0, sizeof(sql_cmd));
                res = 0;
    
                // SET DEVICE ๋ช…๋ น ๋ฉ”์‹œ์ง€ ํŒŒ์‹ฑ
                if (sscanf(msg, "[ALLMSG]SET DEVICE %d", &value) == 1) {
                    // MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—…๋ฐ์ดํŠธ๋ฅผ ์œ„ํ•œ SQL ๋ช…๋ น์–ด ์ƒ์„ฑ
                    sprintf(sql_cmd, "UPDATE device SET value=%d, date=CURDATE(), time=CURTIME() WHERE name='%s'", value, client_info->id);
    
                    // SQL ๋ช…๋ น์–ด ์‹คํ–‰
                    int res = mysql_query(conn, sql_cmd);
    
                    // ์—…๋ฐ์ดํŠธ ์„ฑ๊ณตํ•œ ๊ฒฝ์šฐ
                    if (!res) {
                        printf("[%s] ๋””๋ฐ”์ด์Šค ๊ฐ’์ด %d๋กœ ์—…๋ฐ์ดํŠธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค\n", client_info->id, value);
                    }
                    // ์—…๋ฐ์ดํŠธ ์‹คํŒจํ•œ ๊ฒฝ์šฐ
                    else {
                        fprintf(stderr, "๋””๋ฐ”์ด์Šค ๊ฐ’ ์—…๋ฐ์ดํŠธ ์˜ค๋ฅ˜: %s\n", mysql_error(conn));
                    }}
                // ์ž˜๋ชป๋œ SET ๋ช…๋ น ํ˜•์‹์ธ ๊ฒฝ์šฐ
                else {
                    fprintf(stderr, "์˜ค๋ฅ˜: ์ž˜๋ชป๋œ SET ๋ช…๋ น ํ˜•์‹\n");
                }}
            // ๋ฉ”์‹œ์ง€๋ฅผ [:]๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ๋ฐฐ์—ด์— ์ €์žฅ
            pToken = strtok(msg, "[:]");
            i = 0;
            while (pToken != NULL) {
                pArray[i] = pToken;
                if (i++ >= ARR_CNT)
                    break;
                pToken = strtok(NULL, "[:]");
            }
            // ๋ฉ”์‹œ์ง€ ์ •๋ณด ๊ตฌ์กฐ์ฒด์— ์ •๋ณด ์ €์žฅ
            msg_info.fd = client_info->fd;
            msg_info.from = client_info->id;
            msg_info.to = pArray[0];
            sprintf(to_msg, "[%s]%s", msg_info.from, pArray[1]);
            msg_info.msg = to_msg;
            msg_info.len = strlen(to_msg);
            // ๋ฉ”์‹œ์ง€ ๋ฐœ์‹  ์—ฌ๋ถ€ ์ดˆ๊ธฐํ™”
            msg_info.is_sent = 0;
    
            // ๋กœ๊ทธ ํŒŒ์ผ์— ๋ฉ”์‹œ์ง€ ๊ธฐ๋ก
            log_file(strBuff);
            // send_msg(&msg_info, first_client_info);
        }
    
        // ํด๋ผ์ด์–ธํŠธ ์†Œ์ผ“ ์ข…๋ฃŒ
        close(client_info->fd);
    
        // ์—ฐ๊ฒฐ ์ข…๋ฃŒ ๋ฉ”์‹œ์ง€ ๊ธฐ๋ก
        sprintf(strBuff, "Disconnect ID:%s (ip:%s,fd:%d,sockcnt:%d)\n", client_info->id, client_info->ip, client_info->fd, clnt_cnt - 1);
        log_file(strBuff);
    
        // ๋ฎคํ…์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํด๋ผ์ด์–ธํŠธ ์ˆ˜ ๊ฐฑ์‹ 
        pthread_mutex_lock(&mutx);
        clnt_cnt--;
        client_info->fd = -1;
        pthread_mutex_unlock(&mutx);
    
        // ์“ฐ๋ ˆ๋“œ ์ข…๋ฃŒ
        return 0;
    }
    // ๋ฌธ์ž์—ด ์–‘ ๋์˜ ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•˜๋Š” ํ•จ์ˆ˜
    char* trim(char* str) {
        char* end;
        // ๋ฌธ์ž์—ด ์‹œ์ž‘์˜ ๊ณต๋ฐฑ ์ œ๊ฑฐ
        while (isspace(*str)) str++;
        // ๋นˆ ๋ฌธ์ž์—ด์ธ ๊ฒฝ์šฐ ๋ฌธ์ž์—ด ๋์˜ ๊ณต๋ฐฑ ์ œ๊ฑฐ
        if (*str == 0)
            return str;
        end = str + strlen(str) - 1;
        while (end > str && isspace(*end)) end--;
        // NULL ์ถ”๊ฐ€ํ•˜์—ฌ ๋ฌธ์ž์—ด ์ข…๋ฃŒ
        *(end + 1) = 0;
        return str;
    }
    // ๋ฉ”์‹œ์ง€ ์ „์†ก ํ•จ์ˆ˜
    void send_msg(MSG_INFO *msg_info, CLIENT_INFO *first_client_info) {
        int i = 0;
        // ์ „์ฒด ๋˜๋Š” ํŠน์ • ํด๋ผ์ด์–ธํŠธ์— ๋ฉ”์‹œ์ง€ ์ „์†ก
        if (!strcmp(msg_info->to, "[ALLMSG]") || !strcmp(msg_info->to, "[IDLIST]")) {
            for (i = 0; i < MAX_CLNT; i++) {
                if ((first_client_info + i)->fd != -1) {
                    write((first_client_info + i)->fd, msg_info->msg, msg_info->len);
                }}
            // ๋‹ค์Œ ๋ฉ”์‹œ์ง€๋ฅผ ์œ„ํ•ด is_sent๋ฅผ 0์œผ๋กœ ์ดˆ๊ธฐํ™”
            if ((msg_info->fd != -1) && (msg_info->is_sent == 0)) {
                msg_info->is_sent = 1;
            }
            return;
        }
        // ํŠน์ • ํด๋ผ์ด์–ธํŠธ์— ๋ฉ”์‹œ์ง€ ์ „์†ก
        else {
            if ((msg_info->fd != -1) && (msg_info->is_sent == 0)) {
                write(msg_info->fd, msg_info->msg, msg_info->len);
                msg_info->is_sent = 1;
            }}}
    // ์—๋Ÿฌ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
    void error_handling(char *msg) {
        fputs(msg, stderr);
        fputc('\n', stderr);
        exit(1);
    }
    // ๋กœ๊ทธ ํŒŒ์ผ์— ๋ฉ”์‹œ์ง€ ๊ธฐ๋ก ํ•จ์ˆ˜
    void log_file(char *msgstr) {
        fputs(msgstr, stdout);
    }
  2. iot_client_sensor.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <string.h>
    #include <arpa/inet.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <pthread.h>
    #include <signal.h>
    
    #define BUF_SIZE 100
    #define NAME_SIZE 20
    #define ARR_CNT 5
    
    // ๋ฉ”์‹œ์ง€๋ฅผ ์ „์†กํ•˜๋Š” ์Šค๋ ˆ๋“œ์˜ ์—ญํ• 
    void* send_msg(void* arg);
    
    // ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์‹ ํ•˜๋Š” ์Šค๋ ˆ๋“œ์˜ ์—ญํ• 
    void* recv_msg(void* arg);
    
    // ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ํ”„๋กœ๊ทธ๋žจ์„ ์ข…๋ฃŒํ•˜๋Š” ํ•จ์ˆ˜
    void error_handling(char* msg);
    
    // ์‚ฌ์šฉ์ž์˜ ์ด๋ฆ„๊ณผ ๋ฉ”์‹œ์ง€๋ฅผ ์ €์žฅํ•˜๋Š” ์ „์—ญ ๋ณ€์ˆ˜
    char name[NAME_SIZE] = "[Default]";
    char msg[BUF_SIZE];
    
    int main(int argc, char* argv[])
    {
        int sock;
        struct sockaddr_in serv_addr;
        pthread_t snd_thread, rcv_thread;
        void* thread_return;
    
        // ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์‹œ IP, ํฌํŠธ, ์ด๋ฆ„์„ ์ „๋‹ฌํ•˜์ง€ ์•Š์•˜์„ ๊ฒฝ์šฐ ์‚ฌ์šฉ๋ฒ• ์ถœ๋ ฅ
        if (argc != 4) {
            printf("Usage : %s <IP> <port> <name>\n", argv[0]);
            exit(1);
        }
        // ์ „๋‹ฌ๋ฐ›์€ ์ด๋ฆ„์„ ์ „์—ญ ๋ณ€์ˆ˜์— ์ €์žฅ
        sprintf(name, "%s", argv[3]);
    
        // ์†Œ์ผ“ ์ƒ์„ฑ
        sock = socket(PF_INET, SOCK_STREAM, 0);
        if (sock == -1)
            error_handling("socket() error");
    
        // ์„œ๋ฒ„ ์ฃผ์†Œ ๊ตฌ์กฐ์ฒด ์ดˆ๊ธฐํ™”
        memset(&serv_addr, 0, sizeof(serv_addr));
        serv_addr.sin_family = AF_INET;
        serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
        serv_addr.sin_port = htons(atoi(argv[2]));
    
        // ์„œ๋ฒ„์— ์—ฐ๊ฒฐ
        if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) == -1)
            error_handling("connect() error");
    
        // ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ฉ”์‹œ์ง€๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์„œ๋ฒ„์— ์ „์†ก
        sprintf(msg, "[%s:PASSWD]", name);
        write(sock, msg, strlen(msg));
    
        // ๋ฉ”์‹œ์ง€ ์ „์†ก ๋ฐ ์ˆ˜์‹ ์„ ์œ„ํ•œ ์Šค๋ ˆ๋“œ ์ƒ์„ฑ
        pthread_create(&rcv_thread, NULL, recv_msg, (void*)&sock);
        pthread_create(&snd_thread, NULL, send_msg, (void*)&sock);
    
        // ์Šค๋ ˆ๋“œ ์ข…๋ฃŒ๋ฅผ ๊ธฐ๋‹ค๋ฆผ
        pthread_join(snd_thread, &thread_return);
        pthread_join(rcv_thread, &thread_return);
    
        // ์†Œ์ผ“ ์ข…๋ฃŒ
        close(sock);
        return 0;
    }
    // ๋ฉ”์‹œ์ง€๋ฅผ ์ „์†กํ•˜๋Š” ์Šค๋ ˆ๋“œ์˜ ์—ญํ• 
    void* send_msg(void* arg)
    {
        int* sock = (int*)arg;
        int str_len;
        char name_msg[NAME_SIZE + BUF_SIZE + 2];
    
        while (1) {
            // ๋ฉ”์‹œ์ง€ ์ดˆ๊ธฐํ™”
            memset(msg, 0, sizeof(msg));
            name_msg[0] = '\0';
    
            // ํ‘œ์ค€ ์ž…๋ ฅ(STDIN)์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๊ณ  10ms๋งˆ๋‹ค ๋Œ€๊ธฐ
            fd_set read_fds;
            FD_ZERO(&read_fds);
            FD_SET(STDIN_FILENO, &read_fds);
    
            struct timeval tv;
            tv.tv_sec = 0;
            tv.tv_usec = 10000; // 10ms๋กœ ์„ค์ •
    
            // ํ‘œ์ค€ ์ž…๋ ฅ ์ƒํƒœ ๋ณ€๊ฒฝ์„ ๊ธฐ๋‹ค๋ฆผ
            if (select(STDIN_FILENO + 1, &read_fds, NULL, NULL, &tv) > 0) {
                // ํ‘œ์ค€ ์ž…๋ ฅ์œผ๋กœ๋ถ€ํ„ฐ ๋ฉ”์‹œ์ง€๋ฅผ ์ฝ์–ด์˜ด
                if (FD_ISSET(STDIN_FILENO, &read_fds)) {
                    fgets(msg, BUF_SIZE, stdin);
                    
                    // 'quit' ๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์†Œ์ผ“ ์ข…๋ฃŒ
                    if (!strncmp(msg, "quit\n", 5)) {
                        *sock = -1;
                        return NULL;
                    }
                    // ๋ฉ”์‹œ์ง€๊ฐ€ '['๋กœ ์‹œ์ž‘ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ '[ALLMSG]' ํƒœ๊ทธ๋ฅผ ์ถ”๊ฐ€
                    else if (msg[0] != '[') {
                        strcat(name_msg, "[ALLMSG]");
                        strcat(name_msg, msg);
                    }
                    // ๋ฉ”์‹œ์ง€๊ฐ€ '['๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ์šฐ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉ
                    else {
                        strcpy(name_msg, msg);
                    }
                    // ์„œ๋ฒ„๋กœ ๋ฉ”์‹œ์ง€ ์ „์†ก
                    if (write(*sock, name_msg, strlen(name_msg)) <= 0) {
                        *sock = -1;
                        return NULL;
                    }}}}}
    // ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์‹ ํ•˜๋Š” ์Šค๋ ˆ๋“œ์˜ ์—ญํ• 
    void* recv_msg(void* arg)
    {
        int* sock = (int*)arg;
        char name_msg[NAME_SIZE + BUF_SIZE + 1];
        int str_len;
        
        while (1) {
            // ๋ฉ”์‹œ์ง€ ์ดˆ๊ธฐํ™”
            memset(name_msg, 0x0, sizeof(name_msg));
            // ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฉ”์‹œ์ง€ ์ˆ˜์‹ 
            str_len = read(*sock, name_msg, NAME_SIZE + BUF_SIZE);
            if (str_len <= 0) {
                // ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฑฐ๋‚˜ ์—ฐ๊ฒฐ์ด ๋Š๊ธด ๊ฒฝ์šฐ ์†Œ์ผ“ ์ข…๋ฃŒ
                *sock = -1;
                return NULL;
            }
            name_msg[str_len] = 0;
            // ์ˆ˜์‹ ๋œ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ
            printf("%s", name_msg);
        }}
    // ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ ์ถœ๋ ฅ ๋ฐ ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ
    void error_handling(char* msg)
    {
        fputs(msg, stderr);
        fputc('\n', stderr);
        exit(1);
    }

ํ”„๋กœ๊ทธ๋žจ ๋นŒ๋“œ

1. iot_server, iot_client ๋นŒ๋“œ ๊ฒฐ๊ณผ

iot_server, iot_client ๋นŒ๋“œ ๊ฒฐ๊ณผ

 

๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ์ƒ์„ฑ ๋ฐ ๋ฐ์ดํ„ฐ ์‚ฝ์ž… 

๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ด€๋ จ ๋‚ด์šฉ์€ ํ•ด๋‹น ์นดํ…Œ๊ณ ๋ฆฌ์— ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. -> https://toby12.tistory.com/category/database

1. iotdb ์ƒ์„ฑ

create database iotdb character set utf8;


2. sensor ํ…Œ์ด๋ธ” ์ƒ์„ฑ 

create table sensor (id int not null auto_increment, name varchar(20), date date, time time,
 illu int, temp float, humi float, primary key (id)) default character set=utf8;

 

3. sensor ํ…Œ์ด๋ธ” ๋ฐ์ดํ„ฐ ์‚ฝ์ž… 

insert into sensor (name, date, time, illu, temp, humi) value ("KHJ_SQL", now(),now(), 60, 20, 40);

 

4. device ํ…Œ์ด๋ธ” ์ƒ์„ฑ

create table device (id int not null, name varchar(20), date date, time time,  value int,
 info varchar(20), primary key (id) ) default charset=utf8;

sensor ํ…Œ์ด๋ธ” ์กฐํšŒ ๊ฒฐ๊ณผ

์„œ๋ฒ„, ํด๋ผ์ด์–ธํŠธ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰

1. ์„œ๋ฒ„ ํ”„๋กœ๊ทธ๋žจ

์„œ๋ฒ„ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ๊ฒฐ๊ณผ

2. ํด๋ผ์ด์–ธํŠธ ํ”„๋กœ๊ทธ๋žจ

ํด๋ผ์ด์–ธํŠธ ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ๊ฒฐ๊ณผ

 

ํด๋ผ์ด์–ธํŠธ -> ์„œ๋ฒ„ ์„ผ์„œ ๋ฐ์ดํ„ฐ ์กฐํšŒ ์š”์ฒญ ๋ฐ ํ™•์ธ

1. GET SENSOR 

์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ MYSQL์— ์ €์žฅ๋œ SENSOR ๋ฐ์ดํ„ฐ

2. GET DEIVCE

์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ MYSQL์— ์ €์žฅ๋œ DEVICE ๋ฐ์ดํ„ฐ

 

ํด๋ผ์ด์–ธํŠธ -> ์„œ๋ฒ„ ๋””๋ฐ”์ด์Šค ์„ค์ • ์—…๋ฐ์ดํŠธ ์š”์ฒญ ๋ฐ ํ™•์ธ

SET Device 9 ๋ฉ”์„ธ์ง€๋ฅผ ์„œ๋ฒ„์— ๋ณด๋‚ด์–ด ํ•ด๋‹น ์‚ฌ์šฉ์ž์˜ ๋””๋ฐ”์ด์Šค์ •๋ณด๋ฅผ ์—…๋ฐ์ดํŠธ๋จ ํ™•์ธ

ํด๋ผ์ด์–ธํŠธ์—์„œ SET DEVICE 9์˜ ๊ฐ’์„ ๋ฐ›์€ ํ›„ ์„œ๋ฒ„์—์„œ ์—…๋ฐ์ดํŠธ ์ง„ํ–‰
ํด๋ผ์ด์–ธํŠธ์—์„œ GET ํ•˜์—ฌ ์—…๋ฐ์ดํŠธ๋จ ํ™•์ธ

 

profile

Toby's Study Blog

@Toby12

ํฌ์ŠคํŒ…์ด ์ข‹์•˜๋‹ค๋ฉด "์ข‹์•„์š”โค๏ธ" ๋˜๋Š” "๊ตฌ๋…๐Ÿ‘๐Ÿป" ํ•ด์ฃผ์„ธ์š”!

๊ฒ€์ƒ‰ ํƒœ๊ทธ