Skip to content

Commit

Permalink
Add support for wifi credential update, remove machineid from zeroconf
Browse files Browse the repository at this point in the history
  • Loading branch information
danesparza committed Sep 12, 2017
1 parent 4a7a18e commit e762d93
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
14 changes: 14 additions & 0 deletions network/wifi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// +build !linux !arm

package network

import (
"log"
)

// ResetHostname changes the hostname for the local machine
func UpdateWifiCredentials(ssid, password string) error {
log.Println("[INFO] Not running on Linux/ARM, so wifi can't be changed...")

return nil
}
12 changes: 12 additions & 0 deletions network/wifi_linux_arm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package network

import (
"log"
)

// UpdateWifiCredentials updates the ssid and password used
func UpdateWifiCredentials(ssid, password string) error {
log.Printf("[INFO] Updating the wifi credentials.\nNew SSID: %v\nNew Password: %v\n", ssid, password)

return nil
}
9 changes: 2 additions & 7 deletions zeroconf/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/danesparza/appliance-monitor/data"
"github.com/grandcat/zeroconf"
"github.com/rs/xid"
"github.com/spf13/viper"
)

Expand All @@ -34,14 +33,9 @@ func Serve(ctx context.Context, restart chan bool) {
return
}

// Get our machine id:
guid := xid.New()
machineID := guid.Machine()

// Create the zeroconf server
server, err := zeroconf.Register(appName.Value, "_appliance-monitor._tcp", "local.", 3030, []string{
"txtv=1",
fmt.Sprintf("machineID=%x", machineID),
fmt.Sprintf("deviceID=%s", deviceID.Value)}, nil)

if err != nil {
Expand Down Expand Up @@ -69,7 +63,8 @@ func Serve(ctx context.Context, restart chan bool) {

// Start a new server with the new name
server, err = zeroconf.Register(appName.Value, "_appliance-monitor._tcp", "local.", 3030, []string{
"txtv=1", fmt.Sprintf("machineid=%x", machineID)}, nil)
"txtv=1",
fmt.Sprintf("deviceID=%s", deviceID.Value)}, nil)

if err != nil {
log.Printf("[ERROR] Problem restarting zeroconf server: %v", err)
Expand Down

0 comments on commit e762d93

Please sign in to comment.