Added code documentation
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Jens Christian True 2019-04-25 09:37:34 +02:00
parent 67e2ed854e
commit 0e809715e3
2 changed files with 9 additions and 8 deletions

@ -25,7 +25,7 @@ func main() {
{
Name: "run",
Usage: "Run a script and report to the Homie server",
Action: mqttstuff,
Action: cmdRun,
},
}

15
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")
}
}