mirror of
https://github.com/puzzle/lightning-beer-tap.git
synced 2025-12-17 07:04:21 +01:00
Merge pull request #2 from puzzle/feature_configuration
Create single configuration file
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Java call parameters
|
||||
WEBAPP="wss://localhost/websocket/invoice?access_token="
|
||||
OPTS="-Xms128M -Xmx128M -jar"
|
||||
JARFILE="websocket-bridge-0.0.1-SNAPSHOT.jar"
|
||||
JARPATH="websocket_bridge/build/libs/"
|
||||
TOPIC="/topic/invoice"
|
||||
COMMAND="./gpio_handler/gpio_handler.py"
|
||||
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
|
||||
source ${DIR}/configuration.sh
|
||||
|
||||
usage(){
|
||||
cat << EOF
|
||||
@@ -27,16 +22,17 @@ EOF
|
||||
|
||||
# Start all services on the beer tap device
|
||||
app_start(){
|
||||
JAR=${BRIDGE_JARPATH}${BRIDGE_JARFILE}
|
||||
# Check if the websocket bridge has been built
|
||||
if [ ! -f $JARPATH$JARFILE ]; then
|
||||
if [ ! -f ${JAR} ]; then
|
||||
app_build
|
||||
fi
|
||||
# Start up the dashboard
|
||||
source dashboard/dashboard.sh
|
||||
source ${DIR}/dashboard/dashboard.sh
|
||||
# Hide mouse when still
|
||||
#DISPLAY=:0 unclutter -idle 0.01 -root &
|
||||
# Start websocket bridge, fork to background and no output
|
||||
nohup java $OPTS $JARPATH$JARFILE --url=$WEBAPP --topic=$TOPIC --command=$COMMAND & >/dev/null 2>&1
|
||||
nohup java ${BRIDGE_JAVA_OPTS} ${JAR} --url=${WEBSOCKET_URL} --topic=${WEBSOCKET_TOPIC} --command=${GPIO_HANDLER_COMMAND} --prefix=${MEMO_PREFIX} & >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Stop all services
|
||||
@@ -50,10 +46,9 @@ app_stop(){
|
||||
# Build or rebuild the java lighning node web bridge
|
||||
app_build(){
|
||||
echo "Building the websocket bridge please wait"
|
||||
cd websocket_bridge && exec ./gradlew build >/dev/null 2>&1
|
||||
cd ${DIR}/websocket_bridge && exec ./gradlew build >/dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
# Argument parsing
|
||||
case $1 in
|
||||
start)
|
||||
|
||||
26
configuration.sh
Normal file
26
configuration.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
|
||||
|
||||
# ----------------------------------------------
|
||||
# you probably need to edit the following values
|
||||
# ----------------------------------------------
|
||||
|
||||
# the URL where the websocket bridge will connect to to listen for invoices
|
||||
WEBSOCKET_URL="wss://localhost/websocket/invoice?access_token="
|
||||
|
||||
# the URL that is opened in the browser to show the GUI on the screen
|
||||
FRONTEND_URL="https://localhost/#/self-service-landscape/[pos-Identification]"
|
||||
|
||||
# only listen to paid invoices that have the following text at the beginning of their memo
|
||||
MEMO_PREFIX="beerTap"
|
||||
|
||||
# ----------------------------------------------
|
||||
# most likely you don't need to change anything here
|
||||
# ----------------------------------------------
|
||||
BRIDGE_JAVA_OPTS="-Xms128M -Xmx128M -jar"
|
||||
BRIDGE_JARFILE="websocket-bridge-0.0.1-SNAPSHOT.jar"
|
||||
BRIDGE_JARPATH="websocket_bridge/build/libs/"
|
||||
WEBSOCKET_TOPIC="/topic/invoice"
|
||||
GPIO_HANDLER_COMMAND="${DIR}/gpio_handler/gpio_handler.py"
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
|
||||
source $DIR/../configuration.sh
|
||||
|
||||
# Arguments
|
||||
SHOP="https://localhost/#/self-service-landscape/[pos-Identification]"
|
||||
KIOSK_ARGS="--kiosk --disable-translate --incognito --app=$SHOP"
|
||||
KIOSK_ARGS="--kiosk --disable-translate --incognito --app=${FRONTEND_URL}"
|
||||
|
||||
# Don't sleep, don't blank, waste energy!
|
||||
DISPLAY=:0 xset s off
|
||||
|
||||
@@ -21,10 +21,12 @@ public class MyStompSessionHandler extends StompSessionHandlerAdapter {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MyStompSessionHandler.class);
|
||||
private String topic;
|
||||
private String command;
|
||||
private String memoPrefix;
|
||||
|
||||
public MyStompSessionHandler(String topic, String command) {
|
||||
public MyStompSessionHandler(String topic, String command, String memoPrefix) {
|
||||
this.topic = topic;
|
||||
this.command = command;
|
||||
this.memoPrefix = memoPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,7 +63,7 @@ public class MyStompSessionHandler extends StompSessionHandlerAdapter {
|
||||
String memoArg = "--memo=\"" + invoice.getMemo() + "\"";
|
||||
String productsArg = "--products=" + invoice.getOrderedProducts();
|
||||
|
||||
if(invoice != null && !invoice.getMemo().startsWith("beerTap")) {
|
||||
if(invoice != null && !invoice.getMemo().startsWith(memoPrefix)) {
|
||||
logger.info("Not a beerTap invoice");
|
||||
return;
|
||||
}
|
||||
@@ -69,9 +71,7 @@ public class MyStompSessionHandler extends StompSessionHandlerAdapter {
|
||||
logger.info("Command: " + command + ", Args: " + memoArg + ", " + productsArg);
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(command, memoArg, productsArg);
|
||||
|
||||
Map<String, String> env = pb.environment();
|
||||
env.put("PUZZLE_POS", "beerTap");
|
||||
pb.directory(new File("./"));
|
||||
Process p = pb.start();
|
||||
p.waitFor();
|
||||
|
||||
@@ -32,14 +32,17 @@ public class WebsocketBridge implements Runnable, DisposableBean {
|
||||
private static String DEFAULT_URL = "ws://localhost/websocket/invoice?access_token=";
|
||||
private static String DEFAULT_TOPIC = "/topic/invoice";
|
||||
private static String DEFAULT_COMMAND = "./dummy_command.sh";
|
||||
private static String DEFAULT_MEMO_PREFIX = "beerTap";
|
||||
|
||||
private static String OPTION_ARG_URL = "url";
|
||||
private static String OPTION_ARG_TOPIC = "topic";
|
||||
private static String OPTION_ARG_COMMAND = "command";
|
||||
private static String OPTION_ARG_MEMO_PREFIX = "prefix";
|
||||
|
||||
private String url = DEFAULT_URL;
|
||||
private String topic = DEFAULT_TOPIC;
|
||||
private String command = DEFAULT_COMMAND;
|
||||
private String memoPrefix = DEFAULT_MEMO_PREFIX;
|
||||
|
||||
private Thread thread;
|
||||
|
||||
@@ -74,6 +77,10 @@ public class WebsocketBridge implements Runnable, DisposableBean {
|
||||
if (args.getOptionValues(OPTION_ARG_COMMAND) != null && !args.getOptionValues(OPTION_ARG_COMMAND).equals("")) {
|
||||
command = args.getOptionValues(OPTION_ARG_COMMAND).get(0);
|
||||
}
|
||||
|
||||
if (args.getOptionValues(OPTION_ARG_MEMO_PREFIX) != null && !args.getOptionValues(OPTION_ARG_MEMO_PREFIX).equals("")) {
|
||||
memoPrefix = args.getOptionValues(OPTION_ARG_MEMO_PREFIX).get(0);
|
||||
}
|
||||
}
|
||||
|
||||
private ListenableFuture<StompSession> connect() throws InterruptedException{
|
||||
@@ -82,7 +89,7 @@ public class WebsocketBridge implements Runnable, DisposableBean {
|
||||
WebSocketClient transport = new SockJsClient(transports);
|
||||
WebSocketStompClient stompClient = new WebSocketStompClient(transport);
|
||||
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
|
||||
StompSessionHandler sessionHandler = new MyStompSessionHandler(topic, command);
|
||||
StompSessionHandler sessionHandler = new MyStompSessionHandler(topic, command, memoPrefix);
|
||||
|
||||
ListenableFuture<StompSession> session = null;
|
||||
|
||||
@@ -100,12 +107,9 @@ public class WebsocketBridge implements Runnable, DisposableBean {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ListenableFuture<StompSession> session = null;
|
||||
|
||||
@@ -15,5 +15,4 @@ public class WebsocketBridgeApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebsocketBridgeApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user