개발자/라즈베리파이4

스마트홈 서버 프로그램 데이터 베이스 에러 해결

지구빵집 2023. 5. 12. 17:43
반응형

 

 

고대 벽화에 동물 그림을 그린 이유에 대해 많은 추측들이 있는데 더 많은 동물을 만나게 해달라고 기원하는 것이라고 한다. 아니면 그리면 나온다고 믿었던 것일 수도 있고, 아니면 동료나 후세에게 무언가 남기기 위해 그렸을 수도 있다. 이유야 어쨌든 불변의 사실은 기억하고 있었다는 사실이다. 

 

한 번 해봤던 것들, 전에 알았던 것들을 잊지 않는 방법은 기록하는 것이다. 어디에든 적는 것이다. 무엇으로든 그 사실을 남기는 것이다. 물론 영화 '존 윅'처럼 헤어진 아내를 기억하기 위해 싸우고 죽이고 살아남는 방법을 선택할 수도 있지만 언젠가는 죽는다. 이전에 남긴 기록을 꺼내가며 문제를 해결한다. 문제가 닥치면 "또 하나의 해결 과제가 생겼네." 하면서 기쁘게 받아들인다. 

 

삶은 문제 해결의 연속이며, 아무것도 하지 않으면 문제가 생기는 게 아니라, 문제가 우리를 죽인다. 해결하고 또 해결하고, 해결할 수 없으면 방법을 찾고 끝까지 해결한다. 문제가 없다면 빠른 시도를 통해 문제를 만든다. 이게 우리가 영원히 살 수 있는 방법이다. 피라미드와 스핑크스를 지어라!  

 

 

 

라즈베리파이4 기반 스마트홈 소프트웨어 테스트 방법

 

폴더: iot_homeserver

메이크 파일 만드는 방법: 폴더는 iot_homeserver 이고 $make clean, $make, $make install을 순서대로 실행하여 실행파일을 만든다.

스마트홈 서버 실행 파일 위치와 파일:  /iot_homeserver/output/server_smarthome

 

 

스마트홈 서버 프로그램 컴파일 후 에러 메시지

 

pi@raspberrypi:~/iot_homeserver/output $ sudo ./server_smarthome

Mysql connection error : Access denied for user 'root'@'localhost' (using passwo
validate database...
iot_send_query : query - CREATE TABLE IF NOT EXISTS thomesensorvalue (id INT AUT
세그멘테이션 오류

 

데이터 베이스 주소와 사용자 계정을 아래 코드로 수정: 일단 수정 했는데 $mysql -u toor -p 치고 암호를 1234 입력 후 들어가도 제대로 로그인 된다. 사용자를 또 만들었는지 제대로 된다. 아래 smartiot와 1234 입력은 당연히 동작된다.

 

#define DB_HOST "127.0.0.1"
//#define DB_USER "root"
//#define DB_PASS "root"
#define DB_USER "smartiot"
#define DB_PASS "1234"
//#define DB_NAME "iot"

 

수정 후 다시 컴파일하고 실행하니 아래와 같은 에러 발생

 

pi@raspberrypi:~/iot_homeserver/output $ ./server_smarthome
Mysql connection error : Unknown database 'iotsmarthome'CLOSE
validate database...
iot_send_query : query - CREATE TABLE IF NOT EXISTS thomesensorvalue (id INT AUTO_INCREMENT PRIMARY KEY, date DATE, time TIME, fire INT, gas INT, sound INT, light INT, temperature FLOAT, humid FLOAT, human INT)
세그멘테이션 오류

 

데이터베이스와 테이블이 만들어지지 않은 오류라고 생각하고, 이전에 smartfarm 서버에서 해결한 포스팅을 찾아본다. 이것 말고도 iot farmserver 수정했던 부분도 찾아봐야 한다.

 

위 에러는 데이터 베이스를 만들지 않아서다. 로그인 후 데이터 베이스를 제대로 만들어서 해결한다. 데이터 베이스 명령어는 아래와 같다.

 

 

데이터베이스로 들어가서 smarthome 데이터 베이스 생성하는 과정


pi@raspberrypi:~/iot_homeserver/output $
pi@raspberrypi:~/iot_homeserver/output $ mysql -u smartiot  -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.3.34-MariaDB-0+deb10u1 Raspbian 10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| demofarmdb         |
| information_schema |
| iotfarm            |
| mysql              |
| performance_schema |
| phpmyadmin         |
| smartiot           |
+--------------------+
7 rows in set (0.011 sec)

MariaDB [(none)]> creat database iotsmarthome;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'creat database iotsmarthome' at line 1
MariaDB [(none)]> create database iotsmarthome;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]>
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| demofarmdb         |
| information_schema |
| iotfarm            |
| iotsmarthome       |
| mysql              |
| performance_schema |
| phpmyadmin         |
| smartiot           |
+--------------------+
8 rows in set (0.002 sec)

MariaDB [(none)]>
MariaDB [(none)]>

 

 

smart home 설계 실습 시스템

 

 

반응형