This commit is contained in:
HaiMD 2020-04-22 14:34:02 +07:00
parent 8a7f93f1f1
commit d1d9c41418
2 changed files with 21 additions and 2 deletions

BIN
GPIO/GPIO

Binary file not shown.

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"time"
@ -151,7 +150,7 @@ func LoadConfig(path string) {
}
func main() {
// Bat debug
mqtt.DEBUG = log.New(os.Stderr, "DEBUG ", log.Ltime)
// mqtt.DEBUG = log.New(os.Stderr, "DEBUG ", log.Ltime)
fmt.Println("======== START MAIN ==========")
time.Sleep(1 * time.Second)
if state_read_ecf == false {
@ -275,6 +274,26 @@ func mqtt_messageHandler(mqtt_bi mqtt.Client, message mqtt.Message) {
fmt.Printf("TOPIC: %s\n", message.Topic())
fmt.Printf("MSG:\n %s\n", message.Payload())
}
if string(message.Payload()) == `{"method":"gpio","params":"1"}` {
fmt.Println("MO KHOA")
if door_state == true {
} else {
//relay.High()
relay.Low()
//Name = (list["name"]).(string)
fmt.Println("Xin Chao Mung " + Name)
}
//msg := `{"method":"gpio","params":"1"}`
//CmsResponse(mqtt_bi, topic, msg)
if Debug == 1 {
fmt.Println("Open Door")
fmt.Println("--------------------------------")
}
door_state = true
}
//file.Write_log(string(message.Topic()), path_log)
//file.Write_log(string(message.Payload()), path_log)
dec := json.NewDecoder(bytes.NewReader(message.Payload()))