Skip to content

Instantly share code, notes, and snippets.

@ericboehs
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ericboehs/151176f98682aab65c0b to your computer and use it in GitHub Desktop.
Save ericboehs/151176f98682aab65c0b to your computer and use it in GitHub Desktop.
Script for automating connecting Spark Core device to WiFi via USB (OS X)
#! /usr/bin/env bash
#
# You will need the spark core cli installed first (and nodejs):
# npm install -g spark-cli
# spark cloud login
#
# To set SSID and PASSPHRASE, change below or run:
# git config spc.wifi.ssid YOUR_SSID
# git config spc.wifi.passphrase YOUR_PASSPHRASE
set -e
SSID="$(git config --get spc.wifi.ssid)"
PASSPHRASE="$(git config --get spc.wifi.passphrase)"
ENCRYPTION_TYPE=3
SILENT="false"
SPARK_TTY="$(spark serial list | grep dev | awk '{print $2}')"
[[ ! -e $SPARK_TTY ]] && \
echo "Spark Core not found. Ensure it is connected via USB and in listening mode (flashing blue)." && \
echo "To enter listening mode, hold the mode button for 3 seconds." && \
exit 1
stty -f $SPARK_TTY 9600
if [ "$SILENT" != "true" ]; then
echo "Reading from Spark Core. Password ommited from output..."
echo
grep -v Password $SPARK_TTY &
cat_pid=$!
fi
echo -n "w" > $SPARK_TTY
sleep 0.5
echo $SSID > $SPARK_TTY
sleep 0.5
echo $ENCRYPTION_TYPE > $SPARK_TTY
sleep 0.5
echo $PASSPHRASE > $SPARK_TTY
if [ "$SILENT" != "true" ]; then
sleep 9
kill $cat_pid
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment