This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
forked from cjimti/iotwifi
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters