Metadata-Version: 2.4
Name: numato_http
Version: 0.0.1
Summary: A small Http modules example package
Author-email: Numato systems Pvt Ltd <help@numato.com>
License-Expression: LGPL-3.0
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Python API for Numato HTTP Expanders

This Python API can be used to control [Numato HTTP Relay expanders](https://numato.com/product-category/automation/relay-modules/power-over-ethernet-relay/) and [Numato HTTP GPIO Pluggable expanders](https://numato.com/product-category/automation/gpio-modules/ethernet-gpio/).

* Controlling the Relays "On" or "Off" state
* Configure ports as input or output port
* Write to output ports
* Read from input ports
* Read integer values from ADC input ports

numato-http allows to control relay modules (ON or OFF) states and gpio states. This module is compatible with all Numato ethernet pluggable and PoE series.

## Requirement

The module requires the minimum configuration :

- Windows-10(64 bits) and later
- Linux 64-bits
- Python3.6 and later

## License
This API is licensed under the GNU Lesser General Public License v3.0. See [LICENSE](https://www.gnu.org/licenses/lgpl-3.0.html) for full license text.


## Installation
Install the latest release:

```
pip install numato_http
```

## Usage CLI

Expected output:

Linux :
```
❯ python3 -m numato_http.io --ip=<ip> --username=<username> --password=<password> --gpios=16
Ip: 192.168.10.5 | id: 00000000 | ver: A0M01.01 | ports: 16 
```
Windows :
```
❯ python -m numato_http.io --ip=<ip> --username=<username> --password=<password> --gpios=16
Ip: 192.168.10.5 | id: 00000000 | ver: A0M01.01 | ports: 16
```
<br/>

## How to use it
The command line to drive relays are :

Windows :
```
python -m numato_http.io --ip=<ip> --username=<username> --password=<password> --cmd=<string to drive relays> --relays=8 
```

Linux :
```
python3 -m numato_http.io --ip=<ip> --username=<username> --password=<password> --cmd=<string to drive relays> --relays=8 
```

`Note` : For all CLI commands use `python3` when using in Linux Systems and `python` in Windows Systems.

\
Parameters are :

`--ip` : the ip (default is 192.168.1.0) to connect the module

`--username` : the username (default is admin)

`--password` : the password (default is admin)

`--cmd` : the command to drive individual relays (default is "x")- the number of relays to drive (default is 4)

`--relays` : the number of relays to drive (default is 4)

`--gpios` : the number of gpios (default is 8, if the module is gpio module)

\
A relay can receive two types of orders (OFF or ON). The order in the module is encoding by an ASCII character such as :

`"c"` : close the relay (OFF state)

`"o"` : open the relay (ON state)

`"x"` : do not change the current state of the relay

\
For example consider a 8 channel PoE Relay module :

- 8 available relays : 0, 1, 2, 3, 4, 5, 6, 7 and 8
- ip is 192.168.10.5
- username and password is admin

\
command pattern examples for 8 channel PoE Relay module is given here,

To turn on all relays, string command is `oooooooo` and the command line is :

```
python -m numato_http.io --ip=192.168.10.5 --username=admin --password=admin --cmd="oooooooo" --relays=8
```

To turn off all relays, string command is `cccccccc` and the command line is :

```
python -m numato_http.io --deviceIP=192.168.10.5 --username=admin --password=admin --cmd="cccccccc" --relays=8
```

To turn on the relay 0,1,2,3 and it does not matter about other ones, string command is `ooooxxxx` and the command line is :

```
python -m numato_http.io --deviceIP=192.168.10.5 --username=admin --password=admin --cmd="ooooxxxx" --relays=8
```

To turn on the relays 1, 3, 5 and 7 and it does not matter about other ones, string command is `xoxoxoxo` and the command line is :

```
python -m numato_http.io --deviceIP=192.168.10.5 --username=admin --password=admin --cmd="xoxoxoxo" --relays=8
```

`Note` : There is no CLI command to control gpios.
<br/>

## List of Commands
1. ver()
2. info()
3. idget()
4. usrget()
5. passget()
6. id("x")
7. settings("x","x")
8. reset()
9. relay_on("x")
10. relay_off("x")
11. relay_read("x")
12. relay_readall()
13. relay_writeall("x")
14. gpio_set("x")
15. gpio_clear("x")
16. gpio_read("x")
17. gpio_status("x")
18. gpio_iomask("x")
19. gpio_iodir("x")
20. gpio_writeall("x")
21. gpio_readall()
22. adc_read()
23. modulereboot()
<br/>

`Note`: "x" is the parameter to be passed in the commands, please refer the **"HTTP Command set"** in the documentation for sending the right arguement and to understand the functioning of each command. Relay commands and some of the gpio commands are module specific.
<br/>

## Usage API

The API can be used like:

``` python
from numato_http.io import Http_Module 

# Please change the number of Relays/Gpios and credentials (ipaddress, username, password) accordingly.
Device = Http_Module(ip="192.168.10.5", username="admin", password="admin", numberRelays=8) 

# To get the version of the module
version = Device.ver()
print(version)

# To get the Device Id 
Device.idget()

#To set the Id
Device.id("12345678")

# To turn on all relays
Device.relay_writeall("fF")

# To set a single Gpio & read the status
Device.gpio_set("000")
Device.gpio_read("000")
Device.gpio_clear("000")
Device.gpio_status("000")

#To turn on a single relay
Device.relay_on("006")

```
