-
-
Save alexszilagyi/35fddf9b675eddb71ce2b142a4c1083a to your computer and use it in GitHub Desktop.
OpenBalena - WiFi Connect & Node-Red
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
version: '2.1' | |
services: | |
wifi-connect: | |
build: ./wifi-connect | |
network_mode: "host" | |
labels: | |
io.balena.features.dbus: '1' | |
cap_add: | |
- NET_ADMIN | |
environment: | |
DBUS_SYSTEM_BUS_ADDRESS: "unix:path=/host/run/dbus/system_bus_socket" | |
PORTAL_SSID: 'My custom AP' | |
PORTAL_PASSPHRASE: 'myCustomAPPassword' | |
BALENA_ARCH: rpi | |
BALENA_MACHINE_NAME: raspberry-pi | |
node-red: | |
build: ./node-red/node-red | |
volumes: | |
- 'volume-data:/data' | |
restart: always | |
privileged: true | |
network_mode: host | |
labels: | |
io.balena.features.supervisor-api: '1' | |
cap_add: | |
- SYS_RAWIO | |
devices: | |
- '/dev/mem:/dev/mem' | |
- '/dev/gpiomem:/dev/gpiomem' | |
- '/dev/i2c-1:/dev/i2c-1' | |
ports: | |
- 1880:80 | |
volumes: | |
volume-data: |
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
FROM balenablocks/wifi-connect:%%BALENA_ARCH%% | |
COPY ./scripts/start.sh . |
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
#!/usr/bin/env bash | |
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket | |
# Optional step - it takes couple of seconds (or longer) to establish a WiFi connection | |
# sometimes. In this case, following checks will fail and wifi-connect | |
# will be launched even if the device will be able to connect to a WiFi network. | |
# If this is your case, you can wait for a while and then check for the connection. | |
# sleep 15 | |
# Choose a condition for running WiFi Connect according to your use case: | |
# 1. Is there a default gateway? | |
# ip route | grep default | |
# 2. Is there Internet connectivity? | |
# nmcli -t g | grep full | |
# 3. Is there Internet connectivity via a google ping? | |
wget --spider http://google.com 2>&1 | |
# 4. Is there an active WiFi connection? | |
#iwgetid -r | |
if [ $? -eq 0 ]; then | |
printf 'Skipping WiFi Connect\n' | |
else | |
printf 'Starting WiFi Connect\n' | |
./wifi-connect -s $PORTAL_SSID -p $PORTAL_PASSPHRASE | |
fi | |
# Start your application here. | |
sleep infinity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment