@@ -10,12 +10,13 @@ set -e
1010set -o pipefail
1111
1212# Default configuration can be overloaded from env
13- CONFIG_S2V2_ENABLED=" defined" # TODO: https://github.com/Z-Wave-Alliance/z-wave-stack/pull/700
13+ CONFIG_PLAY_LOOP=false
14+ CONFIG_S2V2=true # TODO: https://github.com/Z-Wave-Alliance/z-wave-stack/pull/700
1415
1516# To be explicilty added to env
1617sudo=" ${sudo:= } "
1718
18- duration=5 # Allocated time in mins until watchdog quit
19+ duration=8 # Allocated time in mins until watchdog quit
1920
2021ZPC_COMMAND=" ${ZPC_COMMAND:=/ usr/ bin/ zpc} "
2122
9798{
9899 [ " $debug " != " " ] && echo \
99100 || clear > /dev/null 2>&1 || reset > /dev/null 2>&1 || :
100- printf " ${yellow} info: $@ ${nocol} \n"
101+ printf " ${nocol}${ yellow} info: $@ ${nocol} \n"
101102}
102103
103104
@@ -145,12 +146,14 @@ sub_()
145146 local sub=" #"
146147 local count=1
147148 local expect=" "
148- local delay=1
149+ local delay=0
149150
150151 [ " $1 " = " " ] || sub=" $1 "
151152 [ " $2 " = " " ] || expect=" $2 "
152153 [ " $3 " = " " ] || count=" $3 "
153154 [ " $4 " = " " ] || delay=" $4 "
155+ [ " " != " $sub " ] || sub=" $pub "
156+ [ " " != " $expect " ] || expect=" $sub "
154157
155158 printf " ${cyan} sub: $sub ${nocol} (count=${count} )\n"
156159 mosquitto_sub -v -t " $sub " -C $count | tee " $mqtt_sub_log "
@@ -186,15 +189,17 @@ pubsub_()
186189 [ " " = " $debug " ] || log_ " pubsub_: $@ "
187190 local pub=" $1 "
188191 local message=" $2 "
189- local sub=" $pub "
190- local expect=" $sub "
192+ local sub=" "
193+ local expect=" "
191194 local delay=1
192195 local count=1
193196
194197 [ " $3 " = " " ] || sub=" $3 "
195198 [ " $4 " = " " ] || expect=" $4 "
196199 [ " $5 " = " " ] || count=" $5 "
197200 [ " $6 " = " " ] || delay=" $6 "
201+ [ " " != " $sub " ] || sub=" $pub "
202+ [ " " != " $expect " ] || expect=" $sub "
198203
199204 if [ " " != " $pub " ] ; then
200205 printf " ${green} pub: $pub ${nocol} \n"
@@ -208,8 +213,9 @@ pubsub_()
208213 sleep $delay # Needed to dedup
209214 if [ " " != " $sub " ] ; then
210215 sub_ " $sub " " $expect " " $count "
216+ else
217+ sleep 1
211218 fi
212- sleep 1
213219 [ " 0" = " $code " ] || exit_ $code # Quit on 1st failure
214220}
215221
@@ -344,7 +350,7 @@ zpc_cli_()
344350 for (( i= 0 ; i< ${# string} ; i++ )) ; do
345351 char=" ${string: $i : 1} "
346352 screen -S " $name " -p " zpc" -t zpc -X stuff " $char "
347- sleep .1
353+ sleep .01
348354 done
349355 screen -S " $name " -p " zpc" -t zpc -X stuff " ^M"
350356 sleep 1
@@ -358,27 +364,27 @@ play_net_add_node_()
358364 node=" soc_switch_on_off"
359365 [ -z $1 ] || node=" $1 "
360366
361- [ 0 -eq 0$nodeid ] || exit_ 21
362-
363367 command=" add_node"
364- log_ " net: $command : (node should be set in learn mode) "
368+ log_ " net: $command : Node should not be included: $node "
365369 node_cli_ " $node " H
370+ [ 0 -eq 0$nodeid ] || exit_ 21
366371
372+ log_ " net: Find controller"
367373 controller_cli_ H
368374 controller_cli_ n
369375
376+ log_ " net: $command : Find controller: $contid "
370377 sub=" ucl/by-unid/$contunid /State"
371378 json=' {"MaximumCommandDelay":0,"NetworkList":[""],"NetworkStatus":"Online functional","Security":"Z-Wave S2 Access Control"}'
372379 expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
373380 sub_ " $sub " " $expect "
374381
375- log_ " net: ${command} : node: Set to learn mode"
382+ log_ " net: ${command} : node: Set to learn mode: $nodeid : $node "
376383 node_cli_ " $node " n
377384 [ 0 -eq 0$nodeid ] || exit_ 16
378385 node_cli_ " $node " l
379- node_cli_ " $node " n
380386
381- log_ " net: cont: Add node "
387+ log_ " net: ${command} : inclusion: $nodeid into ${homeid} "
382388 pub=" ucl/by-unid/$contunid /ProtocolController/NetworkManagement/Write"
383389 message=' {"State":"add node"}'
384390 sub=" ucl/by-unid/+/State/SupportedCommands"
@@ -390,16 +396,16 @@ play_net_add_node_()
390396 node_cli_ " $node " n # Should not be 0
391397 pub=' '
392398 sub=$( echo " $sub " | sed -e " s|/+/|/$nodeunid /|g" )
393- pubsub_ " $pub " " $message " " $sub " " $sub "
399+ pubsub_ " $pub " " $message " " $sub "
394400
395401 node_cli_ " $node " d
396402 node_cli_ " $node " n
397403
398- log_ " Takes time from interviewing to functional "
404+ log_ " net: ${command} : Pass SecurityCode= ${SecurityCode} of $node to controller "
399405 pub=" ucl/by-unid/$contunid /ProtocolController/NetworkManagement/Write"
400406 message=' {"State":"add node","StateParameters":{"UserAccept":true,"SecurityCode":"' ${SecurityCode} ' ","AllowMultipleInclusions":false}}'
401407 sub=" ucl/by-unid/$nodeunid /State"
402- pub_ " $pub " " $message "
408+ pubsub_ " $pub " " $message " " $sub "
403409
404410 NetworkStatus=' .*' # Match: [ "Online interviewing", "Online functional" ]
405411 MaximumCommandDelay=' .*' # Variable: 1, 300
@@ -414,19 +420,11 @@ play_net_add_node_()
414420 over_expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
415421 over_expect=" $sub $over_expect "
416422 over=false
417- while ! $over ; do # Multiple steps: "Online interviewing"+
423+ while ! $over ; do # Multiple steps: "Online interviewing"+
418424 sub_ " $sub " " $expect "
419- # "Z-Wave S2 Authenticated"
420- grep -E " $over_expect " " $mqtt_sub_log " && over=true || :
425+ grep -E " $over_expect " " $mqtt_sub_log " && over=true || sleep 5
421426 done
422427
423- sub=" ucl/by-unid/+/State/Attributes/EndpointIdList/Reported"
424- sub=$( echo " $sub " | sed -e " s|/+/|/$nodeunid /|g" )
425- json=' {"value":[0]}'
426- expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
427- expect=" $sub $expect "
428- # sub_ "$sub" "$expect"
429-
430428 node_cli_ " $node " H # expected on 1st time
431429 [ $conthomeid = $nodehomeid ] || exit_ 17
432430 node_cli_ " $node " n # 2 expected on 1st time
@@ -465,88 +463,98 @@ play_node_soc_switch_on_off_()
465463 echo
466464 node=" soc_switch_on_off"
467465 type=" OnOff"
466+
468467 node_cli_ " $node " n
469468 log_ " $type : Play on $nodeunid ~T738437 ~T738442"
470469 attribute=" $type "
471470
472471 message=" {}"
473472 sub=" ucl/by-unid/$nodeunid /ep0/$type /Attributes/$attribute /Reported"
474- expect=" $sub " ' {"value":false}'
473+ json=' {"value":false}'
474+ expect=" $sub $json "
475475 sub_ " $sub " " $expect "
476476
477477 command=" ForceReadAttributes"
478478 message=" { \" value\" : [\" OnOff\" ] }"
479479 pub=" ucl/by-unid/$nodeunid /ep0/$type /Commands/$command "
480480 sub=" ucl/by-unid/$nodeunid /ep0/$type /Attributes/$attribute /Reported"
481- expect=" $sub " ' {"value":false}'
482481 pubsub_ " $pub " " $message " " $sub " " $expect "
483482
484483 command=" Toggle" # T738442
485484 message=" {}"
486485 pub=" ucl/by-unid/$nodeunid /ep0/$type /Commands/$command "
487486 sub=" ucl/by-unid/$nodeunid /ep0/$type /Attributes/$attribute /Reported"
488- expect=" $sub " ' {"value":true}'
487+ json=' {"value":true}'
488+ expect=" $sub $json "
489489 pubsub_ " $pub " " $message " " $sub " " $expect "
490490
491- expect=" $sub " ' {"value":false}'
491+ json=' {"value":false}'
492+ expect=" $sub $json "
492493 pubsub_ " $pub " " $message " " $sub " " $expect "
493494
494495 command=" On" # T738437
495496 pub=" ucl/by-unid/$nodeunid /ep0/$type /Commands/$command "
496- expect=" $sub " ' {"value":true}'
497+ json=' {"value":true}'
498+ expect=" $sub $json "
497499 pubsub_ " $pub " " $message " " $sub " " $expect "
498500
499501 command=" Off" # T738437
500502 pub=" ucl/by-unid/$nodeunid /ep0/$type /Commands/$command "
501- expect=" $sub " ' {"value":false}'
503+ json=' {"value":false}'
504+ expect=" $sub $json "
502505 pubsub_ " $pub " " $message " " $sub " " $expect "
503506
504- log_ " $type : Events from device $nodeunid "
507+ log_ " $type : Events from device $nodeunid : $node "
505508 node_cli_ " $node " 1 # From Off to On
506- expect=" $sub " ' {"value":true}'
509+ json=' {"value":true}'
510+ expect=" $sub $json "
507511 sub_ " $sub " " $expect "
508512 node_cli_ " $node " 1 # From On to Off
509- expect=" $sub " ' {"value":false}'
513+ json=' {"value":false}'
514+ expect=" $sub $json "
510515 sub_ " $sub " " $expect "
511516}
512517
513518
514519play_node_soc_multilevel_sensor_ ()
515520{
516- local app =" soc_multilevel_sensor"
521+ local node =" soc_multilevel_sensor"
517522 node_cli_ " $node " n
518- log_ " $app :: Play on $nodeid ~T738437 ~T738442"
519-
520- log_ " $app : Initial state reported after inclusion"
523+ log_ " $node : Play on $nodeid " # ~T738437 ~T738442
521524
522- key= ' value ' ; key= ' " ' $key ' " ' # JSON quoted string
525+ log_ " $node : Initial state reported after inclusion "
523526
524527 ep=" ep0/Basic/Attributes/PowerSource/Reported"
525528 sub=" ucl/by-unid/${nodeunid} /$ep "
529+ key=" value" ; key=' "' $key ' "' # JSON string
526530 value=' Battery' ; value=' "' $value ' "'
527- expect =' {' $key ' :' $value ' }'
528- expect=" $sub $expect "
531+ json =' {' $key ' :' $value ' }'
532+ expect=" $sub $json "
529533 sub_ " $sub " " $expect "
530534
531535 ep=' ep0/TemperatureMeasurement/Attributes/MeasuredValue/Reported'
532536 sub=" ucl/by-unid/${nodeunid} /$ep "
533537 value=322
534- expect =' {' $key ' :' $value ' }'
535- expect=" $sub $expect "
538+ json =' {' $key ' :' $value ' }'
539+ expect=" $sub $json "
536540 sub_ " $sub " " $expect "
537541
538542 ep=' ep0/RelativityHumidity/Attributes/MeasuredValue/Reported'
539543 sub=" ucl/by-unid/${nodeunid} /$ep "
540544 value=8
541- expect =' {' $key ' :' $value ' }'
542- expect=" $sub $expect "
545+ json =' {' $key ' :' $value ' }'
546+ expect=" $sub $json "
543547 sub_ " $sub " " $expect "
544548
545549 ep=" ep0/PowerConfiguration/Attributes/BatteryPercentageRemaining/Reported"
546550 sub=" ucl/by-unid/${nodeunid} /$ep "
547551 value=100
548- expect=' {' $key ' :' $value ' }'
549- expect=" $sub $expect "
552+ json=' {' $key ' :' $value ' }'
553+ expect=" $sub $json "
554+ sub_ " $sub " " $expect "
555+
556+ log_ " $type : Events from device $nodeunid : $node "
557+ node_cli_ " $node " 1
550558 sub_ " $sub " " $expect "
551559}
552560
@@ -599,7 +607,7 @@ play_node_()
599607 play_node_${node} _
600608 play_net_remove_node_ $node
601609 fi
602- if [ ! -z ${CONFIG_S2V2_ENABLED} ] ; then
610+ if ${CONFIG_S2V2} ; then
603611 play_net_add_node_ $node
604612 play_node_s2v2_
605613 play_net_remove_node_ $node
@@ -616,7 +624,9 @@ play_nodes_()
616624 soc_multilevel_sensor
617625 )
618626 for node in ${nodes[@]} ; do
619- play_node_ $node
627+ node_cli_ $node h
628+ play_node_ $node || code=$?
629+ [ 0$code -eq 0 ] || break
620630 done
621631}
622632
@@ -640,8 +650,11 @@ play_()
640650 expect=$( echo " $json " | sed ' s/\[/\\[/g; s/\]/\\]/g' )
641651 sub_ " $sub " " $expect "
642652
643- play_nodes_ || code=$?
644-
653+ until ! ${CONFIG_PLAY_LOOP} ; do
654+ play_nodes_ || code=$?
655+ [ 0$code -eq 0 ] || break
656+ done
657+
645658 exit_ 0$code
646659}
647660
@@ -683,35 +696,32 @@ default_()
683696
684697 log_ " z-wave-stack-binaries: Check presence in ${z_wave_stack_binaries_bin_dir} "
685698 file -E " ${z_wave_stack_binaries_bin_dir} /" * " REALTIME" * " .elf"
686- sleep 2
687-
699+ sleep 1
700+
688701 cat << EOF | tee "$file "
689702# https://www.gnu.org/software/screen/manual/screen.html#Command-Summary
690703
691704hardstatus alwayslastline
692-
693705split -v
694- screen -t "ncp_serial_api_controller" "1" $0 run_app_ ncp_serial_api_controller
695- sleep 1
706+ focus left
696707
697708split
698- focus down
709+ focus up
710+ screen -t "ncp_serial_api_controller" "1" $0 run_app_ ncp_serial_api_controller
711+
712+ split -v
713+ focus right
699714screen -t "soc_switch_on_off" "2" $0 run_app_ soc_switch_on_off
700- sleep 1
701715
702- split
703- focus down
716+ split -v
717+ focus right
704718screen -t "soc_multilevel_sensor" "3" $0 run_app_ soc_multilevel_sensor
705- sleep 1
706719
707- split
708720focus down
709- screen -t "zpc" "7" $0 run_ zpc
710- sleep 2
721+ screen -t "zpc" "0" $0 run_ zpc
711722
712723focus right
713724screen -t "mqtt" "8" $0 run_ mqtt
714- sleep 1
715725
716726split
717727focus down
0 commit comments