Added code documentation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
2
main.go
2
main.go
@ -25,7 +25,7 @@ func main() {
|
||||
{
|
||||
Name: "run",
|
||||
Usage: "Run a script and report to the Homie server",
|
||||
Action: mqttstuff,
|
||||
Action: cmdRun,
|
||||
},
|
||||
}
|
||||
|
||||
|
13
run.go
13
run.go
@ -1,4 +1,5 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"bytes"
|
||||
@ -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")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user