rm -f ./CLI_OK ./PLC_OK ./PLC_CONNECTED
# Start runtime one first time to generate PLC PSK
$BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_service.py -s psk.txt -n test_wamp_ID -x 0 &
res=110 # default to ETIMEDOUT
if [[ -a psk.txt ]]; then
if [ "$res" != "0" ] ; then
echo timeout generating PSK.
IFS=':' read -r PLC_wamp_ID PLC_wamp_secret < psk.txt
cp -a $BEREMIZPATH/tests/projects/wamp .
# Start CLI one first time to generate IDE PSK
IDE_PSK=$HOME/.local/share/beremiz/keystore/own/default.psk
$BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_cli.py -k \
--project-home wamp connect &
res=110 # default to ETIMEDOUT
if [[ -a $IDE_PSK ]]; then
echo waiting IDE PSK.... $c
if [ "$res" != "0" ] ; then
echo timeout generating IDE PSK.
IFS=':' read -r IDE_wamp_ID IDE_wamp_secret < $IDE_PSK
# Prepare crossbar server configuration
yes "" | openssl req -nodes -new -x509 -keyout ./.crossbar/server.key \
-addext "subjectAltName = DNS:localhost" \
-out ./.crossbar/server.crt
cat > .crossbar/config.json <<JsonEnd
"id": "automation_router",
"certificate": "server.crt",
"secret": "${IDE_wamp_secret}",
"secret": "${PLC_wamp_secret}",
crossbar start &> crossbar_log.txt &
res=110 # default to ETIMEDOUT
if [[ -a .crossbar/node.pid ]]; then
echo wait for crossbar to start.... $c
if [ "$res" != "0" ] ; then
echo timeout starting crossbar.
# give more time to crossbar
# Prepare runtime Wamp config
cat > wampconf.json <<JsonEnd
"url": "wss://localhost:8888/ws"
# Re-use self-signed server cert for client
cp .crossbar/server.crt wampTrustStore.crt
# Start Beremiz runtime again, with wamp enabled
$BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_service.py -c wampconf.json -s psk.txt -n test_wamp_ID -x 0 &> >(
# Wait for server to print modified value
if [[ "$line" =~ ^"WAMP session joined" ]]; then
if [[ "$line" == "PLCobject : PLC started" ]]; then
echo "PLC was programmed"
echo wait for runtime to come up
res=110 # default to ETIMEDOUT
if [[ -a ./PLC_CONNECTED ]]; then
if [ "$res" != "0" ] ; then
echo timeout connecting PLC to crossbar.
# Re-use self-signed server cert for client in test project
cp .crossbar/server.crt wamp/cert/localhost.crt
# TODO: patch project's URI to connect to $BEREMIZ_LOCAL_HOST
# used in tests instead of 127.0.0.1
# Use CLI to build transfer and start PLC
$BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_cli.py -k \
--project-home wamp build transfer run &> >(
# Wait for PLC runtime to output expected value on stdout
if [[ "$line" == "PLC installed successfully." ]]; then
echo "CLI did transfer PLC program"
echo all subprocess started, start polling results
res=110 # default to ETIMEDOUT
if [[ -a ./CLI_OK && -a ./PLC_OK ]]; then
# Kill PLC and subprocess
echo will kill PLC:$PLC_PID, SERVER:$SERVER_PID and CLI:$CLI_PID