function toggleSwitch($theSwitch) { $switchData = file_get_contents('data/switches.json'); $switchData = json_decode($switchData); $the_data = array(); foreach ($switchData as $switches) { foreach ($switches as $switch) { //$the_data = array( // 'id' => $switch['id'] //); if ($switch->id == $theSwitch) { $outlet = new \wemo\models\Outlet($switch->ipaddress, $switch->port); $state = $outlet->getIsOn(); if ($state) { $outlet->setIsOn(false); } else { $outlet->setIsOn(true); } $iconUrl = $switch->iconUrl; $state = $outlet->getIsOn(); array_push($the_data, array('id' => $switch->id, 'iconurl' => $iconUrl, 'state' => $state)); } } } return $the_data; }
<?php echo "<p>Copyright © 1999-" . date("Y") . " W3Schools.com</p>"; include 'libs/WeMo-PHP-Toolkit-master/models/Device.php'; include 'libs/WeMo-PHP-Toolkit-master/models/Outlet.php'; $outlet = new \wemo\models\Outlet("192.168.1.186"); echo $outlet->getName(); ?> <html> <head> </head> <body> </body> </html>