# PyWiliot: wiliot-deployment-tools #

wiliot-deployment-tools is a python library for accessing Wiliot's Deployment and Automation Tools.
This python package includes the following CLI utilities:
 - Automatic Configuration Tool (`wlt-config`)
 - Power Management Tool (`wlt-power-mgmt`)
 - Calibration Management Tool (`wlt-clibration-mgmt`)
 - Firmware Update Tool (`wlt-firmware`)
 - Log Viewer (`wlt-log`)


## Installing wiliot-deployment-tools
````commandline
pip install wiliot-deployment-tools
````

## Using wiliot-deployment-tools
This package includes the following CLI Utilities:
### Automatic Configuration Tool
Automatically connects to all Gateways / Bridges in the location specified, and configure them to optimal parameters.

```
usage: wlt-config -owner OWNER -location LOCATION [-ota] [-no_gp_zone] [-pacing_interval PACING_INTERVAL] [-ignore_bridges [IGNORE_BRIDGES [IGNORE_BRIDGES ...]]] [--expected_num_brgs EXPECTED_NUM_BRGS]

required arguments:
  -owner OWNER         Platform owner id
  -location LOCATION   Location name in Wiliot platform. If location has ' ' in name, input location wrapped with double quotes: --location "LOCATION NAME"

additional (optional) arguments:
  -ota         Updating FW version to latest for all devices
  -no_gp_zone          don't use Global pacing group by zone (all bridges will be GPG=0)
  -pacing_interval PACING_INTERVAL
                        Pacing interval for all devices
  -ignore_bridges [IGNORE_BRIDGES [IGNORE_BRIDGES ...]]
                        bridges to ignore in the tool - their configuration won't be changed
  -expected_num_brgs EXPECTED_NUM_BRGS
                        Number of expected bridges in location. The tool will try to connect to all bridges (excluding those specified in ignore bridges) until reaching expected number.

example usage: wlt-config --owner wiliot --location "My Deployment" --ota_upgrade --pacing_interval 10 --ignore_bridges 1234ABCD0123
```

### Firmware Update
Update Wiliot Gateways and Bridges firmware version OTA.
 #### Print Available Versions 
 Prints all avaliable Firmware versions for update for every GW Type
```
usage: wlt-firmware -owner OWNER [-beta] versions

optional arguments:
  -beta              show available beta versions / update to beta firmware

example usage: wlt-firmware -o wiliot versions
```
### Calibration Management
Configure Wiliot Bridge calibration mode
```
usage: wlt-calibration-mgmt -owner OwnerID -brg BridgeID -gw GW -mode CalibrationMode [-timeout TIMEOUT]

required arguments:
  -owner OWNER  Owner ID
  -brg BRG      Bridge ID
  -gw GW        GW ID to configure bridge
  -mode Mode    CalibrationMode on of 3 options: 0-regular, 1-no ch37, 2-ch37 on data only

optional arguments:

  -timeout TIMEOUT      Minutes timeout (not required, defaults to 5 minutes)

  example usage: wlt-calibration-mgmt -owner wiliot -brg 0123ABCD -gw AB1234CD -mode 1
```

 #### Firmware Update
 Run OTA Process, first updating specified GWs to latest / specified FW version. Afterwards seuqentially update each specified Bridges / all Bridges to the same Firmware version.
 ```
usage: wlt-firmware update -owner OWNER [-beta] [-version VERSION] [-gw GW [GW ...]] [-brg BRG [BRG ...]] [-all_brgs] [-ignore_bridges IGNORE_BRIDGES [IGNORE_BRIDGES ...]] [-action]

optional arguments:
  -beta              show available beta versions / update to beta firmware
  -version VERSION      Desired version. if not specified, will update to latest available version
  -gw GW [GW ...]       Gateways to update (multiple allowed)
  -brg BRG [BRG ...]    Bridges to update (multiple allowed)
  -all_brgs             update all bridges connected to Gateways
  -ignore_bridges IGNORE_BRIDGES [IGNORE_BRIDGES ...]
                        bridges to ignore
  -action               update using action API
  -force                update bridge even if its already in desired version (applicable only with -action)

  example usage: wlt-firmware -o wiliot update -gw GW0123 -all_brgs
  ```
### Power Management
Use Wiliot Bridge power management functionality
#### Enter Power Management
Configure Specified Bridges to work in power management configuration.
```
usage: wlt-power-mgmt -o OwnerID enter -brg BridgeID -sleepduration SLEEPDURATION -onduration ONDURATION [-keepalive KEEPALIVE] [-scan SCAN] [-ledoff] [-gw GW] [-timeout TIMEOUT]

required arguments:
  -owner OWNER  Owner ID
  -brg BRG      Bridge ID

optional arguments:
  -sleepduration SLEEPDURATION
                        Sleep duration (minutes)
  -onduration ONDURATION
                        On duration (seconds) *rounds to nearest 30 second interval*
  -keepalive KEEPALIVE  Keep alive period (seconds) *rounds to nearest 5 second interval* (not required, defaults to 30 seconds)
  -scan SCAN            Keep alive scan (milliseconds) *rounds to nearest 10 millisecond interval* (not required, defaults to 300 milliseconds)
  -ledoff               Configure LEDs off (on by default)
  -gw GW                GW ID to configure bridge (required only for broadcast mode)
  -timeout TIMEOUT      Minutes timeout (not required, defaults to 5 minutes)

  example usage: wlt-power-mgmt -o wiliot enter -brg 0123ABCD -sleepduration 5 -onduration 60
```
#### Exit Power Management
Return specified bridges out of power management mode and into normal working mode.
```
usage: wlt-power-mgmt -o OwnerID exit -brg BridgeID [-gw GW] [-no_config] [-timeout TIMEOUT]

required arguments:
  -owner OWNER  Owner ID
  -brg BRG      Bridge ID

optional arguments:
  -gw GW            GW ID to configure bridge (not required)
  -no_config        If used, GW will not change to optimal configuration
  -timeout TIMEOUT  Minutes timeout (not required, defaults to 5 minutes)

example usage: wlt-power-mgmt -o wiliot exit -brg BridgeID
```


### Log Viewer
View Wiliot Gateway logs
```
usage: wlt-log -owner OWNER -gw GW

Log Viewer - CLI Tool to view Wiliot Gateway logs

required arguments:
  -owner OWNER  Owner ID
  -gw GW        Gateway ID
```

------------------

For more documentation and instructions, please contact us: support@wiliot.com


## Release Notes:

Version 4.0.8:
* Support for python 3.11
* Added new calibration mgmt tool

Version 4.0.7:
* Android power management support
* Bugfix when no gateway logs found
  
Version 4.0.4:
* Bugfixes, add relevant printouts to CLI to help understand errors.

Version 4.0.3:
* Initial release of CLI tools suite - Automatic Configuration Tool, Firmware Update, Power Management, Log Viewer.

Version 4.0.0:
* First version


The package previous content was published under the name 'wiliot' package.
for more information please read 'wiliot' package's release notes

-----------------

### MacOS Installation
#### Getting around SSL issue on Mac with Python 3.7 and later versions

Python version 3.7 on Mac OS has stopped using the OS's version of SSL and started using Python's implementation instead. As a result, the CA
certificates included in the OS are no longer usable. To avoid getting SSL related errors from the code when running under this setup you need
to execute Install Certificates.command Python script. Typically you will find it under
~~~~
/Applications/Python\ 3.7/Install\ Certificates.command
~~~~

#### Python 3 on MacOS
The default Python version on mac is 2.x. Since Wiliot package requires Python 3.x you should download Python3 
(e.g.  Python3.7) and make python 3 your default.
There are many ways how to do it such as add python3 to your PATH (one possible solution https://www.educative.io/edpresso/how-to-add-python-to-the-path-variable-in-mac) 
