控制NETIO产品设备的接口
Netio的Python项目详细描述
奈蒂奥
用于与NETIO产品设备通信的python 3绑定和CLI
从pip安装最新的包
pip install Netio --upgrade
API接口
登录到您的设备并启用JSON API
导入Netio并创建具有端点的新实例
^{pr2}$HTTPS
使用HTTPS时,必须提供正确的证书,或者完全禁用证书验证。在
- 在
Settings->Network Configuration
下输入正确的主机名和域。在 - 转到
Settings->Security Settings
并选择Generate new certificate - Download使用浏览器从浏览器中获取证书
如果您正在访问Netio wia IP地址,请设置verify=False
以禁用证书验证。在
最后添加带有下载证书路径的verify
参数。在
n = Netio('http://netio-4ll.local:8080/netio.json', auth_rw=('admin', 'password'), verify='/path/to/cert.pem')
控制
要设置输出,请使用操作或整数值
>>> n.set_output(1, 0) # Set output 1 off >>> n.set_output(1, n.ACTION.ON) # Set output 1 on
读取输出状态
>>> for x in range(4): >>> print(n.get_output(x)) Output(ID=1, Name='out_1', State=1, Action=1, Delay=500, Current=0, PowerFactor=0.0, Load=0, Energy=13346833) Output(ID=2, Name='out_2', State=0, Action=0, Delay=500, Current=0, PowerFactor=0.0, Load=0, Energy=2311032) Output(ID=3, Name='out_3', State=1, Action=1, Delay=500, Current=8610, PowerFactor=1.0, Load=2062, Energy=11387035) Output(ID=4, Name='out_4', State=1, Action=1, Delay=500, Current=11540, PowerFactor=1.0, Load=2768, Energy=21077736)
CLI接口
usage: Netio [-h] [-u U] [-p P] [-C] [-c CFG] [-v] [--no-cert-warning] [--version] DEVICE COMMAND ...
positional arguments:
DEVICE Netio device URL or alias from config
COMMAND device command
get (GET, G, g) GET output state
set (SET, S, s) SET output state
info (INFO, I, i) show device info
optional arguments:
-h, --help show this help message and exit
-u U, --user U M2M API username
-p P, --password P M2M API password
-C, --cert HTTPS Certificate
-c CFG, --config CFG Configuration file
-v, --verbose increase verbosity
--no-cert-warning Disable warnings about certificate's subjectAltName versus commonName
--version show program's version number and exit
命令
Netio CLI支持3个不同的命令,下面是一些关于如何使用它们的示例。
有关详细说明,请参见Netio device CMD --help
获取
打印设备输出的当前状态。除非另有说明,否则全部返回
$ NETIO_PASSWORD=secretPass Netio -u read http://netio.local GET
id State Action Delay Current PFactor Load Energy Name
1 1 IGNORED 5000 0 0.0 0 2500 MyNetioOutput12
2 1 IGNORED 5000 127 0.58 17 2363 output_2
3 1 IGNORED 5000 0 0.0 0 0 output_3
4 1 IGNORED 5000 0 0.0 0 1327 Notebook
默认情况下,显示带有说明的标题,可以用--no-header
将其关闭。
默认的分隔符是tab,可以用--delimiter ';'
的-d\;
更改
$ NETIO_PASSWORD=secretPass Netio -u read http://netio.local GET --delimiter ';' --no-header
1;1;IGNORED;5000;0;0.0;0;2500;MyNetioOutput12
2;1;IGNORED;5000;79;0.49;9;2364;output_2
3;1;IGNORED;5000;0;0.0;0;0;output_3
4;1;IGNORED;5000;0;0.0;0;1327;Notebook
要请求单个输出,只需添加具有输出ID的位置参数
$ NETIO_PASSWORD=secretPass Netio -u read http://netio.local GET 2
id State Action Delay Current PFactor Load Energy Name
2 1 IGNORED 5000 80 0.49 9 2365 output_2
设置
SET接受位置参数对ID-ACTION。必须至少提供一对。 请求不成功时返回非零值。在
$ NETIO_PASSWORD=secretPass Netio -u write http://netio.local SET 1 ON 2 OFF 3 OFF
$ echo $?
0
要一次设置所有输出的操作,请使用ALL
作为ID
$ NETIO_PASSWORD=secretPass Netio -u write http://netio.local SET ALL TOGGLE
Warning:当一次切换所有输出时,两者之间没有延迟,在高负载下,这可能导致电流 尖峰 触发你的断路器。在
信息
报告设备的状态
$ Netio -u write -p SecretPass http://netio.local INFO
Agent
Model NETIO 4All
Version 3.4.0
JSONVer 2.1
DeviceName myNetio
VendorID 0
OemID 0
SerialNumber 24:A4:2C:33:27:78
Uptime 1456245
Time 2020-06-01T13:15:27+01:00
NumOutputs 4
GlobalMeasure
Voltage 230.6
Frequency 49.9
TotalCurrent 85
OverallPowerFactor 0.51
TotalLoad 10
TotalEnergy 6195
EnergyStart 2020-03-31T06:38:11+01:00
配置文件
您还可以使用配置文件、指定的wia--config netio.ini
或wiaNETIO_CONFIG
环境变量。
有关文件配置的说明和示例,请参见examples
证书
不禁止使用命令行参数指定凭据,但建议不要这样做, 因为系统上的任何人都可以看到你的用户名和密码。在
您可以指定用户名和密码wia配置文件或wia环境变量
NETIO_USER
为用户名。在NETIO_PASSWORD
输入密码。在
参数查找
提供例如密码时,按以下顺序查找:
- 命令行参数
- 环境变量
- 配置文件(如果提供)
- 专区
- 默认节
- 默认值(如适用)
- 项目
标签: