rm -f ./CLI_OK ./PLC_OK ./PLC_CONNECTED
# Start runtime one first time to generate 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 wamp_ID wamp_secret < psk.txt
# 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": "${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.
cp -a $BEREMIZPATH/tests/projects/wamp .
# place PSK so that IDE already knows runtime
cp psk.txt wamp/psk/${wamp_ID}.secret
# Re-use self-signed server cert for client
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
setsid $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