Best way to determine if the Cellular connection is available?

Home Forums Conduit: AEP Model Best way to determine if the Cellular connection is available?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #31477
    Ajay K
    Participant

    I am trying to figure out the best way to determine if the cellular connection is available from a custom app, so we can transmit data to our servers. Is there a Conduit WEB API that I can call to determine the status unambiguously. The reason we need to know this is because if we make an http call from our custom app, the http calls takes way too long to return when the cellular connection is lost before an error is raised
    Also we can’t lose the packets we want to transmit to the servers, so we temporarily archive it until the cellular connection is re-established.

    Btw we are on conduit firmware version 5.2.1. Also our custom app is written using NODE JS.

    Thanks,
    Ajay

    #31479
    Jeff Hatch
    Keymaster

    Hello Ajay,

    There are ways to do a ping. I would recommend pinging from your app if the remote host will respond. The Cellular connection can get “broken” without the device knowing. The only way to verify that the connection is still working is to ping. That is what the ICMP check does in the Cellular management on the mPower devices. There are ways to check that a tcp connection will be successful also. What the timeout values would need to be is probably empirical based on the application.

    It boils down to this: If the Linux system can route to and ping a remote device then barring firewalls and other things getting in the way, a tcp connection should work. A Cellular connection can still be up, but traffic is either prohibited for some reason or cannot be routed.

    Jeff

    #31495
    Ajay K
    Participant

    Thanks Jeff for taking the time to respond. Does the conduit API expose a ping call or is there a way to make a ping request using node js. Also the server we would be hitting does support an ICMP ping. The ICMP check the cellular management admin screen, does it use native linux calls to make the ping request? Also what is typical payload size of request and response for a ICMP ping request?

    Thanks,
    Ajay

    #31498
    Heath Raftery
    Participant

    The Conduit API does indeed have a ping call. You can see it here:

    http://www.multitech.net/developer/software/mtr-software/mtr-api-reference/command-table/

    Based on the javascript used in the web interface, it looks like you need to pass it an ip field and an interface field. But that’s about all I know.

    Otherwise, calling ping from Node.js may be as simple as using exec. Some great guidance is here:

    https://stackoverflow.com/questions/4737130/how-to-ping-from-a-node-js-app

    The payload is quite arbitrary. The BSD ping uses a 56 byte payload by default. The first 8 bytes is used for a timestamp so it can calculate round trip times. AFAIK, the rest is just garbage.

    #31502
    Ajay K
    Participant

    Thanks Heath for taking the time to respond and for your valuable inputs. I will give that a shot and see how the ping command works?

    Thanks,
    Ajay

    #31505
    Jeff Hatch
    Keymaster

    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

    #31506
    Ajay K
    Participant

    Thanks so much Jeff for your response and the script. I was going to use the ping command that is available via the conduit api mentioned in the command table. However I see it takes a json object for the IP Address or URL, not sure what the actual json object this command expects. Can you point me to an example?

    Meanwhile I will give the attached script a shot to see if it does work?

    Thanks,
    Ajay

    #31507
    Jeff Hatch
    Keymaster

    Hello Ajay,

    I’m pretty sure that “{ “ip” : “192.168.2.200”, “interface” : “ANY” }” is that JSON object referred to that is in the script code. I would start with that. The interface options should be the same as those in the Debug Options in the Web UI.

    Jeff

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.