Error Subcriber
This commit is contained in:
parent
6bcd212077
commit
1ea3619a61
303
2020-4-7.txt
Normal file
303
2020-4-7.txt
Normal file
|
@ -0,0 +1,303 @@
|
||||||
|
2020-04-07 06:26:11.080419966 +0900 KST m=+36709.226992508
|
||||||
|
Error Publish message CMS BI
|
||||||
|
2020-04-07 06:26:11.084932647 +0900 KST m=+36709.231505064
|
||||||
|
Number reconnect publish msg: 1
|
||||||
|
|
||||||
|
2020-04-07 06:26:11.20256125 +0900 KST m=+36709.349133642
|
||||||
|
Lostconnect chanel subcriber: MQTT_OnConnectHandler
|
||||||
|
|
||||||
|
2020-04-07 06:26:11.230794851 +0900 KST m=+36709.377367256
|
||||||
|
Number reconnect subcriber msg: 2
|
||||||
|
|
||||||
|
2020-04-07 06:26:11.236062617 +0900 KST m=+36709.382634996
|
||||||
|
Recall function Subscribe MQTT
|
||||||
|
|
||||||
|
2020-04-07 06:26:15.014195752 +0900 KST m=+36713.160768169
|
||||||
|
MQTT CMS BeetsoftConnected
|
||||||
|
|
||||||
|
2020-04-07 06:26:15.01505725 +0900 KST m=+36713.161629617
|
||||||
|
Lostconnect chanel subcriber: MQTT_OnConnectHandler
|
||||||
|
|
||||||
|
2020-04-07 06:26:15.045926609 +0900 KST m=+36713.192499001
|
||||||
|
Number reconnect subcriber msg: 3
|
||||||
|
|
||||||
|
2020-04-07 06:26:15.050528953 +0900 KST m=+36713.197101320
|
||||||
|
Recall function Subscribe MQTT
|
||||||
|
|
||||||
|
2020-04-07 06:26:15.186509794 +0900 KST m=+36713.333082186
|
||||||
|
Ping_broker_sub() OKIE
|
||||||
|
2020-04-07 06:26:15.223918322 +0900 KST m=+36713.370490752
|
||||||
|
================>> Subcriber is OKIE <==========
|
||||||
|
|
||||||
|
2020-04-07 10:06:45.696330989 +0900 KST m=+49943.842903381
|
||||||
|
Message:{"method":"close_ssh","status": 1}
|
||||||
|
|
||||||
|
2020-04-07 10:10:27.084995356 +0900 KST m=+0.011226089
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 10:10:27.145781306 +0900 KST m=+0.072012014
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 10:10:27.221252448 +0900 KST m=+0.147483193
|
||||||
|
Status_Checkengine () exit status 1
|
||||||
|
2020-04-07 10:10:27.250046658 +0900 KST m=+0.176277666
|
||||||
|
====>>>>Check_engine not run
|
||||||
|
|
||||||
|
2020-04-07 10:10:27.257989078 +0900 KST m=+0.184219823
|
||||||
|
RunCheck() ok
|
||||||
|
2020-04-07 10:10:31.305352967 +0900 KST m=+4.231583737
|
||||||
|
MQTT CMS BeetsoftConnected
|
||||||
|
|
||||||
|
2020-04-07 10:10:31.305686841 +0900 KST m=+4.231917548
|
||||||
|
Lostconnect chanel subcriber: MQTT_OnConnectHandler
|
||||||
|
|
||||||
|
2020-04-07 10:10:31.336252675 +0900 KST m=+4.262483432
|
||||||
|
Number reconnect subcriber msg: 1
|
||||||
|
|
||||||
|
2020-04-07 10:10:31.343759146 +0900 KST m=+4.269989903
|
||||||
|
Recall function Subscribe MQTT
|
||||||
|
|
||||||
|
2020-04-07 10:10:31.484817964 +0900 KST m=+4.411048684
|
||||||
|
Ping_broker_sub() OKIE
|
||||||
|
2020-04-07 10:10:31.5081366 +0900 KST m=+4.434367358
|
||||||
|
================>> Subcriber is OKIE <==========
|
||||||
|
|
||||||
|
2020-04-07 10:11:57.238579075 +0900 KST m=+90.164809833
|
||||||
|
Message response cms:{"method":"open_ssh","status": 1,"params": {"port": "2465"}}
|
||||||
|
|
||||||
|
2020-04-07 10:11:57.27928489 +0900 KST m=+90.205515635
|
||||||
|
Cmd openssh new:autossh -M 0 -f -N -R 2465:localhost:22 boxai@ssh_tunnel.beetai.com > /dev/null 2>&1 &
|
||||||
|
|
||||||
|
2020-04-07 10:12:02.050956968 +0900 KST m=+94.977187675
|
||||||
|
Cmd close :kill $(pgrep ssh)
|
||||||
|
|
||||||
|
2020-04-07 10:12:02.130358243 +0900 KST m=+95.056589001
|
||||||
|
Message:{"method":"close_ssh","status": 1}
|
||||||
|
|
||||||
|
2020-04-07 11:16:45.794114019 +0900 KST m=+0.068860823
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 11:16:45.830566193 +0900 KST m=+0.105313034
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 11:16:45.895177716 +0900 KST m=+0.169924544
|
||||||
|
Status_Checkengine () exit status 1
|
||||||
|
2020-04-07 11:16:45.89922439 +0900 KST m=+0.173971244
|
||||||
|
====>>>>Check_engine not run
|
||||||
|
|
||||||
|
2020-04-07 11:16:45.908386603 +0900 KST m=+0.183133419
|
||||||
|
RunCheck() ok
|
||||||
|
2020-04-07 11:16:49.89811135 +0900 KST m=+4.172858191
|
||||||
|
MQTT CMS BeetsoftConnected
|
||||||
|
|
||||||
|
2020-04-07 11:16:49.921483212 +0900 KST m=+4.196230065
|
||||||
|
Lostconnect chanel subcriber: MQTT_OnConnectHandler
|
||||||
|
|
||||||
|
2020-04-07 11:16:50.064492182 +0900 KST m=+4.339239035
|
||||||
|
Number reconnect subcriber msg: 1
|
||||||
|
|
||||||
|
2020-04-07 11:16:50.161568378 +0900 KST m=+4.436315231
|
||||||
|
Recall function Subscribe MQTT
|
||||||
|
|
||||||
|
2020-04-07 11:16:50.688594283 +0900 KST m=+4.963341124
|
||||||
|
Ping_broker_sub() OKIE
|
||||||
|
2020-04-07 11:28:10.160419894 +0900 KST m=+0.056612799
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 11:28:10.200286405 +0900 KST m=+0.096479322
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 11:28:10.271141202 +0900 KST m=+0.167334094
|
||||||
|
Status_Checkengine () exit status 1
|
||||||
|
2020-04-07 11:28:10.27793324 +0900 KST m=+0.174126132
|
||||||
|
====>>>>Check_engine not run
|
||||||
|
|
||||||
|
2020-04-07 11:28:10.295852764 +0900 KST m=+0.192045656
|
||||||
|
RunCheck() ok
|
||||||
|
2020-04-07 11:28:14.429790431 +0900 KST m=+4.325983348
|
||||||
|
MQTT CMS BeetsoftConnected
|
||||||
|
|
||||||
|
2020-04-07 11:28:14.434804381 +0900 KST m=+4.330997423
|
||||||
|
Lostconnect chanel subcriber: MQTT_OnConnectHandler
|
||||||
|
|
||||||
|
2020-04-07 11:28:14.522056665 +0900 KST m=+4.418249557
|
||||||
|
Number reconnect subcriber msg: 1
|
||||||
|
|
||||||
|
2020-04-07 11:28:14.586845488 +0900 KST m=+4.483038367
|
||||||
|
Recall function Subscribe MQTT
|
||||||
|
|
||||||
|
2020-04-07 11:28:14.891877376 +0900 KST m=+4.788070268
|
||||||
|
Ping_broker_sub() OKIE
|
||||||
|
2020-04-07 11:28:14.926097937 +0900 KST m=+4.822290854
|
||||||
|
================>> Subcriber is OKIE <==========
|
||||||
|
|
||||||
|
2020-04-07 11:28:26.198839845 +0900 KST m=+16.095032737
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 11:28:26.275141167 +0900 KST m=+16.171334034
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 11:28:26.486460221 +0900 KST m=+16.382653113
|
||||||
|
API get module :http://api.biface_kr.beetai.com/api/model/get_model/263
|
||||||
|
2020-04-07 11:28:26.583846368 +0900 KST m=+16.480039247
|
||||||
|
Path:/home/admin/monitor/engine/FacePro_263/FaceRecognition/build/features.json
|
||||||
|
2020-04-07 11:28:26.588540267 +0900 KST m=+16.484733159
|
||||||
|
Save thanh cong modules
|
||||||
|
2020-04-07 11:28:26.616853829 +0900 KST m=+16.513046708
|
||||||
|
Response to server --> update modules Error
|
||||||
|
2020-04-07 11:28:26.622318279 +0900 KST m=+16.518511146
|
||||||
|
Message:{"method":"update_model","status": 1}
|
||||||
|
|
||||||
|
2020-04-07 11:34:57.307322565 +0900 KST m=+0.057778023
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 11:34:57.337238201 +0900 KST m=+0.087693635
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 11:34:57.399773236 +0900 KST m=+0.150228657
|
||||||
|
Status_Checkengine () exit status 1
|
||||||
|
2020-04-07 11:34:57.405998349 +0900 KST m=+0.156453795
|
||||||
|
====>>>>Check_engine not run
|
||||||
|
|
||||||
|
2020-04-07 11:34:57.417440486 +0900 KST m=+0.167895919
|
||||||
|
RunCheck() ok
|
||||||
|
2020-04-07 11:35:06.386659931 +0900 KST m=+9.137115377
|
||||||
|
MQTT CMS BeetsoftConnected
|
||||||
|
|
||||||
|
2020-04-07 11:35:06.388544368 +0900 KST m=+9.138999827
|
||||||
|
Lostconnect chanel subcriber: MQTT_OnConnectHandler
|
||||||
|
|
||||||
|
2020-04-07 11:35:06.460674503 +0900 KST m=+9.211129937
|
||||||
|
Number reconnect subcriber msg: 1
|
||||||
|
|
||||||
|
2020-04-07 11:35:06.501506514 +0900 KST m=+9.251961923
|
||||||
|
Recall function Subscribe MQTT
|
||||||
|
|
||||||
|
2020-04-07 11:35:06.882706537 +0900 KST m=+9.633161983
|
||||||
|
Ping_broker_sub() OKIE
|
||||||
|
2020-04-07 11:35:06.927125323 +0900 KST m=+9.677580781
|
||||||
|
================>> Subcriber is OKIE <==========
|
||||||
|
|
||||||
|
2020-04-07 11:36:11.158582532 +0900 KST m=+0.075096198
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 11:36:11.20423523 +0900 KST m=+0.120748871
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 11:36:11.300082139 +0900 KST m=+0.216595842
|
||||||
|
Status_Checkengine () exit status 1
|
||||||
|
2020-04-07 11:36:11.3218008 +0900 KST m=+0.238314491
|
||||||
|
====>>>>Check_engine not run
|
||||||
|
|
||||||
|
2020-04-07 11:36:11.359831124 +0900 KST m=+0.276344815
|
||||||
|
RunCheck() ok
|
||||||
|
2020-04-07 11:36:15.370420071 +0900 KST m=+4.286933775
|
||||||
|
MQTT CMS BeetsoftConnected
|
||||||
|
|
||||||
|
2020-04-07 11:36:15.381743008 +0900 KST m=+4.298256724
|
||||||
|
Lostconnect chanel subcriber: MQTT_OnConnectHandler
|
||||||
|
|
||||||
|
2020-04-07 11:36:15.443682618 +0900 KST m=+4.360196334
|
||||||
|
Number reconnect subcriber msg: 1
|
||||||
|
|
||||||
|
2020-04-07 11:36:15.473554442 +0900 KST m=+4.390068121
|
||||||
|
Recall function Subscribe MQTT
|
||||||
|
|
||||||
|
2020-04-07 11:36:15.842054128 +0900 KST m=+4.758567807
|
||||||
|
Ping_broker_sub() OKIE
|
||||||
|
2020-04-07 11:36:15.881851302 +0900 KST m=+4.798364968
|
||||||
|
================>> Subcriber is OKIE <==========
|
||||||
|
|
||||||
|
2020-04-07 11:46:08.7594031 +0900 KST m=+0.013336051
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 11:46:08.81896539 +0900 KST m=+0.072898478
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 11:46:08.895592208 +0900 KST m=+0.149525397
|
||||||
|
Status_Checkengine () exit status 1
|
||||||
|
2020-04-07 11:46:08.927968935 +0900 KST m=+0.181902311
|
||||||
|
====>>>>Check_engine not run
|
||||||
|
|
||||||
|
2020-04-07 11:46:08.935994968 +0900 KST m=+0.189927894
|
||||||
|
RunCheck() ok
|
||||||
|
2020-04-07 11:46:12.929799072 +0900 KST m=+4.183732011
|
||||||
|
MQTT CMS BeetsoftConnected
|
||||||
|
|
||||||
|
2020-04-07 11:46:12.930397824 +0900 KST m=+4.184330763
|
||||||
|
Lostconnect chanel subcriber: MQTT_OnConnectHandler
|
||||||
|
|
||||||
|
2020-04-07 11:46:12.963770118 +0900 KST m=+4.217703069
|
||||||
|
Number reconnect subcriber msg: 1
|
||||||
|
|
||||||
|
2020-04-07 11:46:12.979999742 +0900 KST m=+4.233932730
|
||||||
|
Recall function Subscribe MQTT
|
||||||
|
|
||||||
|
2020-04-07 11:46:13.363673793 +0900 KST m=+4.617606757
|
||||||
|
Ping_broker_sub() OKIE
|
||||||
|
2020-04-07 11:46:13.380354225 +0900 KST m=+4.634287189
|
||||||
|
================>> Subcriber is OKIE <==========
|
||||||
|
|
||||||
|
2020-04-07 11:46:36.611343441 +0900 KST m=+27.865276392
|
||||||
|
Message response cms:{"method":"open_ssh","status": 1,"params": {"port": "2466"}}
|
||||||
|
|
||||||
|
2020-04-07 11:46:36.638973661 +0900 KST m=+27.892906674
|
||||||
|
Cmd openssh new:autossh -M 0 -f -N -R 2466:localhost:22 boxai@ssh_tunnel.beetai.com > /dev/null 2>&1 &
|
||||||
|
|
||||||
|
2020-04-07 11:46:41.277133552 +0900 KST m=+32.531066515
|
||||||
|
Cmd close :kill $(pgrep ssh)
|
||||||
|
|
||||||
|
2020-04-07 11:46:41.357834268 +0900 KST m=+32.611767232
|
||||||
|
Message:{"method":"close_ssh","status": 1}
|
||||||
|
|
||||||
|
2020-04-07 11:51:02.948266284 +0900 KST m=+294.202199197
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 11:51:03.021681337 +0900 KST m=+294.275614251
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 11:51:03.178315663 +0900 KST m=+294.432248627
|
||||||
|
API get module :http://api.biface_kr.beetai.com/api/model/get_model/263
|
||||||
|
2020-04-07 11:51:03.269057903 +0900 KST m=+294.522990841
|
||||||
|
Path:/home/admin/monitor/engine/FacePro_263/FaceRecognition/build/features.json
|
||||||
|
2020-04-07 11:51:03.287753025 +0900 KST m=+294.541686001
|
||||||
|
Save thanh cong modules
|
||||||
|
2020-04-07 11:51:03.327277221 +0900 KST m=+294.581210197
|
||||||
|
Response to server --> update modules Error
|
||||||
|
2020-04-07 11:51:03.331905242 +0900 KST m=+294.585838193
|
||||||
|
Message:{"method":"update_model","status": 1}
|
||||||
|
|
||||||
|
2020-04-07 11:58:06.382478385 +0900 KST m=+717.636411323
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 11:58:06.434587385 +0900 KST m=+717.688520299
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 11:58:06.55001063 +0900 KST m=+717.803943619
|
||||||
|
API get module :http://api.biface_kr.beetai.com/api/model/get_model/263
|
||||||
|
2020-04-07 11:58:06.737011667 +0900 KST m=+717.990944618
|
||||||
|
Path:/home/admin/monitor/engine/FacePro_263/FaceRecognition/build/features.json
|
||||||
|
2020-04-07 11:58:06.76557314 +0900 KST m=+718.019506079
|
||||||
|
Save thanh cong modules
|
||||||
|
2020-04-07 11:58:06.802949955 +0900 KST m=+718.056882906
|
||||||
|
Response to server --> update modules Error
|
||||||
|
2020-04-07 11:58:06.808624034 +0900 KST m=+718.062556985
|
||||||
|
Message:{"method":"update_model","status": 1}
|
||||||
|
|
||||||
|
2020-04-07 12:01:38.421545027 +0900 KST m=+929.675477991
|
||||||
|
Stop Check_engine
|
||||||
|
|
||||||
|
2020-04-07 12:01:38.468994274 +0900 KST m=+929.722927237
|
||||||
|
Stop Engine
|
||||||
|
|
||||||
|
2020-04-07 12:01:38.564148969 +0900 KST m=+929.818081945
|
||||||
|
API get module :http://api.biface_kr.beetai.com/api/model/get_model/263
|
||||||
|
2020-04-07 12:01:38.650863713 +0900 KST m=+929.904796814
|
||||||
|
Path:/home/admin/monitor/engine/FacePro_263/FaceRecognition/build/features.json
|
||||||
|
2020-04-07 12:01:38.680428983 +0900 KST m=+929.934361947
|
||||||
|
Save thanh cong modules
|
||||||
|
2020-04-07 12:01:38.722174728 +0900 KST m=+929.976107679
|
||||||
|
Response to server --> update modules Error
|
||||||
|
2020-04-07 12:01:38.730380053 +0900 KST m=+929.984312966
|
||||||
|
Message:{"method":"update_model","status": 1}
|
||||||
|
|
BIN
Check_engine/Check_engine
Normal file
BIN
Check_engine/Check_engine
Normal file
Binary file not shown.
719
Check_engine/Check_engine.go
Normal file
719
Check_engine/Check_engine.go
Normal file
|
@ -0,0 +1,719 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"beetai_BeetAipro/file"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
//"log"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
//"path/filepath"
|
||||||
|
"encoding/json"
|
||||||
|
"strconv" // convert string to int
|
||||||
|
)
|
||||||
|
|
||||||
|
// scp -P 2224 -r -o 'ProxyJump dh.duyhai@ssh_tunnel.beetai.com' Check_engine root@localhost:/root/monitor/check/
|
||||||
|
var name_dir_engine string = ""
|
||||||
|
var state_read_ecf bool = false
|
||||||
|
|
||||||
|
var path_base string = "/home/admin/monitor"
|
||||||
|
var Path_base_engine string = path_base + "/engine/" + name_dir_engine //"count_people_face" // Name dir engine
|
||||||
|
var Path_log_engine string = path_base + "/log/log_engine"
|
||||||
|
var Path_log_luncher string = path_base + "/log/log_launcher"
|
||||||
|
var Path_engine_config string = path_base + "/setup/engine.json" // dia chi duoi file Config.txt
|
||||||
|
var Path_config string = Path_base_engine + "/data/Config.txt"
|
||||||
|
|
||||||
|
// var path = "/root/monitor/log/log_engine.txt"
|
||||||
|
|
||||||
|
//var time_sts int = 0
|
||||||
|
//var cam_sts int = 0
|
||||||
|
|
||||||
|
//var Path_config string = "/root/monitor/face_recognition/data/Config.txt"
|
||||||
|
|
||||||
|
//engine
|
||||||
|
var engine_status int = 0
|
||||||
|
|
||||||
|
var Path_time string = path_base + "/setup/time_run.txt"
|
||||||
|
var time_start int = 0
|
||||||
|
var time_end int = 0
|
||||||
|
var time_start_defaut int = 5
|
||||||
|
var time_end_defaut int = 23
|
||||||
|
var Debug int = 1
|
||||||
|
|
||||||
|
var number_run int = 0 // Check so lan run lai engine khi engine loi
|
||||||
|
|
||||||
|
var message Message
|
||||||
|
|
||||||
|
type Message struct {
|
||||||
|
Error_code int `json:"error_code"`
|
||||||
|
Data Datas `json:"data"`
|
||||||
|
SD_CARD int `json:"sd_card"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// User struct which contains a name
|
||||||
|
// a type and a list of social links
|
||||||
|
type Datas struct {
|
||||||
|
Box_id int `json:"box_id"`
|
||||||
|
//Box_name string `json:"box_name"`
|
||||||
|
Engines []Engine `json:"engines"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Engine struct {
|
||||||
|
IsConfig string `json:"isConfig,omitempty"`
|
||||||
|
Active int `json:"active"`
|
||||||
|
Engine_id int `json:"engine_id"`
|
||||||
|
Id int `json:"id"`
|
||||||
|
Link string `json:"link"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
Time_run string `json:"time_run,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//============================> Main <==========================
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("------------------ Start --------------------")
|
||||||
|
//GetDir() // Check thu muc
|
||||||
|
fmt.Println("--------------------------")
|
||||||
|
file.Check_path(Path_log_engine)
|
||||||
|
file.Write_log("Begin Check, Restart program\n", Path_log_engine)
|
||||||
|
fmt.Printf("Begin Check, Restart program\n")
|
||||||
|
ReadEngineConfig(Path_engine_config) // Pharse engine.json to struct Message
|
||||||
|
// Loop:
|
||||||
|
for {
|
||||||
|
fmt.Println("Path base:" + path_base)
|
||||||
|
fmt.Println("-------------------- 0 ---------------------")
|
||||||
|
//Check_dir_engine() // Check directory engine , Create Path_base engine
|
||||||
|
// ReadTimeRun()
|
||||||
|
//CheckCam()
|
||||||
|
//CheckTime()
|
||||||
|
ActionEngine()
|
||||||
|
fmt.Println("-------------------- 1 ---------------------")
|
||||||
|
Sleep_ms(5000)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//========================> END MAIN <====================
|
||||||
|
//------------------ Function ----------------------------
|
||||||
|
// func Check_dir_engine() {
|
||||||
|
// if Debug == 1 {
|
||||||
|
// fmt.Println("Function Check_dir_engine ()")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// name_dir_engine = strings.Replace(message.Data.Engines[0].Path, ".zip", "", -1)
|
||||||
|
|
||||||
|
// Path_base_engine = path_base + "/engine/" + name_dir_engine
|
||||||
|
// Path_config = Path_base_engine + "/data/Config.txt"
|
||||||
|
// Path_log_engine = path_base + "/log/log_engine"
|
||||||
|
// Path_log_luncher = path_base + "/log/log_launcher"
|
||||||
|
// Path_engine_config = path_base + "/setup/engine.json" // dia chi duoi file Config.txt
|
||||||
|
// Path_config = Path_base_engine + "/data/Config.txt"
|
||||||
|
// if Debug == 1 {
|
||||||
|
// fmt.Printf("Name_dir_engine :" + name_dir_engine + "\t")
|
||||||
|
// fmt.Println("Path_base_engine :" + Path_base_engine)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
func GetDir() {
|
||||||
|
if file.ReadFile("/root/ver_sys.txt") == "1" {
|
||||||
|
path_base = "/home/aibox/Documents/monitor"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func ReadEngineConfig(path string) {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Function ReadEngineConfig ()")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open our jsonFile
|
||||||
|
jsonFile, err := os.Open(path)
|
||||||
|
// if we os.Open returns an error then handle it
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
file.Write_log("ReadEngineConfig 1 () "+err.Error(), Path_log_engine)
|
||||||
|
}
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Successfully Opened engine.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer jsonFile.Close()
|
||||||
|
|
||||||
|
byteValue, err := ioutil.ReadAll(jsonFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
file.Write_log("ReadEngineConfig 2 () "+err.Error(), Path_log_engine)
|
||||||
|
}
|
||||||
|
json.Unmarshal(byteValue, &message)
|
||||||
|
state_read_ecf = true
|
||||||
|
|
||||||
|
file.Println("\nError_code: " + strconv.Itoa(message.Error_code))
|
||||||
|
file.Println("Box_id: " + strconv.Itoa(message.Data.Box_id))
|
||||||
|
// file.Println("---------------------------------------------")
|
||||||
|
// List engine
|
||||||
|
for i := 0; i < len(message.Data.Engines); i++ {
|
||||||
|
file.Println("Isconfig: " + message.Data.Engines[i].IsConfig)
|
||||||
|
file.Println("Active: " + strconv.Itoa(message.Data.Engines[i].Active))
|
||||||
|
file.Println("Engine_id: " + strconv.Itoa(message.Data.Engines[i].Engine_id))
|
||||||
|
file.Println("Id: " + strconv.Itoa(message.Data.Engines[i].Id))
|
||||||
|
file.Println("Link: " + message.Data.Engines[i].Link)
|
||||||
|
file.Println("Name: " + message.Data.Engines[i].Name)
|
||||||
|
file.Println("Path: " + message.Data.Engines[i].Path)
|
||||||
|
file.Println("Version: " + message.Data.Engines[i].Version)
|
||||||
|
file.Println("Time_run: " + message.Data.Engines[i].Time_run)
|
||||||
|
file.Println("---------------------------------------------")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadTimeRun(time string) (int, int) {
|
||||||
|
var t_start int
|
||||||
|
var t_end int
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Function ReadTimeRun ()")
|
||||||
|
}
|
||||||
|
// var value = message.Data.Engines[i].Time_run
|
||||||
|
fmt.Println("\nTime_run:" + time)
|
||||||
|
var list = strings.Split(time, ":")
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println(list)
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
fmt.Print(i)
|
||||||
|
fmt.Print("_")
|
||||||
|
fmt.Printf("%T", list[i])
|
||||||
|
fmt.Print("_")
|
||||||
|
fmt.Printf("%v\n", list[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var x, _ = strconv.Atoi(list[0])
|
||||||
|
t_start = x
|
||||||
|
if t_start < 0 {
|
||||||
|
t_start = 0
|
||||||
|
} else if t_start > 23 {
|
||||||
|
t_start = 23
|
||||||
|
}
|
||||||
|
var z, _ = strconv.Atoi(list[1])
|
||||||
|
t_end = z
|
||||||
|
if t_end < 0 {
|
||||||
|
t_end = 0
|
||||||
|
} else if t_end > 23 {
|
||||||
|
t_end = 23
|
||||||
|
}
|
||||||
|
return t_start, t_end
|
||||||
|
}
|
||||||
|
func ActionEngine() {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Function ActionEngine ()")
|
||||||
|
}
|
||||||
|
for i := 0; i < len(message.Data.Engines); i++ {
|
||||||
|
var t_stt = CheckTime(message.Data.Engines[i].Time_run)
|
||||||
|
//var cam_sts = CheckCam(message.Data.Engines[i].Path + "/data/Config.txt")
|
||||||
|
var cam_sts = 1
|
||||||
|
var enable, _ = strconv.Atoi(message.Data.Engines[i].IsConfig)
|
||||||
|
if cam_sts*t_stt*enable == 1 {
|
||||||
|
STTServerFR()
|
||||||
|
if stt_serverlocal == 1 {
|
||||||
|
fmt.Println("Run Status_engine()")
|
||||||
|
Status_engine()
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(" Setup Run Engine")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Setup off Engine")
|
||||||
|
|
||||||
|
if message.Data.Engines[i].Active == 1 {
|
||||||
|
//var cmd string = "ps -A | grep " + message.Data.Engines[i].Name
|
||||||
|
|
||||||
|
var cmd string = "pidof " + message.Data.Engines[i].Name
|
||||||
|
out2, err := exec.Command("sh", "-c", cmd).Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
//file.Write_log("ActionEngine () "+err.Error(), Path_log_engine)
|
||||||
|
}
|
||||||
|
fmt.Println("Lengh :"+cmd+"%v", len(out2))
|
||||||
|
if len(out2) != 0 {
|
||||||
|
// sudo kill $(pgrep FaceRecognition)
|
||||||
|
|
||||||
|
//var cmd string = "sudo kill $(pgrep " + message.Data.Engines[i].Name + ")"
|
||||||
|
//var cmd string = "pidof " + message.Data.Engines[i].Name
|
||||||
|
var cmd string = "sudo kill -9 $(pidof " + message.Data.Engines[i].Name + ")"
|
||||||
|
fmt.Println("CMD Kill_engine:" + cmd)
|
||||||
|
_, err := exec.Command("sh", "-c", cmd).Output() // kill $(pgrep FaceRecognition)
|
||||||
|
//log.Fatal(err)
|
||||||
|
if err != nil {
|
||||||
|
file.Write_log("sudo kill engine of ActionEngine() Error \n", Path_log_engine)
|
||||||
|
fmt.Println("sudo kill engine of ActionEngine() Error")
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fmt.Println("Engine kill")
|
||||||
|
}
|
||||||
|
out1, _ := exec.Command("sh", "-c", "ps -A | grep loop_run").Output()
|
||||||
|
if len(out1) != 0 {
|
||||||
|
_, err := exec.Command("sh", "-c", " sudo kill $(pgrep loop_run)").Output()
|
||||||
|
if err != nil {
|
||||||
|
file.Write_log("sudo kill $(pgrep loop_run) of CheckActionEngine() \n", Path_log_engine)
|
||||||
|
}
|
||||||
|
//log.Fatal(err) sudo systemctl restart S905X_BI rm /root/monitor/launcher/S905X_BI
|
||||||
|
} else {
|
||||||
|
fmt.Println("loop_run kill")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Engine setting off on engine.json")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func CheckTime(time_run string) int {
|
||||||
|
var time_sts = 0
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Function CheckTime ()")
|
||||||
|
}
|
||||||
|
//ReadTimeRun(time string) (int, int)
|
||||||
|
|
||||||
|
t_start, t_end := ReadTimeRun(time_run)
|
||||||
|
var time_now = time.Now().Hour()
|
||||||
|
if Debug == 1 {
|
||||||
|
//fmt.Printf("Kieu time : %T\n", time)
|
||||||
|
fmt.Printf("time = %v\n", time_now)
|
||||||
|
}
|
||||||
|
if time_now >= t_start && time_now <= t_end {
|
||||||
|
time_sts = 1
|
||||||
|
//Status_engine()
|
||||||
|
fmt.Println(" Time Engine's running")
|
||||||
|
} else {
|
||||||
|
time_sts = 0
|
||||||
|
}
|
||||||
|
return time_sts
|
||||||
|
}
|
||||||
|
func FloatToString(input_num float64) string {
|
||||||
|
fmt.Println("Function FloatToString ()")
|
||||||
|
// to convert a float number to a string
|
||||||
|
return strconv.FormatFloat(input_num, 'f', 3, 64)
|
||||||
|
}
|
||||||
|
func KillFaceDedect() {
|
||||||
|
fmt.Println("Function KillFaceDedect()")
|
||||||
|
var cmd string = "pidof " + message.Data.Engines[0].Name
|
||||||
|
//out1, err := exec.Command("sh", "-c", "ps -A | grep "+message.Data.Engines[0].Name).Output()
|
||||||
|
out1, err := exec.Command("sh", "-c", cmd).Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
file.Write_log("KillFaceDedect() "+err.Error(), Path_log_engine)
|
||||||
|
}
|
||||||
|
if len(out1) != 0 {
|
||||||
|
_, err := exec.Command("sh", "-c", "sudo kill $("+cmd+")").Output() // kill $(pgrep FaceRecognition)
|
||||||
|
//log.Fatal(err)
|
||||||
|
if err != nil {
|
||||||
|
file.Write_log("sudo kill "+message.Data.Engines[0].Name+" of KillFaceDedect() \n", Path_log_engine)
|
||||||
|
}
|
||||||
|
file.Write_log("KillFaceDedect()\n", Path_log_engine)
|
||||||
|
Sleep_ms(500)
|
||||||
|
}
|
||||||
|
fmt.Printf("KillFaceDedect run and Run engine\n")
|
||||||
|
|
||||||
|
}
|
||||||
|
func Status_engine() {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Function Status_engine ()")
|
||||||
|
}
|
||||||
|
for i := 0; i < len(message.Data.Engines); i++ {
|
||||||
|
if message.Data.Engines[i].Active == 1 {
|
||||||
|
//var cmd string = "ps -A | grep " + message.Data.Engines[i].Name
|
||||||
|
var cmd string = "pidof " + message.Data.Engines[i].Name
|
||||||
|
out, err := exec.Command("sh", "-c", cmd).Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
file.Write_log("Status_engine () "+err.Error(), Path_log_engine)
|
||||||
|
}
|
||||||
|
if len(out) == 0 {
|
||||||
|
fmt.Printf(message.Data.Engines[i].Name + "isn't running\n")
|
||||||
|
file.Write_log(message.Data.Engines[i].Name+"isn't running\n", Path_log_engine)
|
||||||
|
//KillLoopRun()
|
||||||
|
RunEngine(message.Data.Engines[i].Name)
|
||||||
|
} else {
|
||||||
|
number_run = 0
|
||||||
|
fmt.Printf(message.Data.Engines[i].Name + " is running\n")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Engine setting off on engine.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckCam(path string) int {
|
||||||
|
var cam_sts int
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Function CheckCam ()")
|
||||||
|
}
|
||||||
|
for i := 0; i < len(message.Data.Engines); i++ {
|
||||||
|
var ip string = ""
|
||||||
|
ip = GetIPCam(path)
|
||||||
|
fmt.Println("Ip camera: " + ip)
|
||||||
|
out, err := exec.Command("ping", ip, "-c 5", "-i 0.2", "-w 5").Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
file.Write_log("CheckCam () "+err.Error(), Path_log_engine)
|
||||||
|
cam_sts = 0
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
if strings.Contains(string(out), "Destination Host Unreachable") {
|
||||||
|
fmt.Println("Disconnect camera...")
|
||||||
|
file.Write_log("Disconnect camera", Path_log_engine)
|
||||||
|
cam_sts = 0
|
||||||
|
} else {
|
||||||
|
fmt.Println("Connected camera...")
|
||||||
|
cam_sts = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return cam_sts
|
||||||
|
//fmt.Println("End Function CheckCam")
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetIPCam(path string) string {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Function GetIPCam ()")
|
||||||
|
}
|
||||||
|
|
||||||
|
var ip string = ""
|
||||||
|
str := ReadFile(path)
|
||||||
|
j := strings.Index(str, "@")
|
||||||
|
if j > -1 {
|
||||||
|
fmt.Println(j)
|
||||||
|
index := str[j+1 : j+20]
|
||||||
|
t := strings.Index(index, "@")
|
||||||
|
if t > -1 {
|
||||||
|
index := str[t+1 : t+15]
|
||||||
|
fmt.Println(index)
|
||||||
|
list_0 := strings.Split(index, ":")
|
||||||
|
ip = list_0[0]
|
||||||
|
} else {
|
||||||
|
fmt.Println(index)
|
||||||
|
list_0 := strings.Split(index, ":")
|
||||||
|
ip = list_0[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
i := strings.Index(str, "192")
|
||||||
|
|
||||||
|
//fmt.Println("Index: ", i)
|
||||||
|
if i > -1 {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println(str[i : i+15])
|
||||||
|
}
|
||||||
|
|
||||||
|
index := str[i : i+15]
|
||||||
|
list := strings.Split(index, ".")
|
||||||
|
//fmt.Println(list)
|
||||||
|
k := strings.Index(list[3], "\n")
|
||||||
|
if k > -1 {
|
||||||
|
x := strings.Split(list[3], "\n")
|
||||||
|
list[3] = x[0]
|
||||||
|
} else {
|
||||||
|
j := strings.Index(list[3], "/")
|
||||||
|
if j > -1 {
|
||||||
|
x := strings.Split(list[3], "/")
|
||||||
|
list[3] = x[0]
|
||||||
|
} else {
|
||||||
|
t := strings.Index(list[3], ":")
|
||||||
|
if t > -1 {
|
||||||
|
x := strings.Split(list[3], ":")
|
||||||
|
list[3] = x[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ip = list[0]
|
||||||
|
for i := 1; i < 4; i++ {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Printf("%v_", list[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
ip = ip + "." + list[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
file.Write_log("cam_id not found", Path_log_engine)
|
||||||
|
fmt.Println("cam_id not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|
||||||
|
var stt_serverlocal = 0
|
||||||
|
var number_run_fr = 0
|
||||||
|
|
||||||
|
func STTServerFR() {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Function STTServerFR ()")
|
||||||
|
}
|
||||||
|
for i := 0; i < len(message.Data.Engines); i++ {
|
||||||
|
if message.Data.Engines[i].Active == 1 {
|
||||||
|
//var cmd string = "ps -A | grep " + message.Data.Engines[i].Name
|
||||||
|
var cmd string = "pidof FaceRecognition" // message.Data.Engines[i].Name
|
||||||
|
out, err := exec.Command("sh", "-c", cmd).Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
file.Write_log("STTServerFR () "+err.Error(), Path_log_engine)
|
||||||
|
}
|
||||||
|
if len(out) == 0 {
|
||||||
|
fmt.Printf("STTServerFR isn't running\n")
|
||||||
|
file.Write_log("STTServerFR isn't running\n", Path_log_engine)
|
||||||
|
KillFaceDedect()
|
||||||
|
RunServerFR(message.Data.Engines[i].Name)
|
||||||
|
} else {
|
||||||
|
number_run_fr = 0
|
||||||
|
fmt.Printf("FaceRecognition is running\n")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Engine setting off on engine.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RunServerFR(name string) {
|
||||||
|
fmt.Println("Function RunEngine ()")
|
||||||
|
number_run_fr = number_run_fr + 1
|
||||||
|
if number_run_fr > 25 {
|
||||||
|
time.Sleep(10000)
|
||||||
|
// RebootBox()
|
||||||
|
number_run_fr = 0
|
||||||
|
file.Write_log(" number_run_fr engine > 25 ----> reset count_number=0 && not reset ", Path_log_engine)
|
||||||
|
} else {
|
||||||
|
//while true; do /home/beetsoft/Desktop/face_recognition_20190308/build/FaceRecognition/FaceRecognition ;done
|
||||||
|
// FaceRecognition/FaceRecognition ../data/Config.txt > /dev/null 2>&1 &
|
||||||
|
//var cmd = "cd " + path_base + "/engine/" + name + "/build/ && " + "screen -dm -S Engine " + name + "/" + name + " ../data/Config.txt > /dev/null 2>&1 &"
|
||||||
|
//var cmd = "export DISPLAY=:0&&export OPENBLAS_NUM_THREADS=1&&cd " + path_base + "/engine/" + name + "/build/ " + "&& " + name + "/" + name + " " + name + "/data/Config.txt > /dev/null 2>&1 &"
|
||||||
|
var cmd = "export DISPLAY=:0&&export OPENBLAS_NUM_THREADS=1&&cd " + path_base + "/engine/" + name + "/FaceRecognition/build/" + "&&./FaceRecognition > /dev/null 2>&1 &"
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("cmd run RunServerFR", cmd)
|
||||||
|
}
|
||||||
|
out, err := exec.Command("sh", "-c", cmd).Output()
|
||||||
|
if err != nil {
|
||||||
|
//log.Fatal(err)
|
||||||
|
stt_serverlocal = 0
|
||||||
|
file.Write_log("RunServerFR () "+err.Error(), Path_log_engine)
|
||||||
|
fmt.Printf("RunServerFR() not run \n")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("RunServerFR() ok \n")
|
||||||
|
file.Write_log("RunServerFR() ok \n", Path_log_engine)
|
||||||
|
stt_serverlocal = 1
|
||||||
|
//RunEngine(name)
|
||||||
|
var out1 = string(out)
|
||||||
|
fmt.Printf(out1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func RunEngine(name string) {
|
||||||
|
fmt.Println("Function RunEngine ()")
|
||||||
|
number_run = number_run + 1
|
||||||
|
if number_run > 25 {
|
||||||
|
time.Sleep(10000)
|
||||||
|
// RebootBox()
|
||||||
|
number_run = 0
|
||||||
|
file.Write_log(" Number run engine > 25 ----> reset count_number=0 && not reset ", Path_log_engine)
|
||||||
|
} else {
|
||||||
|
//while true; do /home/beetsoft/Desktop/face_recognition_20190308/build/FaceRecognition/FaceRecognition ;done
|
||||||
|
// FaceRecognition/FaceRecognition ../data/Config.txt > /dev/null 2>&1 &
|
||||||
|
//var cmd = "cd " + path_base + "/engine/" + name + "/build/ && " + "screen -dm -S Engine " + name + "/" + name + " ../data/Config.txt > /dev/null 2>&1 &"
|
||||||
|
//var cmd = "export DISPLAY=:0&&export OPENBLAS_NUM_THREADS=1&&cd " + path_base + "/engine/" + name + "/build/ " + "&& " + name + "/" + name + " " + name + "/data/Config.txt > /dev/null 2>&1 &"
|
||||||
|
var cmd = "export DISPLAY=:0&&export OPENBLAS_NUM_THREADS=1&&cd " + path_base + "/engine/" + name + "/build/ " + "&& " + name + "/" + name + " ../data/Config.txt > /dev/null 2>&1 &"
|
||||||
|
//var cmd = "export DISPLAY=:0&&export OPENBLAS_NUM_THREADS=1&&cd " + path_base + "/engine/" + name + "/build/ " + "&& " + name + "/" + name + " ../data/Config.txt > /home/admin/monitor/log/logEngine.txt &"
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("cmd run engine", cmd)
|
||||||
|
}
|
||||||
|
out, err := exec.Command("sh", "-c", cmd).Output()
|
||||||
|
if err != nil {
|
||||||
|
//log.Fatal(err)
|
||||||
|
engine_status = 1
|
||||||
|
file.Write_log("RunEngine () "+err.Error(), Path_log_engine)
|
||||||
|
fmt.Printf("RunEngine() not run \n")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("RunEngine() ok \n")
|
||||||
|
file.Write_log("RunEngine() ok \n", Path_log_engine)
|
||||||
|
engine_status = 0
|
||||||
|
var out1 = string(out)
|
||||||
|
fmt.Printf(out1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
func RebootBox() {
|
||||||
|
fmt.Println("Function RebootBox()")
|
||||||
|
_, err := exec.Command("sh", "-c", "reboot").Output()
|
||||||
|
if err == nil {
|
||||||
|
file.Write_log("RebootBox()", Path_log_luncher)
|
||||||
|
}
|
||||||
|
fmt.Println("End Function RebootBox()")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Sleep_ms(ms time.Duration) {
|
||||||
|
time.Sleep(time.Millisecond * ms) // sleep(nano second)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thao tac file
|
||||||
|
func CreateLogfile(path string) {
|
||||||
|
fmt.Println("Function CreateLogfile ()")
|
||||||
|
// detect if file exists
|
||||||
|
var _, err = os.Stat(path)
|
||||||
|
|
||||||
|
// create file if not exists
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
var file, err = os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
//file.Write_log("CreateLogfile() "+err.Error(), Path_log_engine)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("==> done creating file", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// func file.file.Write_log(msg string, path string) {
|
||||||
|
// fmt.Println("Function file.Write_log ()")
|
||||||
|
// // open file using READ & WRITE permission
|
||||||
|
// // fmt.Println("==>begin writting ")
|
||||||
|
// var file, err = os.OpenFile(path, os.O_RDWR|os.O_APPEND, 0777)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// file.Write_log("file.Write_log 1 () "+err.Error(), Path_log_engine)
|
||||||
|
// }
|
||||||
|
// defer file.Close()
|
||||||
|
|
||||||
|
// _, err = file.WriteString(time.Now().String())
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// file.Write_log("file.Write_log 2 () "+err.Error(), Path_log_engine)
|
||||||
|
// }
|
||||||
|
// // write some text line-by-line to file
|
||||||
|
// _, err = file.WriteString("\n")
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// file.Write_log("file.Write_log 3 () "+err.Error(), Path_log_engine)
|
||||||
|
// }
|
||||||
|
// _, err = file.WriteString("Service Check_engine : " + msg)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// file.Write_log("file.Write_log 4 () "+err.Error(), Path_log_engine)
|
||||||
|
// }
|
||||||
|
// _, err = file.WriteString("\n")
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// file.Write_log("file.Write_log 5 () "+err.Error(), Path_log_engine)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // save changes
|
||||||
|
// err = file.Sync()
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// file.Write_log("file.Write_log 6 () "+err.Error(), Path_log_engine)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //fmt.Println("==> done writing to file")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func readFile(path string) string {
|
||||||
|
// if Debug == 1 {
|
||||||
|
// fmt.Println("Function readFile ()")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // re-open file
|
||||||
|
// var msg string = ""
|
||||||
|
// var file, err = os.OpenFile(path, os.O_RDWR, 0644)
|
||||||
|
// if err != nil {
|
||||||
|
// //file.Write_log("readFile 1 () "+err.Error(), Path_log_engine)
|
||||||
|
// time_start = time_start_defaut
|
||||||
|
// time_end = time_end_defaut
|
||||||
|
// } else {
|
||||||
|
// defer file.Close()
|
||||||
|
// // read file, line by line
|
||||||
|
// var text = make([]byte, 1024)
|
||||||
|
// for {
|
||||||
|
// _, err = file.Read(text)
|
||||||
|
// // break if finally arrived at end of file
|
||||||
|
// if err == io.EOF {
|
||||||
|
// //file.Write_log("readFile 2() "+err.Error(), Path_log_engine)
|
||||||
|
// //break
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // break if error occured
|
||||||
|
// if err != nil && err != io.EOF {
|
||||||
|
// //file.Write_log("readFile 3() "+err.Error(), Path_log_engine)
|
||||||
|
// //break
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// //fmt.Println(string(text))
|
||||||
|
// msg = string(text)
|
||||||
|
// }
|
||||||
|
// fmt.Println(time_start)
|
||||||
|
// fmt.Println(time_end)
|
||||||
|
// fmt.Println("read file done")
|
||||||
|
// return msg
|
||||||
|
// }
|
||||||
|
|
||||||
|
func DeleteFile(path string) {
|
||||||
|
fmt.Println("Function DeleteFile ()")
|
||||||
|
// delete file
|
||||||
|
var err = os.Remove(path)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
file.Write_log("DeleteFile () "+err.Error(), Path_log_engine)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("==> done deleting file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsError(err error) bool {
|
||||||
|
//fmt.Println("Function IsError ()")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return (err != nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadFile(path string) string {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println("Function ReadFile ()")
|
||||||
|
}
|
||||||
|
|
||||||
|
// re-open file
|
||||||
|
var msg string = ""
|
||||||
|
var file, err = os.OpenFile(path, os.O_RDWR, 0644)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(" Open file error")
|
||||||
|
//file.Write_log("ReadFile 1 () "+err.Error(), Path_log_engine)
|
||||||
|
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
// read file, line by line
|
||||||
|
var text = make([]byte, 2048)
|
||||||
|
for {
|
||||||
|
_, err = file.Read(text)
|
||||||
|
// break if finally arrived at end of file
|
||||||
|
if err == io.EOF {
|
||||||
|
//file.Write_log("ReadFile 2 () "+err.Error(), Path_log_engine)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// break if error occured
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
//file.Write_log("ReadFile 3 () "+err.Error(), Path_log_engine)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg = string(text)
|
||||||
|
//fmt.Println(msg)
|
||||||
|
return msg
|
||||||
|
}
|
4
Check_engine/build_pc.bat
Normal file
4
Check_engine/build_pc.bat
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
set GOOS=linux
|
||||||
|
set GOARCH=amd64
|
||||||
|
go build
|
||||||
|
pause
|
1
Check_engine/scp.txt
Normal file
1
Check_engine/scp.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
scp -P 2359 -r -o 'ProxyJump dh.duyhai@ssh_tunnel.beetai.com' Check_engine root@localhost:/root/monitor/launcher/
|
217
S905X_BI/2020-4-7.txt
Normal file
217
S905X_BI/2020-4-7.txt
Normal file
|
@ -0,0 +1,217 @@
|
||||||
|
2020-04-07 05:00:03.677070406 +0900 KST m=+31541.566480834
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 05:00:03.709120722 +0900 KST m=+31541.598531425
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 05:00:03.722870177 +0900 KST m=+31541.612280643
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 07:35:52.299638199 +0900 KST m=+40890.189048615
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 07:35:52.340169657 +0900 KST m=+40890.229580448
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 07:35:52.353178631 +0900 KST m=+40890.242589372
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 10:10:27.279442129 +0900 KST m=+0.005871701
|
||||||
|
Begin Check, Restart program
|
||||||
|
|
||||||
|
2020-04-07 10:10:27.315029936 +0900 KST m=+0.041459620
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 10:10:27.323300118 +0900 KST m=+0.049729902
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 10:10:27.359126337 +0900 KST m=+0.085556321
|
||||||
|
KillFaceDedect() exit status 1
|
||||||
|
2020-04-07 10:10:27.373734216 +0900 KST m=+0.100163825
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 10:10:27.407299803 +0900 KST m=+0.133729562
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 10:10:27.411460593 +0900 KST m=+0.137890227
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 10:10:27.419059976 +0900 KST m=+0.145489573
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 11:16:45.9772441 +0900 KST m=+0.017440787
|
||||||
|
Begin Check, Restart program
|
||||||
|
|
||||||
|
2020-04-07 11:16:46.008846461 +0900 KST m=+0.049043174
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 11:16:46.013520724 +0900 KST m=+0.053717436
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:16:46.040633123 +0900 KST m=+0.080829848
|
||||||
|
KillFaceDedect() exit status 1
|
||||||
|
2020-04-07 11:16:46.060103272 +0900 KST m=+0.100299984
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 11:16:46.090554783 +0900 KST m=+0.130751508
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 11:16:46.09532822 +0900 KST m=+0.135524933
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:16:46.108486432 +0900 KST m=+0.148683157
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 11:28:10.396611785 +0900 KST m=+0.024778713
|
||||||
|
Begin Check, Restart program
|
||||||
|
|
||||||
|
2020-04-07 11:28:10.440328121 +0900 KST m=+0.068495098
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 11:28:10.449116558 +0900 KST m=+0.077283473
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:28:10.476824357 +0900 KST m=+0.104991297
|
||||||
|
KillFaceDedect() exit status 1
|
||||||
|
2020-04-07 11:28:10.505974131 +0900 KST m=+0.134141058
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 11:28:10.537712205 +0900 KST m=+0.165879132
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 11:28:10.549698529 +0900 KST m=+0.177865444
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:28:10.580433353 +0900 KST m=+0.208600293
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 11:28:31.015003924 +0900 KST m=+20.643170851
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 11:28:31.046034822 +0900 KST m=+20.674201825
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:28:31.073628109 +0900 KST m=+20.701795049
|
||||||
|
KillFaceDedect() exit status 1
|
||||||
|
2020-04-07 11:28:31.080762196 +0900 KST m=+20.708929124
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 11:28:31.107617195 +0900 KST m=+20.735784123
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 11:28:31.110832132 +0900 KST m=+20.738999060
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:28:31.11673702 +0900 KST m=+20.744903947
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 11:34:57.483810621 +0900 KST m=+0.015374963
|
||||||
|
Begin Check, Restart program
|
||||||
|
|
||||||
|
2020-04-07 11:34:57.514008882 +0900 KST m=+0.045573286
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 11:34:57.519689432 +0900 KST m=+0.051253824
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:34:57.543368881 +0900 KST m=+0.074933285
|
||||||
|
KillFaceDedect() exit status 1
|
||||||
|
2020-04-07 11:34:57.570559767 +0900 KST m=+0.102124172
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 11:34:57.599911216 +0900 KST m=+0.131475608
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 11:34:57.607269153 +0900 KST m=+0.138833545
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:34:57.62067529 +0900 KST m=+0.152239682
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 11:36:11.52646793 +0900 KST m=+0.040988499
|
||||||
|
Begin Check, Restart program
|
||||||
|
|
||||||
|
2020-04-07 11:36:11.581335728 +0900 KST m=+0.095856322
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 11:36:11.595374315 +0900 KST m=+0.109894897
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:36:11.640486951 +0900 KST m=+0.155007570
|
||||||
|
KillFaceDedect() exit status 1
|
||||||
|
2020-04-07 11:36:11.687285149 +0900 KST m=+0.201805743
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 11:36:11.853890368 +0900 KST m=+0.368410974
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 11:36:11.902346991 +0900 KST m=+0.416867572
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:36:11.990085062 +0900 KST m=+0.504605644
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 11:46:08.953091797 +0900 KST m=+0.004787855
|
||||||
|
Begin Check, Restart program
|
||||||
|
|
||||||
|
2020-04-07 11:46:08.988981847 +0900 KST m=+0.040678155
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 11:46:08.996496518 +0900 KST m=+0.048192626
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:46:09.027611861 +0900 KST m=+0.079308319
|
||||||
|
KillFaceDedect() exit status 1
|
||||||
|
2020-04-07 11:46:09.036921962 +0900 KST m=+0.088618107
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 11:46:09.069064216 +0900 KST m=+0.120760586
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 11:46:09.07317524 +0900 KST m=+0.124871311
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:46:09.081086419 +0900 KST m=+0.132782502
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 11:51:03.292933638 +0900 KST m=+294.344629708
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 11:51:03.29878898 +0900 KST m=+294.350485063
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:51:03.396197254 +0900 KST m=+294.447893325
|
||||||
|
KillFaceDedect()
|
||||||
|
|
||||||
|
2020-04-07 11:51:03.94172995 +0900 KST m=+294.993426433
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 11:51:03.999835781 +0900 KST m=+295.051531851
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 11:51:04.004900192 +0900 KST m=+295.056596250
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:51:04.012083581 +0900 KST m=+295.063779664
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 11:58:09.740174328 +0900 KST m=+720.791870411
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 11:58:09.766299521 +0900 KST m=+720.817995617
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:58:09.860822253 +0900 KST m=+720.912518323
|
||||||
|
KillFaceDedect()
|
||||||
|
|
||||||
|
2020-04-07 11:58:10.39739689 +0900 KST m=+721.449093248
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 11:58:10.453585334 +0900 KST m=+721.505281404
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 11:58:10.457441779 +0900 KST m=+721.509137887
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 11:58:10.464019469 +0900 KST m=+721.515715552
|
||||||
|
RunEngine() ok
|
||||||
|
|
||||||
|
2020-04-07 12:01:43.171200712 +0900 KST m=+934.222896795
|
||||||
|
STTServerFR () exit status 1
|
||||||
|
2020-04-07 12:01:43.198262571 +0900 KST m=+934.249958641
|
||||||
|
STTServerFR isn't running
|
||||||
|
|
||||||
|
2020-04-07 12:01:43.278622666 +0900 KST m=+934.330318749
|
||||||
|
KillFaceDedect()
|
||||||
|
|
||||||
|
2020-04-07 12:01:43.819894284 +0900 KST m=+934.871590805
|
||||||
|
RunServerFR() ok
|
||||||
|
|
||||||
|
2020-04-07 12:01:43.875815644 +0900 KST m=+934.927511714
|
||||||
|
Status_engine () exit status 1
|
||||||
|
2020-04-07 12:01:43.87896101 +0900 KST m=+934.930657105
|
||||||
|
FacePro_263isn't running
|
||||||
|
|
||||||
|
2020-04-07 12:01:43.884664149 +0900 KST m=+934.936360232
|
||||||
|
RunEngine() ok
|
||||||
|
|
BIN
S905X_BI/S905X_BI
Normal file
BIN
S905X_BI/S905X_BI
Normal file
Binary file not shown.
585
S905X_BI/S905X_BI.go
Normal file
585
S905X_BI/S905X_BI.go
Normal file
|
@ -0,0 +1,585 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "beetai_BeetAipro/action_engine"
|
||||||
|
"beetai_BeetAipro/box"
|
||||||
|
"beetai_BeetAipro/file"
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AutoServer : Bat che do update engine tu dong
|
||||||
|
var AutoServer = 1
|
||||||
|
|
||||||
|
// MqttCmsBi : Khoi tao doi tuong mqtt
|
||||||
|
var MqttCmsBi mqtt.Client
|
||||||
|
|
||||||
|
// CmsHostBi : host MQTT
|
||||||
|
const CmsHostBi string = "tcp://broker.beetai.com:21883"
|
||||||
|
|
||||||
|
// CmsAccessTokenBi : User
|
||||||
|
const CmsAccessTokenBi = "beeetai"
|
||||||
|
|
||||||
|
// CmsPassBi : Password
|
||||||
|
const CmsPassBi = "5ige8TdfTEHoTgJz"
|
||||||
|
|
||||||
|
const mqtt_disconnect_timeout uint = 5000
|
||||||
|
const mqtt_connect_timeout time.Duration = 5
|
||||||
|
|
||||||
|
var idBox = ""
|
||||||
|
|
||||||
|
// CmsTopicIn : Server to Box
|
||||||
|
var CmsTopicIn = "v1/devices/" + idBox + "/telemetry"
|
||||||
|
|
||||||
|
// CmsTopicOut : Box to Server
|
||||||
|
var CmsTopicOut = "v1/devices/" + idBox + "/request/+"
|
||||||
|
|
||||||
|
// StatusSSH : Cho phep bat tat ssh tu xa
|
||||||
|
var StatusSSH = 0
|
||||||
|
|
||||||
|
var SttNetwork = false
|
||||||
|
|
||||||
|
// SttUpdateEngine : Trang thai update engine
|
||||||
|
// var SttUpdateEngine = false
|
||||||
|
|
||||||
|
// MqttStt : Conect mqtt server yes? no
|
||||||
|
var MqttStt = false
|
||||||
|
|
||||||
|
// SttUpdate: Quyet dinh dung gui message len server mqtt broker
|
||||||
|
var SttUpdate = false
|
||||||
|
var SttPub = true
|
||||||
|
|
||||||
|
// Counter number reconnect publish
|
||||||
|
var number_repub = 0
|
||||||
|
|
||||||
|
// Counter number reconnect subcriber
|
||||||
|
var number_resub = 0
|
||||||
|
|
||||||
|
// Pwd : Password
|
||||||
|
type Pwd struct {
|
||||||
|
Password string `json:"password"`
|
||||||
|
}
|
||||||
|
type Ports struct {
|
||||||
|
Port string `json:"port"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var port Ports
|
||||||
|
var STT_test bool
|
||||||
|
|
||||||
|
//============================> Main <==========================
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
file.Println("----------------------START MAIN -------------------------")
|
||||||
|
mqtt.DEBUG = log.New(os.Stderr, "DEBUG ", log.Ltime) // | log.Lshortfile)
|
||||||
|
//box.GetDir() // Check thu muc goc
|
||||||
|
fmt.Println("FUC......U")
|
||||||
|
file.Check_path(box.Path_log_luncher)
|
||||||
|
file.Check_path(box.Path_log_engine)
|
||||||
|
|
||||||
|
box.Stop_check_engine()
|
||||||
|
box.Stop_engine()
|
||||||
|
box.Stop_Server_Engine()
|
||||||
|
go MqttServer() // Check connect tới server MQTT 5p 1 lần
|
||||||
|
|
||||||
|
// Loop:
|
||||||
|
for {
|
||||||
|
|
||||||
|
if AutoServer == 1 {
|
||||||
|
// Đã được khai báo trên trang quan lý chưa
|
||||||
|
if box.Check_dir(box.Path_engine_config) == 0 { // Chưa được khai báo
|
||||||
|
if box.SetUp() == false {
|
||||||
|
file.Println("Box not register on CMS")
|
||||||
|
time.Sleep(7 * time.Second) // Waitting 7 second for next request
|
||||||
|
} else {
|
||||||
|
if SttNetwork == true {
|
||||||
|
|
||||||
|
// KHoi tao connect MQTT cms.beetai.com
|
||||||
|
if MqttStt == false {
|
||||||
|
if CheckConnectionMQTT() == true { // Server mqtt running ?
|
||||||
|
CreateTopic()
|
||||||
|
MqttBegin()
|
||||||
|
//MqttCmsBi.Subscribe(CmsTopicOut, 1, MqttMessageHandler)
|
||||||
|
MqttStt = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if MqttStt == true && SttUpdate == false && SttPub == true {
|
||||||
|
PublishData()
|
||||||
|
//go Ping_broker_sub()
|
||||||
|
if STT_test == false {
|
||||||
|
// time.Sleep(10)
|
||||||
|
Ping_broker_sub()
|
||||||
|
STT_test = true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MqttStt = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if SttUpdate == false {
|
||||||
|
|
||||||
|
box.RunCheck() // Check Check_engine running ???
|
||||||
|
}
|
||||||
|
//file.Println("Publish data done")
|
||||||
|
}
|
||||||
|
} else { // Đã đươc khai báo trên cms
|
||||||
|
if SttNetwork == true {
|
||||||
|
|
||||||
|
// KHoi tao connect MQTT cms.beetai.com
|
||||||
|
if MqttStt == false { // Chưa connect đến MQTT or mất connect mqtt
|
||||||
|
if CheckConnectionMQTT() == true { // Server mqtt running ?
|
||||||
|
CreateTopic()
|
||||||
|
MqttBegin()
|
||||||
|
//MqttCmsBi.Subscribe(CmsTopicOut, 1, MqttMessageHandler)
|
||||||
|
MqttStt = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if MqttStt == true && SttUpdate == false && SttPub == true { // Check khởi tạo done mqtt and no update and cho phép publish message
|
||||||
|
box.RunCheck()
|
||||||
|
PublishData()
|
||||||
|
//go Ping_broker_sub()
|
||||||
|
if STT_test == false {
|
||||||
|
// time.Sleep(10)
|
||||||
|
Ping_broker_sub()
|
||||||
|
STT_test = true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
MqttStt = false
|
||||||
|
}
|
||||||
|
if SttUpdate == false {
|
||||||
|
|
||||||
|
box.RunCheck() // Check Check_engine running ???
|
||||||
|
}
|
||||||
|
//file.Println("Publish data done")
|
||||||
|
}
|
||||||
|
box.Sleep_ms(3000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTopic : Function
|
||||||
|
//***********************************************//
|
||||||
|
//------------------ Function ---------------------
|
||||||
|
var count = 0
|
||||||
|
|
||||||
|
func Ping_broker_sub() {
|
||||||
|
//for {
|
||||||
|
fmt.Println("Ping thu den sub broker")
|
||||||
|
count = count + 1
|
||||||
|
if count > 10000 {
|
||||||
|
count = 0
|
||||||
|
}
|
||||||
|
payload := `{"method":"sub_begin","status":` + strconv.Itoa(count) + `}`
|
||||||
|
//playload_json := json.NewDecoder(strings.NewReader(payload))
|
||||||
|
Token1 := MqttCmsBi.Publish(CmsTopicOut, 0, false, payload)
|
||||||
|
if Token1.Wait() && Token1.Error() != nil {
|
||||||
|
fmt.Printf("Error Publish message CMS BI: %v\n", Token1.Error())
|
||||||
|
file.Write_log("Error Publish Ping_broker_sub()", box.Path_log_luncher)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Ping_broker_sub() OKIE ")
|
||||||
|
file.Write_log("Ping_broker_sub() OKIE", box.Path_log_luncher)
|
||||||
|
//file.Write _log("Send message CMS BI", box.Path_log_luncher)
|
||||||
|
}
|
||||||
|
// time.Sleep(2 * time.Hour)
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTopic : Function
|
||||||
|
func CreateTopic() {
|
||||||
|
//idBox = box.Get_id()
|
||||||
|
idBox = box.Get_idBox()
|
||||||
|
CmsTopicIn = "v1/devices/" + idBox + "/telemetry"
|
||||||
|
CmsTopicOut = "v1/devices/" + idBox + "/request/+"
|
||||||
|
file.Println("idBox: " + idBox)
|
||||||
|
file.Println("TOPIC IN :" + CmsTopicIn)
|
||||||
|
file.Println("TOPIC OUT :" + CmsTopicOut)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublishData : Function
|
||||||
|
func PublishData() {
|
||||||
|
|
||||||
|
//var payload string = "{" + "\"ip_private\":" + "\"" + ip + "\"" + "," + "\"box_id\":" + "\"" + id_cam + "\"" + "," + "\"engine_status\":" + "\"" + sts_engine + "\"" + "," + "\"temperature\":" + "\"" + temp + "\"" + "," + "\"ip_public\":" + "\"" + ip_public + "\"" + "," + "\"mac_address\":" + "\"" + ether + "\"" + "," + "\"boot_storage\":" + "\"" + sum_boot_stg + "\"" + "," + "\"boot_storage_usage\":" + "\"" + boot_stg + "\"" + "," + "\"memory\":" + "\"" + sum_mem + "\"" + "," + "\"memory_usage\":" + "\"" + mem + "\"" + "," + "\"cpu_usage\":" + "\"" + FloatToString(avg) + "\"" + "," + "\"storage_usage\":" + "\"" + box_stg + "\"" + "," + "\"storage\":" + "\"" + sum_storage + "\"" + "}"
|
||||||
|
var payload = box.Message_pub()
|
||||||
|
//file.Println(payload)
|
||||||
|
//file.Printf("Payload = %v\n\n", payload)
|
||||||
|
Token1 := MqttCmsBi.Publish(CmsTopicIn, 1, false, payload)
|
||||||
|
if Token1.Wait() && Token1.Error() != nil {
|
||||||
|
//fmt.Printf("Error Publish message CMS BI: %v\n", Token1.Error())
|
||||||
|
file.Write_log("Error Publish message CMS BI", box.Path_log_luncher)
|
||||||
|
} else {
|
||||||
|
file.Println("Send message CMS BI")
|
||||||
|
//file.Write_log("Send message CMS BI", box.Path_log_luncher)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MqttBegin : Khoi tao MQTT
|
||||||
|
func MqttBegin() {
|
||||||
|
|
||||||
|
OptsCmsBI := mqtt.NewClientOptions()
|
||||||
|
OptsCmsBI.AddBroker(CmsHostBi)
|
||||||
|
OptsCmsBI.SetUsername(CmsAccessTokenBi)
|
||||||
|
OptsCmsBI.SetPassword(CmsPassBi)
|
||||||
|
OptsCmsBI.SetCleanSession(true)
|
||||||
|
OptsCmsBI.SetConnectionLostHandler(MQTTLostConnectHandler)
|
||||||
|
OptsCmsBI.SetOnConnectHandler(MQTTOnConnectHandler)
|
||||||
|
|
||||||
|
MqttCmsBi = mqtt.NewClient(OptsCmsBI)
|
||||||
|
if Token1 := MqttCmsBi.Connect(); Token1.Wait() && Token1.Error() == nil {
|
||||||
|
fmt.Println("MQTT CMS Beetsoft Connected\n")
|
||||||
|
file.Write_log("MQTT CMS BeetsoftConnected\n", box.Path_log_luncher)
|
||||||
|
MqttCmsBi.Subscribe(CmsTopicOut, 0, MqttMessageHandler)
|
||||||
|
} else {
|
||||||
|
file.Write_log("MQTT CMS Beetsoft cant not Connected\n", box.Path_log_luncher)
|
||||||
|
MqttStt = false
|
||||||
|
fmt.Println("MQTT CMS Beetsoft cant not Connect\n")
|
||||||
|
// fmt.Printf("Loi CMS Beetsoft : %v \n", Token1.Error())
|
||||||
|
file.Println("-------------------\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
func mosquitto_LostConnect_Handler(c mqtt.Client, err error) {
|
||||||
|
fmt.Printf("Mosquitto LostConnect, reason: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func mosquitto_OnConnect_Handler(c mqtt.Client) {
|
||||||
|
fmt.Println("OnConnect Mosquitto")
|
||||||
|
c.Subscribe(CmsTopicOut, 0, DomoticzSubscribe_CallBack)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DomoticzSubscribe_CallBack(c mqtt.Client, message mqtt.Message) {
|
||||||
|
fmt.Printf("TOPIC: %s\n", message.Topic())
|
||||||
|
fmt.Printf("MSG:\n %s\n", message.Payload())
|
||||||
|
} // end function
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
|
func MqttBegin_test() {
|
||||||
|
OptsCmsBI := mqtt.NewClientOptions()
|
||||||
|
OptsCmsBI.AddBroker(CmsHostBi)
|
||||||
|
OptsCmsBI.SetUsername(CmsAccessTokenBi)
|
||||||
|
OptsCmsBI.SetPassword(CmsPassBi)
|
||||||
|
OptsCmsBI.SetCleanSession(true)
|
||||||
|
OptsCmsBI.SetConnectionLostHandler(mosquitto_LostConnect_Handler)
|
||||||
|
OptsCmsBI.SetOnConnectHandler(mosquitto_OnConnect_Handler)
|
||||||
|
|
||||||
|
if MqttCmsBi != nil && MqttCmsBi.IsConnected() {
|
||||||
|
MqttCmsBi.Disconnect(mqtt_disconnect_timeout)
|
||||||
|
}
|
||||||
|
MqttCmsBi = mqtt.NewClient(OptsCmsBI)
|
||||||
|
Token1 := MqttCmsBi.Connect().WaitTimeout(mqtt_connect_timeout * time.Second)
|
||||||
|
if Token1 == true {
|
||||||
|
file.Println("MQTT CMS Beetsoft Connected\n")
|
||||||
|
file.Write_log("MQTT CMS BeetsoftConnected\n", box.Path_log_luncher)
|
||||||
|
MqttCmsBi.Subscribe(CmsTopicOut, 0, MqttMessageHandler)
|
||||||
|
} else {
|
||||||
|
file.Write_log("MQTT CMS Beetsoft cant not Connected\n", box.Path_log_luncher)
|
||||||
|
MqttStt = false
|
||||||
|
file.Println("MQTT CMS Beetsoft cant not Connected\n")
|
||||||
|
// fmt.Printf("Loi CMS Beetsoft : %v \n", Token1.Error())
|
||||||
|
file.Println("-------------------\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check lost connect mqtt server - can't publish msg
|
||||||
|
func MQTTLostConnectHandler(c mqtt.Client, err error) {
|
||||||
|
//c.Disconnect(10)
|
||||||
|
MqttStt = false
|
||||||
|
number_repub = number_repub + 1
|
||||||
|
file.Write_log("MQTT CMS Beetsoft Lost Connect\n", box.Path_log_luncher)
|
||||||
|
file.Write_log("Number reconnect publish msg: "+strconv.Itoa(number_repub)+"\n", box.Path_log_luncher)
|
||||||
|
fmt.Printf("Mosquitto LostConnect, reason: %v\n", err)
|
||||||
|
//file.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check lost connect mqtt server - can't subcriber msg from cms
|
||||||
|
func MQTTOnConnectHandler(client mqtt.Client) {
|
||||||
|
fmt.Println("MQTTOnConnectHandler()")
|
||||||
|
number_resub = number_resub + 1
|
||||||
|
file.Write_log("Lostconnect chanel subcriber: MQTT_OnConnectHandler\n", box.Path_log_luncher)
|
||||||
|
file.Write_log("Number reconnect subcriber msg: "+strconv.Itoa(number_resub)+"\n", box.Path_log_luncher)
|
||||||
|
client.Unsubscribe(CmsTopicOut)
|
||||||
|
time.Sleep(10)
|
||||||
|
client.Subscribe(CmsTopicOut, 0, MqttMessageHandler)
|
||||||
|
STT_test = false
|
||||||
|
file.Write_log("Recall function Subscribe MQTT\n", box.Path_log_luncher)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MqttServer() {
|
||||||
|
// fmt.Println("Check Network")
|
||||||
|
for {
|
||||||
|
if CheckConnectionMQTT() == true {
|
||||||
|
// fmt.Println("CheckConnectionMQTT == true")
|
||||||
|
SttNetwork = true
|
||||||
|
} else {
|
||||||
|
MqttStt = false
|
||||||
|
SttNetwork = false
|
||||||
|
file.Write_log("============>>Network not Foud ! <==========\n ", box.Path_log_luncher)
|
||||||
|
// fmt.Println("============>>Network not Foud ! <==========\n")
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Minute)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckConnectionMQTT: Check connection to MQTT server Beetsoft
|
||||||
|
func CheckConnectionMQTT() bool {
|
||||||
|
// fmt.Println("-----------------------------")
|
||||||
|
var SttMQTTServer = false // Biến trang thái kết nối MQTT với server
|
||||||
|
out, err := exec.Command("ping", "broker.beetai.com", "-c 5", "-i 0.2", "-w 5").Output()
|
||||||
|
if err != nil {
|
||||||
|
// fmt.Println("Loi ham CheckConnectionMQTT() ")
|
||||||
|
fmt.Println(err)
|
||||||
|
file.Write_log("Ping broker.beetai.com timeout ---> recall Mqttbegin() \n", box.Path_log_luncher)
|
||||||
|
SttMQTTServer = false
|
||||||
|
} else {
|
||||||
|
// fmt.Println("out of CheckConnectionMQTT() ")
|
||||||
|
// fmt.Println(out)
|
||||||
|
if strings.Contains(string(out), "Destination Host Unreachable") {
|
||||||
|
file.Println("Destination Host Unreachable MQTT")
|
||||||
|
file.Write_log("Destination Host Unreachable MQTT\n", box.Path_log_luncher)
|
||||||
|
SttMQTTServer = false
|
||||||
|
} else {
|
||||||
|
file.Println("Ping broker.beetai.com OKIE...")
|
||||||
|
SttMQTTServer = true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// fmt.Println(SttMQTTServer)
|
||||||
|
// fmt.Println("-----------------------------")
|
||||||
|
return SttMQTTServer
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
|
// MqttMessageHandler : mqtt callback server beetswoft
|
||||||
|
func MqttMessageHandler(MqttBI mqtt.Client, message mqtt.Message) {
|
||||||
|
fmt.Println("=================== MqttMessageHandler ====================")
|
||||||
|
fmt.Printf("Message %s\n", message)
|
||||||
|
fmt.Printf("TOPIC: %s\n", message.Topic())
|
||||||
|
fmt.Printf("MSG:\n %s\n", message.Payload())
|
||||||
|
fmt.Println("=========================== + = + ==========================")
|
||||||
|
dec := json.NewDecoder(bytes.NewReader(message.Payload()))
|
||||||
|
var list map[string]interface{}
|
||||||
|
if err := dec.Decode(&list); err != nil {
|
||||||
|
//file.Printf("Error:%v\n", err)
|
||||||
|
file.Write_log("Message:Loi form message\n", box.Path_log_luncher)
|
||||||
|
} else {
|
||||||
|
//***********************************************//
|
||||||
|
if list["method"] == "change_passwd" { // {"method" : "change_passwd","params": {"password": "123456@"}}
|
||||||
|
file.Println("Changing password \n")
|
||||||
|
s, err := json.Marshal(list["params"])
|
||||||
|
if err != nil {
|
||||||
|
//file.Println(err)
|
||||||
|
}
|
||||||
|
var pwd Pwd
|
||||||
|
json.Unmarshal([]byte(string(s)), &pwd)
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
//pass := pwd.Password
|
||||||
|
// fmt.Print(topic, "\n\n")
|
||||||
|
// fmt.Printf("New password:%v\n", pass)
|
||||||
|
//box.Set_passwd(pass)
|
||||||
|
msg := `{"method":"change_passwd","status": ` + strconv.Itoa(1) + `}`
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
|
||||||
|
} else if list["method"] == "open_ssh" {
|
||||||
|
file.Println("Open port ssh\n")
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
p, err := json.Marshal(list["params"])
|
||||||
|
if err != nil {
|
||||||
|
//file.Println(err)
|
||||||
|
}
|
||||||
|
var pVal = port.Port
|
||||||
|
if StatusSSH == 0 {
|
||||||
|
json.Unmarshal([]byte(string(p)), &port)
|
||||||
|
pVal = port.Port
|
||||||
|
file.Println(pVal)
|
||||||
|
file.Println("Bat ssh")
|
||||||
|
file.Println("Out ssh")
|
||||||
|
msg := `{"method":"open_ssh","status": ` + strconv.Itoa(1) + `,"params": {"port": "` + pVal + `"}}`
|
||||||
|
file.Write_log("Message response cms:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
box.Ssh_open(pVal)
|
||||||
|
file.Println("chay lenh xong")
|
||||||
|
}
|
||||||
|
StatusSSH = 1
|
||||||
|
// file.Println("Out ssh")
|
||||||
|
// msg := `{"method":"open_ssh","status": ` + strconv.Itoa(1) + `,"params": {"port": "` + pVal + `"}}`
|
||||||
|
// file.Write_log("Message response:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
// CmsResponse(MqttBI, topic, msg)
|
||||||
|
file.Println("Open Done ssh\n")
|
||||||
|
|
||||||
|
} else if list["method"] == "close_ssh" {
|
||||||
|
file.Println("Close port ssh\n")
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
if StatusSSH == 1 {
|
||||||
|
box.Ssh_close()
|
||||||
|
StatusSSH = 0
|
||||||
|
}
|
||||||
|
msg := `{"method":"close_ssh","status": ` + strconv.Itoa(1) + `}`
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
file.Println("Close Done ssh\n")
|
||||||
|
|
||||||
|
} else if list["method"] == "update_engine" {
|
||||||
|
file.Println("Update engine\n")
|
||||||
|
UpdateEngine()
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
msg := `{"method":"update_engine","status": ` + strconv.Itoa(1) + `}`
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
file.Println("Update engine done\n")
|
||||||
|
|
||||||
|
} else if list["method"] == "sub_begin" { // Test subcriber
|
||||||
|
file.Write_log("================>> Subcriber is OKIE <========== \n", box.Path_log_luncher)
|
||||||
|
fmt.Println("================>> Subcriber is OKIE <========== \n")
|
||||||
|
|
||||||
|
} else if list["method"] == "update_model" { // {"method":"update_model","status": 1}
|
||||||
|
file.Println("Update_model \n")
|
||||||
|
fmt.Printf("%v--%T", list["id_box_engine"], list["id_box_engine"])
|
||||||
|
UpdateModule((int)((list["id_box_engine"]).(float64)))
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
msg := `{"method":"update_model","status": ` + strconv.Itoa(1) + `}`
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
file.Println("UpdateModule done\n")
|
||||||
|
|
||||||
|
} else if list["method"] == "inactive_box" {
|
||||||
|
file.Println("Inactive Box\n")
|
||||||
|
SttPub = false
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
msg := `{"method":"inactive_box","status": ` + strconv.Itoa(1) + `}`
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
file.Println("Inactive Box done\n")
|
||||||
|
|
||||||
|
} else if list["method"] == "active_box" {
|
||||||
|
file.Println("Active Box\n")
|
||||||
|
SttPub = true
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
msg := `{"method":"active_box","status": ` + strconv.Itoa(1) + `}`
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
file.Println("Active Box done\n")
|
||||||
|
|
||||||
|
} else if list["method"] == "delete_box" {
|
||||||
|
file.Println("Delete box\n")
|
||||||
|
SttPub = false
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
msg := `{"method":"delete_box","status": ` + strconv.Itoa(1) + `}`
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
file.Println("Delete box done\n")
|
||||||
|
|
||||||
|
} else if list["method"] == "getVersion" {
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
//msg := `{"version":` + box.Get_version() + `}`
|
||||||
|
msg := `{"method":"getVersion","params":` + box.Get_version() + `}`
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
file.Println("Get version done\n")
|
||||||
|
} else if list["method"] == "reboot" {
|
||||||
|
file.Write_log("Message:reboot\n", box.Path_log_luncher)
|
||||||
|
//file.Println("=======================>> Reboot BOX <<=====================")
|
||||||
|
box.Reboot_box()
|
||||||
|
} else if list["method"] == "cmd" {
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
msg := `{"method":"cmd","status": ` + strconv.Itoa(1) + `}`
|
||||||
|
//file.Println(topic)
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
//CmsResponse(MqttBI, topic, msg)
|
||||||
|
//file.Printf("%T_%v", list["params"], list["params"])
|
||||||
|
m, _ := list["params"].(string)
|
||||||
|
var out string
|
||||||
|
k := strings.Index(m, "nano")
|
||||||
|
if k > -1 {
|
||||||
|
if strings.Index(m, "Config.txt") > -1 {
|
||||||
|
path := m[k+5:]
|
||||||
|
file.Println(path)
|
||||||
|
out = file.ReadFile(path)
|
||||||
|
file.Println("0")
|
||||||
|
} else {
|
||||||
|
out = box.Cmd_Box(m)
|
||||||
|
file.Println("1")
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
out = box.Cmd_Box(m)
|
||||||
|
file.Println("2")
|
||||||
|
}
|
||||||
|
//file.Println(out)
|
||||||
|
// out := box.Cmd_Box(m)
|
||||||
|
mg := `{"method":"cmd","status": "` + "\n" + out + "\n" + `"}`
|
||||||
|
file.Println(mg)
|
||||||
|
CmsResponse(MqttBI, topic, mg)
|
||||||
|
} else if list["method"] == "upgrade_engine" {
|
||||||
|
file.Println(`list["method"] == "upgrade_engine"`)
|
||||||
|
s, err := json.Marshal(list["params"])
|
||||||
|
if err != nil {
|
||||||
|
//fmt.Println(err)
|
||||||
|
}
|
||||||
|
topic := strings.Replace(message.Topic(), "request", "response", 1)
|
||||||
|
msg := `{"method":"upgrade_engine","status":` + strconv.Itoa(1) + `}`
|
||||||
|
//file.Println(topic)
|
||||||
|
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||||
|
CmsResponse(MqttBI, topic, msg)
|
||||||
|
params := string(s)
|
||||||
|
UpgradeEngine(params)
|
||||||
|
} else {
|
||||||
|
//fmt.Println(list)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
func UpdateModule(id_engine int) {
|
||||||
|
SttUpdate = true
|
||||||
|
box.Stop_check_engine()
|
||||||
|
box.Stop_Server_Engine()
|
||||||
|
box.RequestUpdate_Module(box.Url_module, id_engine)
|
||||||
|
SttUpdate = false
|
||||||
|
}
|
||||||
|
func UpdateEngine() {
|
||||||
|
SttUpdate = true
|
||||||
|
box.Stop_check_engine()
|
||||||
|
box.Stop_engine()
|
||||||
|
box.RequestUpdate(box.Url)
|
||||||
|
SttUpdate = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// CmsResponse : Phan hoi message tu box to Server
|
||||||
|
func CmsResponse(c mqtt.Client, topic string, msg string) {
|
||||||
|
c.Publish(topic, 0, false, msg)
|
||||||
|
file.Println("Publish message done")
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpgradeEngine : Nang cap engine
|
||||||
|
func UpgradeEngine(params string) {
|
||||||
|
//file.Println("0")
|
||||||
|
box.Check_path(box.Path_upgrade)
|
||||||
|
//file.Println("1")
|
||||||
|
file.Create_file(box.Path_engine_update)
|
||||||
|
file.Write_file(params, box.Path_engine_update)
|
||||||
|
//file.Println("2")
|
||||||
|
SttUpdate = true
|
||||||
|
box.Stop_check_engine()
|
||||||
|
//file.Println("3")
|
||||||
|
box.Stop_engine()
|
||||||
|
//file.Println("4")
|
||||||
|
}
|
BIN
S905X_BI/aibox@gitlab.beetsoft.com.vn
Normal file
BIN
S905X_BI/aibox@gitlab.beetsoft.com.vn
Normal file
Binary file not shown.
BIN
S905X_BI/backup/S905X_BI
Normal file
BIN
S905X_BI/backup/S905X_BI
Normal file
Binary file not shown.
4
S905X_BI/build_BifacePro.bat
Normal file
4
S905X_BI/build_BifacePro.bat
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
set GOOS=linux
|
||||||
|
set GOARCH=amd64
|
||||||
|
go build
|
||||||
|
pause
|
5
S905X_BI/build_pi.bat
Normal file
5
S905X_BI/build_pi.bat
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
set GOOS=linux
|
||||||
|
set GOARCH=arm
|
||||||
|
set GOARM=5
|
||||||
|
go build
|
||||||
|
pause
|
2
S905X_BI/scp.txt
Normal file
2
S905X_BI/scp.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
scp -P 2332 -r -o 'ProxyJump dh.duyhai@ssh_tunnel.beetai.com' S905X_BI root@localhost:/root/monitor/check/
|
15110
S905X_BI/syslog
Normal file
15110
S905X_BI/syslog
Normal file
File diff suppressed because it is too large
Load Diff
124
action_engine/action_engine.go
Normal file
124
action_engine/action_engine.go
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
package action_engine
|
||||||
|
|
||||||
|
import (
|
||||||
|
// "bytes"
|
||||||
|
// "encoding/json"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
// "github.com/eclipse/paho.mqtt.golang"
|
||||||
|
//"io"
|
||||||
|
// "log"
|
||||||
|
// "net"
|
||||||
|
// "os"
|
||||||
|
"os/exec"
|
||||||
|
// "time"
|
||||||
|
//"io/ioutil"
|
||||||
|
//"path/filepath"
|
||||||
|
// "strconv" // convert string to int
|
||||||
|
//"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var debug int = 1
|
||||||
|
|
||||||
|
func Kill_engine() {
|
||||||
|
if debug == 1 {
|
||||||
|
fmt.Printf("Kill_engine()\n")
|
||||||
|
}
|
||||||
|
out1, _ := exec.Command("sh", "-c", "ps -A | grep loop_run").Output()
|
||||||
|
if len(out1) != 0 {
|
||||||
|
_, err := exec.Command("sh", "-c", " kill $(pgrep loop_run)").Output()
|
||||||
|
if err != nil {
|
||||||
|
//log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out2, _ := exec.Command("sh", "-c", "ps -A | grep FaceRecognition").Output()
|
||||||
|
if len(out2) != 0 {
|
||||||
|
_, err := exec.Command("sh", "-c", " kill $(pgrep FaceRecognition)").Output() // kill $(pgrep FaceRecognition)
|
||||||
|
if err != nil {
|
||||||
|
//log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
func Stop_check_engine() {
|
||||||
|
fmt.Println("Kill Check_engine")
|
||||||
|
if debug == 1 {
|
||||||
|
fmt.Printf("Stop_check_engine()\n")
|
||||||
|
}
|
||||||
|
_, err := exec.Command("sh", "-c", "kill $(pgrep Check_engine)").Output()
|
||||||
|
if err != nil {
|
||||||
|
//log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Tranfer_engine() {
|
||||||
|
if debug == 1 {
|
||||||
|
fmt.Printf("Tranfer_engine()\n")
|
||||||
|
fmt.Printf("Begin backup engine\n")
|
||||||
|
}
|
||||||
|
_, err := exec.Command("sh", "-c", "cd /root/monitor/backup").Output()
|
||||||
|
if err != nil {
|
||||||
|
_, err1 := exec.Command("sh", "-c", "mkdir /root/monitor/backup").Output()
|
||||||
|
if err1 != nil {
|
||||||
|
//log.Fatal(err)
|
||||||
|
fmt.Printf(" Backup engine Error\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if debug == 1 {
|
||||||
|
fmt.Printf("Create forder backup\n")
|
||||||
|
}
|
||||||
|
// Xoa file engine cu trong backup
|
||||||
|
_, err0 := exec.Command("sh", "-c", "cd /root/monitor/backup/monitor/").Output()
|
||||||
|
if err0 == nil {
|
||||||
|
_, err1 := exec.Command("sh", "-c", "rm -rf /root/monitor/backup/monitor/").Output()
|
||||||
|
if err1 != nil {
|
||||||
|
//log.Fatal(err1)
|
||||||
|
fmt.Printf(" Xoa file engine cu trong backup Error\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, err2 := exec.Command("sh", "-c", "mv /root/monitor/face_recognition/ /root/monitor/backup/").Output()
|
||||||
|
if err2 != nil {
|
||||||
|
//log.Fatal(err2)
|
||||||
|
fmt.Printf("Move mv /root/monitor/face_recognition/ /root/monitor/backup/ error\n")
|
||||||
|
|
||||||
|
}
|
||||||
|
// fmt.Printf("Done copy\n")
|
||||||
|
}
|
||||||
|
func Backup_engine() {
|
||||||
|
if debug == 1 {
|
||||||
|
fmt.Printf("Backup_engine()\n")
|
||||||
|
}
|
||||||
|
_, err := exec.Command("sh", "-c", "rm -rf /root/monitor/face_recognition/").Output()
|
||||||
|
if err != nil {
|
||||||
|
//log.Fatal(err)
|
||||||
|
} else {
|
||||||
|
_, err1 := exec.Command("sh", "-c", "mv /root/monitor/backup/face_recognition/ /root/monitor/").Output()
|
||||||
|
if err1 != nil {
|
||||||
|
//log.Fatal(err1)
|
||||||
|
} else {
|
||||||
|
_, err2 := exec.Command("sh", "-c", "sudo chmod +x /root/monitor/face_recognition/build/FaceRecognition/FaceRecognition").Output()
|
||||||
|
if err2 != nil {
|
||||||
|
//log.Fatal(err2)
|
||||||
|
} else {
|
||||||
|
//Start_engine()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//fmt.Printf("Done Backup_engine \n")
|
||||||
|
}
|
||||||
|
func Download_engine() {
|
||||||
|
if debug == 1 {
|
||||||
|
fmt.Printf("Download_engine()\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
func Upgrade_engine() {
|
||||||
|
if debug == 1 {
|
||||||
|
fmt.Printf("Upgrade_engine()\n")
|
||||||
|
}
|
||||||
|
Stop_check_engine()
|
||||||
|
Kill_engine()
|
||||||
|
Tranfer_engine()
|
||||||
|
//Start_engine()
|
||||||
|
}
|
1681
box/box.go
Normal file
1681
box/box.go
Normal file
File diff suppressed because it is too large
Load Diff
217
file/file.go
Normal file
217
file/file.go
Normal file
|
@ -0,0 +1,217 @@
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Debug int = 0
|
||||||
|
|
||||||
|
//List function
|
||||||
|
|
||||||
|
// Thao tac file
|
||||||
|
func Create_file(path string) {
|
||||||
|
// detect if file exists
|
||||||
|
var _, err = os.Stat(path)
|
||||||
|
|
||||||
|
// create file if not exists
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
var file, err = os.Create(path)
|
||||||
|
if IsError(err) {
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
//Println("==> done creating file", path)
|
||||||
|
}
|
||||||
|
func Write_file(msg string, path string) {
|
||||||
|
// open file using READ & WRITE permission
|
||||||
|
//Check_dir(path)
|
||||||
|
// Println("==>begin writting ")
|
||||||
|
//var file, err = os.OpenFile(path, os.O_RDWR|os.O_APPEND, 0777)
|
||||||
|
var file, err = os.OpenFile(path, os.O_RDWR, 0777)
|
||||||
|
if IsError(err) {
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
_, err = file.WriteString(msg)
|
||||||
|
if IsError(err) {
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
// save changes
|
||||||
|
err = file.Sync()
|
||||||
|
if IsError(err) {
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
//Println("==> done writing to file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Write_log(msg string, path string) {
|
||||||
|
Check_path(path)
|
||||||
|
year, month, day := time.Now().Date()
|
||||||
|
new_path := strconv.Itoa(year) + "-" + strconv.Itoa(int(month)) + "-" + strconv.Itoa(day) + ".txt"
|
||||||
|
path = path + "/" + new_path
|
||||||
|
Check_dir(path)
|
||||||
|
var file, err = os.OpenFile(path, os.O_RDWR|os.O_APPEND, 0777)
|
||||||
|
if IsError(err) {
|
||||||
|
////return
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Printf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
_, err = file.WriteString(time.Now().String())
|
||||||
|
if IsError(err) {
|
||||||
|
////return
|
||||||
|
}
|
||||||
|
// write some text line-by-line to file
|
||||||
|
_, err = file.WriteString("\n")
|
||||||
|
if IsError(err) {
|
||||||
|
////return
|
||||||
|
}
|
||||||
|
_, err = file.WriteString(msg)
|
||||||
|
if IsError(err) {
|
||||||
|
////return
|
||||||
|
}
|
||||||
|
_, err = file.WriteString("\n")
|
||||||
|
if IsError(err) {
|
||||||
|
////return
|
||||||
|
}
|
||||||
|
|
||||||
|
// save changes
|
||||||
|
err = file.Sync()
|
||||||
|
if IsError(err) {
|
||||||
|
////return
|
||||||
|
}
|
||||||
|
|
||||||
|
//Println("==> done writing to file")
|
||||||
|
}
|
||||||
|
func Println(msg string) {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func DeleteFile(path string) {
|
||||||
|
// delete file
|
||||||
|
var err = os.Remove(path)
|
||||||
|
if IsError(err) {
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
|
||||||
|
Println("==> done deleting file")
|
||||||
|
|
||||||
|
}
|
||||||
|
func DeleteForder(path string) {
|
||||||
|
var cmd = "rm -rf " + path
|
||||||
|
var log = "/admin/monitor/log/log_launcher"
|
||||||
|
_, err := exec.Command("sh", "-c", cmd).Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Delete forder error,Path:" + path)
|
||||||
|
Write_log("Delete forder file error,Path:"+path, log)
|
||||||
|
} else {
|
||||||
|
Println("Delete forder Done ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func CoppyFile(path string, id int) {
|
||||||
|
var cmd = "mv " + path + " /admin/monitor/backup/Config_" + strconv.Itoa(id) + ".txt"
|
||||||
|
var log = "/admin/monitor/log/log_launcher"
|
||||||
|
_, err := exec.Command("sh", "-c", cmd).Output()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Move file error,Path:" + path)
|
||||||
|
Write_log("Move file error,Path:"+path, log)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Move file error,Path:" + path)
|
||||||
|
Write_log("Move file error,Path:"+path, log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func IsError(err error) bool {
|
||||||
|
if err != nil {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return (err != nil)
|
||||||
|
}
|
||||||
|
func Check_path(path string) {
|
||||||
|
// Check directory ?
|
||||||
|
_, err := exec.Command("sh", "-c", "cd "+path).Output()
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
fmt.Println(path + " not Exits\n")
|
||||||
|
|
||||||
|
_, err1 := exec.Command("sh", "-c", "mkdir "+path).Output()
|
||||||
|
if err1 != nil {
|
||||||
|
|
||||||
|
Println(" Cant create " + path)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Println(" Create forder " + path)
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Println(path + " ok \n")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func Check_dir(path string) {
|
||||||
|
|
||||||
|
Println("Function Check_dir ()")
|
||||||
|
|
||||||
|
//Println("------------>Check_dir <------------")
|
||||||
|
var file, err = os.OpenFile(path, os.O_RDWR|os.O_APPEND, 0777)
|
||||||
|
//Printf("Kieu file : %T\t", file)
|
||||||
|
//Printf("Kieu file : %v\n", file)
|
||||||
|
if IsError(err) {
|
||||||
|
if Debug == 1 {
|
||||||
|
fmt.Printf("%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if file == nil {
|
||||||
|
Create_file(path)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadFile(path string) string {
|
||||||
|
// re-open file
|
||||||
|
var msg string = ""
|
||||||
|
var file, err = os.OpenFile(path, os.O_RDWR, 0777)
|
||||||
|
if err != nil {
|
||||||
|
if Debug == 1 {
|
||||||
|
Println(" Open file error")
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// read file, line by line
|
||||||
|
var text = make([]byte, 2048)
|
||||||
|
for {
|
||||||
|
_, err = file.Read(text)
|
||||||
|
// break if finally arrived at end of file
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// break if error occured
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
IsError(err)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg = string(text)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
return msg
|
||||||
|
}
|
5
test/build_pi.bat
Normal file
5
test/build_pi.bat
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
set GOOS=linux
|
||||||
|
set GOARCH=arm
|
||||||
|
set GOARM=5
|
||||||
|
go build
|
||||||
|
pause
|
1
test/path.txt
Normal file
1
test/path.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/home/beetsoft/
|
BIN
test/test.exe
Normal file
BIN
test/test.exe
Normal file
Binary file not shown.
33
test/test.go
Normal file
33
test/test.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var path_base = "/home/ademax/"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
Setpath()
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
}
|
||||||
|
func test() {
|
||||||
|
var path string
|
||||||
|
year, month, day := time.Now().Date()
|
||||||
|
path = strconv.Itoa(year) + "-" + strconv.Itoa(int(month)) + "-" + strconv.Itoa(day) + ".txt"
|
||||||
|
|
||||||
|
fmt.Println(path)
|
||||||
|
}
|
||||||
|
func Setpath() {
|
||||||
|
if os.Args != nil {
|
||||||
|
fmt.Println(os.Args)
|
||||||
|
fmt.Println(path_base)
|
||||||
|
path_base = os.Args[1]
|
||||||
|
fmt.Println("Thay the path_base")
|
||||||
|
fmt.Println("Path_base:", path_base)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user