diff --git a/src/index.ts b/src/index.ts index af09aa4..38ebd17 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,9 @@ import { // defaults const AP_SSID = process.env.AP_SSID || `WiFi Repeater`; -const AP_PASSWORD = process.env.AP_PASSWORD || 'charlietheunicorn'; +const AP_PASSWORD = process.env.AP_PASSWORD || ''; +const AP_CHANNEL = Number(process.env.AP_CHANNEL) || 1; +const AP_BAND = process.env.AP_BAND || 'bg'; const WIFI_SSID = process.env.WIFI_SSID; const WIFI_PASSWORD = process.env.WIFI_PASSWORD; @@ -47,8 +49,8 @@ const LED_ERROR_PATTERNS = { return; } - console.log(`Creating WiFi AP on ${accessPoint.iface} with SSID "${AP_SSID}" and password "${AP_PASSWORD}"...`); - await createAccessPoint({ iface: accessPoint.iface, ssid: AP_SSID, password: AP_PASSWORD }); + console.log(`Creating WiFi AP on ${accessPoint.iface} with SSID "${AP_SSID}", CHANNEL "${AP_CHANNEL}", BAND "${AP_BAND}"...`); + await createAccessPoint({ iface: accessPoint.iface, ssid: AP_SSID, password: AP_PASSWORD, channel: AP_CHANNEL, band: AP_BAND }); // Use secondary wireless device for internet if ethernet doesn't do the job. if (!ethernet) { @@ -83,4 +85,4 @@ const LED_ERROR_PATTERNS = { console.log(`WiFi repeater started in AP mode.`); } -})(); \ No newline at end of file +})(); diff --git a/src/nm.ts b/src/nm.ts index c48e8a8..fa5ccc4 100644 --- a/src/nm.ts +++ b/src/nm.ts @@ -24,6 +24,8 @@ export interface WirelessNetwork { iface: string; ssid: string; password?: string; + channel?: number; + band?: string; } const nm: string = 'org.freedesktop.NetworkManager'; @@ -47,10 +49,8 @@ export const createAccessPoint = async (device: WirelessNetwork): Promise = ['802-11-wireless', [ ['ssid', ['ay', stringToArrayOfBytes(device.ssid)]], ['mode', ['s', 'ap']], - ]], - ['802-11-wireless-security', [ - ['key-mgmt', ['s', 'wpa-psk']], - ['psk', ['s', device.password]], + ['channel', ['u', device.channel]], + ['band', ['s', device.band]], ]], ['ipv4', [ ['method', ['s', 'shared']], @@ -60,6 +60,15 @@ export const createAccessPoint = async (device: WirelessNetwork): Promise = ]], ]; + if (device.password) { + connectionParams.push( + ['802-11-wireless-security', [ + ['key-mgmt', ['s', 'wpa-psk']], + ['psk', ['s', device.password]], + ]] + ); + } + const dbusPath = await getPathByIface(device.iface); const connection = await addConnection(connectionParams); const result = await activateConnection(connection, dbusPath);