Skip to content

Commit da1d3ea

Browse files
committed
Allow auto detection of bridge networks
1 parent 3de3692 commit da1d3ea

File tree

9 files changed

+21
-11
lines changed

9 files changed

+21
-11
lines changed

Dockerfile.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ COPY --from=python-buildstep /root/.local /root/.local
4141
# Insert application
4242
COPY src .
4343

44-
# Check for database migrations then launch controller
45-
CMD ["python3", "run.py"]
44+
# Run the start script
45+
CMD ["sh", "start.sh"]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ If you would prefer to only allow access from your backend, change the `PWC_HOST
3939

4040
Users will then be unable to access the API `http://your-device:9090/v1/connect`. Your backend container on the device, however, can reach the API using `http://127.0.0.1:9090/v1/connect`. This is useful if your user interface has a login process, and you only want users to be able to interact with Wi-Fi after logging in.
4141

42-
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`.
42+
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`. On some devices, the default `172.17.0.1` address can not be guaranteed. You can therefore set `PWC_HOST` to `bridge` and it will detect the default Balena Engine bridge on startup and listen on that IP. You wil then need to identify the IP in your other container in order to communicate. The following command in a shell script will get you the IP:
43+
44+
`ip route | awk '/default / { print $3 }'`
4345

4446
## Changing the default network interface
4547

balena.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ assets:
1111
logo:
1212
type: blob.asset
1313
data:
14-
url: "https://github.com/maggie0002/balena-py-wifi-connect/main/logo.png"
14+
url: "https://raw.githubusercontent.com/maggie0002/balena-py-wifi-connect/main/logo.png"

logo.png

43.9 KB
Loading

src/.env_vars

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env
2+
3+
# Exports the current bridge network IP address
4+
export BRIDGE_NETWORK_IP=$(ip route | awk '/br-/ { print $7 }')

src/common/wifi.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
from time import sleep
1515

1616

17-
# Import DBus mainloop for NetworkManager use
18-
from dbus.mainloop.glib import DBusGMainLoop
19-
20-
DBusGMainLoop(set_as_default=True)
21-
22-
2317
def analyse_access_point(ap):
2418
security = config.type_none
2519

src/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
hotspot_password = None
1414

1515
# Set default host.
16-
if "PWC_HOST" in os.environ:
16+
if "PWC_HOST" in os.environ and os.environ["PWC_HOST"].lower() == "bridge":
17+
host = os.environ["BRIDGE_NETWORK_IP"]
18+
elif "PWC_HOST" in os.environ:
1719
host = os.environ["PWC_HOST"]
1820
else:
1921
host = "0.0.0.0"

src/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@
7171
else:
7272
connect()
7373

74+
logger.info(f"Listening on {host} port {port}")
7475
serve(app, host=host, port=port)

src/start.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env
2+
3+
# Import env variables
4+
. .env_vars
5+
6+
# Execute Python script
7+
exec python3 -u run.py

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy