func (c *CmdRunner) HandleFunc(cmdId string, handler func(cmdMessage CmdMessage)) {
	c.Handlers[cmdId] = handler
}
HandleFunc is a function that gets all channel messages for a command id
package iotwifi
import (
	"bufio"
	"encoding/json"
	"io"
	"io/ioutil"
	"net/http"
	"os"
	"os/exec"
	"regexp"
	"time"
	"github.com/bhoriuchi/go-bunyan/bunyan"
)
type CmdRunner struct {
	Log      bunyan.Logger
	Messages chan CmdMessage
	Handlers map[string]func(CmdMessage)
	Commands map[string]*exec.Cmd
}
type CmdMessage struct {
	Id      string
	Command string
	Message string
	Error   bool
	Cmd     *exec.Cmd
	Stdin   *io.WriteCloser
}
func loadCfg(cfgLocation string) (*SetupCfg, error) {
	v := &SetupCfg{}
	var jsonData []byte
	urlDelimR, _ := regexp.Compile("://")
	isUrl := urlDelimR.Match([]byte(cfgLocation))
	if !isUrl {
		fileData, err := ioutil.ReadFile(cfgLocation)
		if err != nil {
			panic(err)
		}
		jsonData = fileData
	}
	if isUrl {
		res, err := http.Get(cfgLocation)
		if err != nil {
			panic(err)
		}
		defer res.Body.Close()
		urlData, err := ioutil.ReadAll(res.Body)
		if err != nil {
			panic(err)
		}
		jsonData = urlData
	}
	err := json.Unmarshal(jsonData, v)
	return v, err
}
func RunWifi(log bunyan.Logger, messages chan CmdMessage, cfgLocation string) {
	log.Info("Loading IoT Wifi...")
	cmdRunner := CmdRunner{
		Log:      log,
		Messages: messages,
		Handlers: make(map[string]func(cmsg CmdMessage), 0),
		Commands: make(map[string]*exec.Cmd, 0),
	}
	setupCfg, err := loadCfg(cfgLocation)
	if err != nil {
		log.Error("Could not load config: %s", err.Error())
		return
	}
	command := &Command{
		Log:      log,
		Runner:   cmdRunner,
		SetupCfg: setupCfg,
	}
	cmdRunner.HandleFunc("kill", func(cmsg CmdMessage) {
		log.Error("GOT KILL")
		os.Exit(1)
	})
	wpacfg := NewWpaCfg(log, cfgLocation)
	wpacfg.StartAP()
	time.Sleep(10 * time.Second)
	command.StartWpaSupplicant()
	time.Sleep(5 * time.Second)
	wpacfg.ScanNetworks()
	command.StartDnsmasq()
	go func() {
		for {
			wpacfg.ScanNetworks()
			time.Sleep(30 * time.Second)
		}
	}()
	staticFields := make(map[string]interface{})
	for {
		out := <-messages  
		staticFields["cmd_id"] = out.Id
		staticFields["cmd"] = out.Command
		staticFields["is_error"] = out.Error
		log.Info(staticFields, out.Message)
		if handler, ok := cmdRunner.Handlers[out.Id]; ok {
			handler(out)
		}
	}
}