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",
|
Name: "run",
|
||||||
Usage: "Run a script and report to the Homie server",
|
Usage: "Run a script and report to the Homie server",
|
||||||
Action: mqttstuff,
|
Action: cmdRun,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
run.go
15
run.go
@ -1,9 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -13,8 +14,7 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//GetOutboundIP Gets the preferred outbound ip of this machine
|
||||||
// Get preferred outbound ip of this machine
|
|
||||||
func GetOutboundIP() net.IP {
|
func GetOutboundIP() net.IP {
|
||||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -27,7 +27,7 @@ func GetOutboundIP() net.IP {
|
|||||||
return localAddr.IP
|
return localAddr.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the Mac address
|
//getMacAddr fetches the first avaible Mac address
|
||||||
func getMacAddr() (addr string) {
|
func getMacAddr() (addr string) {
|
||||||
interfaces, err := net.Interfaces()
|
interfaces, err := net.Interfaces()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -42,7 +42,7 @@ func getMacAddr() (addr string) {
|
|||||||
return
|
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{}) {
|
func SyncPublish(client mqtt.Client, topic string, qos byte, retained bool, payload interface{}) {
|
||||||
|
|
||||||
hostname, _ := os.Hostname()
|
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()
|
clientid := uuid.New()
|
||||||
|
|
||||||
command := "";
|
command := "";
|
||||||
@ -120,5 +121,5 @@ func mqttstuff(cli *cli.Context) {
|
|||||||
|
|
||||||
client.Disconnect(1000) //Wait one second to disconnect
|
client.Disconnect(1000) //Wait one second to disconnect
|
||||||
log.Println("Disconnected")
|
log.Println("Disconnected")
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user