Tinyos.com到r0x中继模块的接口。
tosr0x的Python项目详细描述
用于与[tinyosshop.com](http://www.tinyosshop.com/index.php?route=product/product&product_id=365)和其他在线零售商提供的“tosr0x”中继控制器通信的python模块。
支持的硬件
- [TOSR0X USB 2-8中继](http://www.tinyosshop.com/index.php?route=product/category&path=141_142)
- [TOSR0X WiFi 2-8中继](http://www.tinyosshop.com/index.php?route=product/category&path=141_143)
- [懒骨头WiFi单中继](http://www.tinyosshop.com/index.php?route=product/category&path=141_129)
功能性
- 检测TOSR0X USB和WiFi设备。
- 设置继电器状态。
- 查询中继状态。
- 查询温度(在支持的模型上)。
要求
- python串行模块(应默认安装)
安装
使用setup.py:
python setup.py install
如果使用Debian或衍生物(ubuntu),可能需要额外的USB权限:
Add the user to the ‘dialout’ group:
$ sudo usermod -G dialout -a <username>添加udev规则文件以允许访问usb设备:
$ cat /etc/udev/rules.d/50-usb.rules # allow access to usb devices for users in dialout group SUBSYSTEM==”usb”, MODE=”0666”, GROUP=”dialout”
用法
调用handler函数返回tosr0x对象的列表:
>import tosr0x >th = tosr0x.handler()
Testing USB serial device on /dev/ttyUSB0 Testing USB serial device on /dev/ttyUSB1 Testing USB serial device on /dev/ttyUSB2 Testing USB serial device on /dev/ttyUSB3 TOSR0x device found on /dev/ttyUSB3
>myTosr0x = th[0] >print myT0sr0x
<tosr0x.relayModule instance at 0xb68be46c>
默认情况下,处理程序会扫描所有USB端口以查找与r0x设备兼容的设备。你 还可以指定要扫描的端口范围:
>th = tosr0x.handler(devicePath=[‘/dev/ttyUSB3’])
Testing USB serial device on /dev/ttyUSB3 TOSR0x device found on /dev/ttyUSB3
通常模块上的所有继电器在初始化时循环,以确定 中继计数。您可以指定一个中继计数来防止此情况:
>th = tosr0x.handler(devicePath=[‘/dev/ttyUSB3’], relayCount=4)
Testing USB serial device on /dev/ttyUSB3 TOSR0x device found on /dev/ttyUSB3
也可以不使用处理程序直接使用类:
FOR SERIAL: >import serial >import tosr0x >sd=serial.Serial(‘/dev/ttyUSB0’, timeout=0.1) >myTosr0x=tosr0x.relayModule(sd) #Num relays not specified in this example
FOR WIFI: >import tosr0x >myTosr0x = tosr0x.relayModule( (‘192.168.1.2’,2000), 2) #Module of 2 relays
将继电器状态设置为0或1:
>myTosr0x.set_relay_position(1,1) True
>myTosr0x.set_relay_position(2,0) True
(注:继电器编号从1开始。使用继电器编号0设置所有继电器的状态。
获取中继位置(返回为dict{relay:state}):
>myTosr0x.get_relay_positions() {1: 1, 2: 0}
对于支持温度探头的模块,获得环境温度摄氏度:
>myTosr0x.get_temperature() 23.94
项目
- james stewart(@amorphic)在一个温度监测框架[braubuddy](http://braubuddy.org)中使用tosr0x来实现环境控制器。
- alex roche(@alexroche)正在使用带有wifi选项的tosr0x,通过运行在覆盆子pi上的openremote控制器来控制百叶窗。