Charging Script Setup
While a device is set to Charge mode, it's unavailable for use and cannot be communicated with through GigaFox. Although Data mode will charge a device, Charge mode may be required for some devices to properly fill their batteries, for example an Amazon Kindle.
To avoid having a device be unavailable during testing hours, a scheduled crontab script can be set to routinely change a device's mode during off hours.
To set up crontab charge script on the GigaFox GEM:
- Open terminal and navigate to the GigaFox directory: /usr/local/deviceConnect.
- Create a folder to store charging scripts (This folder does not need to have a specific name, but for this tutorial, it will be called deviceChargingScripts):
- Navigate into deviceChargingScripts:
- Use a text editor to create a Charge mode script file:
- The script can be set to charge devices on a hub or a specific port number. With either option, copy the Charge mode script, paste it into the deviceChargeScript.sh file, and update the necessary information:
- Save the file changes and quit.
- Create a Data mode script:
- In the deviceDataScript.sh file, enter the Data mode script:
- Save the file changes and quit.
- Open the crontab scheduler:
- Enter the time to routinely run the Charge and
Data mode scripts
in the following crontab format:
<minute 0-59> <hour 0-23> <day of month 1-31> <month 1-12> <day of week 0-6, Sunday-0>
Example: To automatically run the deviceChargeScript.sh script everyday at 2:30am and run deviceDataScript.sh script at 6:30am everyday: - Save the changes and run the scripts:
mkdir deviceChargingScripts
cd deviceChargingScripts
<editor's create command> deviceChargeScript.sh
To charge devices:
curl -k -XPOST -u <username:token> "https://<$service>/apiv1/Device/UsbPort?update&id=<GUID>&usbHubPortState=Charge"
To charge the device on a hub's specified port number:
curl -k -XPOST -u <username:token> "https://<$service>/apiv1/Gateway/UsbHub?update&id=<USB Hub Id>&usbHubPort=<Port Number>&usbHubPortState=Charge"
NOTE: The -k parameter is needed when running the command on HTTPS or SSL. Not necessary if running on HTTP.
<editor's create command> deviceDataScript.sh
curl -k -XPOST -u <username:token> "https://$service/apiv1/Device/UsbPort?update&id=<GUID>&usbHubPortState=Data"
sudo crontab -e
30 02 * * * bash /usr/local/deviceConnect/deviceChargingScripts/deviceChargeScript.sh
30 06 * * * bash /usr/local/deviceConnect/deviceChargingScripts/deviceDataScript.sh
./deviceChargeScript.sh
./deviceDataScript.sh