#!/bin/sh
START_TIME="$1"
TIME_ZONE="$2"
PAYLOAD="$3"

# cfg_date=`date -d "$START_TIME $TIME_ZONE" '+%H:%M %a'`
now=`date '+%a %H:%M'`
# now_date = `date -d "$now $TIME_ZONE" +%s`

# cfg_week = `echo "$cfg_date" | awk -F ' ' '{print $1}'`
# cfg_week = `echo "$cfg_date" | awk -F ' ' '{print $2}'`


if [ "`date +%a`" == "`date -d "$START_TIME $TIME_ZONE" '+%a'`" ]; then
    if [ "`date -d "$START_TIME $TIME_ZONE" '+%s'`" -ge "`date +%s`" ];then
        immd=1
    fi
fi

if [ -n "$immd" ]; then
    echo "mosquitto_pub  -t ipc/IFU/BatterySchedule/Start -m '$PAYLOAD'" | at `date -d "$START_TIME $TIME_ZONE" '+%H:%M'`
    #echo "mosquitto_pub  -t ipc/IFU/BatterySchedule/Start -m '$PAYLOAD'"
else
    echo "mosquitto_pub  -t ipc/IFU/BatterySchedule/Start -m 'PAYLOAD'" | at `date -d "$START_TIME $TIME_ZONE" '+%H:%M %a'`
    #echo "mosquitto_pub  -t ipc/IFU/BatterySchedule/Start -m '$PAYLOAD'"
fi

