Jump to content

Controlling a GPIO box via PHP


animinimo

Recommended Posts

Hi there,

 

I'am trying to control a GPIO box via telnet commands over the internet. The hardware box came with a php script to read the outputs and set the inputs, this is only working for the outputs. I broke the script down to just a simple connect to the box with fsockopen function and now I am trying to send a hex message to it. I have a list of hex messages to set the input states. Still it is not working.

 

The box itself has an windows application wich allows me to set all the parameters of it, so I know it is working properly with this ip and port.

 

My php knowledge is fair, but I cant seem to figure out how to send the hexadecimal message...Probably I am doing something dumb or silly...

 

If someone could take a peek at my script, that would be great.

 

Thanks in advance!

 

This is the script I use to connect to the box. I tried a couple different ways to create my hex message, so that's the command and tryout variables you see. The tryout variable you see typed in here is the hex code I want to send to the unit.

 

$fp = fsockopen( "192.168.147.86", 23, $errno,$errdesc)
  or die("Connection to PP failed");

    $command = Chr(255);
    $command .= Chr(250);
    $command .= Chr(44);
    $command .= Chr(50);
    $command .= Chr(0);
    $command .= Chr(255);
    $command .= Chr(240);
    
    $origineel = '';
    
    $tryout = FFFA2C3440FFF0;

fputs($fp, $tryout);

echo $errno.$errdesc.'<br/>';
echo $tryout;

fclose($fp);

Link to comment
https://forums.phpfreaks.com/topic/196959-controlling-a-gpio-box-via-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.