dirkengels / plugweb-driver Goto Github PK
View Code? Open in Web Editor NEWPlugWeb Driver for PHP
Home Page: http://www.dirkengels.com
PlugWeb Driver for PHP
Home Page: http://www.dirkengels.com
First i got a directory error, i solved this by moving the driver directory up in the tree.
Now i get:
[Tue Feb 07 21:21:02 2012] [error] [client 127.0.0.1] PHP Warning: fread() expects parameter 1 to be resource, boolean given in /home/marco/www/PlugWeb-Driver/lib/PlugWeb/Driver/Serial.php on line 92
I get this error with the following code:
error_reporting(E_ALL);
ini_set('display_errors', '3');
include('bootstrap.php');
// Example mac addresses
$mac = 'C3XXXC'; //mac (normal) Circle
$macStick = '75XXX8'; //mac Stick
// Initialize stick
$device = new \PlugWeb\Driver\Device($mac, '/dev/ttyUSB0');
$device->initStick();
// Keep switching the light on and off with pauses of 3 seconds
while (true) {
$device->powerSwitch(true);
sleep(3);
$device->powerSwitch(false);
sleep(3);
}
Hope you can help me.
When "scanning" the files on there content, i found:
$this->_exec("stty -F " . $this->_device . " 15200");
Would that be:
$this->_exec("stty -F " . $this->_device . " 115200");
more info:
http://www.maartendamen.com/2010/01/plugwise-protocol-unleashed-part-1-introduction/
When i request PowerInfo from my devices, some of them doesn't response.
I found that for the devices that didn't response, the checksum was wrong:
sendstring (without checksum):
0012000D6F0000C3A6FC(20)
generated checksum for the above string:
FC0A(4)
Combined send string is:
0012000D6F0000C3A6FCFC0A (24)
sendstring (without checksum):
0012000D6F0000D3198D(20)
generated checksum for the above string:
1BE(3)
Combined send string is:
0012000D6F0000D3198D1BE (23)
The last string is 1 char to short and so i got no response from the circle.
Whats happening here?
I'm playing around with you're driver for a few day's now and i got strange responses from the plugs:
"ƒ""square""square""square""square"0013010C000D6F0000C3A6FC001E00F10000A9D800000000000A5B94
The "ƒ" character is messing the whole thing up....
After some debugging, i see the following happening:
received datafrom plug:
"square""square""square""square"0000010C00C11F89 ƒ"square""square""square""square"0013010C000D6F0000C3A6FC001E00F10000A9D800000000000A5B94 < (whiteout the ><)
Formdata translates it with:
$lines = explode("\r\n", $data);
in:
Array
(
[0] => "square""square""square""square"0000010C00C11F89
[1] => ƒ"square""square""square""square"0013010C000D6F0000C3A6FC001E00F10000A9D800000000000A5B94
[2] =>
)
Because of the
"ƒ"
_formdata isn't getting by
" $out['data'] = $this->getResponse()->readString($line);" (device->line312).
Result is that it not generates:
$out['ack']
$out['data']
$out['tmp']
I've tried to modify the $data by replace the ƒ with "" (see first line in function):
protected function _formatData($data) {
$data = str_replace("ƒ","",$data);
$lines = explode("\r\n", $data);
$out = array();
$counter = 0;
foreach($lines as $line) {
if (preg_match('/^00/', substr($line, 4, 4))) {
This isn't working and the ƒ is still showing up.
The following is working, but only for responsive functions (powerinfo, deviceinfo) and not for sending function (switchOn, SwitchOff, switch):
protected function _formatData($data) {
$lines = explode("\r\n", $data);
$out = array();
$counter = 0;
foreach($lines as $line) {
if (preg_match('/^00/', substr($line, 5, 4))) {
NOTE the 5 in the last line!
with this solution I skip the "ƒ" and its start on character 5 with reading the response string.
The only solution (for now) i can think off, is to make 2 _formdata functions:
_formDataSend
_formDataReceive
Each function can handle the send en receive string at its own way.
Do you have a solution?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.