PLC Code How To: Webset Every 5 minutes

ccthbsh01

Member
Hi all,
 
I am still pretty new to the WC8 so please excuse me if this should have been obvious. I searched the forum but couldn't come up with the answer.
 
I have my WC8 setup to set variables on my ISY-994 upon the digital input status changes & is working fine. I want to set up a heartbeat to be sent every 5 minutes from the WC8 to the ISY by having the WC8 set an ISY variable every 5 minutes. This way ISY would alert me if the WC8 is down for some reason.
 
My question is how to setup the PLC code to have it do a Webset every 5 minutes? I cannot use delay since that would stop all the other WC8 stuff going on.
 
TIA.
 
Here is one basic idea how you could accomplish this. I created a time slice main routine based on a 6 second repeat / heartbeat.  Remember MOD(ulus) is your friend.
 

SEC0:
MOD CS UROM1 RAM2 # Div C)urrent S)econd by UROM1=6, remainder into RAM2
TSTNE RAM2 0 # check it for 0 remainder = timeslice 0
GOTO SEC0_DUN # not? then forget it
BNZ RAM1B1 SEC1 # Already done this timeslice? Then do next
CALLSUB CLOCK1 #
SET RAM1B1 1 # mark it as complete this timeslice
GOTO MAINLOOP # back to the PLC beginning
SEC0_DUN:
SET RAM1B1 0 # other timeslice? flag ready for next loop

SEC1:
TSTNE RAM2 1 # timeslice at 1 second mark
more PLC jobs

 
 
 
Here is my clock subroutine. I pack all the date and time together and ship it to ISY every 6 seconds and use it for a heartbeat and also to tell ISY what time it is, useable as individual elements.
 

CLOCK1:
TSTLT CYEAR 2014 # if clock isn't valid yet don't send it
GOTO CLOCK_X
MUL CMONTH 100 RAM2 # date and time format will be on integer MMDDhhmmss
ADD RAM2 CDAY RAM2
MUL RAM2 100 RAM2 #shift it left two decimal digits and keep adding LS values
ADD RAM2 CH RAM2
MUL RAM2 100 RAM2
ADD RAM2 CM RAM2
MUL RAM2 100 RAM2
ADD RAM2 CS RAM2
SETLED 1
SET VAR1 RAM2 #RAM2 is my global scratchpad variable.
WEBSET URL1 VAR1 #VAR1 is the last thing sent via WEBSET URL1
SETLED 0
CLOCK_X:
RET

When the WC8 reboots I do a WEBSET URL1 -1   to flag my ISY that the WC8 rebooted. Just for monitoring purposes to establish reliability for now.
If the heartbeat is missing too long an Insteon ON/Off module power cycles the WC8 and the bridged router sending the data to another building where my ISY resides.
Code:
If
        $CAI1_DateTime <= -1
 
Then
    code to record reboot in ISY
 
Else
        Wait  9 seconds
        code to record the first heartbeat period is missed
        Wait  6 seconds
        code to record the second heartbeat period is missed
        Wait  6 seconds
        code to record the third heartbeat period is missed
        Wait  6 seconds
        code to record the fourth heartbeat period is missed
        Wait  60 seconds
        Set 'Workshop / Shop Webcontrol Board' Off
        Wait  15 seconds
        Set 'Workshop / Shop Webcontrol Board' On
 
Hopefully that helps. If there is anything that doesn't make sense feel free to ask.
 
 
 
Which the most annoying?
    "Would you like fries with that?"
   or
   "Is there anything else I can do for you today?"
:D
 
So this what I tried so far to test it:

MOD CM 5 RAM80
TSTEQ RAM80 0
ADD 1 VAR6 VAR6

So VAR6 should increase by 1 every 5 minutes. The problem that I see is that RAM80 stays 0 every 5 minutes for the entire minute which increases VAR6 by thousands. Doing this to Webset a variable on the ISY will hit the ISY thousands of times every 5 minutes.
 
CM has range 0 to 59.  If you conditionally copy CM into another variable RAM80, say only when CM == 0 or CM > RAM80, then you can increase RAM80 when MOD 5 == zero after sending WEBSET.  Since after RAM80 increased after WEBSET, it will no longer get 0 for MOD operation.
 
Look again at the code I posted. See the RAM1B1 bit that is set and cleared?
 
Follow the code and you will see that when CLOCK1 is run the bit is set so that CLOCK1 will not be activated again.
 
When the time is no longer on that second, and safe from further execution, then the bit is cleared again but the time logic isn't right so it won't be run until the next time slice.
 
I doubt you will find another way to stop multiple runnings of your WEBSET without a separate "job done" flag.
I use RAM1B1 to RAM1B8 as individual bit flags for each WEBSET URL1-URL8 port.
 
LarrylLix said:
Look again at the code I posted. See the RAM1B1 bit that is set and cleared?
 
Follow the code and you will see that when CLOCK1 is run the bit is set so that CLOCK1 will not be activated again.
 
When the time is no longer on that second, and safe from further execution, then the bit is cleared again but the time logic isn't right so it won't be run until the next time slice.
 
I doubt you will find another way to stop multiple runnings of your WEBSET without a separate "job done" flag.
I use RAM1B1 to RAM1B8 as individual bit flags for each WEBSET URL1-URL8 port.
 
Hi LarryLix,
 
I am still new to the WC8 and I was having a hard time following your programming as it was too sophisticated for me. I am also still unsure of how the GOTO works and where it goes from there as opposed to the CALLSUB. After reviewing it for along time I think I did get an idea of what you are doing as it pertains to what I am trying to accomplish. So I came up with the following which seems to be working:
 

HEARTBEAT:
MOD CM 5 RAM80 
CZ RAM80 HEARTBT1   
TSTNE RAM80 0  
SET RAM83 0  
RET    
 
HEARTBT1:
CZ RAM83 HEARTBT2   
RET    
 
HEARTBT2:
ADD 1 VAR6 VAR6 
SET RAM83 1  
RET
 
Note that for now I made "HEARTBEAT" into a subroutine just for testing purposes while I am working on it and is being unconditionally called from the main routine. Eventually I will make it part of the main routine.
 
Maybe there is an easier way to do this without so many lines of code and 2 subroutines, but this was the simplest I could come up with for now.
 
Thank you again for your guidance.
 
You're welcome.
 
Looks like you get the idea and are well on your way.
 
As you get more familiar with the conditions testing and some of the weird shortcut methods of test and branch/call opcodes instructions in the PLC language you will feel more comfortable with this and see shorter, more readable and cleaner ways to do it.
 
...
...
If it isn't time - then jump to Not time
If is has been marked already done - then jump to next job
  Do the job - mark it as done - jump over to Next job
 
Not time- safe to mark job NOT done now
 
Next job - do something else
 
Yeah, it's a bit spaghetti bowl code looking at first but without fancy while - do constructs like  high-level languages it has to be a few jump-overs and GOOD labels. Forget how obvious it becomes to you now. Think about when you come back in one year, after you discover a quirk not working right, and think. "Who wrote this confusion?"
 
All the best!
 
 
Help!  I'm turning into a computer!
 
What about a variant not wasting VARs or RAMs, any ideas? May be using a digital output?

Since scratchpad variables are at a premium in  the WC8 I can see that being a possibility. I personally don't like doing it as a future "gottcha' " with some output LED flashing insanely and me wondering if the WC8 has got a mind of it's own.
 
CAI exploded RAM1 into bits (destructive buggers) with the SET RAM1B1-32,  TSTxx RAM1B1-32, etc.  instructions so I figured I should exploit them or nobody will buy me a beer when I go to California next time. :D
 
At first I thought that group of instructions were a little weird but now I see the shortcuts from
    ANDBT RAM1 1024
    GOTO BIT10_SET
   .....
are a little more structured, easier to follow and more standardised with other medium-level languages using the provided for RAM1B1-RAM1B32 instructions.
 
LarrylLix said:
What about a variant not wasting VARs or RAMs, any ideas? May be using a digital output?

Since scratchpad variables are at a premium in  the WC8 I can see that being a possibility. I personally don't like doing it as a future "gottcha' " with some output LED flashing insanely and me wondering if the WC8 has got a mind of it's own.
 
CAI exploded RAM1 into bits (destructive buggers) with the SET RAM1B1-32,  TSTxx RAM1B1-32, etc.  instructions so I figured I should exploit them or nobody will buy me a beer when I go to California next time. :D
 
At first I thought that group of instructions were a little weird but now I see the shortcuts from
    ANDBT RAM1 1024
    GOTO BIT10_SET
   .....
are a little more structured, easier to follow and more standardised with other medium-level languages using the provided for RAM1B1-RAM1B32 instructions.
 
is this a case construct?
switch RAM1:
case 1024:
thanks
 
Back
Top