.
This commit is contained in:
parent
8a7f93f1f1
commit
d1d9c41418
23
GPIO/GPIO.go
23
GPIO/GPIO.go
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -151,7 +150,7 @@ func LoadConfig(path string) {
|
||||||
}
|
}
|
||||||
func main() {
|
func main() {
|
||||||
// Bat debug
|
// Bat debug
|
||||||
mqtt.DEBUG = log.New(os.Stderr, "DEBUG ", log.Ltime)
|
// mqtt.DEBUG = log.New(os.Stderr, "DEBUG ", log.Ltime)
|
||||||
fmt.Println("======== START MAIN ==========")
|
fmt.Println("======== START MAIN ==========")
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
if state_read_ecf == false {
|
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("TOPIC: %s\n", message.Topic())
|
||||||
fmt.Printf("MSG:\n %s\n", message.Payload())
|
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.Topic()), path_log)
|
||||||
//file.Write_log(string(message.Payload()), path_log)
|
//file.Write_log(string(message.Payload()), path_log)
|
||||||
dec := json.NewDecoder(bytes.NewReader(message.Payload()))
|
dec := json.NewDecoder(bytes.NewReader(message.Payload()))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user