FarmOS 설치
Gitlab 주소: https://gitlab.com/JiNong_Public/farmosV2
문서목록: https://gitlab.com/JiNong_Public/farmosV2/-/tree/master/docs
Ubuntu 18.04, 구글클라우드 플랫폼 컴퓨트엔진에서 진행 > NUC에서 진행
#의존성패키지 설치 sudo apt install mariadb-server mosquitto nodejs -y #다운로드 및 설치 git clone https://gitlab.com/JiNong_Public/farmosV2.git cd farmosV2/scripts sudo ./install.sh
실행
sudo service fui start sudo service fcore start sudo service cvtgate start
8081 포트로 웹 접속

유저정보 확인하라고 뜨며, 로그인 안됨.
mysql을 지우고, 재설치 시 작동
기본 아이디 비밀번호: farmos / farmosv2@
KSX3267에 따라 장비를 제작하고, NUC에 연결하였으나, 장비검색이 안됨

200424
각 페이지의 정보는 ui/src/views/app/page에 있음
200507
gate에 파이썬 코드가 있음. 파이썬2 환경에서 실행되는 듯
gate/connection.py를 실행하였을 때에, 오류가 발생

다음 명령 후 재부팅
sudo usermod -a -G dialout 사용자이름
여전히 장비검색 안 됨. 다음 스크립트 시도
sudo chmod 777 /dev/ttyACM0
여전히 장비검색 안 됨
200508
시작시 실행되는 스크립트는 fcore, fui , cvtgate인데, 이것들은 /etc/init.d 폴더에 포함돼 있다. 각 스크립트가 실행하는 코드는 다음과 같다.
여기서 WORK_DIR = “/home/changho/farmosV2/” 를 기본으로 한다.
fcore
WORK_DIR = "/home/changho/farmosV2/fcore/" python fcore.py start
fui
WORK_DIR = "/home/changho/farmosV2/server/api" forever start --uid "farmosV2" -a "${WORK_DIR}/app.js"
cvtgate
WORK_DIR = "/home/changho/farmosV2/gate/cvtgate" python couplemng.py start
fui 실행시 이용하는 api 문서 : http://localhost:8081/docs

200512 FarmOS 지농 세미나
다섯가지 KS 온실표준. 현실성없다.
하드웨어 – 범용이라 아무거나 갖다놔도 돼서
통신 – 위와 비슷한 이유로
소개한 모든기능이 올라가있는지? 아니다. 인공지능, 비표준 장비 업데이트 기능이 빠져있다. 비표준 장비는 오픈할 계획이 없다. 인공지능은 내년..
아키텍쳐
200612
백엔드 통신을 관장하는 cvtgate. ~gate/couplemng.py 코드를 실행하여 관리하는 구조.
couplemng.py 의 134줄
adaemon = Daemon('cpmng', runner)
from daemon import Daemon, Runner
같은 폴더 내의 daemon.py를 열어보니, #Daemon을 만들어주는 클래스를 정의함’ #이라고 돼 있음
class Daemon의 def __init__(self, pname, runner, stdin=’/dev/null’, stdout=’/dev/null’, stderr=’/dev/null’): 을 참조, couplemng.py 134줄의 Daemon 클래스의 인자 cpmng와 runner 는 class Daemon에서 pname, runner에 해당되는 것을 알 수 있다.
pidfile 은 self.pidfile = “/var/run/” + pname + “.pid”, 즉 /var/run/cpmng.pid 에 데몬 pid를 기록한다.
runner 정보는 ~/conf/cpmng.conf 에 json 형식으로 기록되어 있음. 아래와 같은 형식으로 되어 있음
{ "id" : "24969c48-da01-45a4-af73-da7f9aabbdff", "sleep" : 1, "iter" : 60, "mode" : "local" }
sleep은 몇초마다 다시 동작할 것인지 (couplemng.py 124줄)
iter은 수집한 샘플 데이터 중 몇 개의 후보군 중에 선택할 것인지, 후보군의 갯수 (couplemng.py 97 – 125줄) 후보군은 loadcandidates 로 불러오는데, 이는 ../conf/localcouple.json의 json정보를 불러와서, extracouples(gate) 함수를 호출한다. (여기서 gate 는 localcouple.json 파일의 내용) extractcouples 함수는 config.json에 정의된 couples 키가 없다면, localcouple.json 정보의 gate[“children”] 정보를 반환한다.
6월22일
localcouple.json 을 python에서 josn.loads로 읽어들이면 다음과 같다.
{u'children': [{u'ssmate': {u'opt': {u'mqtt': {u'svc': u'cvtgate', u'id': u'4157859e-df55-48e5-b3ac-8e6288f2165e'}, u'db': {u'host': u'localhost', u'password': u'farmosv2@', u'db': u'farmos', u'user': u'farmos'}, u'conn': {u'host': u'localhost', u'port': 1883, u'keepalive': 60}}, u'class': u'FarmosMate', u'mod': u'mate_farmos'}, u'children': [{u'opt': {}, u'dt': u'gw', u'children': [{u'dt': u'nd', u'children': [{u'dt': u'sen', u'children': [], u'id': u'5', u'dk': u'[1,211,["value","status"]]'}, {u'dt': u'sen', u'children': [], u'id': u'6', u'dk': u'[1,221,["value","status"]]'}], u'id': u'4', u'dk': u'[1,201,["opid","status"],501,["operation","opid"]]'}], u'id': u'ACM0', u'dk': u'ACM0'}], u'name': u'\uc2dc\ud5d8\uc628\uc2e4#1', u'dsmate': {u'opt': {u'sleep': {u'noti': 2, u'obs': 10, u'time': 3}, u'conn': [{u'baudrate': 9600, u'method': u'rtu', u'timeout': 5, u'port': u'/dev/ttyACM0'}]}, u'class': u'KSX3267MateV2', u'mod': u'mate_ksx3267v2'}, u'id': u'4157859e-df55-48e5-b3ac-8e6288f2165e'}], u'id': u'c315cb82-0f6c-4ed6-b8cc-b00331789494', u'name': u'Sample'}
localcouple.json –>> children –>0–>> ssmate : gate에서 mqtt를 통해 fui와 통신하는 정보
localcouple.json –>> children –>0–>> dsmate : 센서와 gate 사이의 통신 정보
def loadcandidate 은 localcouple.json의 children 키를 반환하고,
run 명령을 수행하면 위에서 반환된 localcouple.json 의 children의 항목을 def execute의 인수로 입력함. 인수를 전달받아 실행되는 execute에서는 loadmate 함수를 실행하여 실제 메시지 교환, 구동을 하게된다.
def loadmate의 일부는 다음과 같다.
def loadmate(self, conf, devinfo, coupleid): module = importlib.import_module(conf['mod']) class_ = getattr(module, conf['class']) self._logger.info("load a mate : " + str(conf['class']) + " " + str(coupleid)) mate = class_(conf['opt'], devinfo, coupleid, self._logger) return mate
이 때에 conf 는 localcouple.json –>> children –>0–>> dsmate 혹은 ssmate 이며, dsmate일 경우 mod는 ‘mate_ksx3267v2‘로서 프로토콜을 반환한다. importlib.import_module(conf[‘mod’]) 줄에서 mate_ksx3267v2.py를 실행하는데, 해당코드는 표준센서노드와의 통신을 수행한다.
conf[‘class’] = “KSX3267MateV2”
conf[“id”]=’4157859e-df55-48e5-b3ac-8e6288f2165e’
0개의 댓글