Thêm hàm Check Subcriber, disable bien khoi tao mqtt

This commit is contained in:
HaiMD 2020-04-07 16:42:48 +07:00
parent a313f4eeac
commit 4d54d52cad
3 changed files with 15 additions and 9 deletions

Binary file not shown.

View File

@ -1,14 +1,12 @@
package main
import (
_ "beetai_BeetAipro/action_engine"
"beetai_BeetAipro/box"
"beetai_BeetAipro/file"
_ "Beetai_Pro/action_engine"
"Beetai_Pro/box"
"Beetai_Pro/file"
"bytes"
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"strconv"
"strings"
@ -79,7 +77,7 @@ var STT_test bool
func main() {
file.Println("----------------------START MAIN -------------------------")
mqtt.DEBUG = log.New(os.Stderr, "DEBUG ", log.Ltime) // | log.Lshortfile)
// 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)
@ -300,7 +298,7 @@ func MqttBegin_test() {
// Check lost connect mqtt server - can't publish msg
func MQTTLostConnectHandler(c mqtt.Client, err error) {
//c.Disconnect(10)
MqttStt = false
//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)
@ -316,9 +314,17 @@ func MQTTOnConnectHandler(client mqtt.Client) {
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)
//client.Subscribe(CmsTopicOut, 0, MqttMessageHandler)
if token := client.Subscribe(CmsTopicOut, 0, MqttMessageHandler); token.Wait() && token.Error() != nil {
fmt.Println(token.Error())
file.Write_log("Subscriber Error MQTT\n", box.Path_log_luncher)
} else {
fmt.Println("Subcriber is MQTTOnConnectHandler () OKIE ")
file.Write_log("Subcriber is MQTTOnConnectHandler () OKIE\n ", box.Path_log_luncher)
}
STT_test = false
file.Write_log("Recall function Subscribe MQTT\n", box.Path_log_luncher)
// file.Write_log("Recall function Subscribe MQTT\n", box.Path_log_luncher)
}
func MqttServer() {

Binary file not shown.