robstiles/ediplug

用于与EdiMax EdiPlug智能电源插座通信的包。

dev-master 2015-03-18 17:39 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:53:15 UTC


README

用于与EdiMax EdiPlug智能电源插座通信的包。

此包允许您检查插座的电源状态,开关插座以及检索和设置新的电源计划。

一个具有基本功能的工作正在进行中。

示例代码

定位插座

// Create the locator
$locator = new Locator();
// Spend 5 seconds looking for plugs
$plugs = $locator->scan(5);
foreach($plugs as $plug) {
	echo "MAC: $plug->mac\n" ;
	echo "Manufacturer: $plug->manufacturer\n";
	echo "Model: $plug->model\n";
	echo "Version: $plug->version\n";
	echo "IP Address: $plug->ip_address\n";
}

打开或关闭插座

// Create object with address, username and password.
$plug = new EdiPlug('192.168.1.100', 'admin', '1234');
// Turn it on
$plug->on();
// Turn it off
$plug->off()
// Or use its power property
$plug->power = true;

禁用所有计划

	$plug = new EdiPlug('192.168.1.100', 'admin', '1234');

	// Get the week's schedule information from the plug.
	$week_schedule = $plug->schedule;

	// Cycle through each day
	foreach($week_schedule as $day => $day_schedule) {
		// Turn off all the schedules
		$day_schedule->enabled = false;
	}
	// Send new schedule back to the plug
	$plug->schedule = $week_schedule;

遍历星期二的每个时间段

	$plug = new EdiPlug('192.168.1.100', 'admin', '1234');

	// Get the week's schedule information from the plug.
	$week_schedule = $plug->schedule;

	// Cycle through each on/off period for Tuesday
	foreach($week_schedule[WeekSchedule::TUESDAY] as $period) {
		echo "On at $period->on, off at $period->off<br />\n";
	}

将电源设置为周五晚上7点至11点开启

	$plug = new EdiPlug('192.168.1.100', 'admin', '1234');

	$week_schedule = $plug->schedule;

	$friday = $week_schedule[WeekSchedule::FRIDAY];
	$friday->add(TimePeriod::createFromTimes(
		Carbon::createFromTime(19,00),
		Carbon::createFromTime(23,00)
	));
	$friday->enabled = true;

	$plug->schedule = $week_schedule;