본문 바로가기
IoT

[IOT프로젝트] 2. mi-connector on AoL

by ㅋㅋ잠자 2019. 9. 8.
반응형

안녕하세요? docker의 부재를 힘들게 피해가는 중입니다.


샤오미 기기를 ST허브를 통해 ST와 연결하는 아기나무집님께서 만들어주신 mi-connector 입니다.


시작합니다.





1. mi-connector 받기


# 적절한 위치를 선정합니다.

root@AOL-Debian:~# cd /home


# 소스를 받습니다.

root@AOL-Debian:/home# wget http://u5pvr.djjproject.com/miconnector.tar

--2019-09-08 02:26:40--  http://u5pvr.djjproject.com/miconnector.tar

Resolving u5pvr.djjproject.com (u5pvr.djjproject.com)... 211.49.151.29

Connecting to u5pvr.djjproject.com (u5pvr.djjproject.com)|211.49.151.29|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 322734080 (308M) [application/x-tar]

Saving to: ‘miconnector.tar’


miconnector.tar          100%[==================================>] 307.78M  37.2MB/s    in 8.6s    


2019-09-08 02:26:49 (35.6 MB/s) - ‘miconnector.tar’ saved [322734080/322734080]


# 압축을 풉니다.

root@AOL-Debian:/home# tar xf miconnector.tar 


# 이름을 바꿉니다.

root@AOL-Debian:/home# mv app/ miconnector/





2. 의존성 설치하기


# 의존성 패키지를 설치합니다.

root@AOL-Debian:/home/miconnector# apt install build-essential apt-utils iputils-ping git libcairo2-dev libgif-dev libjpeg-dev libgif7 libpango1.0-dev

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following packages were automatically installed and are no longer required:

  apt-transport-https g++-6 g++-8 gnupg-agent libaio1 libcaca0 libcdio-cdda1 libcdio-paranoia1

  libcdio13 libnfs8 libroar2 libsdl1.2debian libspeexdsp1 python3.5 python3.5-minimal rsync

Use 'apt autoremove' to remove them.

The following additional packages will be installed:

  apt binutils binutils-arm-linux-gnueabihf binutils-common cpp cpp-9 g++ g++-9 gcc gcc-9

  gcc-9-base gir1.2-freedesktop gir1.2-harfbuzz-0.0 gir1.2-pango-1.0 git-man libasan5 libatomic1

  libbinutils libcairo-gobject2 libcairo-script-interpreter2 libcc1-0 libfontconfig1

  libfontconfig1-dev libfreetype6 libfreetype6-dev libfribidi-dev libgcc-9-dev libgcc1 libgomp1

  libgraphite2-3 libgraphite2-dev libharfbuzz-dev libharfbuzz-gobject0 libharfbuzz-icu0

  libharfbuzz0b libice-dev libjpeg62-turbo libjpeg62-turbo-dev libpango-1.0-0 libpangocairo-1.0-0

  libpangoft2-1.0-0 libpangoxft-1.0-0 libpixman-1-0 libpixman-1-dev libpng-dev libpng-tools

  libpng16-16 libpthread-stubs0-dev libsm-dev libsm6 libstdc++-9-dev libstdc++6 libubsan1 libudev1

  libx11-6 libx11-dev libxau-dev libxau6 libxcb-render0 libxcb-render0-dev libxcb-shm0

  libxcb-shm0-dev libxcb1 libxcb1-dev libxdmcp-dev libxext-dev libxft-dev libxft2 libxrender-dev

  pango1.0-tools udev x11proto-core-dev x11proto-dev x11proto-xext-dev xorg-sgml-doctools

  xtrans-dev

Suggested packages:

  apt-doc aptitude | synaptic | wajig binutils-doc cpp-doc gcc-9-locales gcc-9-doc

  libstdc++6-9-dbg gcc-multilib flex bison gcc-doc libgcc1-dbg libgomp1-dbg libitm1-dbg

  libatomic1-dbg libasan5-dbg liblsan0-dbg libtsan0-dbg libubsan1-dbg libquadmath0-dbg

  git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs

  git-mediawiki git-svn libcairo2-doc freetype2-doc libgraphite2-utils libice-doc imagemagick

  libpango1.0-doc libsm-doc libstdc++-9-doc libx11-doc libxcb-doc libxext-doc

The following NEW packages will be installed:

  cpp-9 g++-9 gcc-9 gir1.2-freedesktop gir1.2-harfbuzz-0.0 gir1.2-pango-1.0 libcairo-gobject2

  libcairo-script-interpreter2 libcairo2-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev

  libgcc-9-dev libgif-dev libgif7 libgraphite2-dev libharfbuzz-dev libharfbuzz-gobject0

  libharfbuzz-icu0 libice-dev libjpeg-dev libjpeg62-turbo-dev libpango1.0-dev libpangoxft-1.0-0

  libpixman-1-dev libpng-dev libpng-tools libpthread-stubs0-dev libsm-dev libstdc++-9-dev

  libudev-dev libx11-dev libxau-dev libxcb-render0-dev libxcb-shm0-dev libxcb1-dev libxdmcp-dev

  libxext-dev libxft-dev libxft2 libxrender-dev pango1.0-tools x11proto-core-dev x11proto-dev

  x11proto-xext-dev xorg-sgml-doctools xtrans-dev

The following packages will be upgraded:

  apt apt-utils binutils binutils-arm-linux-gnueabihf binutils-common build-essential cpp g++ gcc

  gcc-9-base git git-man iputils-ping libasan5 libatomic1 libbinutils libcc1-0 libfontconfig1

  libfreetype6 libgcc1 libgomp1 libgraphite2-3 libharfbuzz0b libjpeg62-turbo libpango-1.0-0

  libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 libpng16-16 libsm6 libstdc++6 libubsan1

  libudev1 libx11-6 libxau6 libxcb-render0 libxcb-shm0 libxcb1 udev

39 upgraded, 47 newly installed, 0 to remove and 555 not upgraded.

Need to get 54.4 MB of archives.

After this operation, 103 MB of additional disk space will be used.

Do you want to continue? [Y/n] 


root@AOL-Debian:/home/miconnector# curl -sL https://deb.nodesource.com/setup_9.x | sudo bash -


## Installing the NodeSource Node.js 9.x repo...



## Populating apt-get cache...


+ apt-get update

Ign:1 http://ftp.kr.debian.org/debian stretch InRelease

Get:2 http://ftp.kr.debian.org/debian stretch-backports InRelease [91.8 kB]

Get:3 http://ftp.kr.debian.org/debian unstable InRelease [139 kB]                   

Get:4 http://ftp.kr.debian.org/debian stretch Release [118 kB]     

Get:5 http://ftp.kr.debian.org/debian stretch Release.gpg [2,410 B]                               

Get:6 http://ppa.launchpad.net/mhier/libboost-latest/ubuntu eoan InRelease [15.9 kB]              

Get:7 http://ftp.kr.debian.org/debian unstable/non-free Sources.diff/Index [27.8 kB]

Get:8 http://ftp.kr.debian.org/debian unstable/main Sources.diff/Index [27.9 kB]



root@AOL-Debian:/home/miconnector# apt install nodejs ccrypt

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following packages were automatically installed and are no longer required:

  apt-transport-https g++-6 g++-8 gnupg-agent libaio1 libcaca0 libcdio-cdda1 libcdio-paranoia1

  libcdio13 libnfs8 libroar2 libsdl1.2debian libspeexdsp1 python3.5 python3.5-minimal rsync

Use 'apt autoremove' to remove them.

The following additional packages will be installed:

  libc-ares2 libnghttp2-14 libnode64 nodejs-doc

Suggested packages:

  elpa-ps-ccrypt npm

The following NEW packages will be installed:

  ccrypt libc-ares2 libnode64 nodejs nodejs-doc

The following packages will be upgraded:

  libnghttp2-14

1 upgraded, 5 newly installed, 0 to remove and 568 not upgraded.

Need to get 6,066 kB of archives.

After this operation, 26.5 MB of additional disk space will be used.

Do you want to continue? [Y/n] 





3. 설정 폴더 수정하기


# 설정파일이 저장될 곳을 생성합니다.

root@AOL-Debian:/home/miconnector# mkdir config


# 스크립트를 수정하여 설정파일을 찾을 곳을 지정합니다.

root@AOL-Debian:/home/miconnector# nano util/config.js


var jsonfile    = require('jsonfile')

var fs          = require('fs');

const logger    = require('./log').log;

var configPath  = "/home/miconnector/config/config.json";

var cmd         = require('node-cmd');

var util        = require('./util');


# 예제 설정 파일을 복사합니다. (이미 세팅된 파일을 config에 넣어주셔도 됩니다.)

root@AOL-Debian:/home/miconnector# cp config.json config/


mysql(mariadb) 설정은 아래의 글을 참고하시길 바랍니다.


기본적으로 db가 root로 로그인하기 때문에 로컬호스트 연결이 가능해야합니다.


https://blog.djjproject.com/543


config.json 파일을 직접 수정하거나 세팅창에서 아래와 같이 설정하시면 됩니다.






4. mi-connector 시작하기


root@AOL-Debian:/home/miconnector# npm start


> mi-connector@0.0.4 start /home/miconnector

> node ./bin/www


2019-09-08 02:14:07 [] info: WebSocket init

2019-09-08 02:14:09 [] info: Initiallize Ping Processor

2019-09-08 02:14:10 [] info: ********************************

2019-09-08 02:14:10 [] info: Mi Connector Version: 0.0.4.10

2019-09-08 02:14:10 [] info: ********************************

2019-09-08 02:14:10 [] info: Error: Could not connect to device, token needs to be specified[192.168.0.5] id=77398861

2019-09-08 02:14:11 [] info: Error: Could not connect to device, token needs to be specified[192.168.0.3] id=10654782


http://aolipaddr:30000/




잘 작동합니다.






5. 자동 시작 스크립트 만들기


# 스크립트를 받습니다.

root@AOL-Debian:/home/miconnector# wget https://github.com/djjproject/android_over_linux/raw/master/init.d/miconnector -O /etc/init.d/miconnector

--2019-09-08 02:55:51--  https://github.com/djjproject/android_over_linux/raw/master/init.d/miconnector

Resolving github.com (github.com)... 15.164.81.167

Connecting to github.com (github.com)|15.164.81.167|:443... connected.

HTTP request sent, awaiting response... 302 Found

Location: https://raw.githubusercontent.com/djjproject/android_over_linux/master/init.d/miconnector [following]

--2019-09-08 02:55:51--  https://raw.githubusercontent.com/djjproject/android_over_linux/master/init.d/miconnector

Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...

Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 1074 (1.0K) [text/plain]

Saving to: ‘/etc/init.d/miconnector’


/etc/init.d/miconnector  100%[==================================>]   1.05K  --.-KB/s    in 0.001s  


2019-09-08 02:55:52 (1.34 MB/s) - ‘/etc/init.d/miconnector’ saved [1074/1074]


# 실행권한을 줍니다.

root@AOL-Debian:/home/miconnector# chmod a+x /etc/init.d/miconnector 


# 자동실행에 등록합니다.

root@AOL-Debian:/home/miconnector# update-rc.d miconnector defaults


# 시작해봅니다.

root@AOL-Debian:/home/miconnector# service miconnector start

Starting miconnector: miconnector.

root@AOL-Debian:/home/miconnector# ps -ef | grep node

root     14460     1 99 02:56 ?        00:00:08 /usr/bin/node /home/miconnector/bin/www

root     14523  6621  0 02:56 pts/0    00:00:00 grep node


감사합니다.

반응형

댓글