Recently bought some of the LightwaveRF home automation stuff - works really well! After a bit of googling and trial and error I have a couple of PHP scripts that can control the lights!
The main script: control.php is passed a few parameters which it takes in and converts to a string to be broadcast using UDP sockets on port 9760. For example a correct string would be: "001,!R2D2F1|".
R2 = Room 2 D2 = Device 2 F1 = on (acceptables values are F1 = on, F0 = off, or a range between 2-32 for a dimming value. 32 = 100%.
This works fine, however the 'OK' message is then passed back on UDP port 9761 - I need to be able to listen for this OK, so I can chain multiple light commands. If you don't wait and send 4 straight after each other you often only get one or two of the commands actually running.
At the moment, I have a file, listen.php which listens on port 9761 and prints out the message to the screen. I can tie the two together by:
- Running listen.php so it starts listening
- Running control.php once listen.php is runninng
- Sorted. Lights change and the OK is printed and listen.php stops execution.
However, I need this process to be automatic, i.e start listening, send command, wait for OK, finish all in one script - but cant figure out how to do this!
Any ideas are appreciated. Thanks!