check anvui
This commit is contained in:
parent
63727cd2f2
commit
1c552ac0ce
Binary file not shown.
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"beetai_BeetAipro/file"
|
||||
"Beetai_Pro/file"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
|
@ -21,7 +21,9 @@ import (
|
|||
var name_dir_engine string = ""
|
||||
var state_read_ecf bool = false
|
||||
|
||||
var path_base string = "/home/admin/monitor"
|
||||
var path_base = "/root/monitor"
|
||||
|
||||
// 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"
|
||||
|
|
5
Check_engine/build_arm.bat
Normal file
5
Check_engine/build_arm.bat
Normal file
|
@ -0,0 +1,5 @@
|
|||
set GOOS=linux
|
||||
set GOARCH=arm
|
||||
set GOARM=5
|
||||
go build
|
||||
pause
|
BIN
Check_engine/root@192.168.2.35
Normal file
BIN
Check_engine/root@192.168.2.35
Normal file
Binary file not shown.
Binary file not shown.
|
@ -101,24 +101,23 @@ func main() {
|
|||
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 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
|
||||
}
|
||||
// if STT_test == false {
|
||||
// // time.Sleep(10)
|
||||
// Ping_broker_sub()
|
||||
// STT_test = true
|
||||
// }
|
||||
|
||||
}
|
||||
} else {
|
||||
|
@ -136,22 +135,22 @@ func main() {
|
|||
|
||||
// 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 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
|
||||
}
|
||||
// if STT_test == false {
|
||||
// // time.Sleep(10)
|
||||
// Ping_broker_sub()
|
||||
// STT_test = true
|
||||
// }
|
||||
|
||||
}
|
||||
} else {
|
||||
|
@ -456,17 +455,18 @@ func MqttMessageHandler(MqttBI mqtt.Client, message mqtt.Message) {
|
|||
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")
|
||||
file.Write_log("======>> Subcriber is OKIE <========== \n", box.Path_log_luncher)
|
||||
|
||||
} 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"])
|
||||
msg := `{"method":"update_model","status": ` + strconv.Itoa(1) + `}`
|
||||
file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||
if SttUpdate == false {
|
||||
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)
|
||||
|
||||
// file.Write_log("Message:"+msg+" \n", box.Path_log_luncher)
|
||||
CmsResponse(MqttBI, topic, msg)
|
||||
file.Println("UpdateModule done\n")
|
||||
}
|
||||
|
@ -561,8 +561,8 @@ func MqttMessageHandler(MqttBI mqtt.Client, message mqtt.Message) {
|
|||
func UpdateModule(id_engine int) {
|
||||
file.Write_log("-------- START UPDATE MODULE ----------", box.Path_log_luncher)
|
||||
SttUpdate = true
|
||||
box.Stop_check_engine()
|
||||
box.Stop_Server_Engine()
|
||||
// box.Stop_check_engine()
|
||||
// box.Stop_Server_Engine()
|
||||
box.RequestUpdate_Module(box.Url_module, id_engine)
|
||||
SttUpdate = false
|
||||
file.Write_log("---------------------------------------", box.Path_log_luncher)
|
||||
|
|
5
S905X_BI/build_arm.bat
Normal file
5
S905X_BI/build_arm.bat
Normal file
|
@ -0,0 +1,5 @@
|
|||
set GOOS=linux
|
||||
set GOARCH=arm
|
||||
set GOARM=5
|
||||
go build
|
||||
pause
|
145
box/box.go
145
box/box.go
|
@ -5,11 +5,17 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
//"github.com/eclipse/paho.mqtt.golang"
|
||||
"io"
|
||||
// "log"
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
|
@ -77,7 +83,10 @@ const SD_CARD_DEFAULT = 0
|
|||
// const VER_UBUNTU_DEFAUT = 0
|
||||
|
||||
var name_dir_engine = ""
|
||||
var path_base = "/home/admin/monitor"
|
||||
|
||||
var path_base = "/root/monitor"
|
||||
|
||||
// var path_base = "/home/admin/monitor"
|
||||
var Path_base_engine = path_base + "/engine/" + name_dir_engine //"count_people_face" // Name dir engine
|
||||
var Path_log_engine = path_base + "/log/log_engine"
|
||||
var Path_log_luncher = path_base + "/log/log_launcher"
|
||||
|
@ -111,8 +120,9 @@ type Message struct {
|
|||
// 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"`
|
||||
Box_id int `json:"box_id"`
|
||||
QrCode string `json:"qrcode"`
|
||||
License string `json:"license"`
|
||||
Engines []Engine `json:"engines"`
|
||||
}
|
||||
|
||||
|
@ -264,6 +274,7 @@ func Status_Checkengine() int {
|
|||
return stt
|
||||
}
|
||||
func SetUp() bool {
|
||||
// fmt.Println("Link Getrequest:" + Url)
|
||||
Request_msg(Url) // Request down load engine, tạo engine.json
|
||||
file.Println("Request_msg done")
|
||||
LoadConfig(Path_engine_config) // Get thong tin tu file engine.json luu thong so vao struct, add them truong time run
|
||||
|
@ -374,8 +385,10 @@ func DowloadEngineUpdate(name string, link string, version string, id int) {
|
|||
fmt.Println("Path config:", path_val)
|
||||
threshold := fmt.Sprintf("%.2f", message.Data.Engines[index].Threshold)
|
||||
Replace_id(path_val, id_val, threshold, message.Data.Engines[index].Url) // Cap nhap ID BOX cho file config.txt trong engine
|
||||
|
||||
// Do cap nhat chua biet port dang nao la bao nhieu len ko set dc
|
||||
//ChangePort(path_val, port) // Change portstream local cho cac engine thanh khac nhau
|
||||
fmt.Println("---------------------------------------------------")
|
||||
file.Println("---------------------------------------------------")
|
||||
}
|
||||
} // End for array engine
|
||||
|
@ -387,7 +400,7 @@ func Dowload_engine() {
|
|||
file.Println("Version: " + message.Data.Engines[i].Version)
|
||||
file.Println("Link: " + message.Data.Engines[i].Link)
|
||||
if message.Data.Engines[i].Link != "" {
|
||||
var link string = "wget -O " + "" + path_base + "/engine/" + message.Data.Engines[i].Name + ".tar.gz " + message.Data.Engines[i].Link
|
||||
var link string = "wget -c -O " + "" + path_base + "/engine/" + message.Data.Engines[i].Name + ".tar.gz " + message.Data.Engines[i].Link
|
||||
file.Println(link)
|
||||
_, err := exec.Command("sh", "-c", link).Output()
|
||||
if err != nil {
|
||||
|
@ -461,26 +474,50 @@ func FormRequest(Url string) string {
|
|||
file.Create_file(Path_engine_config)
|
||||
GetOutboundIP()
|
||||
mac_s = Get_mac()
|
||||
//mac_s = "c4:2a:fe:37:35:11"
|
||||
// fmt.Println(mac_s)
|
||||
// mac_s = "c4:2a:fe:37:35:11"
|
||||
fmt.Println(mac_s)
|
||||
// `{" private_key": "V7kls@&@IP*fl7R", "mac_address":"c4:6e:00:02:cb:14 "}`
|
||||
var msg string = "{" + "\"private_key\":" + "\"" + Key + "\"" + "," + "\"mac_address\":" + "\"" + mac_s + "\"" + "}"
|
||||
if Debug == 1 {
|
||||
fmt.Printf("Payload = %v\n\n", msg)
|
||||
|
||||
// encode, err := RsaEncrypt([]byte(mac_s), publicKey)
|
||||
encode, err := RsaEncrypt([]byte(mac_s), publicKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("-----------------MA HOA---------------------")
|
||||
// s := []byte("hai")
|
||||
// s1 := Base64Enc(encode)
|
||||
s1 := base64.StdEncoding.EncodeToString(encode)
|
||||
// s1 = strings.Replace(s1, "\n", "\n", -1)
|
||||
fmt.Printf("Payload encode base 64:%v Type: %T\n", s1, s1)
|
||||
|
||||
// var msg string = "{" + "\"data\":" + "\"" + s1 + "\"" + "}"
|
||||
// var msg string = "{\"data\":\"" + s1 + "\"}"
|
||||
var msg string = `{"data":"` + s1 + `"}`
|
||||
// var b bytes.Buffer
|
||||
// b.WriteString("{\"data\":\"")
|
||||
// b.WriteString(s1)
|
||||
// b.WriteString("\"}")
|
||||
|
||||
fmt.Println("\nPAYLOAD:" + msg)
|
||||
|
||||
payload := []byte(msg)
|
||||
resp, err := http.Post(Url, "application/json", bytes.NewBuffer(payload))
|
||||
if err != nil {
|
||||
file.Write_log("Request_msg() Faild", Path_log_luncher)
|
||||
//file.Println("Request_msg() Faild")
|
||||
|
||||
} else {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
file.Write_log("ioutil.ReadAll(resp.Body) Faild", Path_log_luncher)
|
||||
//file.Println("ioutil.ReadAll(resp.Body) Faild")
|
||||
fmt.Println("ioutil.ReadAll(resp.Body) Faild")
|
||||
}
|
||||
respon_msg = string(body)
|
||||
fmt.Println(respon_msg)
|
||||
return respon_msg
|
||||
}
|
||||
func RequestUpdate(Url string) {
|
||||
|
@ -594,7 +631,8 @@ func UpdateConfig(path string) {
|
|||
//file.Printf("Message: \n", message)
|
||||
file.Println("\nError_code: " + strconv.Itoa(message.Error_code))
|
||||
file.Println("Box_id: " + strconv.Itoa(message.Data.Box_id))
|
||||
|
||||
file.Println("QR code: " + message.Data.QrCode)
|
||||
file.Println("License: " + message.Data.License)
|
||||
// file.Println("---------------------------------------------")
|
||||
// List engine
|
||||
for i := 0; i < len(message.Data.Engines); i++ {
|
||||
|
@ -836,6 +874,7 @@ func ChangePort(path string, k int) int {
|
|||
}
|
||||
return p_n
|
||||
}
|
||||
|
||||
func Replace_config(path string, old string, new string) {
|
||||
var msg string = ""
|
||||
var file_r, err = os.OpenFile(path, os.O_RDWR, 0644)
|
||||
|
@ -946,7 +985,6 @@ func Replace_id(path string, id_box string, th string, api_url string) {
|
|||
file.Write_log("cam_id not found", Path_log_luncher)
|
||||
//file.Println("cam_id not found")
|
||||
}
|
||||
|
||||
}
|
||||
func Stop_Server_Engine() {
|
||||
fmt.Println("Stop_Server_Engine()")
|
||||
|
@ -958,6 +996,7 @@ func Stop_Server_Engine() {
|
|||
file.Write_log("sudo kill $(pgrep FaceRecognition) of Stop_Server_Engine()() \n", Path_log_luncher)
|
||||
} else {
|
||||
file.Println("FaceRecognition kill")
|
||||
file.Write_log("FaceRecognition kill", Path_log_luncher)
|
||||
}
|
||||
//log.Fatal(err)
|
||||
} else {
|
||||
|
@ -1002,18 +1041,29 @@ func RequestUpdate_Module(url string, id_engine int) {
|
|||
file.Write_log("Download Started", Path_log_luncher)
|
||||
var number_download = 0
|
||||
for {
|
||||
if number_download > 10000 {
|
||||
number_download = 0
|
||||
}
|
||||
number_download = number_download + 1
|
||||
fmt.Println("Start download")
|
||||
//url = "http://api.biface.beetai.com/api/model/get_model/219"
|
||||
err := DownloadFile(path, url)
|
||||
if err != nil {
|
||||
// panic(err)
|
||||
file.Write_log("Download Error", Path_log_luncher)
|
||||
//fmt.Println("Download error ---> Download again.")
|
||||
} else {
|
||||
file.Write_log("Download Finished", Path_log_luncher)
|
||||
file.Write_log("Save thanh cong modules", Path_log_luncher)
|
||||
Res_Server(message.Data.Engines[i].Url, message.Data.Box_id, message.Data.Engines[i].Id)
|
||||
break
|
||||
}
|
||||
// fmt.Println("Download Finish")
|
||||
// fmt.Printf("Download module number: %v", number_download)
|
||||
time.Sleep(3 * time.Second)
|
||||
}
|
||||
// tat engine
|
||||
Stop_Server_Engine()
|
||||
file.Write_log("Number download module: "+strconv.Itoa(number_download), Path_log_luncher)
|
||||
|
||||
}
|
||||
|
@ -1779,3 +1829,76 @@ func CollectMemoryStats(out io.Reader) (*Stats, error) {
|
|||
func Sleep_ms(ms time.Duration) {
|
||||
time.Sleep(time.Millisecond * ms) // sleep(nano second)
|
||||
}
|
||||
|
||||
//=================== MA HOA ==========================
|
||||
|
||||
func Base64Enc(b1 []byte) string {
|
||||
s1 := base64.StdEncoding.EncodeToString(b1)
|
||||
s2 := ""
|
||||
var LEN int = 76
|
||||
for len(s1) > 76 {
|
||||
s2 = s2 + s1[:LEN] + "\n"
|
||||
s1 = s1[LEN:]
|
||||
}
|
||||
s2 = s2 + s1
|
||||
return s2
|
||||
}
|
||||
|
||||
func Base64Dec(s1 string) ([]byte, error) {
|
||||
s1 = strings.Replace(s1, "\n", "", -1)
|
||||
s1 = strings.Replace(s1, "\r", "", -1)
|
||||
s1 = strings.Replace(s1, " ", "", -1)
|
||||
return base64.StdEncoding.DecodeString(s1)
|
||||
}
|
||||
|
||||
func RsaDecrypt(ciphertext []byte, key []byte) ([]byte, error) {
|
||||
block, _ := pem.Decode(key)
|
||||
if block == nil {
|
||||
return nil, errors.New("private key error!")
|
||||
}
|
||||
priv, err := x509.ParsePKCS1PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rsa.DecryptPKCS1v15(rand.Reader, priv, ciphertext)
|
||||
}
|
||||
|
||||
func RsaEncrypt(origData []byte, key []byte) ([]byte, error) {
|
||||
block, _ := pem.Decode(key)
|
||||
if block == nil {
|
||||
return nil, errors.New("public key error")
|
||||
}
|
||||
pubInterface, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pub := pubInterface.(*rsa.PublicKey)
|
||||
return rsa.EncryptPKCS1v15(rand.Reader, pub, origData)
|
||||
}
|
||||
|
||||
var publicKey = []byte(`
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCF3e0oBwnmlxbb2ibwUhOanRgq
|
||||
8M0zKBuMaz+lQokW8GrKHFbe6DDiPR9N93q2KW4da0T3hL03l4+BTOCRA2lZybDZ
|
||||
xAMWgiQSdF85lH024T67J2y/BW/JHvD7PHbkM8OJ7NUtBPKHN57d+x7tLL6BenJV
|
||||
a+hs5Lo7nE5IwbIurwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
`)
|
||||
|
||||
var privateKey = []byte(`
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXAIBAAKBgQCF3e0oBwnmlxbb2ibwUhOanRgq8M0zKBuMaz+lQokW8GrKHFbe
|
||||
6DDiPR9N93q2KW4da0T3hL03l4+BTOCRA2lZybDZxAMWgiQSdF85lH024T67J2y/
|
||||
BW/JHvD7PHbkM8OJ7NUtBPKHN57d+x7tLL6BenJVa+hs5Lo7nE5IwbIurwIDAQAB
|
||||
AoGALBkYZ8gxzcFV6WSq0R3okVVQwcyDfGeo84/c7n7FlEXsl9nQECwi9lQ2PMPa
|
||||
q6loOc69cGBMyMRnpKuDiqG6ETzxtKw3LPafGsXYD5FIZ34jOxRS2Ccsnwj84REj
|
||||
Ww91iIli3kNZdqETV0Y0KXWkF7wMlQ9U597ZRmxa26BWxYECQQC8ASLpKK8ypRkc
|
||||
C6c9/njZe0OpvLUkppQwe1YIfeMfm4EgzYy5BbjdAavsn9ANfE80A7OIxWqhkRZ7
|
||||
ZkYhoFZBAkEAtkhUcntWM7ZPYvD033Q9JwAhEGf/Ciw0r+X5dwkwGPOoee7Mxd/z
|
||||
zoBmgm0L2/57vrP204tF2vCjktht4Keo7wJAA9pGG98QkAogFJoMiFGxqktDXLQY
|
||||
RjL/sGqmna/uupQWNlTgAF6kpirFmijAO7aDbP5ybGgXQk5V1puG7mN5wQJBAJJn
|
||||
2dvxkDUMswqG+kcXt55Bjkz9Gm1zQAYfspSXPphr69+zm6k6zToJC0yqhSH3bjCn
|
||||
nxIeBMdrDBZ/2xDb2OUCQHnot9aJVhXah5hTPKBG6fOrFLz3tvQiIDoqPmW2TH+g
|
||||
62tZyiZylQ3xhWuPgF0pUbwSJJ46PZ52P6RCnDSMcTk=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
`)
|
||||
|
|
Loading…
Reference in New Issue
Block a user