For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

#!/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

There are two places were the script shall be modified:

Last updated