# Script preparation

The script that requests update from the B3 SMS server and sends SMS can be downloaded from <https://icuscandinavia060.sharepoint.com/:u:/s/Technicalfile/EdQ6VQ3B_BNBh-sSq7GUWv0BP5XJCm1nwqNCFTt88ldhWA?e=tb4orB>

The default script is shown below. It must be modified before it is installed on the router.

{% code overflow="wrap" lineNumbers="true" %}

```sh
#!/bin/sh
APIUniqueID="Customer1b3"
#If you are using Telia SIM with ICU APN you must use IP adress - in other cases you need to use top domain.
API_URL="http://rqs.se/api/data/json.asp?id=$APIUniqueID"
#API_URL="http://10.50.33.14/api/data/json.asp?id=$APIUniqueID"
API_KEY="dZucDUygTFJvgCs7QRDx"
#SMS_GATEWAY="http://172.16.0.32/cgi-bin/sms_send"
SMS_GATEWAY="http://127.0.0.1/cgi-bin/sms_send"
USERNAME="smsuser"
PASSWORD="n2femPSx83PTVhkX"
INTERVAL=60

urlencode() {
  local s="$1"
  local out=""
  local i=1
  local c

  while [ $i -le ${#s} ]; do
    c=$(echo "$s" | cut -c $i)
    case "$c" in
      [a-zA-Z0-9.~_-]) out="$out$c" ;;
      *) out="$out$(printf '%%%02X' "'$c")" ;;
    esac
    i=$((i + 1))
  done

  echo "$out"
}

# Get SIM/modem status using gsmctl
OPERATOR=$(gsmctl --operator)
RSSI=$(gsmctl -q | grep -o '[0-9\-]*')
ICCID=$(gsmctl --iccid)
IMEI=$(gsmctl --imei)

# gsmctl may not provide RSRP/RSRQ; omit if unsupported
RSRP=""
RSRQ=""
SIM_STATE=""  # Not available in gsmctl
SIM_ACTIVE=""

POST_PAYLOAD=$(cat <<EOF
{
  "custId": "$APIUniqueID",
  "signal_rssi": "$RSSI",
  "operator": "$OPERATOR",
  "iccid": "$ICCID",
  "imei": "$IMEI"
}
EOF
)

while true; do

  RESPONSE=$(curl -s -H "x-api-key: $API_KEY" "$API_URL")

  CODE=$(echo "$RESPONSE" | awk -F'"code"[[:space:]]*:[[:space:]]*"' '{print $2}' | awk -F'"' '{print $1}')

  if [ "$CODE" = "99" ]; then
    logger -t poll_api "Received code 99 - no SMS to send"
    SMSNR=""
    TEXT=""
  else
    SMSNR=$(echo "$RESPONSE" | awk -F'"smsnr"[[:space:]]*:[[:space:]]*"' '{print $2}' | awk -F'"' '{print $1}')
    TEXT=$(echo "$RESPONSE" | awk -F'"text"[[:space:]]*:[[:space:]]*"' '{print $2}' | awk -F'"' '{print $1}')

    if [ -n "$SMSNR" ]; then
      ENCODED_TEXT=$(urlencode "$TEXT")
      FULL_URL="${SMS_GATEWAY}?username=${USERNAME}&password=${PASSWORD}&number=${SMSNR}&text=${ENCODED_TEXT}"

      logger -t poll_api "Sending SMS to $SMSNR: $TEXT"
      curl -s "$FULL_URL"
    else
      logger -t poll_api "No SMS number found in response"
    fi
  fi

  curl -s -X POST "$API_URL" -H "x-api-key: $API_KEY" -H "Content-Type: application/json" -d "$POST_PAYLOAD"

  sleep $INTERVAL
done
```

{% endcode %}

There are two places were the script shall be modified:

1. [APIUniqueID](/b3-sms-device-installation-manual/installation-procedures/router-setup/script-preparation/apiuniqueid.md).
2. [SMS server URL](/b3-sms-device-installation-manual/installation-procedures/router-setup/script-preparation/sms-server-url.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.boomerang3.com/b3-sms-device-installation-manual/installation-procedures/router-setup/script-preparation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
