Created
August 28, 2023 09:20
-
-
Save gtxaspec/0c1006d557ed7a7773017b46949717ef to your computer and use it in GitHub Desktop.
openipc qrcode scan demo
This file contains hidden or 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
| #!/bin/sh | |
| #PHONE DISPLAY SHOULD BE SET TO LOWEST BRIGHTNESS FOR QRSCAN TO WORK PROPERLY | |
| CURL_BIN=$(which curl) | |
| QRSCAN_BIN=$(which qrscan) | |
| #Enable night mode for improved scanning | |
| $CURL_BIN -s http://127.0.0.1/night/on | |
| scan_loop() { | |
| local INTERVAL=0.5 # Interval for each QR scan attempt | |
| local COUNTER=0 # Counter to keep track of time since last play_intro | |
| play_intro | |
| while :; do | |
| $CURL_BIN -s -o /tmp/img.jpg http://127.0.0.1/image.jpg | |
| QR_OUTPUT=$($QRSCAN_BIN -p /tmp/img.jpg) | |
| if [ -n "$QR_OUTPUT" ] && echo "$QR_OUTPUT" | grep -q "ERROR"; then | |
| echo "Scan failed, please try again" | |
| elif [ -n "$QR_OUTPUT" ] && echo "$QR_OUTPUT" | grep -q "WIFI"; then | |
| # If Z: is present, extract the timezone | |
| if echo "$QR_OUTPUT" | grep -q "Z:"; then | |
| TZ=$(echo "$QR_OUTPUT" | awk -F'Z:' '{print $2}' | awk -F';' '{print $1}') | |
| fi | |
| # QR Code scanned OK | |
| break | |
| fi | |
| # Increment counter | |
| COUNTER=$(echo "$COUNTER + $INTERVAL" | bc) | |
| sleep $INTERVAL | |
| # Check if it's time to play the intro again | |
| if [ $(echo "$COUNTER >= 5" | bc) -eq 1 ]; then | |
| play_intro | |
| COUNTER=0 | |
| fi | |
| done | |
| PARSED_OUTPUT=$(qrparse $(echo "$QR_OUTPUT" | head -1)) | |
| SSID=$(echo "$PARSED_OUTPUT" | awk -F' = ' '/SSID/ {print $2}') | |
| PASSWORD=$(echo "$PARSED_OUTPUT" | awk -F' = ' '/Password/ {print $2}') | |
| fw_setenv wlanssid $SSID | |
| fw_setenv wlanpass $PASSWORD | |
| fw_setenv timezone $TZ | |
| } | |
| play_intro() { | |
| echo "Waiting for QR Code" | |
| #/usr/sbin/playonspeaker.sh -f wait_qr.wav | |
| } | |
| scan_ok() { | |
| echo "QR Code scanned" | |
| #/usr/sbin/playonspeaker.sh -f qr_ok.wav | |
| $CURL_BIN -s http://127.0.0.1/night/off | |
| rm -f /tmp/img.jpg | |
| } | |
| # Invoke the scan_loop function | |
| scan_loop | |
| scan_ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment