1 minute read

  1. ํ•„์ˆ˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜
    • pip3 install -r requirements.txt
  2. postgresql ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ
    # su - postgres
    
    # psql
    
  • ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ
CREATE DATABASE uyeg
WITH OWNER = postgres
    ENCODING = 'UTF8'
    TABLESPACE = pg_default
    CONNECTION LIMIT = -1;
  1. postgresql ํ…Œ์ด๋ธ” ์ƒ์„ฑ
-- uyeg ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ
\c uyeg

CREATE TABLE public.devicedata (
    id integer NOT NULL,
    datasavedtime timestamp without time zone NOT NULL,
    max_current numeric(10,2) NOT NULL,
    current_r numeric(10,2) NOT NULL,
    current_s numeric(10,2) NOT NULL,
    current_t numeric(10,2) NOT NULL,
    avg_voltage numeric(10,2) NOT NULL,
    voltage_r numeric(10,2) NOT NULL,
    voltage_s numeric(10,2) NOT NULL,
    voltage_t numeric(10,2) NOT NULL,
    temperature numeric(10,2) NOT NULL,
    humidity numeric(10,2) NOT NULL,
    active_power numeric(10,2) NOT NULL,
    active_power_consumption numeric(10,2) NOT NULL,
    reactive_power_consumption numeric(10,2) NOT NULL,
    power_factor numeric(10,2) NOT NULL,
    total_running_hour numeric(10,2) NOT NULL,
    mc_count_display numeric(10,2) NOT NULL,
    ground_current numeric(10,2) NOT NULL,
    pt100_temperature numeric(10,2) NOT NULL,
    vibration numeric(10,2) NOT NULL,
    success boolean NOT NULL,
    PRIMARY KEY (id, datasavedtime)
) WITH (OIDS=False);

CREATE TABLE public.log (
    id SERIAL NOT NULL,
    fk_id integer NOT NULL,
    log text NOT NULL,
    create_at timestamp without time zone NOT NULL,
    PRIMARY KEY (id)
);

CREATE TABLE public.devicelist (
    id SERIAL NOT NULL,
    device_id varchar(30) NOT NULL,
    create_at timestamp without time zone NOT NULL,
    PRIMARY KEY (id)
);

CREATE TABLE public.remapversion (
    id SERIAL NOT NULL,
    version varchar(30) NOT NULL
);

INSERT INTO public.remapversion(id, version) VALUES (1, 'remap_v1');

  1. timescaledb ์ ์šฉ ```sql CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;

SELECT create_hypertable(โ€˜devicedataโ€™, โ€˜datasavedtimeโ€™, create_default_indexes=>FALSE);

CREATE UNIQUE INDEX ON devicedata (id, datasavedtime desc);

CREATE UNIQUE INDEX ON devicedata (datasavedtime desc, id);

SELECT set_chunk_time_interval(โ€˜devicedataโ€™, interval โ€˜24 hoursโ€™);


7. redis ์„ค์น˜

centos => yum install redis

ubuntu => apt-get install redis



8. db migration

python3 manage.py makemigrations python3 manage.py migrate

- super user ์ƒ์„ฑ

python3 manage.py createsuperuser

- django run

python3 manage.py runserver 0:8000


- smart eocr(uyeg-ze) ๋“ฑ๋ก

9. redis server / scada ์‹œ์ž‘

redis-server

  • producer ์‹œ์ž‘

    python3 manage.py producer start

  • consumer ์‹œ์ž‘

    python3 manage.py consumer start

  • producer ์ข…๋ฃŒ

    python3 manage.py producer stop

  • consumer ์ข…๋ฃŒ

    python3 manage.py consumer stop

    10. ์„œ๋น„์Šค ๋“ฑ๋ก
    

    mv /var/www/uyeg_scada/ubuntu_service_file/* /etc/systemd/system/ systemctl enable gunicorn systemctl enable producer systemctl enable consumer

systemctl start gunicorn systemctl start producer systemctl start consumer ```

Updated: