Difference between revisions of "Script Examples"

From ArgentWiki
Jump to: navigation, search
(High Altitude Path)
 
(No difference)

Latest revision as of 09:48, 27 February 2013

The following are example scripts for the Scripting system on the Tracker2, Tracker3, and OpenTracker USB.

High Altitude Path

On GPS Fix
  If Altitude > 5096
    If Flags xxxxxxx0
      Exec "path -"
      Set Flags 00000001
    End Block
  End Block
  If Flags xxxxxxx1
    If Altitude < 5000
      Clear Flags 00000001
      Exec "path wide1-1,wide2-1"
    End Block
  End Block
End Block

This script sets a null path above 10,000 feet, and returns to a wider path when the altitude drops. Note the use of the "On GPS Fix" event so that the altitude test executes only when a valid fix is available, and the use of a flag to avoid repeated execution of the PATH command. This could be accomplished with the "Do Once" command, but the use of the flag allows more flexibility - in this example, the low altitude command is executed only after the altitude has exceeded the first threshold and then dropped below the second.

Multiple Announcements

On Second
  Increment Counter 1
  If Counter 1 = 300
    Exec "BEACON First announcement"
  End Block
  If Counter 1 = 600
    Exec "BEACON Second announcement"
    Set Counter 1 = 0
  End Block
End Block

The following script sends two different announcements at 5-minute intervals. This script can be easily expanded to send as many different announcements as will fit in the available script storage.

Weekly Announcements

On Second				;Run Script every second.
  Increment Counter 1			;Keep track of seconds elapsed
  If Counter 1 = 600			;Has 10 minutes elapsed?
    If Counter 3 = 1			;Is it the first day of the week?
      Exec "BEACON It's Sunday"		;Send Sunday message.
    End Block				;End of Sunday block.
    If Counter 3 = 2			;Is it the second day of the week?
      Exec "BEACON It's Monday"		;Send Monday message.
    End Block				;End of Monday block.
    If Counter 3 = 3			;Is it the third day of the week?
    Exec "BEACON It's Tuesday"		;Send Tuesday message.
    End Block				;End of Tuesday block.
    If Counter 3 = 4			;Is it the fourth day of the week?
      Exec "BEACON It's Wednesday"	;Send Wednesday message.
    End Block				;End of Wednesday block.
    If Counter 3 = 5			;Is it the fifth day of the week?
      Exec "BEACON It's Thursday"	;Send Thursday message.
    End Block				;End of Thursday block.
    If Counter 3 = 6			;Is it the sixth day of the week?
      Exec "BEACON It's Friday"		;Send Friday message.
    End Block				;End of Friday block.
    If Counter 3 = 7			;Is it the seventh day of the week?
      Exec "BEACON It's Saturday"	;Send Saturday message.
    End Block				;End of Saturday block.
    Increment Counter 2			;Keep track of 10 minute intervals
    If Counter 2 = 144			;Has 24 hours elapsed?
      Increment Counter 3		;Keep track of days.
      If Counter 3 = 8			;Has it been a week already?
        Set Counter 3 = 1		;Reset back to Sunday.
      End Block				;End of weekly block.
      Set Counter 2 = 0			;Reset back to Midnight.
    End Block				;End of daily block.
    Set Counter 1 = 0			;Reset back to zero seconds.
  End Block				;End of 10 minute block.
End Block				;End of On Second block.

The following script sends a different announcement on each day of the week at 10 minute intervals. This script can be used to send a single announcement on a specific day (Weekly net announcement only on net day) or announce multiple nets on any day of the week.

If you only want to send an announcement on a single day per week, simply delete all the IF Blocks for the days you don't want an announcement on.

Announcements on a Specific Day Only

On Second				;Run Script every second.
  Increment Counter 1			;Keep track of seconds elapsed
  If Counter 1 = 600			;Has 10 minutes elapsed?
    If Counter 3 = 3			;Is it Tuesday?
      Exec "BEACON ;147.06-HM*111111z5331.59N/11320.77WrT100 R40k Net Tu700 Club Net"		;Send Tuesday message.
    End Block				;End of Tuesday block.
    If Counter 3 = 5			;Is it Thursday?
      Exec "BEACON ;147.06-HM*111111z5331.59N/11320.77WrT100 R40k Net Th700 Newcomer's Net"	;Send Thursday message.
    End Block				;End of Thursday block.
    Increment Counter 2			;Keep track of 10 minute intervals
    If Counter 2 = 144			;Has 24 hours elapsed?
      Increment Counter 3		;Keep track of days.
      If Counter 3 = 8			;Has it been a week already?
        Set Counter 3 = 0		;Reset back to Sunday.
      End Block				;End of weekly block.
      Set Counter 2 = 0			;Reset back to Midnight.
    End Block				;End of daily block.
    Set Counter 1 = 0			;Reset back to zero seconds.
  End Block				;End of 10 minute block.
End Block				;End of On Second block.

Here's the script modified to put repeater objects out on Tuesday and Thursday announcing two different nets. All other days of the week, it stays quiet.

Beacon on Event

If Profile 1
  Do Once
    Exec "BEACON >LOCAL MODE, WIDE1-1"
  End Block
End Block
If Profile 2
  Do Once
    Exec "BEACON >DX MODE, WIDE1-1,WIDE2-1"
  End Block
End Block
On Startup
  Exec "BEA >Ignition on, Argent OT-2 is ready for action. www.argentdata.com"
End Block
On GPS Fix
  If Counter 1 = 0
    Exec "bea >Nuvi-350 is now locked on target, Lets Roll!!!"
    Increment Counter 1
  End Block
End Block

The following script will send a BEACON when the tracker2 is turned on "On Startup". It will send a beacon when the profile is changed "If Profile n". Profile 1 is programmed with a PATH of WIDE1-1, Profile jumper on. Profile 2 is programmed with a PATH of WIDE1-1,WIDE2-1, Profile jumper off. A profile switch is added to the Tracker2. The user can then switch paths, and transmit beacons, with a flip of the switch. It will also send one beacon, after startup, when the GPS locks "On GPS Fix"

Note: the Profile switching GUI in OTWINCFG Has a command that can conflict with this script "Transmit when switching to this profile". Either; un-check both of them, or set Power Control to on, with a 2 second delay. This will separate all packets by 2 second. Otherwise the 1st profile beacon will be sent, and the 2nd profile switch beacon will get clobbered by digi's forwarding your 1st Profile beacon.

Beacon on Event, plus rotating status

If Profile 1
  Do Once
    Exec "BEACON >LOCAL MODE, WIDE1-1"
  End Block
End Block
If Profile 2
  Do Once
    Exec "BEACON >DX MODE, WIDE1-1,WIDE2-1"
  End Block
End Block
On Startup
  Exec "BEA >Ignition on, Argent OT-2 is ready for action. www.argentdata.com"
End Block
On GPS Fix
  If Counter 1 = 0
    Exec "bea > Nuvi-350 locked, Andrew the phone dude to the rescue"
    Increment Counter 1
  End Block
End Block
On Second
  Increment Counter 2
  If Counter 2 = 300
    Exec "bea >Andrew the Phone Dude enroute Code-3"
  End Block
  If Counter 2 = 600
    Exec "bea >Andrew making a HID positive difference"
  End Block
  If Counter 2 = 900
    Exec "bea >Use Caution, Andrew is near"
  End Block
  If Counter 2 = 1800
    Exec "bea > I have a mile of Caution tape and a lime green vest"
  End Block
  If Counter 2 = 2600
    Exec "bea > Andrew on a Road Trip, monitoring all frequencies."
    Decrement Counter 2
  End Block
End Block

Customize your comment or status beacons on a rotation. The above script will increment through five custom beacons at custom intervals.

Send Email on Event

If Profile 2                 ;Are we in Profile 2, meeting specified criteria?
  Do Once                    ;Only do this once to keep from sending multiple messages
    If Flags 0xxxxxxx        ;Check to see if this event has been triggered previously
      Exec "SEND EMAIL ve6srv@gmail.com Edmonton low voltage event" ;Send email
      Set Flags 10000000     ;Set event trigger flag
    End Block                ;End of flag check
  End Block                  ;End of Do Once
End Block                    ;End of Profile check
This script will only trigger when the OT2 is running in Profile 2. Profile switching conditions are set externally to scripting. The conditions set for profile switching for this example, are;
Profile 1 : If voltage <=11 volts switch to profile 2
Profile 2 : If voltage >12 volts, switch to profile 1
If profile switching conditions are met, putting us in Profile 2, a Do Once block starts, so that the commands included only happen once while in Profile 2. A secondary flag check is done to see if the message was sent when in Profile 2 previously, that has not been acknowledged. If all conditions are met, an APRS message is sent to the email gateway, then the event trigger flag is set.

Do Once will trigger each time we switch into Profile 2, so the secondary flag check is required so that if profile switching conditions take us in and out of profile 2 multiple times, only one message is sent.

Macro ALARMACK
  Set Flags 00000000         ;Clear triggered flag
  Exec "SEND VE6SRV AC Power Outage Acknowledged" ;Send a message to let the user know the flag is cleared
End Block

This macro can be called externally to clear the acknowledge flag associated with the above script. Once the alarm condition has been resolved, sending a CMD ALARMACK to the OT2 will reset the acknowledge bit in the flags, allowing the alarm email to be sent once again should the alarm condition parameters be met.

Send Email on Event with Delay

If Profile 1                ;are we in Profile 1 (AC in on)?
  Set Counter 1 = 0         ;clear AC off timer count value
  On Second                 ;keep track of time by 
    Increment Counter 2     ;counting the seconds elapsed
    If Counter 2 = 600      ;after 10 minutes have elapsed
      If Flags 10xxxxxx     ;and we haven't sent this message already (bit 2 is clear)
        Exec "SEND EMAIL ve6srv@gmail.com AC power recovered for 10 minutes" ;send an email
        Set Flags 11000000  ;set bit 1 and 2 to show that we have sent both email messages
      End Block
    End Block
  End Block
End Block
If Profile 2                ;are we in Profile 2 (AC is off)?
  Set Counter 2 = 0         ;clear AC on timer count value
  On Second                 ;keep track of time by
    Increment Counter 1     ;counting the seconds elapsed
    If Counter 1 = 300      ;after 5 minutes have elapsed
      If Flags 0xxxxxxx     ;and we haven't sent this message already (bit 1 is clear)
        Exec "SEND EMAIL ve6srv@gmail.com AC power missing for 5 minutes" ;send and email
        Set Flags 10000000  ;set bit 1 to show that we have sent this email message
      End Block
    End Block
  End Block
End Block
Macro ALARMACK
  Set Flags 00000000         ;Clear triggered flag
  Exec "SEND VE6SRV AC Power Outage Acknowledged" ;Send a message to let the user know the flag is cleared
End Block

This script is designed to send an email message once the unit has been running in profile 2 for 5 minutes. Profile switching is triggered by an AC driven relay connected to shack power. As long as AC is present, the relay is energized, and the OT2 will stay in profile 1. When AC power is interrupted, the OT2 will switch to profile 2 (As per profile switching configuration). While in profile 2, counter 1 is incremented every second. Once 300 seconds have elapsed, an email will be sent. If the AC is intermittent (short power outage), the OT2 will switch back and forth between profile 1 and 2, which will reset the counters back to zero. AC has to be out continuously for 300 seconds before an email is generated. This keeps power bumps from sending false alarms. If AC power comes back online, and stays up for 10 minutes after a 5 minute power outage has been recorded, another email will be generated informing the user that the power has recovered. The first flag is used to keep track of whether an outage of 5 minutes has been seen or not. The second flag keeps track of whether a recovery message has been sent. This ensures only one of each message is sent per event. An ALARMACK macro is used to reset the flags to re-enable sending the email messages for the next AC outage event. The operator is required to check on the site conditions and acknowledge after an AC outage to reset the triggers. It is possible that the power out and power on emails have been sent, and subsequent AC outage(s) have occurred.

Fill-in Digi Beacon

On Second
  Increment Counter 1
  If Counter 1 = 1705
    Exec "PATH WIDE2-1" (Or SSn-N)
    Exec "BEA !3900.00N112300.00W#PHG27302/ W1, Use WIDE1-1,WIDE2-1 for access/A=003000"
  End Block
  If Counter 1 = 1707
    Set Counter 1 = 0
    Exec "PATH -"
  End Block
End Block

The following script will execute a Digi beacon with a Path of WIDE2-1 every 29 minutes, randomized a few seconds to avoid collisions. Fillin Digi's are usually deployed in areas that already have WIDEn-N Digi's nearby. All digi's are encouraged to beacon local information every ten minutes, locally, with no path. It's usually acceptable to Beacon once or twice an hour using a minimal path. The whole idea of Fillin Digis is to forward only first hop mobiles running WIDE1-1,WIDE2-1 to Igates or other WIDEn-N Digi's, without adversely affecting already overloaded networks. If your Digi is heard directly by an igate, no path is ever needed. If it can't be directly heard by an Igate, this beacon, with a one hop Path will keep the Digi on the APRS maps, like fi.

Updated 2009 digi settings: Symbol Chart || Recommended WIDEn-N settings || WIDE1-1 Fillin settings

This script briefly changes the path to WIDE2-1. After the beacon is sent, the path is changed back to PATH - (no path), local beacon mode. This beacon contains info to fill up the bubbles on fi and OpenAPRS. It sets the digi symbol (1#) to a Green star with a 1 inside to signify a fill-in digi (!3900.00N112300.00W#). PHG circle is set, R Packet Rate per hour, any comment like; "/W1 Fillin Bogus Ridge, 145.19 88.5", and elevation (A=003000). See "handy" online PHGR Calculator at: http://www.apritch.myby.co.uk/phgrcalc.htm

Repeater Object

On Second
  Increment Counter 1
  If Counter 1 = 600
    Exec "BEA ;LA5DR    *111111z5943.20N/01014.59Er145.725MHz tOFF -0600kHz"
  End Block
  If Counter 1 = 720
    Set Counter 1 = 0
  End Block
End Block

The settings for this repeater object is set to 10min. w/repeate every 12min. It does not adjust any path settings but use the default from tracker. The 10min. is just an exsample, maybe not the best value but.. it give you an idea

Comparing Analog Readings

Exec "analog 1 in"
Set Counter 1 = Result
Exec "analog 2 in"
If Result > Counter 1
  Do Once
    Exec "echo 2 > 1"
  End Block
Else
  Do Once
    Exec "echo 1 > 2"
  End Block
End Block

This example uses the 'Result' counter to read analog inputs 1 and 2 and compare them, producing a text message once whenever one reading exceeds the other. If fast execution is not required, it is preferable to put this code in an 'On Second' block to reduce processor time used.

Automatic Periodic Reset

On Second
  Increment Counter 1
  If Counter 1 > 43200
    Exec "reset"
  End Block
End Block

This script executes a reset command every 12 hours. It shouldn't ever be necessary, but it may provide an extra degree of safety for remote sites - in the event of a software fault, the unit will reset itself as long as the script engine is still functioning.