Error Subcriber

This commit is contained in:
2020-04-07 15:10:51 +07:00
parent 6bcd212077
commit 1ea3619a61
21 changed files with 19011 additions and 0 deletions

217
S905X_BI/2020-4-7.txt Normal file
View 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

Binary file not shown.

585
S905X_BI/S905X_BI.go Normal file
View 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")
}

Binary file not shown.

BIN
S905X_BI/backup/S905X_BI Normal file

Binary file not shown.

View File

@@ -0,0 +1,4 @@
set GOOS=linux
set GOARCH=amd64
go build
pause

5
S905X_BI/build_pi.bat Normal file
View File

@@ -0,0 +1,5 @@
set GOOS=linux
set GOARCH=arm
set GOARM=5
go build
pause

2
S905X_BI/scp.txt Normal file
View 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

File diff suppressed because it is too large Load Diff