Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Add channel and band to environment variables #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -83,4 +85,4 @@ const LED_ERROR_PATTERNS = {
console.log(`WiFi repeater started in AP mode.`);
}

})();
})();
17 changes: 13 additions & 4 deletions src/nm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface WirelessNetwork {
iface: string;
ssid: string;
password?: string;
channel?: number;
band?: string;
}

const nm: string = 'org.freedesktop.NetworkManager';
Expand All @@ -47,10 +49,8 @@ export const createAccessPoint = async (device: WirelessNetwork): Promise<any> =
['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']],
Expand All @@ -60,6 +60,15 @@ export const createAccessPoint = async (device: WirelessNetwork): Promise<any> =
]],
];

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);
Expand Down