Adapters

An Adapter is a custom software component that is deployed on IoT Gateway devices executing the ClearBlade Edge.

Each Adapter consists of a name, a small number of administrative commands, and a small number of files comprising the administrative and executable assets of an adapter. The files comprising an adapter will consist of executable code and supporting libraries as well as shell scripts used to administer adapters.

Purpose

To serve as a proxy between the ClearBlade platform and IoT devices that cannot directly communicate with the ClearBlade Platform.

Commands

Once an adapter has been successfully deployed to an Edge, it can be started, stopped, or restarted using Edge Management portion of the adapter’s page, located within the ClearBlade Platform developers console. The status of the adapter on each edge is determined by the returned output of the status command from the adapter’s configuration, either “Running” or “Stopped”.If the adapter is not successfully deployed to an edge, the edge will be found in the Disconnected Edges table.

Shell commands or scripts need to be specified in the Configuration section within the adapter’s settings so that the adapter can be correctly administered. Commands are executed from the directory where the Edge was started. The currently supported commands are:

  • Deploy Command - A command or shell script that will be run after the files are installed on a ClearBlade Edge. This is an optional command. A sample shell script, named deploy.sh is as follows:
#!/bin/bash
mkdir ShowTimeAdapter

mv start.sh ShowTimeAdapter
mv stop.sh ShowTimeAdapter
mv status.sh ShowTimeAdapter
mv deploy.sh ShowTimeAdapter
mv undeploy.sh ShowTimeAdapter
mv showTime ShowTimeAdapter

echo "ShowTimeAdapter Deployed"

The deploy command specified to execute the deploy.sh shell script would be

./deploy.sh
  • Start-up Command - A command or shell script that will be executed to start the adapter on a ClearBlade Edge.If a start-up command is not specified , the adapter would need to be manually started by connecting to the gateway device (via ssh) and issuing an appropriate start.An adapter can be started on one or multiple edges from the Stopped tab of the Edge Management table.

A sample shell script, named start.sh is as follows:

#!/bin/bash
nohup ./ShowTimeAdapter/showTime > ./ShowTimeAdapter/showTime.log 2>&1 &

The start-up command specified to execute the start.sh shell script would be

./ShowTimeAdapter/start.sh

Note that the command takes into account the fact that the deploy script copied the start.sh file to a directory named ShowTimeAdapter. Since the shell script only contains one line, we easily could have specified the value of Start-up Command as

nohup ./ShowTimeAdapter/showTime > ./ShowTimeAdapter/showTime.log 2>&1 &
  • Stop Command - A command or shell script that will be run to stop the adapter on a ClearBlade Edge.The stop command is an optional command.If the Stop Command is not specified, the adapter would need to be manually stopped by connecting to the gateway device (via ssh) and issuing an appropriate stop command.An adapter can be stopped or restarted on one or multiple edges from the Running tab of the Edge Management table.

The stop command will most likely be a command that kills the adapter process, such as

ps -ef | grep showTime | grep -v grep | awk '{print $2}' | xargs kill

If a more sophisticated shutdown of the adapter is needed, shutdown logic can be incorporated into a shell script. A sample shell script, named stop.sh is as follows:

#!/bin/bash
ps -ef | grep showTime | grep -v grep | awk '{print $2}' | xargs kill

The stop command specified to execute the stop.sh shell script would be

./ShowTimeAdapter/stop.sh

Note that the command takes into account the fact that the deploy script copied the stop.sh file to a directory named ShowTimeAdapter. Since the shell script only contains one line, we easily could have specified the value of Stop Command as

ps -ef | grep showTime | grep -v grep | awk '{print $2}' | xargs kill
  • Status Command - A command or shell script that will be run to determine the status of the adapter on a specific ClearBlade Edge. A shell script that echoes the status of an adapter should be supplied. The shell script should account for and echo the following values:
  • Deployed
  • Running
  • Stopped A sample shell script, named status.sh is as follows:
#!/bin/bash
# If this script is executed, we know the adapter has been deployed. No need to test for for the "undeployed" status.
STATUS="Deployed"
if [ "ps -ef | grep showTime | grep -v grep" != "" ] ; then
    STATUS="Running"
else
    STATUS="Stopped"
fi

echo $STATUS

The status command specified to execute the status.sh shell script would be

./ShowTimeAdapter/status.sh
  • Undeploy Command - A command or shell script that will be run to uninstall the adapter from a ClearBlade Edge. The undeploy command is an optional command. If the Undeploy Command is not specified the default behavior of the ClearBlade platform is to remove the adapter files from the directory where Edge is running. The default undeploy behavior therefore would not delete any log files that were created or remove any files that were moved to adapter specific directories. The undeploy command will most likely be a command that deletes an adapter specific directory and any files contained within it, such as
rm -rf ./ShowTimeAdapter

If a more sophisticated undeployment/deletion of the adapter is needed, undeploy logic can be incorporated into a shell script.

A sample shell script, named undeploy.sh is as follows:

#!/bin/bash
rm -rf ./ShowTimeAdapter
  • Logs Command - A command or shell script that will be used to retrieve any logs printed out by the adapter while it is.The logs command is an optional command. If the Logs Command is not specified, any log files written by the adapter would need to be viewed manually (via ssh or sftp).You can view the adapter logs, determined by executing the Logs command in the adapter configuration by clicking the View button of the logs column in the Edge Management table. The log command will most likely be a cat or tail command that displays the contents of a file, such as
cat ./ShowTimeAdapter/showTime.log

In many cases, the Logs Command will be directly dependent on the Start-up Command piping output to a file, unless the adapter is written in such a manner that it creates its own log files.

If more sophistication is needed to read log files, the logic can be incorporated into a shell script.

A sample shell script, named log.sh is as follows:

#!/bin/bash
cat ./ShowTimeAdapter/showTime.log

The logs command specified to execute the logs.sh shell script would be

./ShowTimeAdapter/logs.sh

In order to prevent naming collisions resulting in overwritten files, it is recommended that an adapters files be copied to an adapter specific directory. The files can be copied using either a shell command or a shell script.If using a shell script to accomplish tasks needed for deployment, the shell script must be included as one of the adapter files in the File section of the command.A best practice would be to provide an archive/zip file containing all the files required to execute and manage an adapter. The deploy command would the simply be a shell command to extract the contents of the archive, for example:

tar -xvzf MyAdapter.tar.gz -C /MyAdapter