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:

  1. Open terminal and navigate to the GigaFox directory: /usr/local/deviceConnect.
  2. 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):
  3. 
       mkdir deviceChargingScripts
        
  4. Navigate into deviceChargingScripts:
  5. 
       cd deviceChargingScripts
        
  6. Use a text editor to create a Charge mode script file:
  7. 
       <editor's create command> deviceChargeScript.sh
        
  8. 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:
  9. 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.

  10. Save the file changes and quit.
  11. Create a Data mode script:
  12. 
       <editor's create command> deviceDataScript.sh
        
  13. In the deviceDataScript.sh file, enter the Data mode script:
  14. 
       curl -k -XPOST -u <username:token> "https://$service/apiv1/Device/UsbPort?update&id=<GUID>&usbHubPortState=Data"
        
  15. Save the file changes and quit.
  16. Open the crontab scheduler:
  17. 
       sudo crontab -e
       
  18. 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:
  19. 
       30 02 * * * bash /usr/local/deviceConnect/deviceChargingScripts/deviceChargeScript.sh
       30 06 * * * bash /usr/local/deviceConnect/deviceChargingScripts/deviceDataScript.sh
        
  20. Save the changes and run the scripts:
  21. 
       ./deviceChargeScript.sh
       ./deviceDataScript.sh