nerdmann / react-phenocean
ReactPHP 的 Enocean 流
dev-master
2019-08-18 16:02 UTC
Requires
- php: >=7.2
- react/filesystem: ~0.1
- react/socket: ~1.2
- react/stream: ~1.1
This package is auto-updated.
Last update: 2024-09-19 02:46:56 UTC
README
这是一个为 ReactPHP 的 Enocean 设备的流器。您需要一个网关(例如 USB300)来与 Enocean 设备通信。
支持的设备
所有设备都提供了一个(或多个)EnOcean 设备配置文件(EEP)。有关 EEP 的更多信息,请参阅此处。
目前此库支持的 EEP 如下
示例
创建一个 ReactPHP 循环和一个新的 EnoceanStream。第一个参数是网关的设备文件。
$loop = Factory::create();
$stream = new nerdmann\react\phenocean\EnoceanStream("/dev/enocean", $loop);
然后创建所有您想要使用的设备。
$relay = DeviceFactory::create(
array(0xD2, 0x01, 0x12), // The EEP of the device
array(0xDE, 0xAD, 0xBE, 0xEF), // The ID of the device
$stream, // The Enocean Stream
$loop // The loop
);
$rocker = DeviceFactory::create(
array(0xF6, 0x02, 0x02), // The EEP of the device
array(0xDE, 0xCA, 0xFB, 0xAD), // The ID of the device
$stream, // The Enocean Stream
$loop // The loop
);
现在您可以连接这两个设备或做您想做的事情。设备将触发 "event" 事件。NodOn 开关有两个继电器(0x00 和 0x01)。它们可以被激活(0x64,表示 100%)或停用(0x00 或 0%)。如果您有一个可以调光的设备,您还可以发送介于 0x00 和 0x64 之间的值。
$rocker->on("event", function (Event $event) use ($relay) {
if ($event->getProperty("pressed1")) {
switch ($event->getProperty("rocker1")) {
case 0: $relay->setActuator(0x00, 0x64); break;
case 1: $relay->setActuator(0x00, 0x00); break;
case 2: $relay->setActuator(0x01, 0x64); break;
case 3: $relay->setActuator(0x01, 0x00); break;
}
}
});
... 别忘了运行循环
$loop->run();