This commit is contained in:
HaiMD 2020-04-22 13:45:59 +07:00
parent a038d3d801
commit daa3e0660d
2 changed files with 16 additions and 25 deletions

BIN
GPIO/GPIO

Binary file not shown.

View File

@ -151,7 +151,8 @@ func LoadConfig(path string) {
func main() {
// Bat debug
//mqtt.DEBUG = log.New(os.Stderr, "DEBUG ", log.Ltime)
time.Sleep(7 * time.Second)
fmt.Println("======== START MAIN ==========")
time.Sleep(1 * time.Second)
if state_read_ecf == false {
LoadConfig(Path_config)
fmt.Println("Read config done")
@ -185,17 +186,12 @@ func main() {
relay.PullDown()
// Toggle pin 20 times
//go Check_door()
mqtt_begin()
for {
if stt_mqtt == false {
mqtt_begin()
}
Check_door()
}
}
func connLostHandler(c mqtt.Client, err error) {
fmt.Printf("Connection lost, reason: %v\n", err)
mqtt_begin()
}
func Check_door() {
if door_state == true {
time.Sleep(time.Second * time_hold)
@ -222,22 +218,17 @@ func mqtt_begin() {
opts_cms_bi.SetConnectionLostHandler(MQTTLostConnectHandler)
opts_cms_bi.SetOnConnectHandler(MQTTOnConnectHandler)
var reconect = false
for reconect == false {
if token_1 := mqtt_cms_bi.Connect(); token_1.Wait() && token_1.Error() == nil {
//file.Write_log("MQTT CMS Beetsoft Connected\n", path_log)
if Debug == 1 {
fmt.Printf("MQTT CMS Beetsoft Connected\n")
}
reconect = true
} else {
//file.Write_log("MQTT CMS Beetsoft cant not Connected\n", path_log)
if Debug == 1 {
fmt.Printf("MQTT CMS Beetsoft cant not Connected\n")
fmt.Printf("Loi CMS Beetsoft : %v \n", token_1.Error())
fmt.Printf("-------------------\n")
}
reconect = false
if token_1 := mqtt_cms_bi.Connect(); token_1.Wait() && token_1.Error() == nil {
//file.Write_log("MQTT CMS Beetsoft Connected\n", path_log)
if Debug == 1 {
fmt.Printf("MQTT Server Connected\n")
}
} else {
//file.Write_log("MQTT CMS Beetsoft cant not Connected\n", path_log)
if Debug == 1 {
fmt.Printf("MQTT Server cant not Connected\n")
fmt.Printf("Loi Server : %v \n", token_1.Error())
fmt.Printf("-------------------\n")
}
}
@ -250,7 +241,7 @@ func mqtt_begin() {
func MQTTLostConnectHandler(c mqtt.Client, err error) {
// file.Write_log("MQTT CMS Beetsoft Lost Connect\n", box.Path_log_luncher)
fmt.Println("MQTT CMS Beetsoft Lost Connect\n")
fmt.Println("MQTT SERVER Lost Connect\n")
fmt.Println(err)
}
func MQTTOnConnectHandler(client mqtt.Client) {