Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimti committed Feb 12, 2018
1 parent 69780b0 commit e22679b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dev/configs/interfaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
auto lo
auto wlan0
auto uap0

iface lo inet loopback

allow-hotplug wlan0

iface wlan0 inet dhcp
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface uap0 inet static
address 192.168.27.1
netmask 255.255.255.0
network 192.168.27.0
broadcast 192.168.27.255
gateway 192.168.27.1
3 changes: 3 additions & 0 deletions dev/configs/wpa_supplicant.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
81 changes: 81 additions & 0 deletions iotwifi/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package iotwifi

import (
"os/exec"
// "time"
// "fmt"

)
/*
func ConnectWifi(cmdRunner CmdRunner) {
ssid := "straylight-g"
password := "participate621601}fontanelles"
wifi.SetDebugMode()
if conn, err := wifi.ConnectManager.Connect(ssid, password, time.Second * 60); err == nil {
fmt.Println("Connected", conn.NetInterface, conn.SSID, conn.IP4.String(), conn.IP6.String())
} else {
fmt.Println(err)
}
}
*/
// StartWpaSupplicant
func StartWpaSupplicant(cmdRunner CmdRunner) {
args := []string{
"-dd",
"-Dnl80211",
"-iwlan0",
"-c/etc/wpa_supplicant.conf",
}

cmd := exec.Command("wpa_supplicant", args...)
go cmdRunner.ProcessCmd("wpa_supplicant", cmd)
}

// StartDnsmasq
func StartDnsmasq(cmdRunner CmdRunner) {
// hostapd is enabled, fire up dnsmasq
args := []string{
"--no-hosts", // Don't read the hostnames in /etc/hosts.
"--keep-in-foreground",
"--log-queries",
"--no-resolv",
"--address=/#/192.168.27.1",
"--dhcp-range=192.168.27.100,192.168.27.150,1h",
"--dhcp-vendorclass=set:device,IoT",
"--dhcp-authoritative",
"--log-facility=-",
}

cmd := exec.Command("dnsmasq", args...)
go cmdRunner.ProcessCmd("dnsmasq", cmd)
}


// StartHostapd
func StartHostapd(cmdRunner CmdRunner) {

cmdRunner.Log.Info("Starting hostapd.");

cmd := exec.Command("hostapd", "-d", "/dev/stdin")
hostapdPipe, _ := cmd.StdinPipe()
cmdRunner.ProcessCmd("hostapd", cmd)

cfg := `interface=uap0
ssid=iotwifi2
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=iotwifipass
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP`

hostapdPipe.Write([]byte(cfg))
hostapdPipe.Close()

}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func main() {
panic(err)
}


messages := make(chan iotwifi.CmdMessage, 1)

go iotwifi.RunWifi(bunyanLogger, messages)
Expand Down

0 comments on commit e22679b

Please sign in to comment.