Fire a command at a specific time.
I was wondering how to fire commands at specific times now. I used to put it in the define_program section as the IF(TIME = XX:XX:XX or ??), but now I am putting it in my feedback timeline. I feel like there is a more processor friendly approach here. I might be wrong of course
. How do you guys do it?
0
Comments
My preferred method is that I convert all times to an integer starting at midnight. it's basically minutes past midnight. (ex: 3:00 AM equals 180 minutes. there are 1440 minutes per day) I then do a quick check if current time equals the "do something" time - go do it. You can easily also just do the IF(TIME = XX:XX:XX or ??) thing as well.
Obviously the timeline needs to be repeating. Also, there have been times I've seen timelines stall for no apparent reason. I've built in a little named wait in each timeline that gets cancelled upon entering the timeline but restarted when the code section completes. The named wait has code to restart the timeline if it's killed for some reason.
I think they've fixed the bug in FW (this seemed to happen with the first NX series) but I'm probably a little superstitious and gun-shy. Once bitten, twice shy...
An early version of NX FW had a bug that would kill timelines after like 50 days (it had to do with transitioning from 32bit to 64bit).
Paul
in my main I'll have something like this:
DEFINE_FUNCTION fnMain_EveryMinute(INTEGER iMinute) { fnPingURL_CheckMinute(iMinute); fnSnowMelt_EveryMinute(); if(iMinute % 5 == 0 || iMinute == 0)//ever 5 minutes check { fnOfficeFan_EveryMinute(); } if(iMinute == 15 && sMyTime.n24Hour == 6 && !nDisable_Auto_CAM_PIR) { nDisable_Auto_CAM_PIR = 1; } else if(iMinute == 10 && sMyTime.n24Hour == 8 && nDisable_Auto_CAM_PIR) { nDisable_Auto_CAM_PIR = 0; } } DEFINE_FUNCTION fnMain_EverySecond(INTEGER iSecond) { fnTest_RunTests(); fnHAI_IntPIR_1HR_Timer(); fnHAI_ExtPIR_1HR_Timer(); fnUIs_PIR_1HR_Timer(); //not these // nAway[AWAY_INDX_FH1] = [dvRelaysSys1,RELAY_CHNL_FLRHEAT_1] == 0; // nAway[AWAY_INDX_FH2] = [dvRelaysSys1,RELAY_CHNL_FLRHEAT_2] == 0; // SEND_LEVEL dvTP_Arry,LVL_AWAY_FH1,nAway[AWAY_INDX_FH1]; // SEND_LEVEL dvTP_Arry,LVL_AWAY_FH2,nAway[AWAY_INDX_FH2]; // SEND_LEVEL dvTP_Arry,LVL_AWAY_VST,nAway[AWAY_INDX_VST]; // // [dvTP_Arry,I0_FBCHNL_BYP_FLRHT_1] = nIO_Array[IO_CHNL_BYP_FLRHT_1]; // [dvTP_Arry,I0_FBCHNL_BYP_FLRHT_2] = nIO_Array[IO_CHNL_BYP_FLRHT_2]; [dvTP_HAIArray,nEXTPIR_BLOCK] = nDisable_Auto_CAM_PIR; [dvTP_HAIArray,nEXTPIR_BLOCK_5] = nDisable_Auto_CAM_PIR_5min; } DEFINE_FUNCTION fnMain_250ms_Clock()//main feedback / called directly from the timeline time event every 250ms { LOCAL_VAR INTEGER nTicToc; LOCAL_VAR INTEGER nIntLight; STACK_VAR INTEGER i; local_var integer nSBFBRunOnce local_var integer nVStatRunOnce fnRunHWI_FB(); fnCalculator_FB(); fnSServer_CheckListener(); nWaterSense_Wet = ([dv_IO,IO_WATER_SENSE] || nWaterSenseTmr); [dvUI_Arry,BTN_SNOW_MELT] = nSnowMelt_On; [dvUI_Arry,BTN_WATER_SENSE] = nWaterSense_Wet; [dvUI_Arry,CHNL_OFFICE_FAN_FB] = ![dvRelays,RLY_OFFICE_FAN]; SEND_LEVEL dvUI_Arry,LVL_OFFICE_FAN,nOfficeFan; nTicToc++;//control timing. Every count is 250ms SWITCH(nTicToc)//create and add other clocks as needed { CASE 1: CASE 3:{} CASE 2: CASE 4://every 500ms { fnAVSys_500ms_Clock(); nTicToc = 0; } DEFAULT: { if(nTicToc > 4) { nTicToc = 0; } } }This also has a 250ms function call to trigger things faster than every second like FB routines or triggering send queues so this one include can be used for everything on the main side in you want. It also keeps track on everything else time related I could think of like day occurrence per month which is useful for some holiday calculations and DST stuff.