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
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Java call parameters
|
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
|
||||||
WEBAPP="wss://localhost/websocket/invoice?access_token="
|
source ${DIR}/configuration.sh
|
||||||
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"
|
|
||||||
|
|
||||||
usage(){
|
usage(){
|
||||||
cat << EOF
|
cat << EOF
|
||||||
@@ -27,16 +22,17 @@ EOF
|
|||||||
|
|
||||||
# Start all services on the beer tap device
|
# Start all services on the beer tap device
|
||||||
app_start(){
|
app_start(){
|
||||||
|
JAR=${BRIDGE_JARPATH}${BRIDGE_JARFILE}
|
||||||
# Check if the websocket bridge has been built
|
# Check if the websocket bridge has been built
|
||||||
if [ ! -f $JARPATH$JARFILE ]; then
|
if [ ! -f ${JAR} ]; then
|
||||||
app_build
|
app_build
|
||||||
fi
|
fi
|
||||||
# Start up the dashboard
|
# Start up the dashboard
|
||||||
source dashboard/dashboard.sh
|
source ${DIR}/dashboard/dashboard.sh
|
||||||
# Hide mouse when still
|
# Hide mouse when still
|
||||||
#DISPLAY=:0 unclutter -idle 0.01 -root &
|
#DISPLAY=:0 unclutter -idle 0.01 -root &
|
||||||
# Start websocket bridge, fork to background and no output
|
# 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
|
# Stop all services
|
||||||
@@ -50,10 +46,9 @@ app_stop(){
|
|||||||
# Build or rebuild the java lighning node web bridge
|
# Build or rebuild the java lighning node web bridge
|
||||||
app_build(){
|
app_build(){
|
||||||
echo "Building the websocket bridge please wait"
|
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
|
# Argument parsing
|
||||||
case $1 in
|
case $1 in
|
||||||
start)
|
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
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
|
||||||
|
source $DIR/../configuration.sh
|
||||||
|
|
||||||
# Arguments
|
# Arguments
|
||||||
SHOP="https://localhost/#/self-service-landscape/[pos-Identification]"
|
KIOSK_ARGS="--kiosk --disable-translate --incognito --app=${FRONTEND_URL}"
|
||||||
KIOSK_ARGS="--kiosk --disable-translate --incognito --app=$SHOP"
|
|
||||||
|
|
||||||
# Don't sleep, don't blank, waste energy!
|
# Don't sleep, don't blank, waste energy!
|
||||||
DISPLAY=:0 xset s off
|
DISPLAY=:0 xset s off
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ public class MyStompSessionHandler extends StompSessionHandlerAdapter {
|
|||||||
private static final Logger logger = LoggerFactory.getLogger(MyStompSessionHandler.class);
|
private static final Logger logger = LoggerFactory.getLogger(MyStompSessionHandler.class);
|
||||||
private String topic;
|
private String topic;
|
||||||
private String command;
|
private String command;
|
||||||
|
private String memoPrefix;
|
||||||
|
|
||||||
public MyStompSessionHandler(String topic, String command) {
|
public MyStompSessionHandler(String topic, String command, String memoPrefix) {
|
||||||
this.topic = topic;
|
this.topic = topic;
|
||||||
this.command = command;
|
this.command = command;
|
||||||
|
this.memoPrefix = memoPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,7 +63,7 @@ public class MyStompSessionHandler extends StompSessionHandlerAdapter {
|
|||||||
String memoArg = "--memo=\"" + invoice.getMemo() + "\"";
|
String memoArg = "--memo=\"" + invoice.getMemo() + "\"";
|
||||||
String productsArg = "--products=" + invoice.getOrderedProducts();
|
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");
|
logger.info("Not a beerTap invoice");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -69,9 +71,7 @@ public class MyStompSessionHandler extends StompSessionHandlerAdapter {
|
|||||||
logger.info("Command: " + command + ", Args: " + memoArg + ", " + productsArg);
|
logger.info("Command: " + command + ", Args: " + memoArg + ", " + productsArg);
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(command, memoArg, productsArg);
|
ProcessBuilder pb = new ProcessBuilder(command, memoArg, productsArg);
|
||||||
|
|
||||||
Map<String, String> env = pb.environment();
|
Map<String, String> env = pb.environment();
|
||||||
env.put("PUZZLE_POS", "beerTap");
|
|
||||||
pb.directory(new File("./"));
|
pb.directory(new File("./"));
|
||||||
Process p = pb.start();
|
Process p = pb.start();
|
||||||
p.waitFor();
|
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_URL = "ws://localhost/websocket/invoice?access_token=";
|
||||||
private static String DEFAULT_TOPIC = "/topic/invoice";
|
private static String DEFAULT_TOPIC = "/topic/invoice";
|
||||||
private static String DEFAULT_COMMAND = "./dummy_command.sh";
|
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_URL = "url";
|
||||||
private static String OPTION_ARG_TOPIC = "topic";
|
private static String OPTION_ARG_TOPIC = "topic";
|
||||||
private static String OPTION_ARG_COMMAND = "command";
|
private static String OPTION_ARG_COMMAND = "command";
|
||||||
|
private static String OPTION_ARG_MEMO_PREFIX = "prefix";
|
||||||
|
|
||||||
private String url = DEFAULT_URL;
|
private String url = DEFAULT_URL;
|
||||||
private String topic = DEFAULT_TOPIC;
|
private String topic = DEFAULT_TOPIC;
|
||||||
private String command = DEFAULT_COMMAND;
|
private String command = DEFAULT_COMMAND;
|
||||||
|
private String memoPrefix = DEFAULT_MEMO_PREFIX;
|
||||||
|
|
||||||
private Thread thread;
|
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("")) {
|
if (args.getOptionValues(OPTION_ARG_COMMAND) != null && !args.getOptionValues(OPTION_ARG_COMMAND).equals("")) {
|
||||||
command = args.getOptionValues(OPTION_ARG_COMMAND).get(0);
|
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{
|
private ListenableFuture<StompSession> connect() throws InterruptedException{
|
||||||
@@ -82,7 +89,7 @@ public class WebsocketBridge implements Runnable, DisposableBean {
|
|||||||
WebSocketClient transport = new SockJsClient(transports);
|
WebSocketClient transport = new SockJsClient(transports);
|
||||||
WebSocketStompClient stompClient = new WebSocketStompClient(transport);
|
WebSocketStompClient stompClient = new WebSocketStompClient(transport);
|
||||||
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
|
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
|
||||||
StompSessionHandler sessionHandler = new MyStompSessionHandler(topic, command);
|
StompSessionHandler sessionHandler = new MyStompSessionHandler(topic, command, memoPrefix);
|
||||||
|
|
||||||
ListenableFuture<StompSession> session = null;
|
ListenableFuture<StompSession> session = null;
|
||||||
|
|
||||||
@@ -100,12 +107,9 @@ public class WebsocketBridge implements Runnable, DisposableBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ListenableFuture<StompSession> session = null;
|
ListenableFuture<StompSession> session = null;
|
||||||
|
|||||||
@@ -15,5 +15,4 @@ public class WebsocketBridgeApplication {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(WebsocketBridgeApplication.class, args);
|
SpringApplication.run(WebsocketBridgeApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user