Skip to content

Instantly share code, notes, and snippets.

@alexszilagyi
Created June 19, 2021 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexszilagyi/35fddf9b675eddb71ce2b142a4c1083a to your computer and use it in GitHub Desktop.
Save alexszilagyi/35fddf9b675eddb71ce2b142a4c1083a to your computer and use it in GitHub Desktop.
OpenBalena - WiFi Connect & Node-Red
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:
FROM balenablocks/wifi-connect:%%BALENA_ARCH%%
COPY ./scripts/start.sh .
#!/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