After downloading, the software is updated immediately. But, I am tasked to check if the ECU is currently at IDLE state before updating the software. Is there a way for me to delay the update even though the artifact is already downloaded? Which part of the mender codes I can put the checking of the ECU’s state?
I created the following Download_Enter_00 script. It is called but the state does not transition to the next state even after the subscribe_secc function exits. Downloading status is stuck at 69%. Am I missing something?
#!/bin/sh
echo "$(mender -show-artifact): $(basename "$0") was called!" >&2
# This script subscribes to a MQTT topic using mosquitto_sub.
# On each message received, you can execute whatever you want.
# 14 = FW_UpdateSECC
# 5 = FW_UpdateNeeded_SECC
function publish_secc()
{
echo "$(mender -show-artifact): $(basename "$0") - publishing FW_UpdateNeeded_SECC" >&2
while true
do
mosquitto_pub -h localhost -t 'FW_UpdateSECC' -m "{\"FW_UpdateNeeded\":5}"
echo "{ FW_UpdateNeeded:5 }"
done
}
function subscribe_secc()
{
echo "$(mender -show-artifact): $(basename "$0") - waiting for FW_Command = 14" >&2
mosquitto_sub -h localhost -t 'FW_CommandSECC' | while read -r payload
do
# Here is the callback to execute whenever you receive a message:
fwCmd=$(echo "Rx MQTT: ${payload}" | grep -o -E '[0-9]+')
if [ $fwCmd -eq 14 ]
then
kill -9 $(cat /mnt/hero-secc/userdata/publish_secc.pid)
break
else
echo "$(mender -show-artifact): $(basename "$0") - FW_Command = ${fwCmd}" >&2
fi
done
}
publish_secc &
echo $! > /mnt/hero-secc/userdata/publish_secc.pid
subscribe_secc
exit 0
Even though it exits, are you sure all sub processes have also exited, including the background execution and all mosquitto_sub processes? State scripts are executed in their own process group, so I think all sub processes have to exit, not just the mother process.