Quantcast
Channel: MultiTech Developer Resources » All Posts
Viewing all articles
Browse latest Browse all 7111

Reply To: Best way to determine if the Cellular connection is available?

$
0
0

Hello Ajay,

I’m pretty sure that there is an API command that will ping out through the Linux system and not the radio, and is what you could use. There is a brief description here: http://www.multitech.net/developer/software/mtr-software/mtr-api-reference/command-table/

As a matter of fact I have an old script that used to work that would at least give you a head start on how to use the command in the API. I don’t have time at the moment to test it, but maybe it even still works:

#!/bin/bash
# load-config v1

ARG_NUM=$#

show_usage()
{
  echo "Usage: pingAPI:"
  echo ""
  echo "  To ping from the device"
  echo "      pingAPI DEVICE_ADDRESS LOGIN PASSWORD IPADDRESS"
  echo ""
  echo "  All arguments are required"
}

# Checking input arguments number
if [ ${ARG_NUM} -ne 4 ] && [ ${ARG_NUM} -ne 4 ]
then
  echo "Error: incorrect number of input arguments"
  show_usage
  exit 1;
fi

# Arguments input process
ADDRESS=https://$1
LOGIN=$2
PASSWORD=$3
echo "PASSWORD=${PASSWORD}"
if [ ${ARG_NUM} -eq 4 ]
then
  SAVE_PATH=$4
  # If the path is a directory
  if [ -d ${SAVE_PATH} ]; then
    echo "Error: specified path is a directory"
    show_usage
    exit 1;
  fi
else
  # Will be obtained later
  SAVE_PATH=""
fi

# Logging in
TOKEN=$(curl -s -k -X POST "${ADDRESS}/api/login" -d "username=${LOGIN}" -d "password=${PASSWORD}" | grep "token")

echo "response TOKEN: ${TOKEN}"

if [ ${?} -ne 0 ]
then
  echo "Error: cURL could not connect to the specified address"
  show_usage
  exit 1;
fi

# Token extracting
TOKEN=${TOKEN##*'token" : "'}
TOKEN=${TOKEN%%'"'*}

echo "extracted TOKEN: ${TOKEN}"

# Obtaining the file URL
#FILE_URL=$(curl -s -k "${ADDRESS}/api/command/download_config?method=POST&token=${TOKEN}")
PING_RES=$(curl -s -k -X POST -H "Content-Type: application/json" -d '{ "ip" : "192.168.2.200", "interface" : "ANY" }' "${ADDRESS}/api/command/ping?token=${TOKEN}")

if [ ${?} -ne 0 ]
then
  echo "Error: cURL could not obtain file rquest address"
  show_usage
  exit 1;
fi

echo "RESULT: ${PING_RES}"

Jeff


Viewing all articles
Browse latest Browse all 7111

Trending Articles