#!/bin/bash

SVC=afm-service-agl-service-bluetooth--
PORT=$(grep -sr X-AFM-http /var/local/lib/systemd/system/$SVC*.service | cut -f2 -d'=' )

function ts() { date +"%H:%M:%S %N" | awk '{printf("%s.%03d\n",$1,$2/10^6);}'; }
function logts() { echo "--- $(ts): $@"; }

# restart agl-service-bluetooth
logts "restart $SVC"
systemctl restart $SVC*@0.service

for x in {1..10}; do
	logts "power - try $x"
	afb-client-demo "ws://localhost:$PORT/api?token=HELLO" Bluetooth-Manager power
	sleep 0.1
done

