Skip to content
Advertisement

Reading from weight scale problems (PHP)

I’m new in php. For now I can read the code (not good), and can write a little bit.

I have several weight scales. From first one I can read the weight with this script:

    // host and port to connect to
$host = "10.0.0.119";
$port = 3400;

// connect to the port
$fp = fsockopen($host, $port, $errno, $errstr);

// don't die
set_time_limit(0);

// if connection not successfull, display error
if (!$fp)
{
    die("no connection");
}
else
{
    // connection successfull, listen for data (1024 bytes by default)
    $got = fgets($fp);

    // display the data
    echo  $got;
}

fclose($fp);

Here is output from socket listener:

socket listener

And here is from browser:

browser and other scale

But from other scale I can’t read anything. Here is the output from socket terminal: (see pic 3 )

I think the problem is it in the php script, but I cant find it. If someone can help me I will be so happy.

Advertisement

Answer

For now I fix this problem with this:

ini_set("auto_detect_line_endings", true);

and this:

$got = fgets($fp, 120000);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement