Velbus server - programming sockets in PHP

I have a question.
I have written a page in PHP (running on apache) for turning a light on / off. This work very good.
Now I want to read the status of a relais out.
How can I do that?

I tried the following:
$in = hex2bin(“0FFB0302FA08EF04”);
$fp = stream_socket_client(“tcp://127.0.0.1:9999”, $errno, $errstr, 5);
if (!$fp) {
echo “$errstr ($errno)
\n”;
} else {
fwrite($fp, $in);
while (!feof($fp)) {
echo fgets($fp, 1024);
}
fclose($fp);
}

On the (windows) Velbus server I can see that he recieves the $in, but i can’t see the response in PHP

Can somebody help me…
Sven

Hi Sven,

you’re searching for this frame :
0FFB0302FA08EF04 --> module address $03, part 4

However, you’ve to create a loop (While… wend or Repeat… until) because the first feedback message could be an other message : example… LED status blinking (for button’s modules which command the $03 module).

In fact, the loop should be something like this (algorithm, not language code) :

DeltaTime = timer (in ms)
Response = ""
repeat
  frame = ReadNetwork(...)
  if Frame = WaitedFrame
    Response = Frame
  endif
until Response or timer-DeltaTime> 150 ms

In my case, to avoid blocking time (150 ms), I use a linked list and my LOOP is

{
  Action
  Read2List(network)
  ChangeStatus (or SendStatus)
}

ChangeStatus read the list and do some reaction’s display.
A little hard to explain (that means I don’t fully mastered the problem :wink: ) but that’s the way I use in Veltron.

Of course, you can use thread (then, a thread can send action and wait for the right reaction while main program still running).