You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I thought I could share my way how I made my scanstation with barcodebuddy as it is something which works but is definitively something which could be made better as I am not a programmer...
barcodebuddy runs on a virtual server so I couldn't connect directly a barcodescanner but thankfully there is a grabinput.sh in the examples so I thought I could make use of that.
Scanning without knowing what's happening isn't userfriendly so a screen should be there.
But having a screen sitting there forever just for scanning items sometime? When having some kind of smarthomeserver the rest of the time the screen could be used for that, I thought.
So my plan was: Using a raspberry pi with the official touchscreen attached so I have a nice compact unit to attach the scanner, have a screen for bbuddy and a touchscreen for checking and controlling homethings.
After discovering that loops in bash are some kind of tricky because some values couldn't be passed to the script which called them I just made use of cron...
So here is what I did:
Raspberry made ready for headless starting, starting X, start chromium without borders for the homecontrollingsoftware, chromium for bbuddy and an xterm for the modified grabinputscript (just xterm -e /home/pi/grabinput.sh /dev/input/event0 & in the autostart for X)
the modified grabinput.sh script:
#!/bin/bash
SCRIPT_LOCATION="${SCRIPT_LOCATION:="/var/www/html/barcodebuddy/index.php"}"
SERVER_ADDRESS="${SERVER_ADDRESS:="http://blahblah/api/"}"
USE_CURL="${USE_CURL:="true"}"
WWW_USER="${WWW_USER:="www-data"}"
IS_DOCKER="${IS_DOCKER:="false"}"
API_KEY="${API_KEY:=""}"
declare -A CODE_MAP_CHAR=( ["(KEY_0)"]="0" \
["(KEY_1)"]="1" \
["(KEY_2)"]="2" \
["(KEY_3)"]="3" \
["(KEY_4)"]="4" \
["(KEY_5)"]="5" \
["(KEY_6)"]="6" \
["(KEY_7)"]="7" \
["(KEY_8)"]="8" \
["(KEY_9)"]="9" \
["(KEY_KP0)"]="0" \
["(KEY_KP1)"]="1" \
["(KEY_KP2)"]="2" \
["(KEY_KP3)"]="3" \
["(KEY_KP4)"]="4" \
["(KEY_KP5)"]="5" \
["(KEY_KP6)"]="6" \
["(KEY_KP7)"]="7" \
["(KEY_KP8)"]="8" \
["(KEY_KP9)"]="9" \
["(KEY_NUMERIC_0)"]="0" \
["(KEY_NUMERIC_1)"]="1" \
["(KEY_NUMERIC_2)"]="2" \
["(KEY_NUMERIC_3)"]="3" \
["(KEY_NUMERIC_4)"]="4" \
["(KEY_NUMERIC_5)"]="5" \
["(KEY_NUMERIC_6)"]="6" \
["(KEY_NUMERIC_7)"]="7" \
["(KEY_NUMERIC_8)"]="8" \
["(KEY_NUMERIC_9)"]="9" \
["(KEY_A)"]="A" \
["(KEY_B)"]="B" \
["(KEY_C)"]="C" \
["(KEY_D)"]="D" \
["(KEY_E)"]="E" \
["(KEY_F)"]="F" \
["(KEY_G)"]="G" \
["(KEY_H)"]="H" \
["(KEY_I)"]="I" \
["(KEY_J)"]="J" \
["(KEY_K)"]="K" \
["(KEY_L)"]="L" \
["(KEY_M)"]="M" \
["(KEY_N)"]="N" \
["(KEY_O)"]="O" \
["(KEY_P)"]="P" \
["(KEY_Q)"]="Q" \
["(KEY_R)"]="R" \
["(KEY_S)"]="S" \
["(KEY_T)"]="T" \
["(KEY_U)"]="U" \
["(KEY_V)"]="V" \
["(KEY_W)"]="W" \
["(KEY_X)"]="X" \
["(KEY_Y)"]="Y" \
["(KEY_Z)"]="Z" \
["(KEY_DOT)"]="." \
["(KEY_KPDOT)"]="." \
["(KEY_MINUS)"]="-" \
["(KEY_SLASH)"]="-" \
["(KEY_ENTER)"]="KEY_ENTER" \
["(KEY_KPENTER)"]="KEY_ENTER" )
declare NON_ALLOWED_CHAR="NONE";
#removed rootcheck cause this doesn't run as root
#if [[ $EUID -ne 0 ]]; then
# echo "This script must be run as root"
# exit 1
#fi
if [[ $IS_DOCKER == true ]]; then
if [[ $(printenv ATTACH_BARCODESCANNER) != "true" ]]; then
echo "[ScannerConnection] Not starting service, as ATTACH_BARCODESCANNER has not been passed"
exit 0
fi
fi
deviceToUse=""
#If no arguments passed, we check if there is only one input device
#(most likely the case for docker images)
if [ $# -eq 0 ]; then
nInputEvents=$(ls 2>/dev/null -Ubad1 -- /dev/input/event* | wc -l)
if [ $nInputEvents = 1 ]; then
deviceToUse=$(ls /dev/input/event* | head -n 1)
else
echo "No argument provided and more than one device in /dev/input/"
echo "Usage: grabInput.sh /dev/input/eventX"
exit 1
fi
else
deviceToUse="$1"
fi
returnAllowedCharacter() {
for key in "${!CODE_MAP_CHAR[@]}"; do
if [[ $1 =~ "$key" && $1 =~ "time" && $1 =~ "value 1" ]]; then
echo "${CODE_MAP_CHAR[$key]}"
return
fi
done
echo "$NON_ALLOWED_CHAR"
}
enteredText=""
echo "[ScannerConnection] Waiting for scanner input"
# making things ready
wmctrl -a buddy
touch /tmp/focuswindowcron
# end of making ready...
evtest --grab "$deviceToUse" | while read line; do
key="$(returnAllowedCharacter "{$line}")"
if [[ "$key" != "$NON_ALLOWED_CHAR" ]]; then
if [[ "$key" != "KEY_ENTER" ]]; then
enteredText+="$key"
else
echo "[ScannerConnection] Received: $enteredText"
if [[ $USE_CURL == false ]]; then
sudo -H -u $WWW_USER /usr/bin/screen -dm /usr/bin/php "$SCRIPT_LOCATION" $enteredText
else
# setting the window
wmctrl -a buddy
if [[ $(($(date +%s) - $(date +%s -r /tmp/focuswindowcron))) -gt 3600 ]]; then
xdotool key 'ctrl+r'
fi
touch /tmp/focuswindowcron
# end of setting the window...
curl "${SERVER_ADDRESS}action/scan?apikey=${API_KEY}&add=${enteredText}"
fi
enteredText=""
fi
fi
done
What this does is just taking the bbuddy-chromium to foreground and touching a file in /tmp.
The part of checking if the file is older than an hour (3600 seconds) just refreshes the bbuddypage because I sometimes had trouble that it lost the connection to the server. Maybe that isn't necessary anymore, I haven't tried.
Then I have a cronjob running every minute doing this:
#!/bin/bash
export DISPLAY=:0
XAUTHORITY=/home/pi/.Xauthority
if [[ $(($(date +%s) - $(date +%s -r /tmp/focuswindowcron))) -gt 45 ]]; then
wmctrl -a home
fi
Which switches the focus back to my homeautomationwebpage after a moment.
With this setup I have a useful screen for homecontrolling and for bbuddy without having to switch manually things around.
Besides that I used a motionsensor and an ssh-command to turn of the screen when nobody is there.
I think this implementation is far away from elegant but it works. I don't know if this is something which could be polished and put in the examples, too, or somewhere else.
Feel free to close the issue at it isn't really one and if I should put this somewhere else or can do something useful let me know.
This discussion was converted from issue #111 on May 11, 2021 21:06.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I thought I could share my way how I made my scanstation with barcodebuddy as it is something which works but is definitively something which could be made better as I am not a programmer...
barcodebuddy runs on a virtual server so I couldn't connect directly a barcodescanner but thankfully there is a grabinput.sh in the examples so I thought I could make use of that.
Scanning without knowing what's happening isn't userfriendly so a screen should be there.
But having a screen sitting there forever just for scanning items sometime? When having some kind of smarthomeserver the rest of the time the screen could be used for that, I thought.
So my plan was: Using a raspberry pi with the official touchscreen attached so I have a nice compact unit to attach the scanner, have a screen for bbuddy and a touchscreen for checking and controlling homethings.
After discovering that loops in bash are some kind of tricky because some values couldn't be passed to the script which called them I just made use of cron...
So here is what I did:
Raspberry made ready for headless starting, starting X, start chromium without borders for the homecontrollingsoftware, chromium for bbuddy and an xterm for the modified grabinputscript (just
xterm -e /home/pi/grabinput.sh /dev/input/event0 &
in the autostart for X)the modified grabinput.sh script:
What this does is just taking the bbuddy-chromium to foreground and touching a file in /tmp.
The part of checking if the file is older than an hour (3600 seconds) just refreshes the bbuddypage because I sometimes had trouble that it lost the connection to the server. Maybe that isn't necessary anymore, I haven't tried.
Then I have a cronjob running every minute doing this:
Which switches the focus back to my homeautomationwebpage after a moment.
With this setup I have a useful screen for homecontrolling and for bbuddy without having to switch manually things around.
Besides that I used a motionsensor and an ssh-command to turn of the screen when nobody is there.
I think this implementation is far away from elegant but it works. I don't know if this is something which could be polished and put in the examples, too, or somewhere else.
Feel free to close the issue at it isn't really one and if I should put this somewhere else or can do something useful let me know.
Beta Was this translation helpful? Give feedback.
All reactions