From 0e809715e3921a3ebbdc074a02f62bd6df7b9d9d Mon Sep 17 00:00:00 2001 From: Jens Christian True Date: Thu, 25 Apr 2019 09:37:34 +0200 Subject: [PATCH] Added code documentation --- main.go | 2 +- run.go | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 4c1b8d6..b664dc8 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ func main() { { Name: "run", Usage: "Run a script and report to the Homie server", - Action: mqttstuff, + Action: cmdRun, }, } diff --git a/run.go b/run.go index 12ce5a8..f9307b9 100644 --- a/run.go +++ b/run.go @@ -1,9 +1,10 @@ package main + import ( "strconv" "bytes" "log" - "net" + "net" "os" "time" "os/exec" @@ -13,8 +14,7 @@ import ( "github.com/urfave/cli" ) - -// Get preferred outbound ip of this machine +//GetOutboundIP Gets the preferred outbound ip of this machine func GetOutboundIP() net.IP { conn, err := net.Dial("udp", "8.8.8.8:80") if err != nil { @@ -27,7 +27,7 @@ func GetOutboundIP() net.IP { return localAddr.IP } -//Get the Mac address +//getMacAddr fetches the first avaible Mac address func getMacAddr() (addr string) { interfaces, err := net.Interfaces() if err == nil { @@ -42,7 +42,7 @@ func getMacAddr() (addr string) { return } -//Publish a message and wait for confirmation +//SyncPublish Synchronous publish an MQTT topic and wait for confirmation func SyncPublish(client mqtt.Client, topic string, qos byte, retained bool, payload interface{}) { hostname, _ := os.Hostname() @@ -54,7 +54,8 @@ func SyncPublish(client mqtt.Client, topic string, qos byte, retained bool, payl } } -func mqttstuff(cli *cli.Context) { +//cmdRun Command handler for the run command +func cmdRun(cli *cli.Context) { clientid := uuid.New() command := ""; @@ -120,5 +121,5 @@ func mqttstuff(cli *cli.Context) { client.Disconnect(1000) //Wait one second to disconnect log.Println("Disconnected") - } +} \ No newline at end of file