Created
September 24, 2023 01:56
-
-
Save gtxaspec/89922bef097435d0df93bc7ad2f32733 to your computer and use it in GitHub Desktop.
qr scan openipc
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 | |
| #qrencode 'WIFI:T:WPA;S:<ssid>;P:<ssidpw>;Z:America/Los_Angeles;' -l L -t png -o ~/Downloads/qr.png | |
| 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 | |
| ============= | |
| yaml-cli -i /etc/majestic.yaml -s .audio.enabled true | |
| yaml-cli -i /etc/majestic.yaml -s .audio.volume auto | |
| yaml-cli -i /etc/majestic.yaml -s .audio.srate 16000 | |
| yaml-cli -i /etc/majestic.yaml -s .audio.speakerPinInvert false | |
| yaml-cli -i /etc/majestic.yaml -s .audio.outputEnabled true | |
| echo 'speaker_enabled="true" | |
| speaker_url="http://127.0.0.1/play_audio" | |
| speaker_file=""' > /etc/webui/speaker.conf | |
| # Disable during QR scanning for best read | |
| #yaml-cli -i /etc/majestic.yaml -s .nightMode.enabled false | |
| device_model=$(fw_printenv -n device_model) | |
| case "$device_model" in | |
| "wyze-v3") | |
| echo "ir 850" | |
| yaml-cli -i /etc/majestic.yaml -s .nightMode.backlightPin 47 | |
| yaml-cli -i /etc/majestic.yaml -s .nightMode.irCutPin1 53 | |
| yaml-cli -i /etc/majestic.yaml -s .nightMode.irCutPin1 52 | |
| ;; | |
| "wyze-pan-v2") | |
| yaml-cli -i /etc/majestic.yaml -s .nightMode.backlightPin 60 | |
| yaml-cli -i /etc/majestic.yaml -s .nightMode.irCutPin1 50 | |
| yaml-cli -i /etc/majestic.yaml -s .nightMode.irCutPin1 49 | |
| ;; | |
| "wyze-v2" | "wyze-pan-v1") | |
| yaml-cli -i /etc/majestic.yaml -s .nightMode.backlightPin 49 | |
| ;; | |
| "atomcam-2" | "atomcam-1" | "atomcam-swing") | |
| yaml-cli -i /etc/majestic.yaml -s .nightMode.backlightPin 26 | |
| ;; | |
| "personalcam") | |
| yaml-cli -i /etc/majestic.yaml -s .nightMode.backlightPin 26 | |
| ;; | |
| *) | |
| echo "device unknown, disable backlight" | |
| ;; | |
| esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment