#!/bin/sh

sudo systemctl start mosquitto.service

topic='test/topic'


(
    echo "[mosquitto_pub] publishing (no retain)"
    mosquitto_pub -t $topic -m 'helloWorld' 
)

(
    echo "[mosquitto_sub] listening"
    mosquitto_sub -v -t $topic
) & listener_pid=$!

sleep 1s
kill $listener_pid


(
    echo "[mosquitto_pub] publishing (retain set)"
    mosquitto_pub -t $topic -m 'helloWorld' -r
)

(
    echo "[mosquitto_sub] listening"
    mosquitto_sub -v -t $topic
) & listener_pid=$!

sleep 1s
kill $listener_pid


sudo systemctl stop mosquitto.service
