Skip to content

Commit 70a20cc

Browse files
committed
LED on by default
1 parent d7ea3ea commit 70a20cc

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,18 @@ Users will then be unable to access the API `http://your-device:9090/v1/connect`
3737
Alternatively, if you would rather have your backend use specified ports instead of the host network, you can change the `PWC_HOST` environment variable to `172.17.0.1` and access the API from `http://172.17.0.1:9090/v1/connect`.
3838

3939
## Changing the default network interface
40-
By default, the first available Wi-Fi network interface available will be used. For the vast majority of cases there is only one Wi-Fi network interface (`wlan0`) and therefore this is no issue. Similarly, if you plug in a Wi-Fi dongle to a device without its own built-in Wi-Fi, the Wi-Fi dongle will be used by default. If however, you have a device with built in Wi-Fi and a Wi-Fi dongle, you will have a device with two network interfaces (usually `wlan0` and `wlan1`). For these instances, or on other occasions where you have a complex interface setup, you can specify which network interface you would like Py Wi-Fi Connect to use by setting the environment variable shown in the `docker-compose.yml` file:
40+
By default, the first available Wi-Fi network interface available will be used. For the vast majority of cases there is only one Wi-Fi network interface (`wlan0`) and therefore this is no issue. Similarly, if you plug in a Wi-Fi dongle to a device without its own built-in Wi-Fi, the Wi-Fi dongle will be used by default.
41+
42+
If however, you have a device with built in Wi-Fi and a Wi-Fi dongle, you will have a device with two network interfaces (usually `wlan0` and `wlan1`). For these instances, or on other occasions where you have a complex network interface setup, you can specify which network interface you would like Py Wi-Fi Connect to use by setting the environment variable shown in the `docker-compose.yml` file:
4143

4244
````
4345
PWC_INTERFACE: "wlan0"
4446
````
4547

46-
To allow for automatic detection, set the variable to `false` or remove the variable from your `docker-compose.yml` file:
48+
To allow for automatic detection, set the variable to `auto` or remove the variable from your `docker-compose.yml` file:
4749

4850
````
49-
PWC_INTERFACE: false
51+
PWC_INTERFACE: "auto"
5052
````
5153

5254
This setting can also be controlled using the `/set_interface` endpoint.
@@ -170,9 +172,9 @@ Requests are returned immediately and then the process is executed. Otherwise us
170172

171173
By default the Wi-Fi network interface is auto-detected. If you need to specify a network interface, you can do so using this endpoint.
172174

173-
To set back to auto-detection, pass `false` as the value.
175+
To set back to auto-detection, pass `auto` as the value.
174176

175-
Changing the setting will only last until the next restart of the container, when it will resort back to the default setting set by the environment variable in the container.
177+
Changing the setting will only last until the next restart of the container, when it will resort back to the default setting set by the environment variable in the container or `auto` if there is no environment variable in the container.
176178

177179
#### POST
178180
````

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ services:
1717
#PWC_AC_PASSWORD: "your-password" # Optional. Must be 8 characters or more.
1818

1919
## Wi-Fi Interface ##
20-
# PWC_INTERFACE: "wlan0" # When disabled interface is auto detected
20+
#PWC_INTERFACE: "auto"
2121

2222
## Enable/Disable LED interaction ##
23-
PWC_LED: "ON"
23+
#PWC_LED: "ON"
2424

2525
## Required system variables ##
2626
DBUS_SYSTEM_BUS_ADDRESS: "unix:path=/host/run/dbus/system_bus_socket"

src/common/system.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def led(mode):
2727
# Activate LED on compatible devices
2828
# 1 = on
2929
# 0 = off
30-
if "PWC_LED" in os.environ and os.environ['PWC_LED'].lower() == 'on':
30+
if "PWC_LED" not in os.environ or ("PWC_LED" in os.environ and
31+
os.environ['PWC_LED'].lower() == 'on'):
3132
try:
3233
with open('/sys/class/leds/led0/brightness', 'w+') as f:
3334
f.write(str(mode))

src/common/wifi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def get_connection_id():
217217

218218
def get_device():
219219
# Configured interface variable takes precedent.
220-
if config.interface:
220+
if config.interface.lower() != config.auto_interface:
221221
logger.debug(f"Interface {config.interface} selected.")
222222
for device in Pnm.NetworkManager.GetDevices():
223223
if device.DeviceType != Pnm.NM_DEVICE_TYPE_WIFI:

src/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@
3737
auto_connect_kargs = False
3838

3939
# Set default interface
40+
auto_interface = 'auto'
4041
if "PWC_INTERFACE" in os.environ and \
41-
os.environ['PWC_INTERFACE'].lower() != 'false':
42+
os.environ['PWC_INTERFACE'].lower() != auto_interface:
4243
interface = os.environ['PWC_INTERFACE']
4344
else:
44-
interface = False
45+
interface = auto_interface
4546

4647
# Default access point name. No need to change these under usual operation as
4748
# they are for use inside the app only. PWC is acronym for 'Py Wi-Fi Connect'.

src/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
time.sleep(10)
5050

5151
# Log interface status
52-
if config.interface:
52+
if config.interface.lower() != config.auto_interface:
5353
logger.info(f"Interface set to {config.interface}")
5454

5555
# If the Wi-Fi connection or device is already active, do nothing

0 commit comments

Comments
 (0)