Skip to content

Commit

Permalink
Fix some debug messages in MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
toxuin committed Aug 16, 2022
1 parent 21fc6c3 commit c1f1fb6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions buses/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ func (mqtt *Bus) SendMessage(topic string, payload interface{}) {
if token := mqtt.client.Publish(topic, 0, false, payload); token.Wait() && token.Error() != nil {
fmt.Printf("MQTT ERROR, %s\n", token.Error())
}
if mqtt.Debug {
fmt.Printf("MQTT: Sent message to %s\n", topic)
}
}
5 changes: 2 additions & 3 deletions servers/hikvision/httpEventReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"log"
"mime"
"mime/multipart"
Expand All @@ -21,7 +20,7 @@ func (eventReader *HttpEventReader) ReadEvents(camera *HikCamera, channel chan<-
eventReader.client = &http.Client{}
}

request, err := http.NewRequest("GET", camera.Url+"/Event/notification/alertStream", nil)
request, err := http.NewRequest("GET", camera.Url+"Event/notification/alertStream", nil)
if err != nil {
fmt.Printf("HIK: Error: Could not connect to camera %s\n", camera.Name)
fmt.Println("HIK: Error", err)
Expand Down Expand Up @@ -60,7 +59,7 @@ func (eventReader *HttpEventReader) ReadEvents(camera *HikCamera, channel chan<-
fmt.Println(err)
continue
}
body, err := ioutil.ReadAll(part)
body, err := io.ReadAll(part)
if err != nil {
fmt.Println(err)
continue
Expand Down
7 changes: 4 additions & 3 deletions servers/hikvision/tcpEventReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ func (eventReader *TcpEventReader) ReadEvents(camera *HikCamera, channel chan<-

// READ HTTP HEADERS
var headers = make(map[string]string)
if eventReader.Debug {
fmt.Println("HEADERS:")
}
for {
headerLine, err := textConn.ReadLine()
if err == io.EOF {
Expand All @@ -102,6 +99,10 @@ func (eventReader *TcpEventReader) ReadEvents(camera *HikCamera, channel chan<-
headerValue := strings.SplitN(headerLine, ": ", 2)[1]
headers[headerKey] = headerValue
}
if eventReader.Debug {
fmt.Println("HIK-TCP: HEADERS:")
fmt.Println(headers)
}

// PRINT ERROR
if statusCode != "200" {
Expand Down
4 changes: 4 additions & 0 deletions servers/hisilicon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (server *Server) handleTcpConnection(conn net.Conn) {
}
if dataMap["Address"] != nil {
hexAddrStr := fmt.Sprintf("%v", dataMap["Address"])
if len(hexAddrStr) < 2 {
fmt.Printf("HISI: BAD DEVICE ADDRESS: %s\n", hexAddrStr)
return
}
dataMap["ipAddr"] = hexIpToCIDR(hexAddrStr)
}

Expand Down

0 comments on commit c1f1fb6

Please sign in to comment.