> For the complete documentation index, see [llms.txt](https://help.qtech.co.nz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.qtech.co.nz/datran/datran-vi-scada/datran-vi/alarms/force-sms-direct.md).

# Force DATRAN to use SMS Direct

Make DATRAN send alarm texts through SMS Direct when Datashed looks connected but texts aren't being delivered.

When configured as a backup for XDI, DATRAN will automatically fail over to use SMS Direct if Datashed services are unavailable, in order to provide business continuity of alarm notification operations. On rare occasions the XDI service will report that the link is up (healthy) but in fact a problem internal to Datashed is preventing SMS messages from being distributed to the intended recipients on mobile devices. This is problematic because DATRAN alarm notifications will not propagate and because SMS Direct also believes the connection to be healthy and thus will not send messages via SMS Direct.

The only resolution in this case is to force SMS Direct to override its automatic failover and manually force alarm message to be sent via SMS Direct. A **Force SMS Direct On** switch provides a simple mechanism for DATRAN operators to configure their system for manual override to send all new messages via SMS Direct until such time as the problem in Datashed has been resolved and the override can be switched off.

{% hint style="info" %}
**Applies to:** DATRAN VI systems that use Datashed with SMS Direct as the backup. Setting it up is intended for experienced DATRAN administrators who are familiar with editing the DATRAN Real time Tree Database (the TBD). The control mechanism can be exposed to DATRAN Supervisor so that operators with sufficient privileges can activate the manual override. These steps also need to be documented into your local operational procedures.
{% endhint %}

Should a future event cause Datashed to be temporarily unavailable, switching DATRAN to process alarms via SMS Direct is our recommended first step. This will help make sure crucial system alarms get to the relevant staff in a timely manner.

## How it works

To determine if the Datashed link is up, DATRAN monitors a parameter in the XDI service called “Datashed Connected” which checks to see that a web socket connection to Datashed is healthy. If it cannot post messages to Datashed the “Datashed Connected” parameter is set to False (0) and the SMS Direct Service will automatically kick in, as long as it is configured as a backup.

The script is a DATRAN script written to check the state of the “Datashed Connected” parameter and force it to a specific desired state (off or 0). DATRAN regularly polls Datashed to update this parameter so it’s important that the script overrides that update process with the desired manual setting. When Force SMS Direct On is set to 1, outbound messages for Datashed will be rerouted to SMS Direct instead.

![The Datashed Connected node under the XML Data Interface SMS Service](https://3621580088-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa5hMAUl7E1cWeN5Rghg0%2Fuploads%2FnXUOSDx4w57JyYBT8VAZ%2Fxdi-datashed-connected-node.png?alt=media)

{% hint style="warning" %}
Warning, Using SMS Direct for alarm messaging can directly incur mobile operator fees for SMS Messages. If your site is large and generates many SMS messages normally, then it is recommended that the manual override be turned off as soon as normal services are resumed by Datashed. This will usually be notified by administrators at Datashed after an outage.
{% endhint %}

## Before you start

* See [Send alarms by text](https://help.qtech.co.nz/datran/datran-vi-scada/datran-vi/alarms/sms.md).
* The XML Data Interface application needs the **SMS Direct Backup** option checked (under the **Network Info** tab for the XML Data Interface Application).

## Set it up

The easiest way to install the facility is to copy and paste the components and alarm class from a Sample TBD file called **StopDatashed.tbd** into your own DATRAN system TBD. The sample TBD can be provided by QTech on request. You need to be familiar with editing the TBD files on your system to do this. You can double click the sample file to open it in DATRAN Browser and also have your SCADA system DATRAN TBD open at the same time to facilitate the copy and paste.

The second way is to manually construct the nodes. You need to know how to add and edit nodes and scripts to do this.

1. **Add the script.** Place a node under the system folder to hold the script itself, called `Turn Datashed off`. The script is a text file copied into the script node when it is edited:

   ```
   // Script to keep the XML Data Interface running but blocks messages to Datashed.
   // Useful if Datran thinks Datashed is okay but messages aren't being sent.
   // Requires "SMS Direct Backup" to be set under the XML Data Interface for switchover to work.
   PathToDatashed := SymbolicRef([.Programs.\Xml Data Interface\SMS Service\Datashed Connected]);
   OnDo OnStart:
   TrapSingle PathToDatashed, True;
   TrapSingle [.], True;
   //Watches the Datashed Connected node and immediately sets to 0 when changed.
   OnDo OnStart OnTrap:
   If ( [.] And PathToDatashed)
   {
   PathToDatashed := 0;
   }
   ```
2. **Add the switch.** Place a node under the Sites folder called `SMS Direct Test Area`, containing a switch to turn on SMS manual control (`Force SMS Direct On`) and a template for a script. The node can be put anywhere that is convenient, for example the Paging folder. For best use, the node should be put in a site with a `_comms_object_` to be visible and listed in the Supervisor Site List in order to be editable in Supervisor. Set the value for the `Force SMS Direct On` node to 0 initially.
3. Create the script first and then in the template select the **Turn Datashed off** script.
4. When creating the `_view_` node you must give it a string value `digital=1` to indicate to Supervisor that the values is digital. The string value (`digital=1`) must be placed on the third line in the dialog box (the first two are reserved for other purposes). Use the keyboard shortcut CTRL-ENTER to insert a blank line (do this twice to insert two blank lines) before then entering the string value.

## Turn the override on and off

1. Launch Supervisor and in the Site List select (double click) the site that contains the SMS Manual control node. The Force SMS Direct On digital value will be listed in the table in Supervisor.
2. Click the spanner icon in the output column to change the state of the node for Force the use of SMS Direct (set to 1).
3. When set back to 0 messages will resume going out via Datashed once the next poll of the Datashed connection from the XML Data Interface occurs. This can take up to 10 minutes depending on how recent the previous poll was and how frequent the poll interval has been set to.

Note. The polling interval is viewed/configured in the XML Data Interface. Double Click the XML Data Interface Cog icon in the Applications folder then click the SMS menu Tab to view the polling time (typically set to about 2-10 min). Do not adjust this parameter unless you are the DATRAN System Administrator.

## Test it

To test the override function, create a sample alarm class using a SMS message alarm annunciator. Then force SMS Direct on and activate the alarm, this will turn off the Datashed connection and send the alarm message via SMS direct instead of Datashed.

1. Navigate to the Alarm Service and create a new Alarm class called `SMS Direct Test` (or something similar). Add the SMS Message Annunciation to the escalation path.
2. Select an operator to whom messages will be sent. This operator must be in your operators list and already set up with a mobile phone number in both DATRAN and Datashed and be the sort of operator that generally receives alarm messages from DATRAN.
3. Create a new node in the SMS Test Area of your site and call it `Test SMS Direct with Manual Override`. Set its value to 0. Give it an `_alarm_`, using the SMSDirect Test alarm class. Apply the Alarm.

To run a test:

1. With **Force SMS Direct On** set to 0, change `Test SMS Direct with Manual Override` to 1. This will generate an alarm and send it via Datashed to the operator, from a Shortcode number (a short 4 or 5 digit number).
2. Change `Test SMS Direct with Manual Override` back to 0. This will return the alarm to normal.
3. Now set **Force SMS Direct On** to 1. Change `Test SMS Direct with Manual Override` to 1, this will override the connection to Datashed and force messages to be sent by SMS Direct and generate an alarm which will be sent via SMS Direct to the operator, from a mobile number (the phone number of the SIM in the SMS Direct Modem).
4. Lastly reset everything back to a default state. Set **Force SMS Direct On** set back to 0 and monitor the **Datashed Connected** parameter. When it goes to 1 then change `Test SMS Direct with Manual Override` back to 0, which will return the alarm to normal and resume normal operation via Datashed.

Tip: If you don't want to scroll down to the XML Data Interface parameters to monitor the **Datashed Connected** parameter, simply copy it up to the SMS Test area using a formula so you can see it there.

## Another approach: SMS Direct as the last escalation

The approach described above is based on using SMS Direct as a backup to Datashed and automatically failing over except in the case described here where manual failover is needed. This alternative strategy is more time consuming and complicated to set up in the short term but does not rely on managing the failover thereafter.

When Alarm escalation paths are created, they will often send a series of SMS messages via Datashed to different operators, escalating the alarm if an operator does not acknowledge receipt of the alarm. By adding the last escalation in the path to use the SMS Direct annunciator, alarms can propagate through Datashed and ultimately through SMS Direct. If Datashed appears connected (but is not), alarm recipients do not acknowledge alarms (because they did not receive them) and the ultimate escalation is sent via SMS direct to a key operator, who is also likely then to query why Datashed is apparently not working.

This method requires no intervention, but:

* it is not suited to organisations who do not regularly use alarm acknowledgment as a way of terminating the escalation path. In this case messages will go out via Datashed and via SMS Direct, thus incurring additional messaging costs.
* it can also take a while to notify alarm recipients because all the other escalations via Datashed or other annunciators have to fail before the message is sent out via SMS Direct. If significant wait times are programmed into the escalation path there will be significant elapsed time. This may not be acceptable for critical alarms so this method should be used judiciously.

Alternatively, very critical alarms may justify using SMS Direct only and not Datashed or sent first via SMS Direct. The difference is that Datashed tracks delivery of all messages and SMS Direct does not.

See [Test alarm texts from Supervisor](https://help.qtech.co.nz/datran/datran-vi-scada/datran-vi/alarms/test-sms.md).
